IdentityProviderEndpoints implements ApplicationEventPublisherAware { @RequestMapping (value = "{id}/status", method = PATCH) public ResponseEntity<IdentityProviderStatus> updateIdentityProviderStatus(@PathVariable String id, @RequestBody IdentityProviderStatus body) { String zoneId = identityZoneManager.getCurrentIdentityZoneId(); IdentityProvider existing = identityProviderProvisioning.retrieve(id, zoneId); if(body.getRequirePasswordChange() == null || !body.getRequirePasswordChange()) { logger.debug("Invalid payload. The property requirePasswordChangeRequired needs to be set"); return new ResponseEntity<>(body, UNPROCESSABLE_ENTITY); } if(!OriginKeys.UAA.equals(existing.getType())) { logger.debug("Invalid operation. This operation is not supported on external IDP"); return new ResponseEntity<>(body, UNPROCESSABLE_ENTITY); } UaaIdentityProviderDefinition uaaIdentityProviderDefinition = ObjectUtils.castInstance(existing.getConfig(), UaaIdentityProviderDefinition.class); if(uaaIdentityProviderDefinition == null || uaaIdentityProviderDefinition.getPasswordPolicy() == null) { logger.debug("IDP does not have an existing PasswordPolicy. Operation not supported"); return new ResponseEntity<>(body, UNPROCESSABLE_ENTITY); } uaaIdentityProviderDefinition.getPasswordPolicy().setPasswordNewerThan(new Date(System.currentTimeMillis())); identityProviderProvisioning.update(existing, zoneId); logger.info("PasswordChangeRequired property set for Identity Provider: " + existing.getId()); return new ResponseEntity<>(body, 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 testPatchIdentityProviderStatusInvalidPayload() { IdentityProviderStatus identityProviderStatus = new IdentityProviderStatus(); ResponseEntity responseEntity = identityProviderEndpoints.updateIdentityProviderStatus("123", identityProviderStatus); assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode()); }
@Test void testPatchIdentityProviderStatusInvalidIDP() { String zoneId = IdentityZone.getUaaZoneId(); IdentityProviderStatus identityProviderStatus = new IdentityProviderStatus(); identityProviderStatus.setRequirePasswordChange(true); IdentityProvider notUAAIDP = new IdentityProvider(); notUAAIDP.setType("NOT_UAA"); notUAAIDP.setConfig(new SamlIdentityProviderDefinition()); when(mockIdentityProviderProvisioning.retrieve(anyString(), eq(zoneId))).thenReturn(notUAAIDP); ResponseEntity responseEntity = identityProviderEndpoints.updateIdentityProviderStatus("123", identityProviderStatus); assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode()); }
@Test void testPatchIdentityProviderStatusWithNoIDPDefinition() { String zoneId = IdentityZone.getUaaZoneId(); IdentityProviderStatus identityProviderStatus = new IdentityProviderStatus(); identityProviderStatus.setRequirePasswordChange(true); IdentityProvider invalidIDP = new IdentityProvider(); invalidIDP.setConfig(null); invalidIDP.setType(OriginKeys.UAA); when(mockIdentityProviderProvisioning.retrieve(anyString(), eq(zoneId))).thenReturn(invalidIDP); ResponseEntity responseEntity = identityProviderEndpoints.updateIdentityProviderStatus("123", identityProviderStatus); assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode()); }
@Test void testPatchIdentityProviderStatusWithNoPasswordPolicy() { String zoneId = IdentityZone.getUaaZoneId(); IdentityProviderStatus identityProviderStatus = new IdentityProviderStatus(); identityProviderStatus.setRequirePasswordChange(true); IdentityProvider invalidIDP = new IdentityProvider(); invalidIDP.setType(OriginKeys.UAA); invalidIDP.setConfig(new UaaIdentityProviderDefinition(null, null)); when(mockIdentityProviderProvisioning.retrieve(anyString(), eq(zoneId))).thenReturn(invalidIDP); ResponseEntity responseEntity = identityProviderEndpoints.updateIdentityProviderStatus("123", identityProviderStatus); assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, responseEntity.getStatusCode()); }
@Test void testPatchIdentityProviderStatus() { String zoneId = IdentityZone.getUaaZoneId(); IdentityProviderStatus identityProviderStatus = new IdentityProviderStatus(); identityProviderStatus.setRequirePasswordChange(true); IdentityProvider validIDP = new IdentityProvider(); validIDP.setType(OriginKeys.UAA); validIDP.setConfig(new UaaIdentityProviderDefinition(new PasswordPolicy(), null)); when(mockIdentityProviderProvisioning.retrieve(anyString(), eq(zoneId))).thenReturn(validIDP); ResponseEntity responseEntity = identityProviderEndpoints.updateIdentityProviderStatus("123", identityProviderStatus); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); }