List of usage examples for org.springframework.http HttpStatus FOUND
HttpStatus FOUND
To view the source code for org.springframework.http HttpStatus FOUND.
Click Source Link
From source file:org.cloudfoundry.identity.uaa.integration.VmcAuthenticationTests.java
@Test public void testInvalidScopes() { params.set("credentials", String.format("{\"username\":\"%s\",\"password\":\"%s\"}", testAccounts.getUserName(), testAccounts.getPassword())); params.set("scope", "read"); ResponseEntity<Void> response = serverRunning.postForResponse(serverRunning.getAuthorizationUri(), headers, params);/*from www .ja v a 2s. c o m*/ assertEquals(HttpStatus.FOUND, response.getStatusCode()); String location = response.getHeaders().getLocation().toString(); // System.err.println(location); assertTrue(location.startsWith(params.getFirst("redirect_uri"))); assertTrue(location.contains("error=invalid_scope")); assertFalse(location.contains("credentials=")); }
From source file:org.cloudfoundry.identity.uaa.login.integration.VmcAuthenticationTests.java
@Test public void testInvalidScopes() { params.set("source", "credentials"); params.set("username", testAccounts.getUserName()); params.set("password", testAccounts.getPassword()); params.set("scope", "read"); ResponseEntity<Void> response = serverRunning.postForResponse(serverRunning.getAuthorizationUri(), headers, params);//from w w w. j a va 2 s .co m assertEquals(HttpStatus.FOUND, response.getStatusCode()); String location = response.getHeaders().getLocation().toString(); // System.err.println(location); assertTrue(location.startsWith(params.getFirst("redirect_uri"))); assertTrue(location.contains("error=invalid_scope")); assertFalse(location.contains("credentials=")); }
From source file:com.blogspot.sgdev.blog.GrantByAuthorizationCodeProviderTest.java
@Test public void getJwtTokenByAuthorizationCode() throws JsonParseException, JsonMappingException, IOException, URISyntaxException { String redirectUrl = "http://localhost:" + port + "/resources/user"; ResponseEntity<String> response = new TestRestTemplate("user", "password").postForEntity( "http://localhost:" + port + "/oauth/authorize?response_type=code&client_id=normal-app&redirect_uri={redirectUrl}", null, String.class, redirectUrl); assertEquals(HttpStatus.OK, response.getStatusCode()); List<String> setCookie = response.getHeaders().get("Set-Cookie"); String jSessionIdCookie = setCookie.get(0); String cookieValue = jSessionIdCookie.split(";")[0]; HttpHeaders headers = new HttpHeaders(); headers.add("Cookie", cookieValue); response = new TestRestTemplate("user", "password").postForEntity("http://localhost:" + port + "oauth/authorize?response_type=code&client_id=normal-app&redirect_uri={redirectUrl}&user_oauth_approval=true&authorize=Authorize", new HttpEntity<Void>(headers), String.class, redirectUrl); assertEquals(HttpStatus.FOUND, response.getStatusCode()); assertNull(response.getBody());/* ww w . j a va2 s . co m*/ String location = response.getHeaders().get("Location").get(0); URI locationURI = new URI(location); String query = locationURI.getQuery(); location = "http://localhost:" + port + "/oauth/token?" + query + "&grant_type=authorization_code&client_id=normal-app&redirect_uri={redirectUrl}"; response = new TestRestTemplate("normal-app", "").postForEntity(location, new HttpEntity<Void>(new HttpHeaders()), String.class, redirectUrl); assertEquals(HttpStatus.OK, response.getStatusCode()); HashMap jwtMap = new ObjectMapper().readValue(response.getBody(), HashMap.class); String accessToken = (String) jwtMap.get("access_token"); headers = new HttpHeaders(); headers.set("Authorization", "Bearer " + accessToken); response = new TestRestTemplate().exchange("http://localhost:" + port + "/resources/client", HttpMethod.GET, new HttpEntity<String>(null, headers), String.class); assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode()); response = new TestRestTemplate().exchange("http://localhost:" + port + "/resources/user", HttpMethod.GET, new HttpEntity<String>(null, headers), String.class); assertEquals(HttpStatus.OK, response.getStatusCode()); response = new TestRestTemplate().exchange("http://localhost:" + port + "/resources/principal", HttpMethod.GET, new HttpEntity<String>(null, headers), String.class); assertEquals("user", response.getBody()); response = new TestRestTemplate().exchange("http://localhost:" + port + "/resources/roles", HttpMethod.GET, new HttpEntity<String>(null, headers), String.class); assertEquals("[{\"authority\":\"ROLE_USER\"}]", response.getBody()); }
From source file:org.cloudfoundry.identity.statsd.integration.UaaMetricsEmitterIT.java
@Test public void testStatsDClientEmitsMetricsCollectedFromUAA() throws InterruptedException, IOException { RestTemplate template = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set(headers.ACCEPT, MediaType.TEXT_HTML_VALUE); ResponseEntity<String> loginResponse = template.exchange(UAA_BASE_URL + "/login", HttpMethod.GET, new HttpEntity<>(null, headers), String.class); if (loginResponse.getHeaders().containsKey("Set-Cookie")) { for (String cookie : loginResponse.getHeaders().get("Set-Cookie")) { headers.add("Cookie", cookie); }//from ww w . j a v a 2 s.c om } String csrf = IntegrationTestUtils.extractCookieCsrf(loginResponse.getBody()); LinkedMultiValueMap<String, String> body = new LinkedMultiValueMap<>(); body.add("username", TEST_USERNAME); body.add("password", TEST_PASSWORD); body.add(CookieBasedCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME, csrf); loginResponse = template.exchange(UAA_BASE_URL + "/login.do", HttpMethod.POST, new HttpEntity<>(body, headers), String.class); assertEquals(HttpStatus.FOUND, loginResponse.getStatusCode()); assertNotNull(getMessage("uaa.audit_service.user_authentication_count:1", 5000)); }
From source file:comsat.sample.ui.method.SampleMethodSecurityApplicationTests.java
@Test public void testLogin() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.set("username", "admin"); form.set("password", "admin"); getCsrf(form, headers);//from ww w . j ava2 s. c o m ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/login", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertEquals("http://localhost:" + this.port + "/", entity.getHeaders().getLocation().toString()); }
From source file:com.interop.webapp.WebAppTests.java
@Test public void testLogin() throws Exception { HttpHeaders headers = getHeaders();//from w w w. j ava2s. co m headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.set("username", "user"); form.set("password", "user"); ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/login", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertTrue("Wrong location:\n" + entity.getHeaders(), entity.getHeaders().getLocation().toString().endsWith(port + "/")); assertNotNull("Missing cookie:\n" + entity.getHeaders(), entity.getHeaders().get("Set-Cookie")); }
From source file:org.zaizi.AuthServerApplicationTests.java
@Test public void authorizationRedirects() { ResponseEntity<String> response = template .getForEntity("http://localhost:" + port + contextPath + "/oauth/authorize", String.class); assertEquals(HttpStatus.FOUND, response.getStatusCode()); String location = response.getHeaders().getFirst("Location"); assertTrue("Wrong header: " + location, location.startsWith("http://localhost:" + port + contextPath + "/login")); }
From source file:plbtw.klmpk.barang.hilang.controller.BarangController.java
@RequestMapping(method = RequestMethod.GET, produces = "application/json") public CustomResponseMessage /*Collection<Barang>*/ getAllBarang(@RequestHeader String apiKey) { try {/*from ww w .j a v a 2s . c o m*/ if (!authApiKey(apiKey)) { return new CustomResponseMessage(HttpStatus.FORBIDDEN, "Please use your api key to authentication"); } LogRequest temp = DependencyFactory.createLog(apiKey, "Get"); if (checkRateLimit(RATE_LIMIT, apiKey)) { return new CustomResponseMessage(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED, "Please wait a while, you have reached your rate limit"); } Log log = new Log(); log.setApiKey(temp.getApiKey()); log.setStatus(temp.getStatus()); log.setTimeRequest(temp.getTime_request()); logService.addLog(log); List<Barang> allBarang = (List<Barang>) barangService.getAllBarang(); for (Barang barang : allBarang) { Link selfLink = linkTo(BarangController.class).withSelfRel(); barang.add(selfLink); } CustomResponseMessage result = new CustomResponseMessage(); result.add(linkTo(BarangController.class).withSelfRel()); result.setHttpStatus(HttpStatus.FOUND); result.setMessage("Success"); result.setResult(allBarang); return result; } catch (NullPointerException ex) { return new CustomResponseMessage(HttpStatus.NOT_FOUND, "Data not found"); } catch (Exception ex) { return new CustomResponseMessage(HttpStatus.FORBIDDEN, ex.getMessage()); } }