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);
}
}
}
}
}
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.");
}
}
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);
}
}
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').");
}
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.");
}
}
Aggregations