-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Update of Users with Alias during Login (#3014)
* Add ScimUserService as central entrypoint for ScimUser update with alias handling * Move ScimUser update logic from ScimUserEndpoints to ScimUserService * Add injection of ScimUserService into ScimUserBootstrap * Reformat * Add handling of alias users in ScimUserBootstrap * Fix ScimUserEndpointsAliasMockMvcTests * Add test for new behavior to ScimUserBootstrapTests * Add unit test for ScimUserService.update * Add documentation for alias user handling during logon * Inject 'aliasEntitiesEnabled into ScimUserBootstrap' * Handle login of users with alias when alias entities are enabled: only update original user while alias properties remain unchanged * Update documentation * Sonar
- Loading branch information
1 parent
0ac2c30
commit 4c05f30
Showing
12 changed files
with
699 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...er/src/main/java/org/cloudfoundry/identity/uaa/alias/AliasPropertiesInvalidException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.cloudfoundry.identity.uaa.alias; | ||
|
||
public class AliasPropertiesInvalidException extends RuntimeException { | ||
public AliasPropertiesInvalidException() { | ||
super("The fields 'aliasId' and/or 'aliasZid' are invalid."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
server/src/main/java/org/cloudfoundry/identity/uaa/scim/services/ScimUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.cloudfoundry.identity.uaa.scim.services; | ||
|
||
import org.cloudfoundry.identity.uaa.alias.AliasPropertiesInvalidException; | ||
import org.cloudfoundry.identity.uaa.alias.EntityAliasFailedException; | ||
import org.cloudfoundry.identity.uaa.scim.ScimUser; | ||
import org.cloudfoundry.identity.uaa.scim.ScimUserAliasHandler; | ||
import org.cloudfoundry.identity.uaa.scim.ScimUserProvisioning; | ||
import org.cloudfoundry.identity.uaa.zone.beans.IdentityZoneManager; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.dao.OptimisticLockingFailureException; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.support.TransactionTemplate; | ||
|
||
@Component | ||
public class ScimUserService { | ||
|
||
private final ScimUserAliasHandler aliasHandler; | ||
private final ScimUserProvisioning scimUserProvisioning; | ||
private final IdentityZoneManager identityZoneManager; | ||
private final TransactionTemplate transactionTemplate; | ||
private final boolean aliasEntitiesEnabled; | ||
|
||
public ScimUserService( | ||
final ScimUserAliasHandler aliasHandler, | ||
final ScimUserProvisioning scimUserProvisioning, | ||
final IdentityZoneManager identityZoneManager, | ||
final TransactionTemplate transactionTemplate, | ||
@Qualifier("aliasEntitiesEnabled") final boolean aliasEntitiesEnabled | ||
) { | ||
this.aliasHandler = aliasHandler; | ||
this.scimUserProvisioning = scimUserProvisioning; | ||
this.identityZoneManager = identityZoneManager; | ||
this.transactionTemplate = transactionTemplate; | ||
this.aliasEntitiesEnabled = aliasEntitiesEnabled; | ||
} | ||
|
||
public ScimUser updateUser(final String userId, final ScimUser user) | ||
throws AliasPropertiesInvalidException, OptimisticLockingFailureException, EntityAliasFailedException { | ||
final ScimUser existingScimUser = scimUserProvisioning.retrieve( | ||
userId, | ||
identityZoneManager.getCurrentIdentityZoneId() | ||
); | ||
if (!aliasHandler.aliasPropertiesAreValid(user, existingScimUser)) { | ||
throw new AliasPropertiesInvalidException(); | ||
} | ||
|
||
if (!aliasEntitiesEnabled) { | ||
// update user without alias handling | ||
return scimUserProvisioning.update(userId, user, identityZoneManager.getCurrentIdentityZoneId()); | ||
} | ||
|
||
// update user and create/update alias, if necessary | ||
return updateUserWithAliasHandling(userId, user, existingScimUser); | ||
} | ||
|
||
private ScimUser updateUserWithAliasHandling( | ||
final String userId, | ||
final ScimUser user, | ||
final ScimUser existingUser | ||
) { | ||
return transactionTemplate.execute(txStatus -> { | ||
final ScimUser updatedOriginalUser = scimUserProvisioning.update( | ||
userId, | ||
user, | ||
identityZoneManager.getCurrentIdentityZoneId() | ||
); | ||
return aliasHandler.ensureConsistencyOfAliasEntity(updatedOriginalUser, existingUser); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.