Search in sources :

Example 61 with WrongAttributeAssignmentException

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;
}
Also used : ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Member(cz.metacentrum.perun.core.api.Member)

Example 62 with WrongAttributeAssignmentException

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;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) HashMap(java.util.HashMap) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) VoNotExistsException(cz.metacentrum.perun.core.api.exceptions.VoNotExistsException) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) Vo(cz.metacentrum.perun.core.api.Vo) List(java.util.List) ArrayList(java.util.ArrayList) Member(cz.metacentrum.perun.core.api.Member)

Example 63 with WrongAttributeAssignmentException

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);
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) HashMap(java.util.HashMap) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ArrayList(java.util.ArrayList) List(java.util.List) Member(cz.metacentrum.perun.core.api.Member)

Example 64 with WrongAttributeAssignmentException

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);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 65 with WrongAttributeAssignmentException

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;
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)127 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)97 Attribute (cz.metacentrum.perun.core.api.Attribute)95 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)61 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)59 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)55 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)52 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)42 User (cz.metacentrum.perun.core.api.User)31 ArrayList (java.util.ArrayList)31 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)14 Facility (cz.metacentrum.perun.core.api.Facility)14 LinkedHashMap (java.util.LinkedHashMap)11 Member (cz.metacentrum.perun.core.api.Member)10 Map (java.util.Map)9 Group (cz.metacentrum.perun.core.api.Group)8 List (java.util.List)8 Resource (cz.metacentrum.perun.core.api.Resource)7 Vo (cz.metacentrum.perun.core.api.Vo)6 HashMap (java.util.HashMap)6