Search in sources :

Example 46 with Attribute

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);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 47 with Attribute

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.");
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) Attribute(cz.metacentrum.perun.core.api.Attribute) Resource(cz.metacentrum.perun.core.api.Resource) Matchers.anyString(org.mockito.Matchers.anyString) Facility(cz.metacentrum.perun.core.api.Facility) Test(org.junit.Test)

Example 48 with Attribute

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);
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) Test(org.junit.Test)

Example 49 with 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);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) Test(org.junit.Test)

Example 50 with Attribute

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));
    }
}
Also used : PerunSession(cz.metacentrum.perun.core.api.PerunSession) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) Resource(cz.metacentrum.perun.core.api.Resource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Test(org.junit.Test)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1689 Test (org.junit.Test)615 ArrayList (java.util.ArrayList)492 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)489 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)478 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)313 User (cz.metacentrum.perun.core.api.User)301 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)280 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)231 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)221 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)218 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)197 Facility (cz.metacentrum.perun.core.api.Facility)190 Resource (cz.metacentrum.perun.core.api.Resource)187 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)180 List (java.util.List)177 LinkedHashMap (java.util.LinkedHashMap)158 Before (org.junit.Before)156 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)145 Method (java.lang.reflect.Method)140