use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllUserFacilityAttributes.
public void removeAllUserFacilityAttributes(PerunSession sess, User user) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
List<RichAttribute<User, Facility>> userFacilitiesAttributes = getAttributesManagerImpl().getAllUserFacilityRichAttributes(sess, user);
//remove all non-virtual attributes
getAttributesManagerImpl().removeAllUserFacilityAttributes(sess, user);
getPerunBl().getAuditer().log(sess, "All non-virtual user-facility attributes removed for all facilities and {}", user);
for (RichAttribute<User, Facility> richAttribute : userFacilitiesAttributes) {
try {
checkAttributeValue(sess, richAttribute.getSecondaryHolder(), richAttribute.getPrimaryHolder(), new Attribute(richAttribute.getAttribute()));
this.checkAttributeDependencies(sess, richAttribute);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
}
for (RichAttribute<User, Facility> attribute : userFacilitiesAttributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, attribute.getSecondaryHolder(), attribute.getPrimaryHolder(), new Attribute(attribute.getAttribute()));
} catch (WrongAttributeValueException ex) {
//TODO better exception here
throw new InternalErrorException(ex);
} catch (WrongReferenceAttributeValueException ex) {
//TODO better exception here
throw new InternalErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class AttributesManagerEntry method getRequiredAttributes.
@Override
public HashMap<Member, List<Attribute>> getRequiredAttributes(PerunSession sess, Service service, Resource resource, List<Member> members, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException, ServiceNotExistsException, ResourceNotExistsException, MemberNotExistsException, FacilityNotExistsException {
Utils.checkPerunSession(sess);
getPerunBl().getServicesManagerBl().checkServiceExists(sess, service);
getPerunBl().getResourcesManagerBl().checkResourceExists(sess, resource);
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
for (Member member : members) {
getPerunBl().getMembersManagerBl().checkMemberExists(sess, member);
}
HashMap<Member, List<Attribute>> result = getAttributesManagerBl().getRequiredAttributes(sess, service, facility, resource, members, workWithUserAttributes);
for (Member member : result.keySet()) {
Iterator<Attribute> attrIter = result.get(member).iterator();
//Choose to which attributes has the principal access
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
while (attrIter.hasNext()) {
Attribute attrNext = attrIter.next();
if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_RESOURCE_ATTR)) {
if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, resource, member))
attrIter.remove();
else
attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, resource, member));
} else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_MEMBER_ATTR)) {
if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, member, null))
attrIter.remove();
else
attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, member, null));
} else if (getAttributesManagerBl().isFromNamespace(sess, attrNext, NS_USER_ATTR)) {
if (!AuthzResolver.isAuthorizedForAttribute(sess, ActionType.READ, attrNext, user, null))
attrIter.remove();
else
attrNext.setWritable(AuthzResolver.isAuthorizedForAttribute(sess, ActionType.WRITE, attrNext, user, null));
} 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 type of any possible choice.");
}
}
}
return result;
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class AttributesManagerBlImpl method getResourceRequiredAttributes.
public List<Attribute> getResourceRequiredAttributes(PerunSession sess, Resource resourceToGetServicesFrom, Resource resource, Member member, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException {
this.checkMemberIsFromTheSameVoLikeResource(sess, member, resource);
List<Attribute> attributes = new ArrayList<Attribute>();
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, resource, member));
if (workWithUserAttributes) {
User user;
Facility facility;
try {
user = getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
facility = getPerunBl().getFacilitiesManagerBl().getFacilityById(sess, resource.getFacilityId());
} catch (UserNotExistsException e) {
throw new ConsistencyErrorException("Member has non-existent user.", e);
} catch (FacilityNotExistsException e) {
throw new ConsistencyErrorException("Resource has non-existent facility.", e);
}
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, facility, user));
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, user));
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, resourceToGetServicesFrom, member));
}
return attributes;
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class AttributesManagerBlImpl method isTrulyRequiredAttribute.
public boolean isTrulyRequiredAttribute(PerunSession sess, Facility facility, User user, AttributeDefinition attributeDefinition) throws InternalErrorException, WrongAttributeAssignmentException {
this.checkNamespace(sess, attributeDefinition, NS_USER_FACILITY_ATTR);
List<Facility> allowedFacilities = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
if (!allowedFacilities.contains(facility)) {
return false;
} else {
if (!getAttributesManagerImpl().isAttributeRequiredByFacility(sess, facility, attributeDefinition))
return false;
List<Resource> resources = getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
resources.retainAll(getPerunBl().getUsersManagerBl().getAllowedResources(sess, user));
for (Resource resource : resources) {
if (getAttributesManagerImpl().isAttributeRequiredByResource(sess, resource, attributeDefinition))
return true;
}
return false;
}
}
use of cz.metacentrum.perun.core.api.Facility in project perun by CESNET.
the class AttributesManagerBlImpl method removeAttributes.
public void removeAttributes(PerunSession sess, Resource resource, Member member, List<? extends AttributeDefinition> attributes, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
if (!(workWithUserAttributes)) {
removeAttributes(sess, resource, member, attributes);
} else {
List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
for (AttributeDefinition attribute : attributes) {
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
if (removeAttributeWithoutCheck(sess, resource, member, attribute))
attributesToCheck.add(attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
if (removeAttributeWithoutCheck(sess, facility, user, attribute))
attributesToCheck.add(attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
if (removeAttributeWithoutCheck(sess, user, attribute))
attributesToCheck.add(attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
if (removeAttributeWithoutCheck(sess, member, attribute))
attributesToCheck.add(attribute);
} else {
throw new WrongAttributeAssignmentException(attribute);
}
}
}
checkAttributesValue(sess, resource, member, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
this.checkAttributesDependencies(sess, resource, member, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
}
}
Aggregations