Search in sources :

Example 1 with Member

use of cz.metacentrum.perun.core.api.Member 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 2 with Member

use of cz.metacentrum.perun.core.api.Member in project perun by CESNET.

the class Utils method generateAllGroupsToWriter.

/**
	 * Method generate all Groups to the text for using in LDIF.
	 * Write all these information to writer in perunInitializer object.
	 *
	 * @param perunInitializer need to be loaded to get all needed dependencies
	 *
	 * @throws InternalErrorException if some problem with initializer or objects in perun-core
	 * @throws IOException if some problem with writer
	 */
public static void generateAllGroupsToWriter(PerunInitializer perunInitializer) throws InternalErrorException, IOException {
    //Load basic variables
    if (perunInitializer == null)
        throw new InternalErrorException("PerunInitializer must be loaded before using in generating methods!");
    PerunSession perunSession = perunInitializer.getPerunSession();
    PerunBl perun = perunInitializer.getPerunBl();
    BufferedWriter writer = perunInitializer.getOutputWriter();
    //First get all vos
    List<Vo> vos = perun.getVosManagerBl().getVos(perunSession);
    //Then from all vos get all assigned groups and generate data about them to the writer
    for (Vo vo : vos) {
        List<Group> groups;
        groups = perun.getGroupsManagerBl().getGroups(perunSession, vo);
        for (Group group : groups) {
            String dn = "dn: ";
            String oc1 = "objectclass: top";
            String oc3 = "objectclass: perunGroup";
            String cn = "cn: ";
            String perunVoId = "perunVoId: ";
            String parentGroup = "perunParentGroup: ";
            String parentGroupId = "perunParentGroupId: ";
            String perunGroupId = "perunGroupId: ";
            String owner = "owner: ";
            String description = "description: ";
            String perunUniqueGroupName = "perunUniqueGroupName: ";
            List<Member> members;
            members = perun.getGroupsManagerBl().getGroupMembers(perunSession, group, Status.VALID);
            perunGroupId += String.valueOf(group.getId());
            perunVoId += String.valueOf(group.getVoId());
            dn += "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + ",dc=perun,dc=cesnet,dc=cz";
            cn += group.getName();
            perunUniqueGroupName += vo.getShortName() + ":" + group.getName();
            if (group.getDescription() != null)
                description += group.getDescription();
            if (group.getParentGroupId() != null) {
                parentGroupId += group.getParentGroupId();
                parentGroup += "perunGroupId=" + group.getParentGroupId() + ",perunVoId=" + group.getVoId() + ",dc=perun,dc=cesnet,dc=cz";
            }
            List<Member> admins = new ArrayList<>();
            writer.write(dn + '\n');
            writer.write(oc1 + '\n');
            writer.write(oc3 + '\n');
            writer.write(cn + '\n');
            writer.write(perunUniqueGroupName + '\n');
            writer.write(perunGroupId + '\n');
            writer.write(perunVoId + '\n');
            if (group.getDescription() != null)
                writer.write(description + '\n');
            if (group.getParentGroupId() != null) {
                writer.write(parentGroupId + '\n');
                writer.write(parentGroup + '\n');
            }
            //ADD Group Members
            for (Member m : members) {
                writer.write("uniqueMember: " + "perunUserId=" + m.getUserId() + ",ou=People,dc=perun,dc=cesnet,dc=cz");
                writer.write('\n');
            }
            //ADD resources which group is assigned to
            List<Resource> associatedResources;
            associatedResources = perun.getResourcesManagerBl().getAssignedResources(perunSession, group);
            for (Resource r : associatedResources) {
                writer.write("assignedToResourceId: " + r.getId());
                writer.write('\n');
            }
            //FOR NOW No groups has owner
            writer.write(owner + '\n');
            writer.write('\n');
        }
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) PerunSession(cz.metacentrum.perun.core.api.PerunSession) ArrayList(java.util.ArrayList) Resource(cz.metacentrum.perun.core.api.Resource) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) BufferedWriter(java.io.BufferedWriter) Vo(cz.metacentrum.perun.core.api.Vo) Member(cz.metacentrum.perun.core.api.Member)

Example 3 with Member

use of cz.metacentrum.perun.core.api.Member in project perun by CESNET.

the class MembersManagerBlImpl method createSpecificMember.

public Member createSpecificMember(PerunSession sess, Vo vo, Candidate candidate, List<User> specificUserOwners, SpecificUserType specificUserType, List<Group> groups) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, AlreadyMemberException, ExtendMembershipException, GroupOperationsException {
    if (specificUserType.equals(SpecificUserType.SERVICE))
        candidate.setFirstName("(Service)");
    //Set organization only if user in sessione exists (in tests there is no user in session)
    if (sess.getPerunPrincipal().getUser() != null) {
        String userOrganization = AttributesManager.NS_USER_ATTR_DEF + ":organization";
        String memberOrganization = AttributesManager.NS_MEMBER_ATTR_DEF + ":organization";
        Map<String, String> candidateAttributes = new HashMap<>();
        if (candidate.getAttributes() != null)
            candidateAttributes.putAll(candidate.getAttributes());
        if (candidateAttributes.get(memberOrganization) == null) {
            Attribute actorUserOrganization;
            String actorUserOrganizationValue;
            try {
                actorUserOrganization = perunBl.getAttributesManagerBl().getAttribute(sess, sess.getPerunPrincipal().getUser(), userOrganization);
                actorUserOrganizationValue = (String) actorUserOrganization.getValue();
            } catch (WrongAttributeAssignmentException | AttributeNotExistsException ex) {
                throw new InternalErrorException(ex);
            }
            if (actorUserOrganizationValue != null) {
                candidateAttributes.put(memberOrganization, actorUserOrganizationValue);
                candidate.setAttributes(candidateAttributes);
            }
        }
    }
    //create member for service user from candidate
    Member member = createMember(sess, vo, specificUserType, candidate, groups, null);
    //set specific user owners or sponsors
    User specificUser = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
    for (User u : specificUserOwners) {
        try {
            getPerunBl().getUsersManagerBl().addSpecificUserOwner(sess, u, specificUser);
        } catch (RelationExistsException ex) {
            throw new InternalErrorException(ex);
        }
    }
    return member;
}
Also used : User(cz.metacentrum.perun.core.api.User) RelationExistsException(cz.metacentrum.perun.core.api.exceptions.RelationExistsException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Example 4 with Member

use of cz.metacentrum.perun.core.api.Member in project perun by CESNET.

the class ServicesManagerBlImpl method getData.

private ServiceAttributes getData(PerunSession sess, Service service, Facility facility, Resource resource, Group group, Map<Member, ServiceAttributes> memberAttributes) throws InternalErrorException {
    ServiceAttributes groupServiceAttributes = new ServiceAttributes();
    try {
        groupServiceAttributes.addAttributes(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, service, resource, group, true));
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
    ServiceAttributes groupsSubGroupsElement = new ServiceAttributes();
    // FIXME Do not get subgroups of the members group
    if (!group.getName().equals(VosManager.MEMBERS_GROUP)) {
        List<Group> subGroups = getPerunBl().getGroupsManagerBl().getSubGroups(sess, group);
        for (Group subGroup : subGroups) {
            groupsSubGroupsElement.addChildElement(getData(sess, service, facility, resource, subGroup, memberAttributes));
        }
    }
    ServiceAttributes groupsMembersElement = new ServiceAttributes();
    //Invalid and disabled are not allowed here
    List<Member> members = getPerunBl().getGroupsManagerBl().getGroupMembersExceptInvalidAndDisabled(sess, group);
    for (Member member : members) {
        groupsMembersElement.addChildElement(memberAttributes.get(member));
    }
    groupServiceAttributes.addChildElement(groupsSubGroupsElement);
    groupServiceAttributes.addChildElement(groupsMembersElement);
    return groupServiceAttributes;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ServiceAttributes(cz.metacentrum.perun.core.api.ServiceAttributes) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Member(cz.metacentrum.perun.core.api.Member)

Example 5 with Member

use of cz.metacentrum.perun.core.api.Member in project perun by CESNET.

the class FacilitiesManagerBlImpl method getAllowedFacilities.

public List<Facility> getAllowedFacilities(PerunSession sess, User user) throws InternalErrorException {
    List<Member> members = perunBl.getMembersManagerBl().getMembersByUser(sess, user);
    Set<Facility> assignedFacilities = new HashSet<Facility>();
    for (Member member : members) {
        if (!getPerunBl().getMembersManagerBl().haveStatus(sess, member, Status.INVALID)) {
            assignedFacilities.addAll(this.getAssignedFacilities(sess, member));
        }
    }
    return new ArrayList<Facility>(assignedFacilities);
}
Also used : ArrayList(java.util.ArrayList) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) RichFacility(cz.metacentrum.perun.core.api.RichFacility) Member(cz.metacentrum.perun.core.api.Member) HashSet(java.util.HashSet)

Aggregations

Member (cz.metacentrum.perun.core.api.Member)573 Test (org.junit.Test)369 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)331 RichMember (cz.metacentrum.perun.core.api.RichMember)258 User (cz.metacentrum.perun.core.api.User)238 Group (cz.metacentrum.perun.core.api.Group)183 ArrayList (java.util.ArrayList)153 Vo (cz.metacentrum.perun.core.api.Vo)149 Attribute (cz.metacentrum.perun.core.api.Attribute)137 RichUser (cz.metacentrum.perun.core.api.RichUser)108 Resource (cz.metacentrum.perun.core.api.Resource)93 Facility (cz.metacentrum.perun.core.api.Facility)73 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)69 LinkedHashMap (java.util.LinkedHashMap)66 HashSet (java.util.HashSet)65 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)56 RichGroup (cz.metacentrum.perun.core.api.RichGroup)52 LocalDate (java.time.LocalDate)52 Candidate (cz.metacentrum.perun.core.api.Candidate)51 HashMap (java.util.HashMap)50