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:spring.AbstractAuthorizationCodeProviderTests.java
@Test @Ignore("TODO")/* w w w . j a v a 2s .c o m*/ public void testInvalidScopeInAuthorizationRequest() throws Exception { HttpHeaders headers = getAuthenticatedHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); String scope = "bogus"; String redirectUri = "http://anywhere?key=value"; String clientId = "my-client-with-registered-redirect"; UriBuilder uri = http.buildUri(authorizePath()).queryParam("response_type", "code") .queryParam("state", "mystateid").queryParam("scope", scope); if (clientId != null) { uri.queryParam("client_id", clientId); } if (redirectUri != null) { uri.queryParam("redirect_uri", redirectUri); } ResponseEntity<String> response = http.getForString(uri.pattern(), headers, uri.params()); assertEquals(HttpStatus.FOUND, response.getStatusCode()); String location = response.getHeaders().getLocation().toString(); assertTrue(location.startsWith("http://anywhere")); assertTrue(location.contains("error=invalid_scope")); assertFalse(location.contains("redirect_uri=")); }
From source file:sparklr.common.AbstractAuthorizationCodeProviderTests.java
@Test @OAuth2ContextConfiguration(resource = MyTrustedClient.class, initialize = false) public void testUserDeniesConfirmation() throws Exception { approveAccessTokenGrant("http://anywhere", false); String location = null;//from w ww . jav a2 s .c om try { assertNotNull(context.getAccessToken()); fail("Expected UserRedirectRequiredException"); } catch (UserRedirectRequiredException e) { location = e.getRedirectUri(); } assertTrue("Wrong location: " + location, location.contains("state=")); assertTrue(location.startsWith("http://anywhere")); assertTrue(location.substring(location.indexOf('?')).contains("error=access_denied")); // It was a redirect that triggered our client redirect exception: assertEquals(HttpStatus.FOUND, tokenEndpointResponse.getStatusCode()); }
From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.implicit.Oauth2ImplicitFlowPredefinedTests.java
@Test public void obtainTokenFromOuth2LoginEndpoint() throws Exception { UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(authServerBaseUrl + oauth2AuthorizeEndpointPath); builder.queryParam("username", getUsername()); builder.queryParam("password", getPassword()); builder.queryParam("client_id", getClientId()); builder.queryParam("response_type", "token"); builder.queryParam("redirect_uri", "http://anywhere"); HttpEntity<String> entity = new HttpEntity<>(""); ResponseEntity<String> result2 = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entity, String.class); // This means the user was correctly authenticated, then a redirection was performed to /oauth/authorize to obtain the token. // Then the token was sucessfully obtained (authenticating the client properly) and a last redirection was performed to the // redirect_uri with the token after # assertEquals(HttpStatus.FOUND, result2.getStatusCode()); // Obtain the token from redirection URL after # URI location = result2.getHeaders().getLocation(); accessToken = extractToken(location.getFragment().toString()); assertNotNull(accessToken);//w w w .j a v a 2 s . c o m if (!isJwtTokenStore) { // Temporarily we can't not apply the default token enhacer adding the authorities if we use a JwtTokenStore // TODO: Put again the login endpoint separated for CSRF and return the authorities there // Obtain the user credentials from redirection URL after # String extractUserAuthorities = extractUserAuthorities(location.getFragment().toString()); assertNotNull(extractUserAuthorities); } }
From source file:org.apigw.authserver.AuthorizationCodeProviderIntegrationtest.java
@Test public void testUserDeniesConfirmation() throws Exception { log.debug("testUserDeniesConfirmation"); String cookie = helper.loginAndGetConfirmationPage(CLIENT_ID, REDIRECT_URL, SCOPE); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.set("Cookie", cookie); MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("user_oauth_approval", "false"); ResponseEntity<Void> result = serverRunning.postForStatus("/apigw-auth-server-web/oauth/authorize", headers, formData);// w ww .ja va 2 s . c o m assertEquals(HttpStatus.FOUND, result.getStatusCode()); String location = result.getHeaders().getFirst("Location"); assertTrue(location.startsWith(REDIRECT_URL)); assertTrue(location.substring(location.indexOf('?')).contains("error=access_denied")); assertTrue(location.contains("state=gzzFqB!!!")); }
From source file:org.cloudfoundry.identity.batch.integration.ServerRunning.java
public ResponseEntity<Void> postForRedirect(String path, HttpHeaders headers, MultiValueMap<String, String> params) { ResponseEntity<Void> exchange = postForResponse(path, headers, params); if (exchange.getStatusCode() != HttpStatus.FOUND) { throw new IllegalStateException( "Expected 302 but server returned status code " + exchange.getStatusCode()); }// w w w . j a v a2s. c om if (exchange.getHeaders().containsKey("Set-Cookie")) { String cookie = exchange.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); } String location = exchange.getHeaders().getLocation().toString(); return client.exchange(location, HttpMethod.GET, new HttpEntity<Void>(null, headers), null); }
From source file:org.apigw.authserver.ServerRunning.java
public ResponseEntity<Void> postForRedirect(String path, HttpHeaders headers, MultiValueMap<String, String> params) { ResponseEntity<Void> exchange = postForStatus(path, headers, params); if (exchange.getStatusCode() != HttpStatus.FOUND) { throw new IllegalStateException( "Expected 302 but server returned status code " + exchange.getStatusCode()); }/*from w w w.jav a2 s .c o m*/ if (exchange.getHeaders().containsKey("Set-Cookie")) { String cookie = exchange.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); } String location = exchange.getHeaders().getLocation().toString(); return client.exchange(location, HttpMethod.GET, new HttpEntity<Void>(null, headers), Void.class); }
From source file:sparklr.common.AbstractAuthorizationCodeProviderTests.java
@Test public void testInvalidScopeInAuthorizationRequest() throws Exception { HttpHeaders headers = getAuthenticatedHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); String scope = "bogus"; String redirectUri = "http://anywhere?key=value"; String clientId = "my-client-with-registered-redirect"; UriBuilder uri = http.buildUri(authorizePath()).queryParam("response_type", "code") .queryParam("state", "mystateid").queryParam("scope", scope); if (clientId != null) { uri.queryParam("client_id", clientId); }/* w w w . ja va 2 s. c o m*/ if (redirectUri != null) { uri.queryParam("redirect_uri", redirectUri); } ResponseEntity<String> response = http.getForString(uri.pattern(), headers, uri.params()); assertEquals(HttpStatus.FOUND, response.getStatusCode()); String location = response.getHeaders().getLocation().toString(); assertTrue(location.startsWith("http://anywhere")); assertTrue(location.contains("error=invalid_scope")); assertFalse(location.contains("redirect_uri=")); }
From source file:com.projectx.mvc.servicehandler.quickregister.QuickRegisterHandler.java
@Override public EmailVerificationDetailsDTO getEmailVerificationDetailsByCustomerIdTypeAndEmail(Long customerId, Integer customerType, Integer emailType) throws EmailVerificationDetailNotFoundException { CustomerIdTypeEmailTypeDTO emailDTO = new CustomerIdTypeEmailTypeDTO(customerId, customerType, emailType); HttpEntity<CustomerIdTypeEmailTypeDTO> entity = new HttpEntity<CustomerIdTypeEmailTypeDTO>(emailDTO); ResponseEntity<EmailVerificationDetailsDTO> result = restTemplate.exchange( env.getProperty("rest.host") + "/customer/quickregister/getEmailVerificationDetails", HttpMethod.POST, entity, EmailVerificationDetailsDTO.class); if (result.getStatusCode() == HttpStatus.FOUND) return result.getBody(); else//w w w . j a va2s . com throw new EmailVerificationDetailNotFoundException(); }