use of cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException in project perun by CESNET.
the class SitolaPasswordManagerModule method validatePassword.
@Override
public void validatePassword(PerunSession sess, String userLogin, User user) throws InvalidLoginException {
if (user == null) {
user = ((PerunBl) sess.getPerun()).getModulesUtilsBl().getUserByLoginInNamespace(sess, userLogin, actualLoginNamespace);
}
if (user == null) {
log.warn("No user was found by login '{}' in {} namespace.", userLogin, actualLoginNamespace);
} else {
// set extSources and extSource related attributes
try {
List<String> kerberosLogins = new ArrayList<>();
ExtSource extSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, "SITOLA.FI.MUNI.CZ");
UserExtSource ues = new UserExtSource(extSource, userLogin + "@SITOLA.FI.MUNI.CZ");
ues.setLoa(0);
try {
((PerunBl) sess.getPerun()).getUsersManagerBl().addUserExtSource(sess, user, ues);
} catch (UserExtSourceExistsException ex) {
// this is OK
}
// Store also Kerberos logins
Attribute kerberosLoginsAttr = ((PerunBl) sess.getPerun()).getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":" + "kerberosLogins");
if (kerberosLoginsAttr != null && kerberosLoginsAttr.getValue() != null) {
kerberosLogins.addAll((List<String>) kerberosLoginsAttr.getValue());
}
if (!kerberosLogins.contains(userLogin + "@SITOLA.FI.MUNI.CZ") && kerberosLoginsAttr != null) {
kerberosLogins.add(userLogin + "@SITOLA.FI.MUNI.CZ");
kerberosLoginsAttr.setValue(kerberosLogins);
((PerunBl) sess.getPerun()).getAttributesManagerBl().setAttribute(sess, user, kerberosLoginsAttr);
}
} catch (WrongAttributeAssignmentException | AttributeNotExistsException | ExtSourceNotExistsException | WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
}
}
// validate password
super.validatePassword(sess, userLogin, user);
}
use of cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException in project perun by CESNET.
the class VsupPasswordManagerModule method validatePassword.
@Override
public void validatePassword(PerunSession sess, String userLogin, User user) throws InvalidLoginException {
if (user == null) {
user = ((PerunBl) sess.getPerun()).getModulesUtilsBl().getUserByLoginInNamespace(sess, userLogin, actualLoginNamespace);
}
if (user == null) {
log.warn("No user was found by login '{}' in {} namespace.", userLogin, actualLoginNamespace);
} else {
// set extSources and extSource related attributes
try {
// Add UES in their ActiveDirectory to access Perun by it
ExtSource extSource = ((PerunBl) sess.getPerun()).getExtSourcesManagerBl().getExtSourceByName(sess, "AD");
UserExtSource ues = new UserExtSource(extSource, userLogin);
ues.setLoa(0);
try {
((PerunBl) sess.getPerun()).getUsersManagerBl().addUserExtSource(sess, user, ues);
} catch (UserExtSourceExistsException ex) {
// this is OK
}
} catch (ExtSourceNotExistsException ex) {
throw new InternalErrorException(ex);
}
}
// validate password
super.validatePassword(sess, userLogin, user);
}
use of cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException in project perun by CESNET.
the class UserPersistentShadowAttribute method changedAttributeHook.
/**
* ChangedAttributeHook() sets UserExtSource with following properties:
* - extSourceType is IdP
* - extSourceName is {getExtSourceName()}
* - user's extSource login is the same as his persistent attribute
*/
@Override
public void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute) {
try {
String userNamespace = attribute.getFriendlyNameParameter();
if (userNamespace.equals(getFriendlyNameParameter()) && attribute.getValue() != null) {
ExtSource extSource = session.getPerunBl().getExtSourcesManagerBl().getExtSourceByName(session, getExtSourceName());
UserExtSource userExtSource = new UserExtSource(extSource, 0, attribute.getValue().toString());
session.getPerunBl().getUsersManagerBl().addUserExtSource(session, user, userExtSource);
}
} catch (UserExtSourceExistsException ex) {
log.warn("Attribute: {}, External source already exists for the user.", getFriendlyNameParameter(), ex);
} catch (ExtSourceNotExistsException ex) {
throw new InternalErrorException("Attribute: " + getFriendlyNameParameter() + ", IdP external source doesn't exist.", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException 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.core.api.exceptions.UserExtSourceExistsException in project perun by CESNET.
the class UsersManagerBlImpl method moveUserExtSource.
@Override
public void moveUserExtSource(PerunSession sess, User sourceUser, User targetUser, UserExtSource userExtSource) {
List<Attribute> userExtSourceAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, userExtSource);
// remove all virtual attributes (we don't need to take care about them)
userExtSourceAttributes.removeIf(attribute -> getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute));
// cannot move duplicated IDPs
if (Objects.equals(userExtSource.getExtSource().getType(), ExtSourcesManager.EXTSOURCE_IDP) && getAllUserExtSourcesByTypeAndLogin(sess, ExtSourcesManager.EXTSOURCE_IDP, userExtSource.getLogin()).size() > 1) {
throw new InternalErrorException("IDP UserExtSource " + userExtSource + " with duplicated login cannot be moved.");
}
// remove userExtSource
try {
this.removeUserExtSource(sess, sourceUser, userExtSource);
} catch (UserExtSourceAlreadyRemovedException ex) {
// this is little weird, will be better to report exception
throw new InternalErrorException("UserExtSource was unexpectedly removed while moving " + userExtSource + " from " + sourceUser + " to " + targetUser);
}
// change userId for userExtSource
userExtSource.setUserId(targetUser.getId());
// add userExtSource to the targetUser
try {
userExtSource = this.addUserExtSource(sess, targetUser, userExtSource);
} catch (UserExtSourceExistsException ex) {
// someone moved this UserExtSource before us
throw new InternalErrorException("Moving " + userExtSource + " from " + sourceUser + " to " + targetUser + " failed because someone already moved this UserExtSource.", ex);
}
// set all attributes back to this UserExtSource when it is already assigned to the targetUser
try {
getPerunBl().getAttributesManagerBl().setAttributes(sess, userExtSource, userExtSourceAttributes);
} catch (WrongAttributeAssignmentException | WrongReferenceAttributeValueException | WrongAttributeValueException ex) {
throw new InternalErrorException("Moving " + userExtSource + " from " + sourceUser + " to " + targetUser + " failed because of problem with setting removed attributes back to the UserExtSource.", ex);
}
}
Aggregations