List of usage examples for org.springframework.security.oauth2.provider.client BaseClientDetails BaseClientDetails
public BaseClientDetails(String clientId, String resourceIds, String scopes, String grantTypes,
String authorities)
From source file:org.cloudfoundry.identity.uaa.mock.zones.IdentityZoneSwitchingFilterMockMvcTest.java
private ClientDetails createClientInOtherZone(String accessToken, ResultMatcher statusMatcher, String headerKey, String headerValue) throws Exception { String clientId = generator.generate(); BaseClientDetails client = new BaseClientDetails(clientId, null, null, "client_credentials", null); client.setClientSecret("secret"); getMockMvc()//from w w w . ja v a 2 s . c om .perform(post("/oauth/clients").header(headerKey, headerValue) .header("Authorization", "Bearer " + accessToken).accept(APPLICATION_JSON) .contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(client))) .andExpect(statusMatcher); return client; }
From source file:org.cloudfoundry.identity.uaa.oauth.UaaTokenServicesTests.java
@Before public void setUp() throws Exception { IdentityZoneHolder.clear();/* ww w . j ava 2 s . c om*/ IdentityZoneProvisioning provisioning = mock(IdentityZoneProvisioning.class); IdentityZoneHolder.setProvisioning(provisioning); IdentityZone zone = IdentityZone.getUaa(); IdentityZoneConfiguration config = new IdentityZoneConfiguration(); tokenPolicy = new TokenPolicy(accessTokenValidity, refreshTokenValidity); Map<String, String> keys = new HashMap<>(); keys.put("testKey", "9c247h8yt978w3nv45y978w45hntv6"); keys.put("otherKey", "unc0uf98gv89egh4v98749978hv"); tokenPolicy.setKeys(keys); tokenPolicy.setActiveKeyId("testKey"); config.setTokenPolicy(tokenPolicy); zone.setConfig(config); when(provisioning.retrieve("uaa")).thenReturn(zone); mockAuthentication = new MockAuthentication(); SecurityContextHolder.getContext().setAuthentication(mockAuthentication); requestedAuthScopes = Arrays.asList(READ, WRITE, OPENID); clientScopes = Arrays.asList(READ, WRITE, OPENID); readScope = Arrays.asList(READ); writeScope = Arrays.asList(WRITE); expandedScopes = Arrays.asList(READ, WRITE, DELETE, OPENID); resourceIds = Arrays.asList(SCIM, CLIENTS); expectedJson = "[\"" + READ + "\",\"" + WRITE + "\",\"" + OPENID + "\"]"; defaultClient = new BaseClientDetails(CLIENT_ID, SCIM + "," + CLIENTS, READ + "," + WRITE + "," + OPENID + "," + UAA_REFRESH_TOKEN, ALL_GRANTS_CSV, CLIENT_AUTHORITIES); clientDetailsService.setClientDetailsStore(Collections.singletonMap(CLIENT_ID, defaultClient)); tokenProvisioning = mock(RevocableTokenProvisioning.class); when(tokenProvisioning.create(anyObject())).thenAnswer((Answer<RevocableToken>) invocation -> { RevocableToken arg = (RevocableToken) invocation.getArguments()[0]; tokens.put(arg.getTokenId(), arg); return arg; }); when(tokenProvisioning.update(anyString(), anyObject())).thenAnswer((Answer<RevocableToken>) invocation -> { String id = (String) invocation.getArguments()[0]; RevocableToken arg = (RevocableToken) invocation.getArguments()[1]; arg.setTokenId(id); tokens.put(arg.getTokenId(), arg); return arg; }); when(tokenProvisioning.retrieve(anyString())).thenAnswer((Answer<RevocableToken>) invocation -> { String id = (String) invocation.getArguments()[0]; RevocableToken result = tokens.get(id); if (result == null) { throw new EmptyResultDataAccessException(1); } return result; }); AbstractOAuth2AccessTokenMatchers.revocableTokens.set(tokens); requestFactory = new DefaultOAuth2RequestFactory(clientDetailsService); tokenServices.setClientDetailsService(clientDetailsService); tokenServices.setTokenPolicy(tokenPolicy); tokenServices.setDefaultUserAuthorities(AuthorityUtils.authorityListToSet(USER_AUTHORITIES)); tokenServices.setIssuer("http://localhost:8080/uaa"); tokenServices.setUserDatabase(userDatabase); tokenServices.setApprovalStore(approvalStore); tokenServices.setApplicationEventPublisher(publisher); tokenServices.setTokenProvisioning(tokenProvisioning); tokenServices.setUaaTokenEnhancer(tokenEnhancer); tokenServices.afterPropertiesSet(); thousandScopes = new HashSet<>(); for (int i = 0; i < 1000; i++) { thousandScopes.add(String.valueOf(i)); } persistToken = new CompositeAccessToken("token-value"); expiration = new Date(System.currentTimeMillis() + 10000); persistToken.setScope(thousandScopes); persistToken.setExpiration(expiration); }
From source file:org.cloudfoundry.identity.uaa.test.TestAccountSetup.java
private void createScimClient(RestOperations client) { BaseClientDetails clientDetails = new BaseClientDetails("scim", "oauth", "uaa.none", "client_credentials", "scim.read,scim.write,password.write,oauth.approvals"); clientDetails.setClientSecret("scimsecret"); createClient(client, testAccounts.getClientDetails("oauth.clients.scim", clientDetails)); }
From source file:org.cloudfoundry.identity.uaa.test.TestAccountSetup.java
private void createAppClient(RestOperations client) { BaseClientDetails clientDetails = new BaseClientDetails("app", "none", "cloud_controller.read,cloud_controller_service_permissions.read,openid,password.write", "password,authorization_code,refresh_token", "uaa.resource"); clientDetails.setClientSecret("appclientsecret"); createClient(client, testAccounts.getClientDetails("oauth.clients.app", clientDetails)); }