Search in sources :

Example 41 with WrongAttributeValueException

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

the class AttributesManagerBlImpl method removeAllAttributes.

public void removeAllAttributes(PerunSession sess, Facility facility, boolean removeAlsoUserFacilityAttributes) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
    removeAllAttributes(sess, facility);
    if (removeAlsoUserFacilityAttributes) {
        List<Attribute> userFacilityAttributes = getUserFacilityAttributesForAnyUser(sess, facility);
        getAttributesManagerImpl().removeAllUserFacilityAttributesForAnyUser(sess, facility);
        getPerunBl().getAuditer().log(sess, "All user-facility attributes removed for {} for any user.", facility);
        for (Attribute attribute : userFacilityAttributes) attribute.setValue(null);
        List<User> facilityUsers = perunBl.getFacilitiesManagerBl().getAllowedUsers(sess, facility);
        for (User user : facilityUsers) {
            try {
                checkAttributesValue(sess, facility, user, userFacilityAttributes);
                this.checkAttributesDependencies(sess, facility, user, userFacilityAttributes);
            } catch (WrongAttributeAssignmentException ex) {
                throw new ConsistencyErrorException(ex);
            }
            for (Attribute attribute : userFacilityAttributes) {
                try {
                    getAttributesManagerImpl().changedAttributeHook(sess, facility, user, new Attribute(attribute));
                } catch (WrongAttributeValueException ex) {
                    //TODO better exception here
                    throw new InternalErrorException(ex);
                } catch (WrongReferenceAttributeValueException ex) {
                    //TODO better exception here
                    throw new InternalErrorException(ex);
                }
            }
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 42 with WrongAttributeValueException

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

the class urn_perun_group_attribute_def_def_collectionID method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl sess, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    String collectionID = null;
    // null attribute
    if (attribute.getValue() == null)
        throw new WrongAttributeValueException(attribute, "Attribute collectionID cannot be null.");
    // wrong type of the attribute
    if (!(attribute.getValue() instanceof String))
        throw new WrongAttributeValueException(attribute, "Wrong type of the attribute. Expected: String");
    collectionID = (String) attribute.getValue();
    if (collectionID.isEmpty()) {
        throw new WrongAttributeValueException(attribute, "Attribute collectionID cannot be empty.");
    }
}
Also used : WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 43 with WrongAttributeValueException

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

the class urn_perun_facility_attribute_def_def_unixGID_namespace method checkAttributeValue.

public void checkAttributeValue(PerunSessionImpl sess, Facility facility, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    if (attribute.getValue() == null)
        throw new WrongAttributeValueException(attribute, "Attribute value can't be null");
    try {
        sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace:" + (String) attribute.getValue());
        sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGID-namespace:" + (String) attribute.getValue());
    } catch (AttributeNotExistsException e) {
        throw new WrongAttributeValueException(attribute, e);
    }
}
Also used : AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 44 with WrongAttributeValueException

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

the class urn_perun_facility_attribute_def_def_scratchDirPermissions method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl perunSession, Facility facility, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    //Null is ok, it means use default permissions in script (probably 0700)
    if (attribute.getValue() == null)
        return;
    String attrValue = (String) attribute.getValue();
    Matcher match = pattern.matcher(attrValue);
    if (!match.matches())
        throw new WrongAttributeValueException(attribute, facility, "Bad format of attribute, (expected something like '750' or '0700').");
}
Also used : Matcher(java.util.regex.Matcher) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 45 with WrongAttributeValueException

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

the class urn_perun_group_attribute_def_def_googleGroupName_namespace method checkAttributeValue.

@Override
public void checkAttributeValue(PerunSessionImpl sess, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    //prepare groupName value variable
    String groupName = null;
    if (attribute.getValue() != null)
        groupName = (String) attribute.getValue();
    if (groupName == null) {
        // if this is group attribute, its ok
        return;
    } else if (!groupName.matches("^[-_a-zA-Z0-9']+$")) {
        throw new WrongAttributeValueException(attribute, group, "GroupName attributte content invalid characters. Allowed are only letters, numbers and characters _ and -.");
    }
    //TODO Check reserved google group names
    //sess.getPerunBl().getModulesUtilsBl().checkReservedGoogleGroupNames(attribute);
    //prepare lists of groups with the same groupName value in the same namespace
    List<Group> groupsWithSameGroupNameInTheSameNamespace = new ArrayList<Group>();
    //Fill lists of groups
    groupsWithSameGroupNameInTheSameNamespace.addAll(sess.getPerunBl().getGroupsManagerBl().getGroupsByAttribute(sess, attribute));
    //If there is no group with same GroupNameInTheSameNamespace, its ok. Remove this group from the list first just to be sure.
    groupsWithSameGroupNameInTheSameNamespace.remove(group);
    if (groupsWithSameGroupNameInTheSameNamespace.isEmpty())
        return;
    else //if any other group with same GroupName in this namespace exists, check if user has right to use this name at least in one of these groups
    {
        boolean haveRights = false;
        for (Group groupWithSameGroupName : groupsWithSameGroupNameInTheSameNamespace) {
            if (AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attribute, groupWithSameGroupName, null)) {
                haveRights = true;
                break;
            }
        }
        //if not, than can't use already used groupName
        if (!haveRights)
            throw new WrongAttributeValueException(attribute, group, "GroupName is already used in this namespace: " + attribute.getFriendlyNameParameter() + " and you haven't right to use it.");
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)135 Attribute (cz.metacentrum.perun.core.api.Attribute)100 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)83 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)82 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)75 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)66 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)54 Matcher (java.util.regex.Matcher)31 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)27 ArrayList (java.util.ArrayList)17 LinkedHashMap (java.util.LinkedHashMap)16 Facility (cz.metacentrum.perun.core.api.Facility)14 Map (java.util.Map)14 Resource (cz.metacentrum.perun.core.api.Resource)12 User (cz.metacentrum.perun.core.api.User)11 Group (cz.metacentrum.perun.core.api.Group)9 Pattern (java.util.regex.Pattern)8 BigDecimal (java.math.BigDecimal)7 List (java.util.List)7 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5