Search in sources :

Example 6 with RichMember

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

the class MembersManagerBlImpl method filterOnlyAllowedAttributes.

public List<RichMember> filterOnlyAllowedAttributes(PerunSession sess, List<RichMember> richMembers, boolean useContext) throws InternalErrorException {
    //If no context should be used - every attribute is unique in context of member (for every member test access rights for all attributes again)
    if (!useContext)
        return filterOnlyAllowedAttributes(sess, richMembers);
    //If context should be used - every attribute is unique in context of friendlyName (every attribute test only once per friendlyName)
    List<RichMember> filteredRichMembers = new ArrayList<RichMember>();
    if (richMembers == null || richMembers.isEmpty())
        return filteredRichMembers;
    // attr_name to boolean where null means - no rights at all, false means no write rights, true means read and write rights
    Map<String, Boolean> contextMap = new HashMap<>();
    // voId is there the context
    Integer voId = null;
    for (RichMember rm : richMembers) {
        //set or test voId for testing of context
        if (voId == null) {
            voId = rm.getVoId();
        } else {
            if (rm.getVoId() != voId)
                throw new InternalErrorException("Method using filtering by context, but some members are not from the same Vo!");
        }
        //Filtering members attributes
        if (rm.getMemberAttributes() != null) {
            List<Attribute> memberAttributes = rm.getMemberAttributes();
            List<Attribute> allowedMemberAttributes = new ArrayList<Attribute>();
            for (Attribute membAttr : memberAttributes) {
                //if there is record in contextMap, use it
                if (contextMap.containsKey(membAttr.getFriendlyName())) {
                    Boolean isWritable = contextMap.get(membAttr.getFriendlyName());
                    if (isWritable != null) {
                        membAttr.setWritable(isWritable);
                        allowedMemberAttributes.add(membAttr);
                    }
                //if not, get information about authz rights and set record to contextMap
                } else {
                    if (AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, membAttr, rm, null)) {
                        boolean isWritable = AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, membAttr, rm, null);
                        membAttr.setWritable(isWritable);
                        allowedMemberAttributes.add(membAttr);
                        contextMap.put(membAttr.getFriendlyName(), isWritable);
                    } else {
                        contextMap.put(membAttr.getFriendlyName(), null);
                    }
                }
            }
            rm.setMemberAttributes(allowedMemberAttributes);
        }
        //Filtering users attributes
        if (rm.getUserAttributes() != null) {
            List<Attribute> userAttributes = rm.getUserAttributes();
            List<Attribute> allowedUserAttributes = new ArrayList<Attribute>();
            for (Attribute userAttr : userAttributes) {
                //if there is record in contextMap, use it
                if (contextMap.containsKey(userAttr.getFriendlyName())) {
                    Boolean isWritable = contextMap.get(userAttr.getFriendlyName());
                    if (isWritable != null) {
                        userAttr.setWritable(isWritable);
                        allowedUserAttributes.add(userAttr);
                    }
                //if not, get information about authz rights and set record to contextMap
                } else {
                    if (AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, userAttr, rm.getUser(), null)) {
                        boolean isWritable = AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, userAttr, rm.getUser(), null);
                        userAttr.setWritable(isWritable);
                        allowedUserAttributes.add(userAttr);
                        contextMap.put(userAttr.getFriendlyName(), isWritable);
                    } else {
                        contextMap.put(userAttr.getFriendlyName(), null);
                    }
                }
                rm.setUserAttributes(allowedUserAttributes);
            }
        }
        filteredRichMembers.add(rm);
    }
    return filteredRichMembers;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 7 with RichMember

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

the class MembersManagerBlImpl method findRichMembers.

@Override
public List<RichMember> findRichMembers(PerunSession sess, String searchString) throws InternalErrorException {
    List<User> users = getPerunBl().getUsersManagerBl().findUsers(sess, searchString);
    List<Member> members = new ArrayList<Member>();
    for (User user : users) {
        members.addAll(getMembersByUser(sess, user));
    }
    return this.convertMembersToRichMembers(sess, this.setAllMembersSameType(members, MembershipType.DIRECT));
}
Also used : User(cz.metacentrum.perun.core.api.User) ArrayList(java.util.ArrayList) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Example 8 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, Group group, List<String> attrsNames) throws InternalErrorException, AttributeNotExistsException {
    List<Member> members = new ArrayList<Member>();
    members.addAll(perunBl.getGroupsManagerBl().getGroupMembers(sess, group));
    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 9 with RichMember

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

the class ExtSourcePerun method findRichUsers.

private List<RichUser> findRichUsers(Integer groupId) throws InternalErrorException {
    // we don't need to encode query params here, no unsafe char in fixed string
    String query = "group=" + groupId + "&" + "allowedStatuses[]=" + "VALID";
    List<RichMember> richMembers;
    try {
        richMembers = this.call("membersManager", "getRichMembersWithAttributes", query).readList(RichMember.class);
    } catch (PerunException ex) {
        throw new InternalErrorException(ex);
    }
    return convertListOfRichMembersToListOfRichUsers(richMembers);
}
Also used : PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember)

Example 10 with RichMember

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

the class MembersManagerBlImpl method getOnlyRichMembersWithAllowedStatuses.

/**
	 * Return list of RichMembers with allowed statuses contains in list of allowedStatuses.
	 * If allowedStatuses is empty or null, get richMembers with all statuses.
	 *
	 * @param sess
	 * @param richMembers
	 * @param allowedStatuses
	 * @return list of allowed richMembers
	 * @throws InternalErrorException
	 */
private List<RichMember> getOnlyRichMembersWithAllowedStatuses(PerunSession sess, List<RichMember> richMembers, List<String> allowedStatuses) throws InternalErrorException {
    List<RichMember> allowedRichMembers = new ArrayList<RichMember>();
    if (richMembers == null || richMembers.isEmpty())
        return allowedRichMembers;
    if (allowedStatuses == null || allowedStatuses.isEmpty())
        return richMembers;
    //Covert statuses to objects Status
    List<Status> statuses = new ArrayList<Status>();
    for (String status : allowedStatuses) {
        statuses.add(Status.valueOf(status));
    }
    for (RichMember rm : richMembers) {
        if (statuses.contains(rm.getStatus()))
            allowedRichMembers.add(rm);
    }
    return allowedRichMembers;
}
Also used : Status(cz.metacentrum.perun.core.api.Status) ArrayList(java.util.ArrayList) 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