Search in sources :

Example 71 with AttributeNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.

the class urn_perun_user_facility_attribute_def_virt_login method setAttributeValue.

@Override
public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    AttributeDefinition userLoginAttributeDefinition;
    try {
        // Get the f:login-namespace attribute
        Attribute loginNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":login-namespace");
        if (loginNamespaceAttribute.getValue() == null) {
            throw new WrongReferenceAttributeValueException(attribute, loginNamespaceAttribute, user, facility, "Facility need to have nonempty login-namespace attribute.");
        }
        userLoginAttributeDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:" + (String) loginNamespaceAttribute.getValue());
    } catch (AttributeNotExistsException e) {
        throw new InternalErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
    Attribute userLoginAttribute = new Attribute(userLoginAttributeDefinition);
    userLoginAttribute.setValue(attribute.getValue());
    try {
        return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userLoginAttribute);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
}
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) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 72 with AttributeNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.

the class urn_perun_user_facility_attribute_def_virt_UID method fillAttribute.

/**
	 * Fills the new UID for the user at the specified facility. First empty slot
	 * in range (minUID, maxUID) is returned.
	 */
@Override
public Attribute fillAttribute(PerunSessionImpl sess, Facility facility, User user, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
    try {
        Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
        Attribute attr = new Attribute(attribute);
        if (uidNamespaceAttribute.getValue() != null) {
            // Get the u:uid-namespace[uidNamespaceAttribute]
            Attribute uidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + (String) uidNamespaceAttribute.getValue());
            uidAttribute = sess.getPerunBl().getAttributesManagerBl().fillAttribute(sess, user, uidAttribute);
            attr.setValue(uidAttribute.getValue());
        } else {
            attr.setValue(null);
        }
        return attr;
    } catch (AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)

Example 73 with AttributeNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.

the class urn_perun_user_facility_attribute_def_virt_UID method getAttributeValue.

/**
	 * Gets the value of the attribute f:uid-namespace and then finds the value of the attribute u:uid-namespace:[uid-namespace]
	 */
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
    Attribute attr = new Attribute(attributeDefinition);
    Attribute uidAttribute = null;
    try {
        // Get the f:uid-namespace attribute
        Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
        if (uidNamespaceAttribute.getValue() != null) {
            // Get the u:uid-namespace[uidNamespaceAttribute]
            uidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + (String) uidNamespaceAttribute.getValue());
            attr = Utils.copyAttributeToVirtualAttributeWithValue(uidAttribute, attr);
        } else {
            attr.setValue(null);
        }
    } catch (AttributeNotExistsException e) {
        throw new ConsistencyErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
    return attr;
}
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) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)

Example 74 with AttributeNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.

the class urn_perun_user_facility_attribute_def_virt_UID method setAttributeValue.

@Override
public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
    AttributeDefinition userUidAttributeDefinition;
    try {
        // Get the f:uid-namespace attribute
        Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
        if (uidNamespaceAttribute.getValue() == null) {
            throw new WrongReferenceAttributeValueException(attribute, uidNamespaceAttribute);
        }
        userUidAttributeDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + (String) uidNamespaceAttribute.getValue());
    } catch (AttributeNotExistsException e) {
        throw new InternalErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
    Attribute userUidAttribute = new Attribute(userUidAttributeDefinition);
    userUidAttribute.setValue(attribute.getValue());
    try {
        return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userUidAttribute);
    } catch (WrongAttributeValueException e) {
        throw new InternalErrorException(e);
    } catch (WrongAttributeAssignmentException e) {
        throw new ConsistencyErrorException(e);
    }
}
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) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 75 with AttributeNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.

the class ModulesUtilsEntryIntegrationTest method setUpFacilityGroupNameAndGIDNamespaceAttributes.

private List<Attribute> setUpFacilityGroupNameAndGIDNamespaceAttributes() throws Exception {
    Attribute facilityGroupNameNamespace = new Attribute();
    Attribute facilityGIDNamespace = new Attribute();
    List<Attribute> attributes = new ArrayList<Attribute>();
    try {
        facilityGIDNamespace = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace"));
        facilityGIDNamespace.setValue(namespace);
    } catch (AttributeNotExistsException ex) {
        facilityGIDNamespace.setNamespace(AttributesManager.NS_FACILITY_ATTR_DEF);
        facilityGIDNamespace.setFriendlyName("unixGID-namespace");
        facilityGIDNamespace.setType(String.class.getName());
        facilityGIDNamespace.setValue(namespace);
        assertNotNull("unable to create group attribute", perun.getAttributesManagerBl().createAttribute(sess, facilityGIDNamespace));
    }
    attributes.add(facilityGIDNamespace);
    try {
        facilityGroupNameNamespace = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGroupName-namespace"));
        facilityGroupNameNamespace.setValue(namespace);
    } catch (AttributeNotExistsException ex) {
        facilityGroupNameNamespace.setNamespace(AttributesManager.NS_FACILITY_ATTR_DEF);
        facilityGroupNameNamespace.setFriendlyName("unixGroupName-namespace");
        facilityGroupNameNamespace.setType(String.class.getName());
        facilityGroupNameNamespace.setValue(namespace);
        assertNotNull("unable to create group attribute", perun.getAttributesManagerBl().createAttribute(sess, facilityGroupNameNamespace));
    }
    attributes.add(facilityGroupNameNamespace);
    return attributes;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList)

Aggregations

AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)138 Attribute (cz.metacentrum.perun.core.api.Attribute)120 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)94 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)81 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)75 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)64 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)59 ArrayList (java.util.ArrayList)30 Resource (cz.metacentrum.perun.core.api.Resource)25 Matcher (java.util.regex.Matcher)19 Facility (cz.metacentrum.perun.core.api.Facility)17 User (cz.metacentrum.perun.core.api.User)17 LinkedHashMap (java.util.LinkedHashMap)15 Group (cz.metacentrum.perun.core.api.Group)14 Map (java.util.Map)13 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)12 List (java.util.List)11 HashSet (java.util.HashSet)8 BigDecimal (java.math.BigDecimal)7 Pattern (java.util.regex.Pattern)6