use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_login method checkAttributeValue.
@Override
public /**
* Calls checkAttribute on u:login-namespace:[login-namespace]
*/
void checkAttributeValue(PerunSessionImpl sess, Facility facility, User user, Attribute attribute) throws WrongAttributeValueException, WrongReferenceAttributeValueException, InternalErrorException, WrongAttributeAssignmentException {
try {
Attribute loginNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":login-namespace");
Attribute loginAttribute = null;
if (loginNamespaceAttribute.getValue() != null) {
loginAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:" + (String) loginNamespaceAttribute.getValue());
if (attribute.getValue() == null)
throw new WrongAttributeValueException(loginAttribute, user, facility, "Login can't be null");
loginAttribute.setValue(attribute.getValue());
sess.getPerunBl().getAttributesManagerBl().checkAttributeValue(sess, user, loginAttribute);
} else {
throw new WrongAttributeValueException(loginNamespaceAttribute, user, facility, "Login-namespace for facility can not be empty.");
}
} catch (AttributeNotExistsException e) {
throw new ConsistencyErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_resource_attribute_def_def_shellsTest method testCheckAttributeValueWrongShellFormatShellIsDirectory.
@Test(expected = WrongAttributeValueException.class)
public void testCheckAttributeValueWrongShellFormatShellIsDirectory() throws Exception {
System.out.println("testCheckAttributeValueWrongShellFormatShellIsDirectory()");
Attribute attributeToCheck = new Attribute();
attributeToCheck.setValue(new ArrayList<String>() {
{
add("/bin/bash/");
}
});
when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Facility.class), anyString())).thenReturn(listOfShells);
classInstance.checkAttributeValue(session, new Resource(), attributeToCheck);
fail("Shell attribute with inappropriate format was approved.");
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_user_attribute_def_def_login_namespace_elixir_persistent_shadowTest method testCheckAttributeValueElixirNamespace.
@Test
public void testCheckAttributeValueElixirNamespace() throws Exception {
System.out.println("testCheckAttributeValue()");
Attribute attribute = new Attribute();
attribute.setFriendlyName("login-namespace:elixir-persistent");
attribute.setValue("28c5353b8bb34984a8bd4169ba94c606@elixir-europe.org");
when(session.getPerunBl().getUsersManagerBl().getUsersByAttribute(any(PerunSession.class), any(Attribute.class))).thenReturn(new ArrayList<User>() {
{
add(user);
}
});
when(session.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(User.class), anyString())).thenReturn(new Attribute() {
{
setValue("28c5353b8bb34984a8bd4169ba94c606@elixir-europe.org");
}
});
assertEquals(attribute.getValue().toString(), "28c5353b8bb34984a8bd4169ba94c606@elixir-europe.org");
classInstance.checkAttributeValue(session, user, attribute);
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_user_attribute_def_def_timezoneTest method testCheckAttributeValue.
@Test
public void testCheckAttributeValue() throws Exception {
System.out.println("testCheckAttributeValue()");
Attribute attributeToCheck = new Attribute();
attributeToCheck.setValue("Europe/Prague");
classInstance.checkAttributeValue(session, user, attributeToCheck);
attributeToCheck.setValue("Africa/Johannesburg");
classInstance.checkAttributeValue(session, user, attributeToCheck);
attributeToCheck.setValue("Jamaica");
classInstance.checkAttributeValue(session, user, attributeToCheck);
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class urn_perun_resource_attribute_def_def_defaultShellTest method checkAttributeValueWhichNotExists.
@Test
public void checkAttributeValueWhichNotExists() throws Exception {
System.out.println("checkAttributeValueWhichNotExists()");
// hledame neexistujici atribut, proto ocekavame vyjimku
when(ps.getPerunBl().getAttributesManagerBl().getAttribute(any(PerunSession.class), any(Resource.class), anyString())).thenThrow(new AttributeNotExistsException("neexistuje"));
final Attribute attribute = new Attribute();
attribute.setValue("mujShell");
try {
defShellAttr.checkAttributeValue(ps, new Resource(), attribute);
fail();
} catch (InternalErrorException ex) {
assertTrue("Mela byt vyhozena vyjimka AttributeNotExistsException", (ex.getCause() instanceof AttributeNotExistsException));
}
}
Aggregations