use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_def_shellTest method testCheckAttributeValueWithEmptyAttribute.
/**
* Test of checkAttributeValue method, of class urn_perun_user_facility_attribute_def_def_shell.
* with empty attribute.
*/
public void testCheckAttributeValueWithEmptyAttribute() throws Exception {
System.out.println("testCheckAttributeValueWithEmptyAttribute()");
when(session.getPerunBl().getUsersManagerBl().getAllowedResources(any(PerunSession.class), any(Facility.class), any(User.class))).thenReturn(new ArrayList<Resource>() {
{
add(resource);
}
});
when(session.getPerunBl().getFacilitiesManagerBl().getAssignedResources(any(PerunSession.class), any(Facility.class))).thenReturn(new ArrayList<Resource>() {
{
add(resource);
}
});
when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenReturn(listOfShells);
classInstance.checkAttributeValue(session, facility, user, new Attribute());
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method checkAttributesSemantics.
@Override
public void checkAttributesSemantics(PerunSession sess, Member member, Resource resource, List<Attribute> attributes, boolean workWithUserAttributes) throws WrongAttributeAssignmentException, WrongReferenceAttributeValueException, MemberResourceMismatchException {
this.checkMemberIsFromTheSameVoLikeResource(sess, member, resource);
if (!workWithUserAttributes) {
for (Attribute attribute : attributes) {
getAttributesManagerImpl().checkNamespace(sess, attribute, NS_MEMBER_RESOURCE_ATTR);
if (attribute.getValue() == null && !isTrulyRequiredAttribute(sess, member, resource, attribute))
continue;
getAttributesManagerImpl().checkAttributeSemantics(sess, member, resource, attribute);
}
} else {
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
for (Attribute attribute : attributes) {
if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
if (attribute.getValue() == null && !isTrulyRequiredAttribute(sess, member, resource, attribute))
continue;
getAttributesManagerImpl().checkAttributeSemantics(sess, member, resource, attribute);
} else if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
if (attribute.getValue() == null && !isTrulyRequiredAttribute(sess, facility, user, attribute))
continue;
getAttributesManagerImpl().checkAttributeSemantics(sess, facility, user, attribute);
} else if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_USER_ATTR)) {
if (attribute.getValue() == null && !isTrulyRequiredAttribute(sess, user, attribute))
continue;
getAttributesManagerImpl().checkAttributeSemantics(sess, user, attribute);
} else if (getAttributesManagerImpl().isFromNamespace(attribute, AttributesManager.NS_MEMBER_ATTR)) {
if (attribute.getValue() == null && !isTrulyRequiredAttribute(sess, member, attribute))
continue;
getAttributesManagerImpl().checkAttributeSemantics(sess, member, attribute);
} else {
throw new WrongAttributeAssignmentException(attribute);
}
}
}
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method getRequiredAttributes.
@Override
public List<Attribute> getRequiredAttributes(PerunSession sess, Service service, Resource resource, Group group, Member member, boolean workWithUserAttributes) throws MemberResourceMismatchException, GroupResourceMismatchException {
this.checkMemberIsFromTheSameVoLikeResource(sess, member, resource);
this.checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
List<Attribute> attributes = new ArrayList<>();
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, service, member));
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, service, member, group));
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, service, member, resource));
if (workWithUserAttributes) {
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, service, facility, user));
attributes.addAll(getAttributesManagerImpl().getRequiredAttributes(sess, service, user));
}
return attributes;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
@Override
public void removeAllAttributes(PerunSession sess, User user) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, user);
if (getAttributesManagerImpl().removeAllAttributes(sess, user)) {
getPerunBl().getAuditer().log(sess, new AllAttributesRemovedForUser(user));
}
log.info("{} removed all attributes from user {}.", sess.getLogId(), user.getId());
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesSemantics(sess, user, attributes);
checkAttributesDependencies(sess, user, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, user, new Attribute(attribute));
} catch (WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
}
}
}
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 resource 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 resource.
* 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 resource resource
* @param attrDef type of attribute that will be returned
* @return List of RichAttribute
*/
private List<RichAttribute> getUserFacilityAttributes(PerunSession sess, Member member, Resource resource, AttributeDefinition attrDef) throws AttributeNotExistsException, WrongAttributeAssignmentException {
List<RichAttribute> listOfRichAttributes = new ArrayList<>();
if (getPerunBl().getMembersManagerBl().isMemberAllowed(sess, member)) {
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<Resource> memberResources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, member);
if (memberResources.contains(resource)) {
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
Attribute attribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, user, attrDef.getName());
listOfRichAttributes.add(new RichAttribute<>(facility, user, attribute));
}
}
listOfRichAttributes = new ArrayList<>(new HashSet<>(listOfRichAttributes));
return listOfRichAttributes;
}
Aggregations