use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_attribute_def_def_eduroamIdentities method fillAttribute.
@Override
public Attribute fillAttribute(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) throws WrongAttributeAssignmentException {
List<String> value = new ArrayList<>();
try {
String loginMU = (String) sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, "urn:perun:user:attribute-def:def:login-namespace:mu").getValue();
if (loginMU != null)
value.add(loginMU + "@eduroam.muni.cz");
String loginCesnet = (String) sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, "urn:perun:user:attribute-def:def:login-namespace:cesnet").getValue();
if (loginCesnet != null)
value.add(loginCesnet + "@cesnet.cz");
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
Attribute attribute = new Attribute(attributeDefinition);
attribute.setValue(value);
return attribute;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_resource_attribute_def_virt_unixGID method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Resource resource, Attribute attribute) throws WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
Attribute unixGIDNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGIDNamespaceAttributeWithNotNullValue(sess, resource);
Attribute gidAttribute;
try {
gidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_unixGID_namespace + unixGIDNamespaceAttribute.getValue());
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
gidAttribute.setValue(attribute.getValue());
try {
sess.getPerunBl().getAttributesManagerBl().forceCheckAttributeSemantics(sess, resource, gidAttribute);
} catch (WrongReferenceAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, ex.getReferenceAttribute(), ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class ModulesUtilsBlImpl method getSetOfGIDNamespacesWhereFacilitiesHasTheSameGroupNameNamespace.
@Override
public Set<String> getSetOfGIDNamespacesWhereFacilitiesHasTheSameGroupNameNamespace(PerunSessionImpl sess, List<Facility> facilities, Attribute unixGroupNameNamespace) throws WrongAttributeAssignmentException {
Set<String> gidNamespaces = new HashSet<>();
if (facilities == null || facilities.isEmpty())
return gidNamespaces;
Utils.notNull(facilities, "facilities");
for (Facility f : facilities) {
Attribute facilityGroupNameNamespace;
try {
facilityGroupNameNamespace = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, f, A_F_unixGroupName_namespace);
if (facilityGroupNameNamespace.getValue() != null) {
// if they are same, save GID-namespace from this facility to hashSet
if (unixGroupNameNamespace.getFriendlyNameParameter().equals(facilityGroupNameNamespace.getValue())) {
Attribute facilityGIDNamespace = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, f, A_F_unixGID_namespace);
// If facilityGIDNamespace exists and is not null, save to the hashSet of gidNamespaces
if (facilityGIDNamespace.getValue() != null) {
gidNamespaces.add((String) facilityGIDNamespace.getValue());
}
}
}
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
return gidNamespaces;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class ModulesUtilsBlImpl method getUserByLoginInNamespace.
@Override
public User getUserByLoginInNamespace(PerunSession sess, String login, String namespace) {
String attrName = AttributesManager.NS_USER_ATTR_DEF + ":" + AttributesManager.LOGIN_NAMESPACE + ":" + namespace;
List<User> usersByLoginInNamespace = getPerunBl().getUsersManagerBl().getUsersByAttributeValue(sess, attrName, login);
if (usersByLoginInNamespace.isEmpty()) {
return null;
} else if (usersByLoginInNamespace.size() == 1) {
return usersByLoginInNamespace.get(0);
} else {
throw new ConsistencyErrorException("There is more than 1 login '" + login + "' in namespace " + namespace + ".");
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException 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