Search in sources :

Example 56 with ConsistencyErrorException

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;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 57 with ConsistencyErrorException

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);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AlreadyReservedLoginException(cz.metacentrum.perun.core.api.exceptions.AlreadyReservedLoginException)

Example 58 with ConsistencyErrorException

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);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AlreadyReservedLoginException(cz.metacentrum.perun.core.api.exceptions.AlreadyReservedLoginException)

Example 59 with ConsistencyErrorException

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;
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 60 with ConsistencyErrorException

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");
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) HashSet(java.util.HashSet)

Aggregations

ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)281 Attribute (cz.metacentrum.perun.core.api.Attribute)212 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)162 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)120 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)111 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)102 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)84 User (cz.metacentrum.perun.core.api.User)60 ArrayList (java.util.ArrayList)51 Group (cz.metacentrum.perun.core.api.Group)44 Facility (cz.metacentrum.perun.core.api.Facility)41 Resource (cz.metacentrum.perun.core.api.Resource)37 Member (cz.metacentrum.perun.core.api.Member)30 LinkedHashMap (java.util.LinkedHashMap)23 Vo (cz.metacentrum.perun.core.api.Vo)22 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)21 GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)20 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)19 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)17 VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)17