use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_login method setAttributeValue.
@Override
public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
AttributeDefinition userLoginAttributeDefinition;
try {
// Get the f:login-namespace attribute
Attribute loginNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":login-namespace");
if (loginNamespaceAttribute.getValue() == null) {
throw new WrongReferenceAttributeValueException(attribute, loginNamespaceAttribute, user, facility, "Facility need to have nonempty login-namespace attribute.");
}
userLoginAttributeDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:" + (String) loginNamespaceAttribute.getValue());
} catch (AttributeNotExistsException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
Attribute userLoginAttribute = new Attribute(userLoginAttributeDefinition);
userLoginAttribute.setValue(attribute.getValue());
try {
return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userLoginAttribute);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_UID method fillAttribute.
/**
* Fills the new UID for the user at the specified facility. First empty slot
* in range (minUID, maxUID) is returned.
*/
@Override
public Attribute fillAttribute(PerunSessionImpl sess, Facility facility, User user, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
try {
Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
Attribute attr = new Attribute(attribute);
if (uidNamespaceAttribute.getValue() != null) {
// Get the u:uid-namespace[uidNamespaceAttribute]
Attribute uidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + (String) uidNamespaceAttribute.getValue());
uidAttribute = sess.getPerunBl().getAttributesManagerBl().fillAttribute(sess, user, uidAttribute);
attr.setValue(uidAttribute.getValue());
} else {
attr.setValue(null);
}
return attr;
} catch (AttributeNotExistsException e) {
throw new ConsistencyErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_UID method getAttributeValue.
/**
* Gets the value of the attribute f:uid-namespace and then finds the value of the attribute u:uid-namespace:[uid-namespace]
*/
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Facility facility, User user, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attr = new Attribute(attributeDefinition);
Attribute uidAttribute = null;
try {
// Get the f:uid-namespace attribute
Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
if (uidNamespaceAttribute.getValue() != null) {
// Get the u:uid-namespace[uidNamespaceAttribute]
uidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + (String) uidNamespaceAttribute.getValue());
attr = Utils.copyAttributeToVirtualAttributeWithValue(uidAttribute, attr);
} else {
attr.setValue(null);
}
} catch (AttributeNotExistsException e) {
throw new ConsistencyErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
return attr;
}
use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_UID method setAttributeValue.
@Override
public boolean setAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
AttributeDefinition userUidAttributeDefinition;
try {
// Get the f:uid-namespace attribute
Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
if (uidNamespaceAttribute.getValue() == null) {
throw new WrongReferenceAttributeValueException(attribute, uidNamespaceAttribute);
}
userUidAttributeDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + (String) uidNamespaceAttribute.getValue());
} catch (AttributeNotExistsException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
Attribute userUidAttribute = new Attribute(userUidAttributeDefinition);
userUidAttribute.setValue(attribute.getValue());
try {
return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userUidAttribute);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException in project perun by CESNET.
the class ModulesUtilsEntryIntegrationTest method setUpFacilityGroupNameAndGIDNamespaceAttributes.
private List<Attribute> setUpFacilityGroupNameAndGIDNamespaceAttributes() throws Exception {
Attribute facilityGroupNameNamespace = new Attribute();
Attribute facilityGIDNamespace = new Attribute();
List<Attribute> attributes = new ArrayList<Attribute>();
try {
facilityGIDNamespace = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGID-namespace"));
facilityGIDNamespace.setValue(namespace);
} catch (AttributeNotExistsException ex) {
facilityGIDNamespace.setNamespace(AttributesManager.NS_FACILITY_ATTR_DEF);
facilityGIDNamespace.setFriendlyName("unixGID-namespace");
facilityGIDNamespace.setType(String.class.getName());
facilityGIDNamespace.setValue(namespace);
assertNotNull("unable to create group attribute", perun.getAttributesManagerBl().createAttribute(sess, facilityGIDNamespace));
}
attributes.add(facilityGIDNamespace);
try {
facilityGroupNameNamespace = new Attribute(perun.getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGroupName-namespace"));
facilityGroupNameNamespace.setValue(namespace);
} catch (AttributeNotExistsException ex) {
facilityGroupNameNamespace.setNamespace(AttributesManager.NS_FACILITY_ATTR_DEF);
facilityGroupNameNamespace.setFriendlyName("unixGroupName-namespace");
facilityGroupNameNamespace.setType(String.class.getName());
facilityGroupNameNamespace.setValue(namespace);
assertNotNull("unable to create group attribute", perun.getAttributesManagerBl().createAttribute(sess, facilityGroupNameNamespace));
}
attributes.add(facilityGroupNameNamespace);
return attributes;
}
Aggregations