use of cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_o365EmailAddresses_mu method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
List<String> emails = attribute.valueAsList();
if (emails == null)
emails = new ArrayList<>();
// at least one value if adName is set
AttributesManagerBl am = sess.getPerunBl().getAttributesManagerBl();
try {
if (emails.isEmpty()) {
Attribute adName = am.getAttribute(sess, resource, group, ADNAME_ATTRIBUTE);
if (adName.getValue() != null) {
throw new WrongReferenceAttributeValueException(attribute, adName, resource, group, resource, group, "at least one email must be defined");
}
return;
}
} catch (AttributeNotExistsException | GroupResourceMismatchException e) {
throw new InternalErrorException(e.getMessage(), e);
}
// check for duplicities among all members and groups
AttributesManagerBl attributesManagerBl = sess.getPerunBl().getAttributesManagerBl();
Set<Pair<Integer, Integer>> groupResourcePairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, attribute);
groupResourcePairs.remove(new Pair<>(group.getId(), resource.getId()));
if (!groupResourcePairs.isEmpty()) {
throw new WrongReferenceAttributeValueException(attribute, attribute, group, resource, "some of the email addresses are already assigned to the following group_resource pairs: " + groupResourcePairs);
}
Attribute userO365EmailAddresses = new Attribute(new urn_perun_user_attribute_def_def_o365UserEmailAddresses_mu().getAttributeDefinition());
userO365EmailAddresses.setValue(emails);
Set<Pair<Integer, Integer>> userPairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, userO365EmailAddresses);
if (!userPairs.isEmpty()) {
throw new WrongReferenceAttributeValueException(attribute, userO365EmailAddresses, group, resource, "user " + BeansUtils.getSingleId(userPairs) + " ");
}
}
use of cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_projectName method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
String name = attribute.valueAsString();
if (name == null)
return;
// Prepare this resource projectsBasePath
Attribute thisResourceProjectsBasePath;
try {
thisResourceProjectsBasePath = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_projectsBasePath);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute projectBasePath not exists!", ex);
}
// Prepare value of this resource projectsBasePath
String thisResourceProjectBasePathValue;
if (thisResourceProjectsBasePath.getValue() != null) {
thisResourceProjectBasePathValue = thisResourceProjectsBasePath.valueAsString();
} else {
throw new WrongReferenceAttributeValueException(attribute, thisResourceProjectsBasePath, group, resource, resource, null, "Resource must have set projectsBasePath if attribute projectName for it's group need to be set.");
}
// Get All Resources with the same project_base_path
Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<Resource> resources = sess.getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
resources.remove(resource);
// Remove all resources which has other
Iterator<Resource> iterator = resources.iterator();
while (iterator.hasNext()) {
Resource r = iterator.next();
Attribute otherResourceProjectsBasePath;
try {
otherResourceProjectsBasePath = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, A_R_projectsBasePath);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute projectBasePath not exists!", ex);
}
if (otherResourceProjectsBasePath.getValue() != null) {
String otherResourceProjectsBasePathValue = otherResourceProjectsBasePath.valueAsString();
if (!thisResourceProjectBasePathValue.equals(otherResourceProjectsBasePathValue))
iterator.remove();
} else {
// If projectsBasePath is null, also remove resource
iterator.remove();
}
}
// For all resources with the same project_base_path look for groups with the same projectName
for (Resource r : resources) {
List<Group> groups = sess.getPerunBl().getGroupsManagerBl().getAssignedGroupsToResource(sess, r);
// Our group may also be part of assigned Group, so it needs to be removed
groups.remove(group);
for (Group g : groups) {
Attribute groupProjectName;
try {
groupProjectName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, g, A_GR_projectName);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute projectName not exists!", ex);
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
String groupProjectNameValue = null;
if (groupProjectName.getValue() != null) {
groupProjectNameValue = groupProjectName.valueAsString();
}
// If the name is somewhere same, exception must be thrown
if (name.equals(groupProjectNameValue)) {
throw new WrongReferenceAttributeValueException(attribute, groupProjectName, group, resource, g, r, "Group " + group + " and " + g + " have the same projectName in the same projectsBasePath.");
}
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_systemUnixGID method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
Integer gid = attribute.valueAsInteger();
// Gid should not be null if is system unix group or if less than 1
Attribute isSystemGroup;
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);
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
if (isSystemGroup.getValue() != null && isSystemGroup.valueAsInteger() == 1) {
throw new WrongReferenceAttributeValueException(attribute, isSystemGroup, group, resource, "Attribute cant be null if " + group + " on " + resource + " is system unix group.");
}
}
// 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;
Attribute group2GroupName;
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);
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(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);
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
if (facilityForTest.equals(facility) && !(group1GroupName.getValue().equals(group2GroupName.getValue())))
throw new WrongReferenceAttributeValueException(attribute, attribute, group, resource, "Gid " + gid + "is already used by another group-resource. " + p.getLeft() + " " + p.getRight());
}
}
}
Aggregations