IdentityProviderEndpoints implements ApplicationEventPublisherAware { protected void patchSensitiveData(String id, IdentityProvider provider) { String zoneId = identityZoneManager.getCurrentIdentityZoneId(); if (provider.getConfig() == null) { return; } switch (provider.getType()) { case LDAP: { if (provider.getConfig() instanceof LdapIdentityProviderDefinition) { LdapIdentityProviderDefinition definition = (LdapIdentityProviderDefinition) provider.getConfig(); if (definition.getBindPassword() == null) { IdentityProvider existing = identityProviderProvisioning.retrieve(id, zoneId); if (existing!=null && existing.getConfig()!=null && existing.getConfig() instanceof LdapIdentityProviderDefinition) { LdapIdentityProviderDefinition existingDefinition = (LdapIdentityProviderDefinition)existing.getConfig(); definition.setBindPassword(existingDefinition.getBindPassword()); } } } break; } case OAUTH20 : case OIDC10 : { if (provider.getConfig() instanceof AbstractExternalOAuthIdentityProviderDefinition) { AbstractExternalOAuthIdentityProviderDefinition definition = (AbstractExternalOAuthIdentityProviderDefinition) provider.getConfig(); if (definition.getRelyingPartySecret() == null) { IdentityProvider existing = identityProviderProvisioning.retrieve(id, zoneId); if (existing!=null && existing.getConfig()!=null && existing.getConfig() instanceof AbstractExternalOAuthIdentityProviderDefinition) { AbstractExternalOAuthIdentityProviderDefinition existingDefinition = (AbstractExternalOAuthIdentityProviderDefinition)existing.getConfig(); definition.setRelyingPartySecret(existingDefinition.getRelyingPartySecret()); } } } break; } default: break; } } IdentityProviderEndpoints(
            final @Qualifier("identityProviderProvisioning") IdentityProviderProvisioning identityProviderProvisioning,
            final @Qualifier("externalGroupMembershipManager") ScimGroupExternalMembershipManager scimGroupExternalMembershipManager,
            final @Qualifier("scimGroupProvisioning") ScimGroupProvisioning scimGroupProvisioning,
            final @Qualifier("metaDataProviders") SamlIdentityProviderConfigurator samlConfigurator,
            final @Qualifier("identityProviderConfigValidator") IdentityProviderConfigValidator configValidator,
            final IdentityZoneManager identityZoneManager); @Override void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher); @RequestMapping(method = POST) ResponseEntity<IdentityProvider> createIdentityProvider(@RequestBody IdentityProvider body, @RequestParam(required = false, defaultValue = "false") boolean rawConfig); @RequestMapping(value = "{id}", method = DELETE) @Transactional ResponseEntity<IdentityProvider> deleteIdentityProvider(@PathVariable String id, @RequestParam(required = false, defaultValue = "false") boolean rawConfig); @RequestMapping(value = "{id}", method = PUT) ResponseEntity<IdentityProvider> updateIdentityProvider(@PathVariable String id, @RequestBody IdentityProvider body, @RequestParam(required = false, defaultValue = "false") boolean rawConfig); @RequestMapping (value = "{id}/status", method = PATCH) ResponseEntity<IdentityProviderStatus> updateIdentityProviderStatus(@PathVariable String id, @RequestBody IdentityProviderStatus body); @RequestMapping(method = GET) ResponseEntity<List<IdentityProvider>> retrieveIdentityProviders(@RequestParam(value = "active_only", required = false) String activeOnly, @RequestParam(required = false, defaultValue = "false") boolean rawConfig); @RequestMapping(value = "{id}", method = GET) ResponseEntity<IdentityProvider> retrieveIdentityProvider(@PathVariable String id, @RequestParam(required = false, defaultValue = "false") boolean rawConfig); @RequestMapping(value = "test", method = POST) ResponseEntity<String> testIdentityProvider(@RequestBody IdentityProviderValidationRequest body); @ExceptionHandler(MetadataProviderException.class) ResponseEntity<String> handleMetadataProviderException(MetadataProviderException e); @ExceptionHandler(JsonUtils.JsonUtilException.class) ResponseEntity<String> handleMetadataProviderException(); @ExceptionHandler(EmptyResultDataAccessException.class) ResponseEntity<String> handleProviderNotFoundException();  }
@Test void patch_bind_password() { IdentityProvider provider = getLdapDefinition(); LdapIdentityProviderDefinition def = (LdapIdentityProviderDefinition) provider.getConfig(); def.setBindPassword(null); LdapIdentityProviderDefinition spy = Mockito.spy(def); provider.setConfig(spy); reset(mockIdentityProviderProvisioning); String zoneId = IdentityZone.getUaaZoneId(); when(mockIdentityProviderProvisioning.retrieve(eq(provider.getId()), eq(zoneId))).thenReturn(getLdapDefinition()); identityProviderEndpoints.patchSensitiveData(provider.getId(), provider); verify(spy, times(1)).setBindPassword(eq(getLdapDefinition().getConfig().getBindPassword())); }
@Test void patch_client_secret() { for (String type : Arrays.asList(OIDC10, OAUTH20)) { IdentityProvider<AbstractExternalOAuthIdentityProviderDefinition> provider = getExternalOAuthProvider(); AbstractExternalOAuthIdentityProviderDefinition def = provider.getConfig(); def.setRelyingPartySecret(null); AbstractExternalOAuthIdentityProviderDefinition spy = Mockito.spy(def); provider.setConfig(spy); provider.setType(type); reset(mockIdentityProviderProvisioning); String zoneId = IdentityZone.getUaaZoneId(); when(mockIdentityProviderProvisioning.retrieve(eq(provider.getId()), eq(zoneId))).thenReturn(getExternalOAuthProvider()); identityProviderEndpoints.patchSensitiveData(provider.getId(), provider); verify(spy, times(1)).setRelyingPartySecret(eq(getExternalOAuthProvider().getConfig().getRelyingPartySecret())); } }