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;
}
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;
}
Aggregations