use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class urn_perun_group_attribute_def_def_groupStructureSynchronizationEnabled method changedAttributeHook.
@Override
public void changedAttributeHook(PerunSessionImpl session, Group group, Attribute attribute) {
if (attribute.getValue() == null) {
try {
AttributesManagerBl attributesManager = session.getPerunBl().getAttributesManagerBl();
AttributeDefinition removeAttrDef = attributesManager.getAttributeDefinition(session, new urn_perun_group_attribute_def_def_flatGroupStructureEnabled().getAttributeDefinition().getName());
attributesManager.removeAttributeWithoutCheck(session, group, removeAttrDef);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
log.debug("Attribute for flat group structure synchronization does not exist", ex);
}
}
}
use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class UserVirtualAttributeCollectedFromUserExtSource method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition destinationAttributeDefinition) {
T ctx = initModifyValueContext(sess, user, destinationAttributeDefinition);
Attribute destinationAttribute = new Attribute(destinationAttributeDefinition);
// for values use set because of avoiding duplicities
Set<String> valuesWithoutDuplicities = new HashSet<>();
String sourceAttributeFriendlyName = getSourceAttributeFriendlyName();
List<UserExtSource> userExtSources = sess.getPerunBl().getUsersManagerBl().getUserExtSources(sess, user);
AttributesManagerBl am = sess.getPerunBl().getAttributesManagerBl();
for (UserExtSource userExtSource : userExtSources) {
try {
String sourceAttributeName = getSourceAttributeName();
Attribute a = am.getAttribute(sess, userExtSource, sourceAttributeName);
Object value = a.getValue();
if (value != null && value instanceof String) {
// Apache mod_shib joins multiple values with ';', split them again
String[] rawValues = ((String) value).split(";");
// add non-null values returned by modifyValue()
Arrays.stream(rawValues).map(v -> modifyValue(sess, ctx, userExtSource, v)).filter(Objects::nonNull).forEachOrdered(valuesWithoutDuplicities::add);
} else if (value != null && value instanceof ArrayList) {
// If values are already separated to list of strings
a.valueAsList().stream().map(v -> modifyValue(sess, ctx, userExtSource, v)).filter(Objects::nonNull).forEachOrdered(valuesWithoutDuplicities::add);
}
} catch (WrongAttributeAssignmentException | AttributeNotExistsException e) {
log.error("cannot read " + sourceAttributeFriendlyName + " from userExtSource " + userExtSource.getId() + " of user " + user.getId(), e);
}
}
// convert set to list (values in list will be without duplicities)
destinationAttribute.setValue(new ArrayList<>(valuesWithoutDuplicities));
return destinationAttribute;
}
use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class UsersManagerBlImpl method convertUsersToRichUsersWithAttributesByNames.
@Override
public List<RichUser> convertUsersToRichUsersWithAttributesByNames(PerunSession sess, List<User> users, List<String> attrNames) {
// TODO - optimzization needed - at least there should be single select on RichUser object in impl !!
List<RichUser> result = new ArrayList<>();
AttributesManagerBl attributesManagerBl = this.getPerunBl().getAttributesManagerBl();
for (User u : users) {
RichUser ru = new RichUser(u, getUserExtSources(sess, u));
ru.setUserAttributes(attributesManagerBl.getAttributes(sess, u, attrNames));
result.add(ru);
}
return result;
}
use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class UsersManagerBlImpl method convertUserToRichUserWithAttributesByNames.
@Override
public RichUser convertUserToRichUserWithAttributesByNames(PerunSession sess, User user, List<String> attrNames) {
AttributesManagerBl attributesManagerBl = this.getPerunBl().getAttributesManagerBl();
RichUser richUser = new RichUser(user, getUserExtSources(sess, user));
richUser.setUserAttributes(attributesManagerBl.getAttributes(sess, user, attrNames));
return richUser;
}
use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.
the class ResourcesManagerBlImpl method assignService.
public void assignService(PerunSession sess, Resource resource, Service service) throws InternalErrorException, ServiceNotExistsException, ServiceAlreadyAssignedException, WrongAttributeValueException, WrongReferenceAttributeValueException {
getResourcesManagerImpl().assignService(sess, resource, service);
getPerunBl().getAuditer().log(sess, "{} asigned to {}", service, resource);
AttributesManagerBl attributesManagerBl = getPerunBl().getAttributesManagerBl();
try {
//group and group-resource
List<Group> groups = getAssignedGroups(sess, resource);
for (Group group : groups) {
List<Attribute> attributes;
attributes = attributesManagerBl.getRequiredAttributes(sess, service, resource, group, true);
attributes = attributesManagerBl.fillAttributes(sess, resource, group, attributes, true);
attributesManagerBl.setAttributes(sess, resource, group, attributes, true);
}
// call check of facility's resource's member's user's attributes
Facility facility = getFacility(sess, resource);
attributesManagerBl.checkAttributesValue(sess, facility, attributesManagerBl.getRequiredAttributes(sess, facility));
attributesManagerBl.checkAttributesValue(sess, resource, attributesManagerBl.getRequiredAttributes(sess, resource));
List<Member> members = getAllowedMembers(sess, resource);
for (Member member : members) {
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
// use complex method for getting and setting member-resource, member, user-facility and user-facility required attributes for the service
getPerunBl().getAttributesManagerBl().setRequiredAttributes(sess, service, facility, resource, user, member);
}
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
Aggregations