use of cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_myaccessid_persistent_shadow 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(FRIENDLY_NAME_PARAMETER) && attribute.getValue() != null && !attribute.valueAsString().isEmpty()) {
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.", FRIENDLY_NAME_PARAMETER, ex);
} catch (ExtSourceNotExistsException ex) {
throw new InternalErrorException("Attribute: " + FRIENDLY_NAME_PARAMETER + ", IdP external source doesn't exist.", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_vsup method changedAttributeHook.
/**
* When login changes: first set / changed always change eduroam-vsup login too !!
* When login is set add UserExtSource, since logins are generated in Perun.
* When login is set, set also school mail u:d:vsupMail
*
* @param session
* @param user
* @param attribute
* @throws InternalErrorException
* @throws WrongReferenceAttributeValueException
*/
@Override
public void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute) throws WrongReferenceAttributeValueException {
if (attribute.getValue() != null) {
// add UES
ExtSource es;
try {
es = session.getPerunBl().getExtSourcesManagerBl().getExtSourceByName(session, "AD");
} catch (ExtSourceNotExistsException ex) {
throw new InternalErrorException("AD ext source on VŠUP doesn't exists.", ex);
}
try {
session.getPerunBl().getUsersManagerBl().getUserExtSourceByExtLogin(session, es, (String) attribute.getValue());
} catch (UserExtSourceNotExistsException ex) {
// add UES
UserExtSource ues = new UserExtSource(es, 2, (String) attribute.getValue());
try {
session.getPerunBl().getUsersManagerBl().addUserExtSource(session, user, ues);
} catch (UserExtSourceExistsException ex2) {
throw new ConsistencyErrorException(ex2);
}
}
// set eduroam-login
Attribute eduroamLogin = null;
try {
eduroamLogin = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, EDUROAM_VSUP_NAMESPACE);
if (!Objects.equals(attribute.getValue(), eduroamLogin.getValue())) {
eduroamLogin.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, eduroamLogin);
}
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, eduroamLogin, "Mismatch in checking of users VŠUP login and eduroam login.", ex);
}
// set všup school mail
Attribute schoolMail = null;
try {
schoolMail = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, VSUP_MAIL_NAMESPACE);
if (!Objects.equals(attribute.getValue(), schoolMail.getValue())) {
schoolMail.setValue(attribute.getValue() + "@vsup.cz");
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, schoolMail);
}
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, schoolMail, "Mismatch in checking of users VŠUP login and schoolMail.", ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_umbrellaid_persistent_shadow 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(FRIENDLY_NAME_PARAMETER) && attribute.getValue() != null && !attribute.valueAsString().isEmpty()) {
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.", FRIENDLY_NAME_PARAMETER, ex);
} catch (ExtSourceNotExistsException ex) {
throw new InternalErrorException("Attribute: " + FRIENDLY_NAME_PARAMETER + ", IdP external source doesn't exist.", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_studentIdentifiers method processAddUserExtSource.
/**
* Set userExtSource with attributes for member's user if not exists.
*
* @param sess Perun session
* @param group from which appropriate attributes will be obtained
* @param member for which the xtSource with attributes will be processed
*/
private void processAddUserExtSource(PerunSessionImpl sess, Group group, Member member) {
User user = sess.getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
Attribute organizationScope = tryGetAttribute(sess, group, A_G_D_organizationScopeFriendlyName);
if (organizationScope == null || organizationScope.getValue() == null) {
return;
}
Attribute organizationNamespace = this.tryGetAttribute(sess, group, A_G_D_organizationNamespaceFriendlyName);
if (organizationNamespace == null || organizationNamespace.getValue() == null) {
return;
}
Attribute userLoginID = tryGetAttribute(sess, user, A_U_D_loginNamespaceFriendlyNamePrefix + organizationNamespace.valueAsString());
if (userLoginID == null || userLoginID.getValue() == null) {
return;
}
ExtSource extSource = tryGetExtSource(sess, organizationScope.valueAsString());
// Create and set userExtSource if not exists
try {
sess.getPerunBl().getUsersManagerBl().getUserExtSourceByExtLogin(sess, extSource, userLoginID.valueAsString());
} catch (UserExtSourceNotExistsException e) {
UserExtSource ues = new UserExtSource(extSource, userLoginID.valueAsString());
try {
ues = sess.getPerunBl().getUsersManagerBl().addUserExtSource(sess, user, ues);
} catch (UserExtSourceExistsException userExtSourceExistsException) {
// Should not happened
throw new InternalErrorException(e);
}
Attribute schacHomeOrganization = tryGetAttribute(sess, ues, A_UES_D_schacHomeOrganizationFriendlyName);
Attribute eduPersonScopedAffiliation = tryGetAttribute(sess, ues, A_UES_D_eduPersonScopedAffiliationFriendlyName);
Attribute schacPersonalUniqueCode = tryGetAttribute(sess, ues, A_UES_D_schacPersonalUniqueCodeFriendlyName);
schacHomeOrganization.setValue(organizationScope.valueAsString());
eduPersonScopedAffiliation.setValue(affiliationPrefix + organizationScope.valueAsString());
List<String> spucValue = new ArrayList<>();
spucValue.add(studentIdentifiersValuePrefix + organizationScope.valueAsString() + ":" + userLoginID.valueAsString());
schacPersonalUniqueCode.setValue(spucValue);
try {
sess.getPerunBl().getAttributesManagerBl().setAttributes(sess, ues, Arrays.asList(schacHomeOrganization, eduPersonScopedAffiliation, schacPersonalUniqueCode));
} catch (WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException ex) {
// Should not happened
throw new InternalErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException in project perun by CESNET.
the class EgiuiPasswordManagerModule 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, "EGI");
UserExtSource ues = new UserExtSource(extSource, userLogin + "@EGI");
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 + "@EGI") && kerberosLoginsAttr != null) {
kerberosLogins.add(userLogin + "@EGI");
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);
}
Aggregations