Class SynchronizingSamlUserMapper<T extends JmixSamlUserDetails>
- Type Parameters:
T- class of Jmix user
- All Implemented Interfaces:
SamlUserMapper<T>
SamlUserMapper that maps the external user object to the persistent user
and also stores the user and optionally their role assignment to the database.
If role assignment synchronization is enabled (see setSynchronizeRoleAssignments(boolean)), the
identity provider owns all role assignments of the synchronized user: on every login the stored
assignments are replaced with the roles derived from the SAML assertion. Role assignments granted manually
(e.g. by an administrator in the UI) are removed by the next login and therefore must not be combined with
the synchronization mode.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected UnconstrainedDataManagerprotected RoleGrantedAuthorityUtilsprotected SamlAssertionRolesMapperprotected booleanprotected UserRepositoryFields inherited from class io.jmix.saml.mapper.user.BaseSamlUserMapper
locks, samlProperties -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected List<RoleAssignmentEntity> buildRoleAssignmentEntities(String username, Collection<? extends org.springframework.security.core.GrantedAuthority> grantedAuthorities) protected voidcheckUsernameIsNotReserved(String username) Throws an exception if the given username belongs to the built-in system or anonymous user.Returns a class of the user used by the application.protected TinitJmixUser(org.opensaml.saml.saml2.core.Assertion assertion) Returns an instance of Jmix user, which may be either a new instance or an instance loaded from the user repository.booleanWhether role assignment synchronization is enabled.protected voidperformAdditionalModifications(org.opensaml.saml.saml2.core.Assertion assertion, org.springframework.security.saml2.provider.service.authentication.OpenSaml5AuthenticationProvider.ResponseToken responseToken, T jmixUser) Performs additional modifications of Jmix user instance.protected voidpopulateUserAuthorities(org.opensaml.saml.saml2.core.Assertion assertion, T jmixUser) Fills authorities ofjmixUserbased on information from theassertionprotected voidsaveJmixUserAndRoleAssignments(org.opensaml.saml.saml2.core.Assertion assertion, T jmixUser) Saves Jmix user and synchronizes role assignmentsvoidsetSynchronizeRoleAssignments(boolean synchronizeRoleAssignments) Enables role assignment synchronization.protected voidsetUsernameToNewUser(T jmixUser, String username) Sets the username to a newly created user instance.protected voidupdateRoleAssignmentsSaveContext(List<RoleAssignmentEntity> existingAssignments, List<RoleAssignmentEntity> actualAssignments, SaveContext saveContext) Fills save context with role assignment operations.Methods inherited from class io.jmix.saml.mapper.user.BaseSamlUserMapper
getSamlUsername, initLocks, populateUserAttributes, toJmixUser
-
Field Details
-
dataManager
-
userRepository
-
rolesMapper
-
roleGrantedAuthorityUtils
-
synchronizeRoleAssignments
protected boolean synchronizeRoleAssignments
-
-
Constructor Details
-
SynchronizingSamlUserMapper
public SynchronizingSamlUserMapper()
-
-
Method Details
-
getApplicationUserClass
Returns a class of the user used by the application. This user is set to the security context. -
initJmixUser
Description copied from class:BaseSamlUserMapperReturns an instance of Jmix user, which may be either a new instance or an instance loaded from the user repository. Attributes and authorities will lately be filled in other methods. The responsibility of the current method is just to create or load an existing instance.- Specified by:
initJmixUserin classBaseSamlUserMapper<T extends JmixSamlUserDetails>- Parameters:
assertion- SAML assertion- Returns:
- new Jmix user instance or Jmix user loaded from user repository
-
checkUsernameIsNotReserved
Throws an exception if the given username belongs to the built-in system or anonymous user. Otherwise, an identity provider asserting such a username would map the external user onto a built-in one and persist it. -
setUsernameToNewUser
Sets the username to a newly created user instance. The default implementation writes theusernameentity attribute. Override this method if the application user class stores the login differently. -
populateUserAuthorities
protected void populateUserAuthorities(org.opensaml.saml.saml2.core.Assertion assertion, T jmixUser) Description copied from class:BaseSamlUserMapperFills authorities ofjmixUserbased on information from theassertion- Specified by:
populateUserAuthoritiesin classBaseSamlUserMapper<T extends JmixSamlUserDetails>- Parameters:
assertion- SAML assertionjmixUser- Jmix user instance
-
performAdditionalModifications
protected void performAdditionalModifications(org.opensaml.saml.saml2.core.Assertion assertion, org.springframework.security.saml2.provider.service.authentication.OpenSaml5AuthenticationProvider.ResponseToken responseToken, T jmixUser) Description copied from class:BaseSamlUserMapperPerforms additional modifications of Jmix user instance. Override this method in case you want to do some additional attribute values computations or if you want to do some operations with Jmix user instance, e.g., to store it in the database, like it is done in theSynchronizingSamlUserMapper- Overrides:
performAdditionalModificationsin classBaseSamlUserMapper<T extends JmixSamlUserDetails>- Parameters:
assertion- SAML assertionresponseToken- the object that stores information about the authentication response from SAML providerjmixUser- Jmix user instance
-
saveJmixUserAndRoleAssignments
protected void saveJmixUserAndRoleAssignments(org.opensaml.saml.saml2.core.Assertion assertion, T jmixUser) Saves Jmix user and synchronizes role assignments -
updateRoleAssignmentsSaveContext
protected void updateRoleAssignmentsSaveContext(List<RoleAssignmentEntity> existingAssignments, List<RoleAssignmentEntity> actualAssignments, SaveContext saveContext) Fills save context with role assignment operations.- Parameters:
existingAssignments- Current role assignments in databaseactualAssignments- New role assignments from SAML assertionsaveContext- SaveContext to add remove/save operations
-
buildRoleAssignmentEntities
protected List<RoleAssignmentEntity> buildRoleAssignmentEntities(String username, Collection<? extends org.springframework.security.core.GrantedAuthority> grantedAuthorities) -
isSynchronizeRoleAssignments
public boolean isSynchronizeRoleAssignments()Whether role assignment synchronization is enabled. -
setSynchronizeRoleAssignments
public void setSynchronizeRoleAssignments(boolean synchronizeRoleAssignments) Enables role assignment synchronization. If true then role assignment entities will be stored to the database.When enabled, the identity provider becomes the single source of truth for all role assignments of the user: on every login the assignments stored in the database are replaced with the roles derived from the SAML assertion. Any assignment granted through other means (e.g. manually by an administrator) is removed, because the
SEC_ROLE_ASSIGNMENTtable has no marker distinguishing the origin of an assignment. Do not assign roles manually to users synchronized with this mode.
-