use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_cesnet_eduroam method fillAttribute.
/**
* Fills login based on counter of IDs for cesnet-eduroam namespace.
*
* @param perunSession PerunSession
* @param user User to fill attribute for
* @param attribute Attribute to fill value to
* @return Filled attribute
* @throws InternalErrorException
*/
@Override
public Attribute fillAttribute(PerunSessionImpl perunSession, User user, AttributeDefinition attribute) {
// Get attribute with login of user in namespace cesnet-eduroam
Attribute filledAttribute = new Attribute(attribute);
// Get IDs counter and lock its value
Attribute idsCounter;
try {
idsCounter = perunSession.getPerunBl().getAttributesManagerBl().getEntitylessAttributeForUpdate(perunSession, cesnet_eduroam_key, CESNET_EDUROAM_IDS_COUNTER);
} catch (AttributeNotExistsException e) {
throw new ConsistencyErrorException("Attribute doesn't exists.", e);
}
Integer counterValue;
// Get value of counter to integer or set it to 1000, if counter is empty
if (idsCounter.getValue() == null) {
counterValue = 1000;
} else {
counterValue = (Integer) idsCounter.getValue();
}
// Set login of user in namespace cesnet-eduroam with value of counter
filledAttribute.setValue(counterValue.toString());
// Increment value of counter
counterValue++;
// Save changes in entityless attribute and unlock it
try {
idsCounter.setValue(counterValue);
perunSession.getPerunBl().getAttributesManagerBl().setAttribute(perunSession, cesnet_eduroam_key, idsCounter);
} catch (WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
}
return filledAttribute;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_einfra method checkAttributeSemantics.
/**
* Checks if the user's login is unique in the namespace organization
*
* @param sess PerunSession
* @param user User to check attribute for
* @param attribute Attribute to check value to
* @throws InternalErrorException
* @throws WrongReferenceAttributeValueException
* @throws WrongAttributeAssignmentException
*/
@Override
public void checkAttributeSemantics(PerunSessionImpl sess, User user, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
if (attribute.getValue() == null)
throw new WrongReferenceAttributeValueException(attribute, null, user, null, "Value can't be null");
boolean ignoreCase = !allowCaseIgnoreCollision(attribute.getValue().toString());
List<User> usersWithSameLogin = sess.getPerunBl().getUsersManagerBl().getUsersByAttribute(sess, attribute, ignoreCase);
// remove self
usersWithSameLogin.remove(user);
if (!usersWithSameLogin.isEmpty()) {
if (usersWithSameLogin.size() > 1)
throw new ConsistencyErrorException("FATAL ERROR: Duplicated Login detected." + attribute + " " + usersWithSameLogin);
throw new WrongReferenceAttributeValueException(attribute, attribute, user, null, usersWithSameLogin.get(0), null, "This login " + attribute.getValue() + " is already occupied.");
}
try {
sess.getPerunBl().getUsersManagerBl().checkReservedLogins(sess, attribute.getFriendlyNameParameter(), attribute.valueAsString(), ignoreCase);
} catch (AlreadyReservedLoginException ex) {
throw new WrongReferenceAttributeValueException(attribute, null, user, null, null, null, "Login in specific namespace already reserved.", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace method checkAttributeSemantics.
/**
* Checks if the user's login is unique in the namespace organization
*
* @param sess PerunSession
* @param user User to check attribute for
* @param attribute Attribute to check value to
* @throws cz.metacentrum.perun.core.api.exceptions.InternalErrorException
* @throws cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException
* @throws cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException
*/
@Override
public void checkAttributeSemantics(PerunSessionImpl sess, User user, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
String userLogin = attribute.valueAsString();
if (userLogin == null)
throw new WrongReferenceAttributeValueException(attribute, null, user, null, "Value can't be null");
// Get all users who have set attribute urn:perun:member:attribute-def:def:login-namespace:[login-namespace], with the value.
List<User> usersWithSameLogin = sess.getPerunBl().getUsersManagerBl().getUsersByAttribute(sess, attribute);
// remove self
usersWithSameLogin.remove(user);
if (!usersWithSameLogin.isEmpty()) {
if (usersWithSameLogin.size() > 1)
throw new ConsistencyErrorException("FATAL ERROR: Duplicated Login detected." + attribute + " " + usersWithSameLogin);
throw new WrongReferenceAttributeValueException(attribute, attribute, user, null, usersWithSameLogin.get(0), null, "This login " + attribute.getValue() + " is already occupied.");
}
try {
sess.getPerunBl().getUsersManagerBl().checkReservedLogins(sess, attribute.getFriendlyNameParameter(), userLogin, false);
} catch (AlreadyReservedLoginException ex) {
throw new WrongReferenceAttributeValueException(attribute, null, user, null, null, null, "Login in specific namespace already reserved.", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_resource_attribute_def_virt_unixGroupName method fillAttribute.
@Override
public Attribute fillAttribute(PerunSessionImpl sess, Resource resource, AttributeDefinition attributeDefinition) throws WrongAttributeAssignmentException {
Attribute attribute = new Attribute(attributeDefinition);
Attribute unixGroupNameNamespaceAttribute;
try {
unixGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
} catch (WrongReferenceAttributeValueException ex) {
return attribute;
}
Attribute groupNameAttribute;
try {
groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_unixGroupName_namespace + unixGroupNameNamespaceAttribute.getValue());
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
try {
sess.getPerunBl().getAttributesManagerBl().checkAttributeSyntax(sess, resource, groupNameAttribute);
sess.getPerunBl().getAttributesManagerBl().checkAttributeSemantics(sess, resource, groupNameAttribute);
// check passed, we can use value from this physical attribute
attribute.setValue(groupNameAttribute.getValue());
return attribute;
} catch (WrongAttributeValueException ex) {
// Physical attribute have wrong value, let's find a new one
groupNameAttribute.setValue(null);
groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().fillAttribute(sess, resource, groupNameAttribute);
attribute.setValue(groupNameAttribute.getValue());
return attribute;
} catch (WrongReferenceAttributeValueException ex) {
return attribute;
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_cnCeitecAD method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl perunSession, User user, Attribute attribute) throws WrongReferenceAttributeValueException {
if (attribute.getValue() == null) {
throw new WrongReferenceAttributeValueException(attribute, null, user, null, "Value can't be null");
}
// check existing DN
Set<User> usersWithSameCN = new HashSet<>(perunSession.getPerunBl().getUsersManagerBl().getUsersByAttribute(perunSession, attribute));
// check existing DN without accents
String normalizedValue = java.text.Normalizer.normalize((String) attribute.getValue(), java.text.Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
if (!Objects.equals(normalizedValue, attribute.getValue())) {
Attribute changedAttribute = new Attribute(attribute);
changedAttribute.setValue(normalizedValue);
usersWithSameCN.addAll(perunSession.getPerunBl().getUsersManagerBl().getUsersByAttribute(perunSession, changedAttribute));
}
// remove self
usersWithSameCN.remove(user);
if (!usersWithSameCN.isEmpty()) {
if (usersWithSameCN.size() > 1)
throw new ConsistencyErrorException("FATAL ERROR: Duplicated CN detected." + attribute + " " + usersWithSameCN);
throw new WrongReferenceAttributeValueException(attribute, attribute, user, null, usersWithSameCN.iterator().next(), null, "This CN " + attribute.getValue() + " is already occupied for CEITEC AD");
}
}
Aggregations