use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class AttributesManagerBlImpl method checkMemberIsFromTheSameVoLikeGroup.
/**
* Check if Member is from the same VO like Group. If not, throw MemberGroupMismatchException
*/
private void checkMemberIsFromTheSameVoLikeGroup(PerunSession sess, Member member, Group group) throws MemberGroupMismatchException {
Utils.notNull(sess, "sess");
Utils.notNull(member, "member");
Utils.notNull(group, "group");
if (member.getVoId() != group.getVoId())
throw new MemberGroupMismatchException("Member is not from the same vo like Group: " + member + " " + group, member, group);
}
use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class MembersManagerBlImpl method getMembersPage.
@Override
public Paginated<RichMember> getMembersPage(PerunSession sess, Vo vo, MembersPageQuery query, List<String> attrNames) {
Paginated<Member> paginatedMembers = membersManagerImpl.getMembersPage(sess, vo, query);
List<RichMember> richMembers = convertMembersToRichMembers(sess, paginatedMembers.getData());
List<AttributeDefinition> attrDefs = new ArrayList<>();
for (String attrsName : attrNames) {
try {
attrDefs.add(getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, attrsName));
} catch (AttributeNotExistsException e) {
// pass
}
}
if (query.getGroupId() == null) {
richMembers = convertMembersToRichMembersWithAttributes(sess, richMembers, attrDefs);
} else {
try {
richMembers = convertMembersToRichMembersWithAttributes(sess, perunBl.getGroupsManagerBl().getGroupById(sess, query.getGroupId()), richMembers, attrDefs);
} catch (GroupNotExistsException | MemberGroupMismatchException e) {
throw new InternalErrorException(e);
}
}
return new Paginated<>(richMembers, paginatedMembers.getOffset(), paginatedMembers.getPageSize(), paginatedMembers.getTotalCount());
}
use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class MembersManagerBlImpl method moveMembersAttributes.
/**
* Moves member related attributes from source member to target member.
*
* @param sess
* @param vo VO where sourceUser and targetUser are members
* @param sourceMember member to move attributes from
* @param targetMember member to move attributes to
* @param groups groups for which move member-group attributes
*/
private void moveMembersAttributes(PerunSession sess, Vo vo, Member sourceMember, Member targetMember, List<Group> groups) {
try {
// set member attributes
List<Attribute> memberAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceMember);
for (Attribute attribute : memberAttributes) {
if (!getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute) && !getPerunBl().getAttributesManagerBl().isCoreAttribute(sess, attribute))
getPerunBl().getAttributesManagerBl().setAttribute(sess, targetMember, attribute);
}
// set member-group attributes
for (Group group : groups) {
List<Attribute> groupMemberAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceMember, group);
for (Attribute attribute : groupMemberAttributes) {
if (!getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute)) {
getPerunBl().getAttributesManagerBl().setAttribute(sess, targetMember, group, attribute);
}
}
}
// set member-resource attributes
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
for (Resource resource : resources) {
List<Attribute> memberResourceAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceMember, resource);
for (Attribute attribute : memberResourceAttributes) {
if (!getPerunBl().getAttributesManagerBl().isVirtAttribute(sess, attribute)) {
getPerunBl().getAttributesManagerBl().setAttribute(sess, targetMember, resource, attribute);
}
}
}
} catch (WrongAttributeValueException | WrongAttributeAssignmentException | WrongReferenceAttributeValueException | MemberGroupMismatchException | MemberResourceMismatchException e) {
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class AttributesManagerEntry method getResourceRequiredAttributes.
@Override
public List<Attribute> getResourceRequiredAttributes(PerunSession sess, Resource resourceToGetServicesFrom, Resource resource, Group group, Member member, boolean workWithUserAttributes) throws ResourceNotExistsException, GroupNotExistsException, GroupResourceMismatchException, MemberNotExistsException, MemberGroupMismatchException, UserNotExistsException, FacilityNotExistsException, MemberResourceMismatchException {
Utils.checkPerunSession(sess);
getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resourceToGetServicesFrom);
getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resource);
getPerunBl().getGroupsManagerBl().checkGroupExists(sess, group);
getPerunBl().getMembersManagerBl().checkMemberExists(sess, member);
if (group.getVoId() != resource.getVoId()) {
throw new GroupResourceMismatchException("Group and resource are not in the same VO.");
}
if (member.getVoId() != group.getVoId()) {
throw new MemberGroupMismatchException("Member and Group are not in the same VO.", member, group);
}
List<Attribute> attributes = getAttributesManagerBl().getResourceRequiredAttributes(sess, resourceToGetServicesFrom, member, resource, workWithUserAttributes);
attributes.addAll(getAttributesManagerBl().getResourceRequiredAttributes(sess, resourceToGetServicesFrom, member, group));
User user = getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
Facility facility = getPerunBl().getFacilitiesManagerBl().getFacilityById(sess, resource.getFacilityId());
Iterator<Attribute> attrIter = attributes.iterator();
// Choose to which attributes has the principal access
while (attrIter.hasNext()) {
Attribute attrNext = attrIter.next();
if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_ATTR)) {
if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, member))
attrIter.remove();
else
attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, member));
} else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_USER_ATTR)) {
if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, user))
attrIter.remove();
else
attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, user));
} else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_GROUP_ATTR)) {
if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, member, group))
attrIter.remove();
else
attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, member, group));
} else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_RESOURCE_ATTR)) {
if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, member, resource))
attrIter.remove();
else
attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, member, resource));
} else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_USER_FACILITY_ATTR)) {
if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, user, facility))
attrIter.remove();
else
attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, user, facility));
} else {
throw new ConsistencyErrorException("There is some attribute which is not of expected type (member, user, user_facility, member_group, member_resource).");
}
}
return attributes;
}
use of cz.metacentrum.perun.core.api.exceptions.MemberGroupMismatchException in project perun by CESNET.
the class MembersManagerBlImpl method getRichMembersWithAttributesByNames.
@Override
public List<RichMember> getRichMembersWithAttributesByNames(PerunSession sess, Group group, Resource resource, List<String> attrsNames) throws AttributeNotExistsException, GroupResourceMismatchException {
getPerunBl().getAttributesManagerBl().checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
List<Member> members = new ArrayList<>(perunBl.getGroupsManagerBl().getGroupMembers(sess, group));
List<RichMember> richMembers = this.convertMembersToRichMembers(sess, members);
List<AttributeDefinition> attrsDef = new ArrayList<>();
for (String atrrName : attrsNames) {
AttributeDefinition attrDef = perunBl.getAttributesManagerBl().getAttributeDefinition(sess, atrrName);
attrsDef.add(attrDef);
}
List<RichMember> richMembersWithAttributes;
try {
richMembersWithAttributes = this.convertMembersToRichMembersWithAttributes(sess, group, resource, richMembers, attrsDef);
} catch (MemberResourceMismatchException | MemberGroupMismatchException ex) {
throw new ConsistencyErrorException(ex);
}
return richMembersWithAttributes;
}
Aggregations