Search in sources :

Example 1 with UserExtSourceAddedToUser

use of cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser in project perun by CESNET.

the class UsersManagerBlImpl method addUserExtSource.

@Override
public UserExtSource addUserExtSource(PerunSession sess, User user, UserExtSource userExtSource) throws UserExtSourceExistsException {
    // Check if the userExtSource already exists
    if (usersManagerImpl.userExtSourceExists(sess, userExtSource)) {
        throw new UserExtSourceExistsException("UserExtSource " + userExtSource + " already exists.");
    }
    // Check if userExtsource is type of IDP (special testing behavior)
    if (userExtSource.getExtSource().getType().equals(ExtSourcesManager.EXTSOURCE_IDP)) {
        // If extSource of this userExtSource is type of IDP, test uniqueness of login in this extSource type for all users
        String login = userExtSource.getLogin();
        List<UserExtSource> userExtSources = getAllUserExtSourcesByTypeAndLogin(sess, ExtSourcesManager.EXTSOURCE_IDP, login);
        if (!userExtSources.stream().allMatch(ues -> ues.getUserId() == user.getId())) {
            if (userExtSources.stream().allMatch(ues -> ues.getUserId() == userExtSources.get(0).getUserId())) {
                // Duplicate identity belongs to different user - block it!!
                throw new InternalErrorException("ExtLogin: " + login + " is already used for extSourceType: " + ExtSourcesManager.EXTSOURCE_IDP);
            } else {
                // more users cannot have the same login
                throw new ConsistencyErrorException("There are " + userExtSources.size() + " extLogins: " + login + " for  extSourceType: " + ExtSourcesManager.EXTSOURCE_IDP);
            }
        }
    }
    userExtSource = getUsersManagerImpl().addUserExtSource(sess, user, userExtSource);
    getPerunBl().getAuditer().log(sess, new UserExtSourceAddedToUser(userExtSource, user));
    return userExtSource;
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserVirtualAttributesModuleImplApi(cz.metacentrum.perun.core.implApi.modules.attributes.UserVirtualAttributesModuleImplApi) Pair(cz.metacentrum.perun.core.api.Pair) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) Vo(cz.metacentrum.perun.core.api.Vo) SpecificUserType(cz.metacentrum.perun.core.api.SpecificUserType) PasswordOperationTimeoutRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordOperationTimeoutRuntimeException) ExtSource(cz.metacentrum.perun.core.api.ExtSource) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) Map(java.util.Map) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) MemberAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException) PasswordCreationFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordCreationFailedException) OwnershipRemovedForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser) BeansUtils(cz.metacentrum.perun.core.api.BeansUtils) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserExtSourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceAlreadyRemovedException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Set(java.util.Set) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) User(cz.metacentrum.perun.core.api.User) OwnershipEnabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser) UserAddedToOwnersOfSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser) PasswordDoesntMatchRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDoesntMatchRuntimeException) UsersPageQuery(cz.metacentrum.perun.core.api.UsersPageQuery) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) LoginNotExistsRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.LoginNotExistsRuntimeException) PasswordStrengthFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthFailedException) UserExtSourceUpdated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceUpdated) PasswordCreationFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordCreationFailedRuntimeException) SpecificUserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserAlreadyRemovedException) AlreadyReservedLoginException(cz.metacentrum.perun.core.api.exceptions.AlreadyReservedLoginException) UserUpdated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserUpdated) SpecificUserOwnerAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.SpecificUserOwnerAlreadyRemovedException) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) IllegalArgumentException(cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser) AlreadyAdminException(cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException) RichUser(cz.metacentrum.perun.core.api.RichUser) PasswordChangeFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordChangeFailedException) Member(cz.metacentrum.perun.core.api.Member) AttributesManager(cz.metacentrum.perun.core.api.AttributesManager) PasswordResetLinkExpiredException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkExpiredException) Utils(cz.metacentrum.perun.core.impl.Utils) InvalidLoginException(cz.metacentrum.perun.core.api.exceptions.InvalidLoginException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PasswordManagerModule(cz.metacentrum.perun.core.implApi.modules.pwdmgr.PasswordManagerModule) Candidate(cz.metacentrum.perun.core.api.Candidate) AuthzResolver(cz.metacentrum.perun.core.api.AuthzResolver) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) MemberNotExistsException(cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException) LoggerFactory(org.slf4j.LoggerFactory) PasswordChangeFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordChangeFailedRuntimeException) UserNotAdminException(cz.metacentrum.perun.core.api.exceptions.UserNotAdminException) LoginNotExistsException(cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) PasswordStrengthFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordStrengthFailedRuntimeException) OwnershipDisabledForSpecificUser(cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Resource(cz.metacentrum.perun.core.api.Resource) UserDeleted(cz.metacentrum.perun.audit.events.UserManagerEvents.UserDeleted) PerunSession(cz.metacentrum.perun.core.api.PerunSession) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Paginated(cz.metacentrum.perun.core.api.Paginated) GenericPasswordManagerModule(cz.metacentrum.perun.core.impl.modules.pwdmgr.GenericPasswordManagerModule) Group(cz.metacentrum.perun.core.api.Group) UsersManagerImplApi(cz.metacentrum.perun.core.implApi.UsersManagerImplApi) PasswordDeletionFailedException(cz.metacentrum.perun.core.api.exceptions.PasswordDeletionFailedException) HashSet(java.util.HashSet) UserCreated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserCreated) UserAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.UserAlreadyRemovedException) PasswordOperationTimeoutException(cz.metacentrum.perun.core.api.exceptions.PasswordOperationTimeoutException) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) RichResource(cz.metacentrum.perun.core.api.RichResource) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) RelationNotExistsException(cz.metacentrum.perun.core.api.exceptions.RelationNotExistsException) ActionType(cz.metacentrum.perun.core.api.ActionType) PasswordDoesntMatchException(cz.metacentrum.perun.core.api.exceptions.PasswordDoesntMatchException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) Host(cz.metacentrum.perun.core.api.Host) PasswordResetLinkNotValidException(cz.metacentrum.perun.core.api.exceptions.PasswordResetLinkNotValidException) AllUserExtSourcesDeletedForUser(cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) PasswordDeletionFailedRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.PasswordDeletionFailedRuntimeException) Collections(java.util.Collections) Status(cz.metacentrum.perun.core.api.Status) AnonymizationNotSupportedException(cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 2 with UserExtSourceAddedToUser

use of cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser in project perun by CESNET.

the class urn_perun_user_attribute_def_virt_loa method resolveVirtualAttributeValueChange.

@Override
public List<AuditEvent> resolveVirtualAttributeValueChange(PerunSessionImpl sess, AuditEvent message) throws AttributeNotExistsException, WrongAttributeAssignmentException {
    List<AuditEvent> resolvingMessages = new ArrayList<>();
    if (message == null)
        return resolvingMessages;
    User user = null;
    try {
        if (message instanceof UserExtSourceAddedToUser) {
            user = ((UserExtSourceAddedToUser) message).getUser();
            sess.getPerunBl().getUsersManagerBl().checkUserExists(sess, user);
            resolvingMessages.add(resolveEvent(sess, user));
        } else if (message instanceof UserExtSourceRemovedFromUser) {
            user = ((UserExtSourceRemovedFromUser) message).getUser();
            sess.getPerunBl().getUsersManagerBl().checkUserExists(sess, user);
            resolvingMessages.add(resolveEvent(sess, user));
        } else if (message instanceof UserExtSourceUpdated) {
            resolvingMessages.add(resolveEvent(sess, sess.getPerunBl().getUsersManagerBl().getUserById(sess, ((UserExtSourceUpdated) message).getUserExtSource().getUserId())));
        }
    } catch (UserNotExistsException e) {
        log.warn("User {} associated with event {} no longer exists while resolving virtual attribute value change for LoA.", user, message.getName());
    }
    return resolvingMessages;
}
Also used : UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) AttributeChangedForUser(cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser) User(cz.metacentrum.perun.core.api.User) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser) UserExtSourceAddedToUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) UserExtSourceUpdated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceUpdated) ArrayList(java.util.ArrayList) AuditEvent(cz.metacentrum.perun.audit.events.AuditEvent) UserExtSourceRemovedFromUser(cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser)

Aggregations

UserExtSourceAddedToUser (cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceAddedToUser)2 UserExtSourceRemovedFromUser (cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceRemovedFromUser)2 UserExtSourceUpdated (cz.metacentrum.perun.audit.events.UserManagerEvents.UserExtSourceUpdated)2 User (cz.metacentrum.perun.core.api.User)2 AttributeChangedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser)1 AuditEvent (cz.metacentrum.perun.audit.events.AuditEvent)1 AllUserExtSourcesDeletedForUser (cz.metacentrum.perun.audit.events.UserManagerEvents.AllUserExtSourcesDeletedForUser)1 OwnershipDisabledForSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipDisabledForSpecificUser)1 OwnershipEnabledForSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipEnabledForSpecificUser)1 OwnershipRemovedForSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.OwnershipRemovedForSpecificUser)1 UserAddedToOwnersOfSpecificUser (cz.metacentrum.perun.audit.events.UserManagerEvents.UserAddedToOwnersOfSpecificUser)1 UserCreated (cz.metacentrum.perun.audit.events.UserManagerEvents.UserCreated)1 UserDeleted (cz.metacentrum.perun.audit.events.UserManagerEvents.UserDeleted)1 UserUpdated (cz.metacentrum.perun.audit.events.UserManagerEvents.UserUpdated)1 ActionType (cz.metacentrum.perun.core.api.ActionType)1 Attribute (cz.metacentrum.perun.core.api.Attribute)1 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)1 AttributesManager (cz.metacentrum.perun.core.api.AttributesManager)1 AuthzResolver (cz.metacentrum.perun.core.api.AuthzResolver)1 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)1