use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method setAttributeWithoutCheck.
@Override
public boolean setAttributeWithoutCheck(PerunSession sess, Resource resource, Group group, Attribute attribute) throws WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException, GroupResourceMismatchException {
this.checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_GROUP_RESOURCE_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed;
if (isVirtAttribute(sess, attribute)) {
// FIXME Zatim je zakazane nastavovani virtualnich atributu group_resource
Attribute storedAttribute;
try {
storedAttribute = getAttribute(sess, resource, group, attribute.getName());
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
if (!(storedAttribute.getValue() == null ? attribute.getValue() == null : storedAttribute.getValue().equals(attribute.getValue()))) {
// FIXME
if (attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGID") || attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGroupName")) {
return getAttributesManagerImpl().setVirtualAttribute(sess, resource, group, attribute);
} else {
throw new InternalErrorException("Virtual attribute can't be set this way yet. Please set physical attribute. " + attribute);
}
} else {
return false;
}
} else {
changed = getAttributesManagerImpl().setAttribute(sess, resource, group, attribute);
}
if (changed) {
getPerunBl().getAuditer().log(sess, new AttributeSetForGroupAndResource(attribute, group, resource));
getAttributesManagerImpl().changedAttributeHook(sess, resource, group, attribute);
}
return changed;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method getAttributeById.
@Override
public Attribute getAttributeById(PerunSession sess, Group group, int id) throws WrongAttributeAssignmentException, AttributeNotExistsException {
Attribute attribute = getAttributesManagerImpl().getAttributeById(sess, group, id);
getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_GROUP_ATTR);
return attribute;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method getUserFacilityAttributes.
/**
* Returns all relevant UserFacility RichAttributes for given group and member.
* That means, returns all UserFacility rich attributes for user of the given member and for facilities this member
* can access via the given group.
* If the given member is not allowed, returns an empty list.
* Each rich attribute is returned only once.
*
* @param sess session
* @param member member
* @param group group
* @param attrDef type of attribute that will be returned
* @return List of RichAttribute
*/
private List<RichAttribute> getUserFacilityAttributes(PerunSession sess, Member member, Group group, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException {
List<RichAttribute> listOfRichAttributes = new ArrayList<>();
if (getPerunBl().getMembersManagerBl().isMemberAllowed(sess, member)) {
List<Resource> resourcesFromGroup = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
List<Facility> facilitiesFromResources = new ArrayList<>();
for (Resource resourceElement : resourcesFromGroup) {
facilitiesFromResources.add(getPerunBl().getResourcesManagerBl().getFacility(sess, resourceElement));
}
facilitiesFromResources = new ArrayList<>(new HashSet<>(facilitiesFromResources));
User userFromMember = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
for (Facility facilityElement : facilitiesFromResources) {
Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facilityElement, userFromMember, attrDef.getName());
listOfRichAttributes.add(new RichAttribute<>(facilityElement, userFromMember, attribute));
}
}
listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
return listOfRichAttributes;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method removeAttributeWithoutCheck.
private boolean removeAttributeWithoutCheck(PerunSession sess, UserExtSource ues, AttributeDefinition attribute) throws WrongAttributeAssignmentException {
getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_UES_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = getAttributesManagerImpl().removeAttribute(sess, ues, attribute);
if (changed) {
getAttributesManagerImpl().changedAttributeHook(sess, ues, new Attribute(attribute));
log.info("{} removed attribute {} from user external source {}.", sess.getLogId(), attribute.getName(), ues.getId());
getPerunBl().getAuditer().log(sess, new AttributeRemovedForUes(new AttributeDefinition(attribute), ues));
}
return changed;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method getMemberGroupAttributes.
/**
* Returns all relevant MemberGroup RichAttributes for given member and resource.
* That means, returns all MemberGroup rich attributes for the given member and groups that can access the given resource.
* If the member is not allowed, an empty list is returned.
* Each rich attribute is returned only once.
*
* @param sess session
* @param member member
* @param resource resource
* @param attrDef type of attribute that will be returned
* @return List of RichAttribute
*/
private List<RichAttribute> getMemberGroupAttributes(PerunSession sess, Member member, Resource resource, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException, MemberGroupMismatchException {
List<RichAttribute> listOfRichAttributes = new ArrayList<>();
// If member is not allowed, skip whole process
if (!getPerunBl().getMembersManagerBl().isMemberAllowed(sess, member))
return listOfRichAttributes;
List<Group> groupFromMembers = new ArrayList<>();
if (getPerunBl().getMembersManagerBl().isMemberAllowed(sess, member)) {
groupFromMembers = getPerunBl().getGroupsManagerBl().getAllMemberGroups(sess, member);
}
List<Group> groupsFromResources = getPerunBl().getResourcesManagerBl().getAssignedGroups(sess, resource);
groupsFromResources.retainAll(groupFromMembers);
groupsFromResources = new ArrayList<>(new HashSet<>(groupsFromResources));
for (Group groupElement : groupsFromResources) {
Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, groupElement, attrDef.getName());
listOfRichAttributes.add(new RichAttribute<>(member, groupElement, attribute));
}
listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
return listOfRichAttributes;
}
Aggregations