IdentityProviderEndpoints implements ApplicationEventPublisherAware { @RequestMapping(value = "{id}", method = PUT) public ResponseEntity<IdentityProvider> updateIdentityProvider(@PathVariable String id, @RequestBody IdentityProvider body, @RequestParam(required = false, defaultValue = "false") boolean rawConfig) throws MetadataProviderException { body.setSerializeConfigRaw(rawConfig); String zoneId = identityZoneManager.getCurrentIdentityZoneId(); IdentityProvider existing = identityProviderProvisioning.retrieve(id, zoneId); body.setId(id); body.setIdentityZoneId(zoneId); patchSensitiveData(id, body); try { configValidator.validate(body); } catch (IllegalArgumentException e) { logger.debug("IdentityProvider[origin="+body.getOriginKey()+"; zone="+body.getIdentityZoneId()+"] - Configuration validation error for update.", e); return new ResponseEntity<>(body, UNPROCESSABLE_ENTITY); } if (OriginKeys.SAML.equals(body.getType())) { body.setOriginKey(existing.getOriginKey()); SamlIdentityProviderDefinition definition = ObjectUtils.castInstance(body.getConfig(), SamlIdentityProviderDefinition.class); definition.setZoneId(zoneId); definition.setIdpEntityAlias(body.getOriginKey()); samlConfigurator.validateSamlIdentityProviderDefinition(definition); body.setConfig(definition); } IdentityProvider updatedIdp = identityProviderProvisioning.update(body, zoneId); updatedIdp.setSerializeConfigRaw(rawConfig); redactSensitiveData(updatedIdp); return new ResponseEntity<>(updatedIdp, OK); } 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 update_ldap_provider_patches_password() throws Exception { IdentityProvider<LdapIdentityProviderDefinition> provider = retrieve_ldap_provider_by_id("id"); provider.getConfig().setBindPassword(null); LdapIdentityProviderDefinition spy = Mockito.spy(provider.getConfig()); provider.setConfig(spy); reset(mockIdentityProviderProvisioning); String zoneId = IdentityZone.getUaaZoneId(); when(mockIdentityProviderProvisioning.retrieve(eq(provider.getId()), eq(zoneId))).thenReturn(getLdapDefinition()); when(mockIdentityProviderProvisioning.update(any(), eq(zoneId))).thenReturn(getLdapDefinition()); ResponseEntity<IdentityProvider> response = identityProviderEndpoints.updateIdentityProvider(provider.getId(), provider, true); verify(spy, times(1)).setBindPassword(eq(getLdapDefinition().getConfig().getBindPassword())); ArgumentCaptor<IdentityProvider> captor = ArgumentCaptor.forClass(IdentityProvider.class); verify(mockIdentityProviderProvisioning, times(1)).update(captor.capture(), eq(zoneId)); assertNotNull(captor.getValue()); assertEquals(1, captor.getAllValues().size()); assertEquals(getLdapDefinition().getConfig().getBindPassword(), ((LdapIdentityProviderDefinition) captor.getValue().getConfig()).getBindPassword()); assertNotNull(response); assertEquals(200, response.getStatusCode().value()); assertNotNull(response.getBody()); assertNotNull(response.getBody().getConfig()); assertTrue(response.getBody().getConfig() instanceof LdapIdentityProviderDefinition); assertNull(((LdapIdentityProviderDefinition) response.getBody().getConfig()).getBindPassword()); }
@Test void update_ldap_provider_takes_new_password() throws Exception { IdentityProvider<LdapIdentityProviderDefinition> provider = retrieve_ldap_provider_by_id("id"); LdapIdentityProviderDefinition spy = Mockito.spy(provider.getConfig()); provider.setConfig(spy); spy.setBindPassword("newpassword"); String zoneId = IdentityZone.getUaaZoneId(); reset(mockIdentityProviderProvisioning); when(mockIdentityProviderProvisioning.retrieve(eq(provider.getId()), eq(zoneId))).thenReturn(getLdapDefinition()); when(mockIdentityProviderProvisioning.update(any(), eq(zoneId))).thenReturn(getLdapDefinition()); ResponseEntity<IdentityProvider> response = identityProviderEndpoints.updateIdentityProvider(provider.getId(), provider, true); verify(spy, times(1)).setBindPassword(eq("newpassword")); ArgumentCaptor<IdentityProvider> captor = ArgumentCaptor.forClass(IdentityProvider.class); verify(mockIdentityProviderProvisioning, times(1)).update(captor.capture(), eq(zoneId)); assertNotNull(captor.getValue()); assertEquals(1, captor.getAllValues().size()); assertEquals("newpassword", ((LdapIdentityProviderDefinition) captor.getValue().getConfig()).getBindPassword()); assertNotNull(response); assertEquals(200, response.getStatusCode().value()); assertNotNull(response.getBody()); assertNotNull(response.getBody().getConfig()); assertTrue(response.getBody().getConfig() instanceof LdapIdentityProviderDefinition); assertNull(((LdapIdentityProviderDefinition) response.getBody().getConfig()).getBindPassword()); }