public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException { int count = jdbcTemplate.update(updateClientDetailsSql, getFieldsForUpdate(clientDetails)); if (count != 1) { throw new NoSuchClientException("No client found with id = " + clientDetails.getClientId()); } }
public TokenRequest createTokenRequest(Map<String, String> requestParameters, ClientDetails authenticatedClient) { String clientId = requestParameters.get(OAuth2Utils.CLIENT_ID); if (clientId == null) { // if the clientId wasn't passed in in the map, we add pull it from the authenticated client object clientId = authenticatedClient.getClientId(); } else { // otherwise, make sure that they match if (!clientId.equals(authenticatedClient.getClientId())) { throw new InvalidClientException("Given client ID does not match authenticated client"); } } String grantType = requestParameters.get(OAuth2Utils.GRANT_TYPE); Set<String> scopes = extractScopes(requestParameters, clientId); TokenRequest tokenRequest = new TokenRequest(requestParameters, clientId, scopes, grantType); return tokenRequest; }
public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyExistsException { try { jdbcTemplate.update(insertClientDetailsSql, getFields(clientDetails)); } catch (DuplicateKeyException e) { throw new ClientAlreadyExistsException("Client already exists: " + clientDetails.getClientId(), e); } }
public static String getRevocableTokenSignature(ClientDetails client, String clientSecret, UaaUser user) { String tokenSalt = (String) client.getAdditionalInformation().get(ClientConstants.TOKEN_SALT); String clientId = client.getClientId(); return getRevocableTokenSignature(user, tokenSalt, clientId, clientSecret); }
public OAuth2Request createOAuth2Request(ClientDetails client) { Map<String, String> requestParameters = getRequestParameters(); HashMap<String, String> modifiable = new HashMap<String, String>(requestParameters); // Remove password if present to prevent leaks modifiable.remove("password"); modifiable.remove("client_secret"); // Add grant type so it can be retrieved from OAuth2Request modifiable.put("grant_type", grantType); return new OAuth2Request(modifiable, client.getClientId(), client.getAuthorities(), true, this.getScope(), client.getResourceIds(), null, null, null); }
@Override public void clearApprovedSitesForClient(ClientDetails client) { Collection<ApprovedSite> approvedSites = approvedSiteRepository.getByClientId(client.getClientId()); if (approvedSites != null) { for (ApprovedSite approvedSite : approvedSites) { remove(approvedSite); } } }
@Override public ClientDetails create(ClientDetails resource, String zoneId) { delegate.addClientDetails(resource, zoneId); return delegate.loadClientByClientId(resource.getClientId(), zoneId); }
@Override public void updateClientDetails(ClientDetails clientDetails, String zoneId) throws NoSuchClientException { int count = jdbcTemplate.update(DEFAULT_UPDATE_STATEMENT, getFieldsForUpdate(clientDetails, zoneId)); if (count != 1) { throw new NoSuchClientException("No client found with id = " + clientDetails.getClientId() + " in identity zone "+IdentityZoneHolder.get().getName()); } }
@Test void listClientTokenAs_Other_Client() throws Exception { for (String clientId : Arrays.asList(client1withTokensListScope.getClientId(), client2.getClientId(), client3.getClientId())) { listTokens("/oauth/token/list/client/" + clientId, adminClientToken, tokensPerClient.get(clientId), status().isOk()); } }
@Override public void publishEvent(ApplicationEvent event) { if (event instanceof EntityDeletedEvent) { ClientDetails client = (ClientDetails)((EntityDeletedEvent)event).getDeleted(); clientRegistrationService.removeClientDetails(client.getClientId()); } } @Override
@Test void listClientTokensAsAnotherClient() throws Exception { getTokenList("/oauth/token/list/client/" + client1withTokensListScope.getClientId(), tokensPerClient.getFirst(client3.getClientId()), status().isForbidden()); getTokenList("/oauth/token/list/client/" + client1withTokensListScope.getClientId(), tokensListToken, status().isOk()); }
@Test void testCreateClient() throws Exception { ClientDetails client = createClient(adminToken, new RandomValueStringGenerator().generate(), SECRET, Collections.singleton("client_credentials")); verify(mockApplicationEventPublisher, times(1)).publishEvent(abstractUaaEventCaptor.capture()); assertEquals(AuditEventType.ClientCreateSuccess, abstractUaaEventCaptor.getValue().getAuditEvent().getType()); assertEquals("Client " + client.getClientId(), client.getAdditionalInformation().get("name")); }
@Test public void provider_authenticate_client_with_two_passwords_test_1() throws Exception { jdbcClientDetailsService.addClientSecret(client.getClientId(), "secret2", IdentityZoneHolder.get().getId()); testClientAuthentication(getToken(client.getClientId(), SECRET)); }
@Test public void provider_authenticate_client_with_two_passwords_test_2() throws Exception { jdbcClientDetailsService.addClientSecret(client.getClientId(), "secret2", IdentityZoneHolder.get().getId()); testClientAuthentication(getToken(client.getClientId(), "secret2")); }
@Test public void provider_authenticate_client_with_one_password() throws Exception { Authentication a = getToken(client.getClientId(), SECRET); testClientAuthentication(a); }
@Test(expected = AuthenticationException.class) public void provider_authenticate_client_with_two_passwords_test_3() throws Exception { jdbcClientDetailsService.addClientSecret(client.getClientId(), "secret2", IdentityZoneHolder.get().getId()); testClientAuthentication(getToken(client.getClientId(), "secret3")); }
@Test public void testGetClientById() { String token = getToken(); ClientDetails clientDetails = TokenValidation.buildAccessTokenValidator(token, new KeyInfoService("https://localhost")) .getClientDetails(clientDetailsService); assertThat(clientDetails.getClientId(), equalTo(content.get("cid"))); }
@AfterEach void teardownClients() { for (ClientDetails clientDetail : clientDetails) { delete("/oauth/clients/" + clientDetail.getClientId()) .header("Authorization", "Bearer" + adminUserToken) .accept(APPLICATION_JSON); } }
public BaseClientDetails(ClientDetails prototype) { this(); setAccessTokenValiditySeconds(prototype.getAccessTokenValiditySeconds()); setRefreshTokenValiditySeconds(prototype .getRefreshTokenValiditySeconds()); setAuthorities(prototype.getAuthorities()); setAuthorizedGrantTypes(prototype.getAuthorizedGrantTypes()); setClientId(prototype.getClientId()); setClientSecret(prototype.getClientSecret()); setRegisteredRedirectUri(prototype.getRegisteredRedirectUri()); setScope(prototype.getScope()); setResourceIds(prototype.getResourceIds()); }
@Test public void test_get_approvals() throws Exception { test_oauth_authorize_without_csrf(); MockHttpSession session = getAuthenticatedSession(user1); mockMvc.perform( get("/profile") .session(session) ) .andExpect(status().isOk()) .andExpect(content().string(containsString(client1.getClientId() + "-test.scope1"))); }