use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_facility_attribute_def_virt_minGID method checkAttributeValue.
public void checkAttributeValue(PerunSessionImpl sess, Facility facility, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
try {
Attribute gidNamespaceAttribute = getUnixGIDNamespaceAttribute(sess, facility);
if (gidNamespaceAttribute.getValue() == null)
throw new WrongReferenceAttributeValueException(attribute, gidNamespaceAttribute);
Attribute namespaceMinGidAttribute = getNamespaceMinGidAttribute(sess, (String) gidNamespaceAttribute.getValue());
sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, (String) gidNamespaceAttribute.getValue(), namespaceMinGidAttribute);
} catch (WrongReferenceAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, ex.getReferenceAttribute());
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_preferredUnixGroupName method checkAttributeValue.
@Override
public void checkAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws WrongAttributeValueException, WrongReferenceAttributeValueException, InternalErrorException, WrongAttributeAssignmentException {
try {
Attribute facilityGroupNameNamespaceAttr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, A_FACILITY_DEF_UNIX_GROUPNAME_NAMESPACE);
if (facilityGroupNameNamespaceAttr.getValue() == null) {
throw new WrongReferenceAttributeValueException(attribute, facilityGroupNameNamespaceAttr, user, facility, facility, null, "GroupName-namespace for racility cannot be null.");
}
String namespace = (String) facilityGroupNameNamespaceAttr.getValue();
Attribute preferredUnixGroupNameAttr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, A_USER_DEF_PREFERRED_UNIX_GROUPNAME_NAMESPACE + namespace);
if (attribute.getValue() != null) {
preferredUnixGroupNameAttr.setValue(attribute.getValue());
sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, user, preferredUnixGroupNameAttr);
}
// Null is ok, can be empty
} catch (AttributeNotExistsException e) {
throw new ConsistencyErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_preferredUnixGroupName method setAttributeValue.
@Override
public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
AttributeDefinition userPreferredGroupNameDefinition;
try {
Attribute facilityGroupNameNamespaceAttr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, A_FACILITY_DEF_UNIX_GROUPNAME_NAMESPACE);
if (facilityGroupNameNamespaceAttr.getValue() == null) {
throw new WrongReferenceAttributeValueException(attribute, facilityGroupNameNamespaceAttr, facility, user, facility, null, "Facility need to have nonempty groupName-namespace attribute.");
}
String namespace = (String) facilityGroupNameNamespaceAttr.getValue();
userPreferredGroupNameDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, A_USER_DEF_PREFERRED_UNIX_GROUPNAME_NAMESPACE + namespace);
} catch (AttributeNotExistsException e) {
throw new ConsistencyErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
}
Attribute userPreferredGroupName = new Attribute(userPreferredGroupNameDefinition);
userPreferredGroupName.setValue(attribute.getValue());
try {
return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userPreferredGroupName);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_systemUnixGID method checkAttributeValue.
public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
Integer gid = (Integer) attribute.getValue();
//Gid should not be null if is system unix group or if less than 1
Attribute isSystemGroup = new Attribute();
if (gid == null) {
try {
isSystemGroup = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemIsUnixGroup);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Not exist Attribute " + A_GR_systemIsUnixGroup + " for group " + group, ex);
}
if (isSystemGroup.getValue() != null && (Integer) isSystemGroup.getValue() == 1) {
throw new WrongReferenceAttributeValueException(attribute, "Attribute cant be null if " + group + " on " + resource + " is system unix group.");
}
} else if (gid < 1) {
throw new WrongAttributeValueException(attribute, "GID number less than 1 is not allowed value.");
}
//Get facility for the resource
Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
//List of pairs (group and resource) which has the attribute with the value
List<Pair<Group, Resource>> listGroupPairsResource = sess.getPerunBl().getGroupsManagerBl().getGroupResourcePairsByAttribute(sess, attribute);
//Searching through all pairs and if is not checking group/resource/attribute, then try for being on the same facility, if yes then throw exception but only if these groups have not the same GroupName too.
for (Pair<Group, Resource> p : listGroupPairsResource) {
if (!p.getLeft().equals(group) || !p.getRight().equals(resource)) {
Facility facilityForTest = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, p.getRight());
Attribute group1GroupName = new Attribute();
Attribute group2GroupName = new Attribute();
try {
group1GroupName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemUnixGroupName);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute " + A_GR_systemUnixGroupName + " not exists for group " + group, ex);
}
try {
group2GroupName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, p.getRight(), p.getLeft(), A_GR_systemUnixGroupName);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute " + A_GR_systemUnixGroupName + " not exists for group " + p.getLeft(), ex);
}
if (facilityForTest.equals(facility) && !(group1GroupName.getValue().equals(group2GroupName.getValue())))
throw new WrongAttributeValueException(attribute, "Gid " + gid + "is allready used by another group-resource. " + p.getLeft() + " " + p.getRight());
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_unixGroupName method checkAttributeValue.
@Override
public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
Attribute unixGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
Attribute groupNameAttribute;
try {
groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + unixGroupNameNamespaceAttribute.getValue());
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
groupNameAttribute.setValue(attribute.getValue());
try {
sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, group, groupNameAttribute);
} catch (WrongAttributeValueException ex) {
throw new WrongAttributeValueException(attribute, ex.getMessage(), ex);
} catch (WrongReferenceAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, ex.getAttribute(), ex);
}
}
Aggregations