private Object[] getFields(ClientDetails clientDetails) { Object[] fieldsForUpdate = getFieldsForUpdate(clientDetails); Object[] fields = new Object[fieldsForUpdate.length + 1]; System.arraycopy(fieldsForUpdate, 0, fields, 1, fieldsForUpdate.length); fields[0] = clientDetails.getClientSecret() != null ? passwordEncoder.encode(clientDetails.getClientSecret()) : null; return fields; }
@Override public void addClientSecret(String clientId, String newSecret, String zoneId) throws NoSuchClientException { ClientDetails clientDetails = loadClientByClientId(clientId, zoneId); String encodedNewSecret = passwordEncoder.encode(newSecret); StringBuilder newSecretBuilder = new StringBuilder() .append(clientDetails.getClientSecret()==null ? "" : clientDetails.getClientSecret() +" ") .append(encodedNewSecret); int count = jdbcTemplate.update(DEFAULT_UPDATE_SECRET_STATEMENT, newSecretBuilder.toString(), clientId, zoneId); if (count != 1) { throw new NoSuchClientException("No client found with id = " + clientId); } }
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { ClientDetails clientDetails; try { clientDetails = clientDetailsService.loadClientByClientId(username); } catch (NoSuchClientException e) { throw new UsernameNotFoundException(e.getMessage(), e); } String clientSecret = clientDetails.getClientSecret(); if (clientSecret== null || clientSecret.trim().length()==0) { clientSecret = emptyPassword; } return new User(username, clientSecret, clientDetails.getAuthorities()); }
private void throwIfInvalidRevocationHashSignature(String revocableHashSignature, UaaUser user, ClientDetails client) { if (hasText(revocableHashSignature)) { String clientSecretForHash = client.getClientSecret(); if(clientSecretForHash != null && clientSecretForHash.split(" ").length > 1){ clientSecretForHash = clientSecretForHash.split(" ")[1]; } String newRevocableHashSignature = UaaTokenUtils.getRevocableTokenSignature(client, clientSecretForHash, user); if (!revocableHashSignature.equals(newRevocableHashSignature)) { throw new TokenRevokedException("Invalid refresh token: revocable signature mismatch"); } } }
private Object[] getInsertClientDetailsFields(ClientDetails clientDetails, String zoneId) { Object[] fieldsForUpdate = getFieldsForUpdate(clientDetails, zoneId); Object[] clientDetailFieldsForUpdate = new Object[fieldsForUpdate.length + 2]; System.arraycopy(fieldsForUpdate, 0, clientDetailFieldsForUpdate, 1, fieldsForUpdate.length); clientDetailFieldsForUpdate[0] = clientDetails.getClientSecret() != null ? passwordEncoder.encode(clientDetails.getClientSecret()) : null; clientDetailFieldsForUpdate[clientDetailFieldsForUpdate.length - 1] = getUserId(); return clientDetailFieldsForUpdate; }
@Override public void deleteClientSecret(String clientId, String zoneId) throws NoSuchClientException { ClientDetails clientDetails = loadClientByClientId(clientId, zoneId); String clientSecret = clientDetails.getClientSecret().split(" ")[1]; int count = jdbcTemplate.update(DEFAULT_UPDATE_SECRET_STATEMENT, clientSecret, clientId, zoneId); if (count != 1) { throw new NoSuchClientException("Unable to update client with " + clientId); } }
protected boolean didPasswordChange(String clientId, String rawPassword) { if (getPasswordEncoder()!=null) { ClientDetails existing = clientRegistrationService.loadClientByClientId(clientId, IdentityZoneHolder.get().getId()); String existingPasswordHash = existing.getClientSecret(); return !getPasswordEncoder().matches(rawPassword, existingPasswordHash); } else { return true; } }
@Test public void testCreateClientDetails() throws Exception { when(clientDetailsService.retrieve(anyString(), anyString())).thenReturn(input); ClientDetails result = endpoints.createClientDetails(input); assertNull(result.getClientSecret()); verify(clientDetailsService).create(detail, IdentityZoneHolder.get().getId()); assertEquals(1463510591, result.getAdditionalInformation().get("lastModified")); }
@Test(expected = InvalidClientDetailsException.class) public void testCreateClientDetailsWithPasswordGrant() throws Exception { input.setAuthorizedGrantTypes(Arrays.asList("password")); ClientDetails result = endpoints.createClientDetails(input); assertNull(result.getClientSecret()); verify(clientRegistrationService).addClientDetails(detail); }
@Test public void testCreateClientDetailsWithClientCredentials() throws Exception { when(clientDetailsService.retrieve(anyString(), anyString())).thenReturn(input); input.setAuthorizedGrantTypes(Arrays.asList("client_credentials")); detail.setAuthorizedGrantTypes(input.getAuthorizedGrantTypes()); ClientDetails result = endpoints.createClientDetails(input); assertNull(result.getClientSecret()); verify(clientDetailsService).create(detail, IdentityZoneHolder.get().getId()); }
@Test public void testCreateClientDetailsWithAdditionalInformation() throws Exception { when(clientDetailsService.retrieve(anyString(), anyString())).thenReturn(input); input.setAdditionalInformation(Collections.singletonMap("foo", "bar")); detail.setAdditionalInformation(input.getAdditionalInformation()); ClientDetails result = endpoints.createClientDetails(input); assertNull(result.getClientSecret()); verify(clientDetailsService).create(detail, IdentityZoneHolder.get().getId()); }
@Test public void testClientinfo() { Mockito.when(clientDetailsService.loadClientByClientId("foo", "uaa")).thenReturn(foo); ClientDetails client = endpoint.clientinfo(new UsernamePasswordAuthenticationToken("foo", "<NONE>")); assertEquals("foo", client.getClientId()); assertNull(client.getClientSecret()); assertTrue(client.getAdditionalInformation().isEmpty()); }
@Test public void testCreateClientDetailsWithJwtBearer() throws Exception { when(clientDetailsService.retrieve(anyString(), anyString())).thenReturn(input); input.setAuthorizedGrantTypes(Arrays.asList(GRANT_TYPE_JWT_BEARER)); input.setScope(Arrays.asList(input.getClientId()+".scope")); detail.setAuthorizedGrantTypes(input.getAuthorizedGrantTypes()); detail.setScope(input.getScope()); ClientDetails result = endpoints.createClientDetails(input); assertNull(result.getClientSecret()); verify(clientDetailsService).create(detail, IdentityZoneHolder.get().getId()); }
@Test public void testMultipleCreateClientDetails() throws Exception { ClientDetails[] results = endpoints.createClientDetailsTx(inputs); assertEquals("We should have created "+inputs.length+" clients.", inputs.length, results.length); for (int i=0; i<inputs.length; i++) { ClientDetails result = results[i]; assertNull(result.getClientSecret()); } }
@Test(expected = InvalidClientDetailsException.class) public void testUpdateClientDetailsWithNullCallerAndInvalidScope() throws Exception { Mockito.when(clientDetailsService.retrieve(input.getClientId(), IdentityZoneHolder.get().getId())).thenReturn( new BaseClientDetails(input)); input.setScope(Arrays.asList("read")); ClientDetails result = endpoints.updateClientDetails(input, input.getClientId()); assertNull(result.getClientSecret()); detail.setScope(Arrays.asList("read")); verify(clientRegistrationService).updateClientDetails(detail); }
@Test public void testUpdateClientDetailsRemoveAdditionalInformation() throws Exception { input.setAdditionalInformation(Collections.singletonMap("foo", "bar")); Mockito.when(clientDetailsService.retrieve(input.getClientId(), IdentityZoneHolder.get().getId())).thenReturn( new BaseClientDetails(input)); input.setAdditionalInformation(Collections.<String, Object> emptyMap()); ClientDetails result = endpoints.updateClientDetails(input, input.getClientId()); assertNull(result.getClientSecret()); verify(clientRegistrationService).updateClientDetails(detail, "testzone"); }
@Test public void testUpdateClientDetails() throws Exception { Mockito.when(clientDetailsService.retrieve(input.getClientId(), IdentityZoneHolder.get().getId())).thenReturn( new BaseClientDetails(input)); input.setScope(Arrays.asList(input.getClientId() + ".read")); ClientDetails result = endpoints.updateClientDetails(input, input.getClientId()); assertNull(result.getClientSecret()); detail.setScope(Arrays.asList(input.getClientId() + ".read")); verify(clientRegistrationService).updateClientDetails(detail, "testzone"); }
@Test public void testGetClientDetails() throws Exception { Mockito.when(clientDetailsService.retrieve(input.getClientId(), IdentityZoneHolder.get().getId())).thenReturn(input); input.setScope(Arrays.asList(input.getClientId() + ".read")); input.setAdditionalInformation(Collections.singletonMap("foo", "bar")); ClientDetails result = endpoints.getClientDetails(input.getClientId()); assertNull(result.getClientSecret()); assertEquals(input.getAdditionalInformation(), result.getAdditionalInformation()); }
@Test public void testUpdateClientDetailsWithAdditionalInformation() throws Exception { Mockito.when(clientDetailsService.retrieve(input.getClientId(), IdentityZoneHolder.get().getId())).thenReturn( new BaseClientDetails(input)); input.setScope(Arrays.asList(input.getClientId() + ".read")); input.setAdditionalInformation(Collections.singletonMap("foo", "bar")); ClientDetails result = endpoints.updateClientDetails(input, input.getClientId()); assertNull(result.getClientSecret()); detail.setScope(input.getScope()); detail.setAdditionalInformation(input.getAdditionalInformation()); verify(clientRegistrationService).updateClientDetails(detail, "testzone"); }
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()); }