List of usage examples for org.springframework.security.oauth2.client.token.grant.implicit ImplicitResourceDetails getClientId
public String getClientId()
From source file:org.cloudfoundry.identity.uaa.integration.ClientInfoEndpointIntegrationTests.java
@Test public void testImplicitClientInfo() throws Exception { HttpHeaders headers = new HttpHeaders(); ImplicitResourceDetails app = testAccounts.getDefaultImplicitResource(); headers.set("Authorization", testAccounts.getAuthorizationHeader(app.getClientId(), "")); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.getForObject("/clientinfo", Map.class, headers); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(app.getClientId(), response.getBody().get("client_id")); }
From source file:org.cloudfoundry.identity.uaa.integration.VmcAuthenticationTests.java
@Before public void init() { ImplicitResourceDetails resource = testAccounts.getDefaultImplicitResource(); params = new LinkedMultiValueMap<String, String>(); params.set("client_id", resource.getClientId()); params.set("redirect_uri", resource.getRedirectUri(new DefaultAccessTokenRequest())); params.set("response_type", "token"); headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); }
From source file:org.cloudfoundry.identity.uaa.integration.LoginServerSecurityIntegrationTests.java
@Test @OAuth2ContextConfiguration(LoginClient.class) public void testLoginServerCanAuthenticateUserForCf() throws Exception { ImplicitResourceDetails resource = testAccounts.getDefaultImplicitResource(); params.set("client_id", resource.getClientId()); params.set("username", userForLoginServer.getUserName()); params.set(OriginKeys.ORIGIN, userForLoginServer.getOrigin()); params.set(UaaAuthenticationDetails.ADD_NEW, "false"); String redirect = resource.getPreEstablishedRedirectUri(); if (redirect != null) { params.set("redirect_uri", redirect); }/*from ww w . j a v a 2 s . co m*/ @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap(serverRunning.getAuthorizationUri(), params, headers); assertEquals(HttpStatus.FOUND, response.getStatusCode()); String results = response.getHeaders().getLocation().toString(); assertNotNull("There should be scopes: " + results, results.contains("#access_token")); }
From source file:org.cloudfoundry.identity.uaa.integration.LoginServerSecurityIntegrationTests.java
@Test @OAuth2ContextConfiguration(LoginClient.class) public void testWrongUsernameIsErrorAddNewEnabled() throws Exception { ((RestTemplate) serverRunning.getRestTemplate()) .setRequestFactory(new HttpComponentsClientHttpRequestFactory()); ImplicitResourceDetails resource = testAccounts.getDefaultImplicitResource(); params.set("client_id", resource.getClientId()); params.set("username", "bogus1"); params.set(UaaAuthenticationDetails.ADD_NEW, "true"); String redirect = resource.getPreEstablishedRedirectUri(); if (redirect != null) { params.set("redirect_uri", redirect); }// w w w . jav a 2s. c o m @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap(serverRunning.getAuthorizationUri(), params, headers); // add_new:true user accounts are automatically provisioned. assertEquals(HttpStatus.FOUND, response.getStatusCode()); String results = response.getHeaders().getLocation().getFragment(); assertTrue("There should be an access token: " + results, results.contains("access_token")); }
From source file:org.cloudfoundry.identity.uaa.integration.LoginServerSecurityIntegrationTests.java
@Test @OAuth2ContextConfiguration(LoginClient.class) public void testWrongUsernameIsErrorAddNewDisabled() throws Exception { ((RestTemplate) serverRunning.getRestTemplate()) .setRequestFactory(new HttpComponentsClientHttpRequestFactory()); ImplicitResourceDetails resource = testAccounts.getDefaultImplicitResource(); params.set("client_id", resource.getClientId()); params.set("username", "bogus2"); params.set(UaaAuthenticationDetails.ADD_NEW, "false"); String redirect = resource.getPreEstablishedRedirectUri(); if (redirect != null) { params.set("redirect_uri", redirect); }/*from w ww. ja va 2 s . c o m*/ @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap(serverRunning.getAuthorizationUri(), params, headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); @SuppressWarnings("unchecked") Map<String, String> results = response.getBody(); assertNotNull("There should be an error: " + results, results.containsKey("error")); }
From source file:org.cloudfoundry.identity.uaa.integration.LoginServerSecurityIntegrationTests.java
@Test @OAuth2ContextConfiguration(LoginClient.class) public void testLoginServerCfPasswordToken() throws Exception { ImplicitResourceDetails resource = testAccounts.getDefaultImplicitResource(); HttpHeaders headers = new HttpHeaders(); headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); params.set("client_id", resource.getClientId()); params.set("client_secret", ""); params.set("source", "login"); params.set("username", userForLoginServer.getUserName()); params.set(OriginKeys.ORIGIN, userForLoginServer.getOrigin()); params.set(UaaAuthenticationDetails.ADD_NEW, "false"); params.set("grant_type", "password"); String redirect = resource.getPreEstablishedRedirectUri(); if (redirect != null) { params.set("redirect_uri", redirect); }//from ww w.j ava 2 s . co m @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap(serverRunning.getAccessTokenUri(), params, headers); assertEquals(HttpStatus.OK, response.getStatusCode()); Map results = response.getBody(); assertTrue("There should be a token: " + results, results.containsKey("access_token")); assertTrue("There should be a refresh: " + results, results.containsKey("refresh_token")); }
From source file:org.cloudfoundry.identity.uaa.integration.LoginServerSecurityIntegrationTests.java
@Test @OAuth2ContextConfiguration(LoginClient.class) public void testLoginServerWithoutBearerToken() throws Exception { ImplicitResourceDetails resource = testAccounts.getDefaultImplicitResource(); HttpHeaders headers = new HttpHeaders(); headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); headers.add("Authorization", getAuthorizationEncodedValue(resource.getClientId(), "")); params.set("client_id", resource.getClientId()); params.set("client_secret", ""); params.set("source", "login"); params.set(UaaAuthenticationDetails.ADD_NEW, "false"); params.set("grant_type", "password"); String redirect = resource.getPreEstablishedRedirectUri(); if (redirect != null) { params.set("redirect_uri", redirect); }/*from w w w . j av a 2 s. c o m*/ @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap(serverRunning.getAccessTokenUri(), params, headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); }
From source file:org.cloudfoundry.identity.uaa.integration.LoginServerSecurityIntegrationTests.java
@Test @OAuth2ContextConfiguration(LoginClient.class) public void testLoginServerCfInvalidClientPasswordToken() throws Exception { ImplicitResourceDetails resource = testAccounts.getDefaultImplicitResource(); HttpHeaders headers = new HttpHeaders(); headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); params.set("client_id", resource.getClientId()); params.set("client_secret", "bogus"); params.set("source", "login"); params.set(UaaAuthenticationDetails.ADD_NEW, "false"); params.set("grant_type", "password"); String redirect = resource.getPreEstablishedRedirectUri(); if (redirect != null) { params.set("redirect_uri", redirect); }// w ww. j a v a 2s.c om @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap(serverRunning.getAccessTokenUri(), params, headers); HttpStatus statusCode = response.getStatusCode(); assertTrue("Status code should be 401 or 403.", statusCode == HttpStatus.FORBIDDEN || statusCode == HttpStatus.UNAUTHORIZED); }
From source file:org.cloudfoundry.identity.uaa.integration.LoginServerSecurityIntegrationTests.java
@Test @OAuth2ContextConfiguration(AppClient.class) public void testLoginServerCfInvalidClientToken() throws Exception { ImplicitResourceDetails resource = testAccounts.getDefaultImplicitResource(); HttpHeaders headers = new HttpHeaders(); headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); params.set("client_id", resource.getClientId()); params.set("client_secret", "bogus"); params.set("source", "login"); params.set(UaaAuthenticationDetails.ADD_NEW, "false"); params.set("grant_type", "password"); String redirect = resource.getPreEstablishedRedirectUri(); if (redirect != null) { params.set("redirect_uri", redirect); }/* w w w . j ava 2s . c om*/ @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap(serverRunning.getAccessTokenUri(), params, headers); HttpStatus statusCode = response.getStatusCode(); assertTrue("Status code should be 401 or 403.", statusCode == HttpStatus.FORBIDDEN || statusCode == HttpStatus.UNAUTHORIZED); }