IdentityProviderEndpoints implements ApplicationEventPublisherAware { @RequestMapping(method = POST) public ResponseEntity<IdentityProvider> createIdentityProvider(@RequestBody IdentityProvider body, @RequestParam(required = false, defaultValue = "false") boolean rawConfig) throws MetadataProviderException{ body.setSerializeConfigRaw(rawConfig); String zoneId = identityZoneManager.getCurrentIdentityZoneId(); body.setIdentityZoneId(zoneId); try { configValidator.validate(body); } catch (IllegalArgumentException e) { logger.debug("IdentityProvider[origin="+body.getOriginKey()+"; zone="+body.getIdentityZoneId()+"] - Configuration validation error.", e); return new ResponseEntity<>(body, UNPROCESSABLE_ENTITY); } if (OriginKeys.SAML.equals(body.getType())) { SamlIdentityProviderDefinition definition = ObjectUtils.castInstance(body.getConfig(), SamlIdentityProviderDefinition.class); definition.setZoneId(zoneId); definition.setIdpEntityAlias(body.getOriginKey()); samlConfigurator.validateSamlIdentityProviderDefinition(definition); body.setConfig(definition); } try { IdentityProvider createdIdp = identityProviderProvisioning.create(body, zoneId); createdIdp.setSerializeConfigRaw(rawConfig); redactSensitiveData(createdIdp); return new ResponseEntity<>(createdIdp, CREATED); } catch (IdpAlreadyExistsException e) { return new ResponseEntity<>(body, CONFLICT); } catch (Exception x) { logger.debug("Unable to create IdentityProvider[origin="+body.getOriginKey()+"; zone="+body.getIdentityZoneId()+"]", x); return new ResponseEntity<>(body, INTERNAL_SERVER_ERROR); } } 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 create_ldap_provider_removes_password() throws Exception { String zoneId = IdentityZone.getUaaZoneId(); IdentityProvider<LdapIdentityProviderDefinition> ldapDefinition = getLdapDefinition(); assertNotNull(ldapDefinition.getConfig().getBindPassword()); when(mockIdentityProviderProvisioning.create(any(), eq(zoneId))).thenReturn(ldapDefinition); ResponseEntity<IdentityProvider> response = identityProviderEndpoints.createIdentityProvider(ldapDefinition, true); IdentityProvider created = response.getBody(); assertNotNull(created); assertEquals(LDAP, created.getType()); assertNotNull(created.getConfig()); assertTrue(created.getConfig() instanceof LdapIdentityProviderDefinition); assertNull(((LdapIdentityProviderDefinition) created.getConfig()).getBindPassword()); }
@Test void create_oauth_provider_removes_password() throws Exception { String zoneId = IdentityZone.getUaaZoneId(); for (String type : Arrays.asList(OIDC10, OAUTH20)) { IdentityProvider<AbstractExternalOAuthIdentityProviderDefinition> externalOAuthDefinition = getExternalOAuthProvider(); assertNotNull(externalOAuthDefinition.getConfig().getRelyingPartySecret()); externalOAuthDefinition.setType(type); when(mockIdentityProviderProvisioning.create(any(), eq(zoneId))).thenReturn(externalOAuthDefinition); ResponseEntity<IdentityProvider> response = identityProviderEndpoints.createIdentityProvider(externalOAuthDefinition, true); IdentityProvider created = response.getBody(); assertNotNull(created); assertEquals(type, created.getType()); assertNotNull(created.getConfig()); assertTrue(created.getConfig() instanceof AbstractExternalOAuthIdentityProviderDefinition); assertNull(((AbstractExternalOAuthIdentityProviderDefinition) created.getConfig()).getRelyingPartySecret()); } }