Search in sources :

Example 1 with RichMember

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

the class ExtSourcePerun method convertListOfRichMembersToListOfRichUsers.

private List<RichUser> convertListOfRichMembersToListOfRichUsers(List<RichMember> richMembers) throws InternalErrorException {
    List<RichUser> richUsers = new ArrayList<>();
    if (richMembers == null || richMembers.isEmpty())
        return richUsers;
    for (RichMember rm : richMembers) {
        RichUser ru = new RichUser(rm.getUser(), rm.getUserExtSources(), rm.getUserAttributes());
        richUsers.add(ru);
    }
    return richUsers;
}
Also used : RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 2 with RichMember

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

the class MembersManagerBlImpl method getRichMembersWithAttributesByNames.

public List<RichMember> getRichMembersWithAttributesByNames(PerunSession sess, Vo vo, List<String> attrsNames) throws InternalErrorException, AttributeNotExistsException {
    List<Member> members = new ArrayList<Member>();
    members.addAll(perunBl.getMembersManagerBl().getMembers(sess, vo));
    List<RichMember> richMembers = this.convertMembersToRichMembers(sess, members);
    List<AttributeDefinition> attrsDef = new ArrayList<AttributeDefinition>();
    for (String atrrName : attrsNames) {
        AttributeDefinition attrDef = perunBl.getAttributesManagerBl().getAttributeDefinition(sess, atrrName);
        attrsDef.add(attrDef);
    }
    List<RichMember> richMembersWithAttributes = this.convertMembersToRichMembersWithAttributes(sess, richMembers, attrsDef);
    return richMembersWithAttributes;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 3 with RichMember

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

the class MembersManagerBlImpl method convertMembersToRichMembersWithAttributes.

public List<RichMember> convertMembersToRichMembersWithAttributes(PerunSession sess, List<RichMember> richMembers, List<AttributeDefinition> attrsDef) throws InternalErrorException {
    List<AttributeDefinition> usersAttributesDef = new ArrayList<AttributeDefinition>();
    List<AttributeDefinition> membersAttributesDef = new ArrayList<AttributeDefinition>();
    for (AttributeDefinition attrd : attrsDef) {
        if (attrd.getName().startsWith(AttributesManager.NS_USER_ATTR))
            usersAttributesDef.add(attrd);
        else if (attrd.getName().startsWith(AttributesManager.NS_MEMBER_ATTR))
            membersAttributesDef.add(attrd);
    }
    for (RichMember richMember : richMembers) {
        List<Attribute> userAttributes = new ArrayList<Attribute>();
        List<Attribute> memberAttributes = new ArrayList<Attribute>();
        List<String> userAttrNames = new ArrayList<String>();
        for (AttributeDefinition ad : usersAttributesDef) {
            userAttrNames.add(ad.getName());
        }
        userAttributes.addAll(getPerunBl().getAttributesManagerBl().getAttributes(sess, richMember.getUser(), userAttrNames));
        List<String> memberAttrNames = new ArrayList<String>();
        for (AttributeDefinition ad : membersAttributesDef) {
            memberAttrNames.add(ad.getName());
        }
        memberAttributes.addAll(getPerunBl().getAttributesManagerBl().getAttributes(sess, richMember, memberAttrNames));
        richMember.setUserAttributes(userAttributes);
        richMember.setMemberAttributes(memberAttributes);
    }
    return richMembers;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 4 with RichMember

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

the class MembersManagerEntry method getRichMemberById.

public RichMember getRichMemberById(PerunSession sess, int id) throws InternalErrorException, PrivilegeException, MemberNotExistsException {
    Utils.checkPerunSession(sess);
    Member member = getPerunBl().getMembersManagerBl().getMemberById(sess, id);
    Vo vo = getPerunBl().getMembersManagerBl().getMemberVo(sess, member);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, vo) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, vo) && !AuthzResolver.isAuthorized(sess, Role.SELF, member)) {
        throw new PrivilegeException(sess, "getRichMemberById");
    }
    return getPerunBl().getMembersManagerBl().getRichMember(sess, member);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Vo(cz.metacentrum.perun.core.api.Vo) Member(cz.metacentrum.perun.core.api.Member) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 5 with RichMember

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

the class MembersManagerEntry method findCompleteRichMembers.

@Override
public List<RichMember> findCompleteRichMembers(PerunSession sess, List<String> attrsNames, List<String> allowedStatuses, String searchString) throws InternalErrorException, MemberNotExistsException, PrivilegeException, VoNotExistsException, AttributeNotExistsException {
    Utils.checkPerunSession(sess);
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN) && !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN) && !AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN)) {
        throw new PrivilegeException(sess, "findCompleteRichMembers");
    }
    List<RichMember> richMembers = getMembersManagerBl().findCompleteRichMembers(sess, attrsNames, allowedStatuses, searchString);
    Iterator<RichMember> richMemberIter = richMembers.iterator();
    while (richMemberIter.hasNext()) {
        RichMember richMember = richMemberIter.next();
        //if voadmin or voobserver or groupadmin has right to this member, its ok
        if (AuthzResolver.isAuthorized(sess, Role.VOADMIN, richMember) || AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, richMember) || AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, richMember))
            continue;
        //if not, then try facility admin rights
        List<Resource> membersResources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, richMember);
        boolean found = false;
        for (Resource resource : membersResources) {
            if (AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, resource)) {
                found = true;
                break;
            }
        }
        if (found)
            continue;
        richMemberIter.remove();
    }
    return getPerunBl().getMembersManagerBl().filterOnlyAllowedAttributes(sess, richMembers, false);
}
Also used : PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Resource(cz.metacentrum.perun.core.api.Resource) RichMember(cz.metacentrum.perun.core.api.RichMember)

Aggregations

RichMember (cz.metacentrum.perun.core.api.RichMember)13 ArrayList (java.util.ArrayList)9 Member (cz.metacentrum.perun.core.api.Member)6 Attribute (cz.metacentrum.perun.core.api.Attribute)3 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)3 User (cz.metacentrum.perun.core.api.User)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)2 Resource (cz.metacentrum.perun.core.api.Resource)1 RichUser (cz.metacentrum.perun.core.api.RichUser)1 Status (cz.metacentrum.perun.core.api.Status)1 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)1 Vo (cz.metacentrum.perun.core.api.Vo)1 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)1 PerunException (cz.metacentrum.perun.core.api.exceptions.PerunException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1