use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class ServicesManagerBlImpl method getData.
private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource) throws InternalErrorException {
ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
List<Member> members;
members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
HashMap<Member, List<Attribute>> attributes;
try {
attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, true);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
for (Member mem : attributes.keySet()) {
ServiceAttributes serviceAttributes = new ServiceAttributes();
serviceAttributes.addAttributes(attributes.get(mem));
resourceServiceAttributes.addChildElement(serviceAttributes);
}
return resourceServiceAttributes;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class ServicesManagerBlImpl method getDataWithGroups.
private ServiceAttributes getDataWithGroups(PerunSession sess, Service service, Facility facility, Resource resource) throws InternalErrorException {
ServiceAttributes resourceServiceAttributes = new ServiceAttributes();
resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource));
//Add there also voRequiredAttributes for service
try {
Vo resourceVo = getPerunBl().getVosManagerBl().getVoById(sess, resource.getVoId());
resourceServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resourceVo));
} catch (VoNotExistsException ex) {
throw new ConsistencyErrorException("There is missing Vo for existing resource " + resource);
}
ServiceAttributes membersAbstractSA = new ServiceAttributes();
Map<Member, ServiceAttributes> memberAttributes = new HashMap<Member, ServiceAttributes>();
List<Member> members = getPerunBl().getResourcesManagerBl().getAllowedMembers(sess, resource);
HashMap<Member, List<Attribute>> attributes;
try {
attributes = getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, true);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
for (Member mem : attributes.keySet()) {
ServiceAttributes tmpAttributes = new ServiceAttributes();
tmpAttributes.addAttributes(attributes.get(mem));
memberAttributes.put(mem, tmpAttributes);
membersAbstractSA.addChildElement(tmpAttributes);
}
ServiceAttributes groupsAbstractSA = new ServiceAttributes();
List<Group> groups = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
for (Group group : groups) {
groupsAbstractSA.addChildElement(getData(sess, service, facility, resource, group, memberAttributes));
}
//assign abstract services attributes to resource service attributes
resourceServiceAttributes.addChildElement(groupsAbstractSA);
resourceServiceAttributes.addChildElement(membersAbstractSA);
return resourceServiceAttributes;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_defaultUnixGID method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attr = new Attribute(attributeDefinition);
try {
//first phase: if attribute UF:D:defaultUnixGID is set, it has top priority
Attribute defaultUnixGID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, user, AttributesManager.NS_USER_FACILITY_ATTR_DEF + ":defaultUnixGID");
if (defaultUnixGID.getValue() != null) {
Utils.copyAttributeToVirtualAttributeWithValue(defaultUnixGID, attr);
return attr;
}
//second phase: UF:D:defaultUnixGID is not set, module will select unix group name from preffered list
String namespace = (String) sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace").getValue();
if (namespace == null) {
return attr;
}
Attribute userPreferredGroupNames = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":preferredUnixGroupName-namespace:" + namespace);
List<Resource> resources = sess.getPerunBl().getUsersManagerBl().getAllowedResources(sess, facility, user);
if (userPreferredGroupNames.getValue() != null) {
Map<String, Resource> resourcesWithName = new HashMap<>();
for (Resource resource : resources) {
String groupNameForTest = (String) sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGroupName-namespace:" + namespace).getValue();
if (groupNameForTest != null) {
resourcesWithName.put(groupNameForTest, resource);
}
}
List<Member> userMembers = sess.getPerunBl().getMembersManagerBl().getMembersByUser(sess, user);
Map<String, Group> groupsWithName = new HashMap<>();
for (Resource resource : resources) {
List<Group> groupsFromResource = sess.getPerunBl().getGroupsManagerBl().getAssignedGroupsToResource(sess, resource);
for (Group group : groupsFromResource) {
List<Member> groupMembers = sess.getPerunBl().getGroupsManagerBl().getGroupMembers(sess, group);
groupMembers.retainAll(userMembers);
if (!groupMembers.isEmpty()) {
String groupNamesForTest = (String) sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + namespace).getValue();
if (groupNamesForTest != null) {
groupsWithName.put(groupNamesForTest, group);
}
}
}
}
for (String pGroupName : (List<String>) userPreferredGroupNames.getValue()) {
if (resourcesWithName.containsKey(pGroupName)) {
Resource resource = resourcesWithName.get(pGroupName);
Attribute resourceUnixGID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, AttributesManager.NS_RESOURCE_ATTR_DEF + ":unixGID-namespace:" + namespace);
if (resourceUnixGID.getValue() != null) {
Utils.copyAttributeToViAttributeWithoutValue(userPreferredGroupNames, attr);
attr.setValue(resourceUnixGID.getValue());
return attr;
}
}
if (groupsWithName.containsKey(pGroupName)) {
Group group = groupsWithName.get(pGroupName);
Attribute groupUnixGID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGID-namespace:" + namespace);
if (groupUnixGID.getValue() != null) {
Utils.copyAttributeToViAttributeWithoutValue(userPreferredGroupNames, attr);
attr.setValue(groupUnixGID.getValue());
return attr;
}
}
}
}
//third phase: Preferred unix name is not on the facility and it is choosen basicDefaultGID
Attribute basicGid = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, user, AttributesManager.NS_USER_FACILITY_ATTR_DEF + ":basicDefaultGID");
Utils.copyAttributeToVirtualAttributeWithValue(basicGid, attr);
return attr;
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException 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.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_login method getAttributeValue.
@Override
public /**
* Gets the value of the attribute f:login-namespace and then finds the value of the attribute u:login-namespace:[login-namespace]
*/
Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attr = new Attribute(attributeDefinition);
Attribute loginAttribute = null;
try {
// Get the f:login-namespace attribute
Attribute loginNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":login-namespace");
if (loginNamespaceAttribute.getValue() != null) {
// Get the u:login-namespace[loginNamespaceAttribute]
loginAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:" + (String) loginNamespaceAttribute.getValue());
attr = Utils.copyAttributeToVirtualAttributeWithValue(loginAttribute, attr);
} else {
attr.setValue(null);
}
} catch (AttributeNotExistsException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
return attr;
}
Aggregations