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;
}
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));
}
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;
}
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);
}
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;
}
Aggregations