use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class RTMessagesManagerBlImpl method findUserPreferredEmail.
private String findUserPreferredEmail(PerunSession sess, User user) throws InternalErrorException {
String email = null;
Attribute userPreferredMail = null;
try {
userPreferredMail = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, "urn:perun:user:attribute-def:def:preferredMail");
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
if (userPreferredMail == null || userPreferredMail.getValue() == null) {
try {
userPreferredMail = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, "urn:perun:user:attribute-def:def:mail");
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
if (userPreferredMail != null && userPreferredMail.getValue() != null) {
email = (String) userPreferredMail.getValue();
}
return email;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_login_namespace_elixir_persistent method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute elixirPersistent = new Attribute(attributeDefinition);
try {
Attribute elixirPersistentShadow = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, SHADOW);
if (elixirPersistentShadow.getValue() == null) {
elixirPersistentShadow = sess.getPerunBl().getAttributesManagerBl().fillAttribute(sess, user, elixirPersistentShadow);
if (elixirPersistentShadow.getValue() == null) {
throw new InternalErrorException("Elixir id couldn't be set automatically");
}
sess.getPerunBl().getAttributesManagerBl().setAttribute(sess, user, elixirPersistentShadow);
}
elixirPersistent.setValue(elixirPersistentShadow.getValue());
return elixirPersistent;
} catch (WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
} catch (AttributeNotExistsException e) {
throw new InternalErrorException(e);
} catch (WrongReferenceAttributeValueException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_vsupPreferredMail method changedAttributeHook.
@Override
public void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
// map of reserved vsup mails
Attribute reservedMailsAttribute;
Map<String, String> reservedMailsAttributeValue;
// other vsup mail attributes to get values from
Attribute vsupMailAttribute;
Attribute vsupMailAliasAttribute;
Attribute mailAliasesAttribute;
// output sets used for comparison
Set<String> reservedMailsOfUser = new HashSet<>();
Set<String> actualMailsOfUser = new HashSet<>();
try {
reservedMailsAttribute = session.getPerunBl().getAttributesManagerBl().getEntitylessAttributeForUpdate(session, usedMailsKeyVsup, usedMailsUrn);
vsupMailAttribute = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, vsupMailUrn);
mailAliasesAttribute = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, vsupMailAliasesUrn);
vsupMailAliasAttribute = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, vsupMailAliasUrn);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute doesn't exists.", ex);
} catch (WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
}
if (attribute.getValue() == null && reservedMailsAttribute.getValue() == null) {
throw new ConsistencyErrorException("Entityless attribute 'urn:perun:entityless:attribute-def:def:usedMails' is empty, but we are removing 'vsupPreferredMail' value, so there should have been entry in entityless attribute.");
}
if (reservedMailsAttribute.getValue() == null) {
reservedMailsAttributeValue = new LinkedHashMap<>();
} else {
reservedMailsAttributeValue = (Map<String, String>) reservedMailsAttribute.getValue();
}
// if SET action and mail is already reserved by other user
if (attribute.getValue() != null) {
String ownersUserId = reservedMailsAttributeValue.get((String) attribute.getValue());
if (ownersUserId != null && !Objects.equals(ownersUserId, String.valueOf(user.getId()))) {
// TODO - maybe get actual owners attribute and throw WrongReferenceAttributeException to be nice in a GUI ?
throw new InternalErrorException("VŠUP preferred mail: '" + attribute.getValue() + "' is already in use by User ID: " + ownersUserId + ".");
}
}
for (Map.Entry<String, String> entry : reservedMailsAttributeValue.entrySet()) {
if (Objects.equals(entry.getValue(), String.valueOf(user.getId()))) {
// reserved mails of a user
reservedMailsOfUser.add(entry.getKey());
}
}
if (vsupMailAttribute.getValue() != null) {
actualMailsOfUser.add((String) vsupMailAttribute.getValue());
}
if (vsupMailAliasAttribute.getValue() != null) {
actualMailsOfUser.add((String) vsupMailAliasAttribute.getValue());
}
if (mailAliasesAttribute.getValue() != null) {
actualMailsOfUser.addAll((ArrayList<String>) mailAliasesAttribute.getValue());
}
for (String mail : reservedMailsOfUser) {
if (!actualMailsOfUser.contains(mail)) {
// Remove mail, which is not in attributes anymore
reservedMailsAttributeValue.remove(mail);
// since this attribute holds single value, we can break the cycle here
break;
}
}
// Put in which is in attribute but not in a map
if (attribute.getValue() != null) {
reservedMailsAttributeValue.putIfAbsent((String) attribute.getValue(), String.valueOf(user.getId()));
}
// save changes in entityless attribute
try {
// always set value to attribute, since we might start with null in attribute and empty map in variable !!
reservedMailsAttribute.setValue(reservedMailsAttributeValue);
session.getPerunBl().getAttributesManagerBl().setAttribute(session, usedMailsKeyVsup, reservedMailsAttribute);
} catch (WrongAttributeValueException | WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
// update user:preferredMail so admin can see users preferred mail in GUI.
try {
if (attribute.getValue() != null) {
Attribute userPreferredMail = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, "urn:perun:user:attribute-def:def:preferredMail");
if (!Objects.equals(userPreferredMail.getValue(), attribute.getValue())) {
// if preferred mail is different, update user:preferredMail
userPreferredMail.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPreferredMail);
}
}
} catch (WrongAttributeValueException | WrongAttributeAssignmentException | AttributeNotExistsException ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_vomsDiracNickname method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
try {
Attribute loginInEgiui = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:egi-ui");
attribute = Utils.copyAttributeToVirtualAttributeWithValue(loginInEgiui, attribute);
} catch (AttributeNotExistsException ex) {
//That means that egi-ui attribute not exists at all, return empty attribute
return attribute;
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
return attribute;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_optionalLogin_namespace_mu method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
try {
Attribute loginInMU = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:mu");
attribute = Utils.copyAttributeToVirtualAttributeWithValue(loginInMU, attribute);
} catch (AttributeNotExistsException ex) {
//That means that mu login attribute not exists at all
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
//if attribute is still null (empty login in mu or not existing attribute), try to find uco in user ext sources
if (attribute.getValue() == null) {
List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
for (UserExtSource userExtSource : userExtSources) {
ExtSource extSource = userExtSource.getExtSource();
//Skip if extSource is not the one we are looking for
if (userExtSource.getLogin() == null || extSource == null)
continue;
if (!ExtSourcesManager.EXTSOURCE_IDP.equals(extSource.getType()))
continue;
if (!EXTSOURCE_MUNI_IDP2.equals(extSource.getName()))
continue;
//Get login from this extSource and get only UCO from it
String login = userExtSource.getLogin();
Matcher loginMUMatcher = loginMUPattern.matcher(login);
//This user has login in mu, but in weird format so skip this one
if (!loginMUMatcher.find())
continue;
//It is ok, take UCO from login and set it to attribute value
String UCO = loginMUMatcher.group(1);
attribute.setValue(UCO);
break;
}
}
return attribute;
}
Aggregations