use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_systemUnixGroupName method checkAttributeValue.
public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
String groupName = (String) attribute.getValue();
Attribute isSystemGroup = new Attribute();
if (groupName == 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 (groupName.matches("^[-_a-zA-Z0-9]*$") != true) {
throw new WrongAttributeValueException(attribute, "String with other chars than numbers, letters or symbols _ and - 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 GID 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 group1GID = new Attribute();
Attribute group2GID = new Attribute();
try {
group1GID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemUnixGID);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute " + A_GR_systemUnixGID + " not exists for group " + group + " and resource " + resource, ex);
}
try {
group2GID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, p.getRight(), p.getLeft(), A_GR_systemUnixGID);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute " + A_GR_systemUnixGID + " not exists for group " + p.getLeft() + " and resource " + p.getRight(), ex);
}
if (facilityForTest.equals(facility) && (group1GID.getValue() != null ? (!group1GID.getValue().equals(group2GID.getValue())) : group2GID != null)) {
throw new WrongAttributeValueException(attribute, "Group name " + groupName + "is allready used by another group-resource and these have not the same GID and GroupName. " + p.getLeft() + " " + p.getRight());
}
}
}
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_googleGroupName method checkAttributeValue.
@Override
public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
Attribute googleGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getGoogleGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
Attribute groupNameAttribute;
try {
groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":googleGroupName-namespace:" + googleGroupNameNamespaceAttribute.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);
}
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_unixGroupName method fillAttribute.
@Override
public Attribute fillAttribute(PerunSessionImpl sess, Resource resource, Group group, AttributeDefinition attributeDefinition) throws InternalErrorException, 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, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + unixGroupNameNamespaceAttribute.getValue());
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
try {
sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, group, 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, group, groupNameAttribute);
attribute.setValue(groupNameAttribute.getValue());
return attribute;
} catch (WrongReferenceAttributeValueException ex) {
return attribute;
}
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_unixGroupName method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Resource resource, Group group, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
Attribute unixGroupNameNamespaceAttribute;
try {
unixGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
} catch (WrongReferenceAttributeValueException ex) {
return attribute;
}
try {
Attribute groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + unixGroupNameNamespaceAttribute.getValue());
attribute = Utils.copyAttributeToVirtualAttributeWithValue(groupNameAttribute, attribute);
return attribute;
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_unixGroupName method setAttributeValue.
@Override
public boolean setAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
Attribute unixGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
try {
Attribute groupNameAttribute = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + unixGroupNameNamespaceAttribute.getValue()));
groupNameAttribute.setValue(attribute.getValue());
return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, group, groupNameAttribute);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new InternalErrorException(ex);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
}
Aggregations