Search in sources :

Example 1 with AttributeRights

use of cz.metacentrum.perun.core.api.AttributeRights in project perun by CESNET.

the class AttributesManagerEntryIntegrationTest method getAttributeRights.

@Test
public void getAttributeRights() throws Exception {
    System.out.println(CLASS_NAME + "getAttributeRights");
    // setting rights
    List<ActionType> listOfActions = new ArrayList<ActionType>();
    listOfActions.add(ActionType.WRITE);
    listOfActions.add(ActionType.READ);
    List<AttributeRights> rights = new ArrayList<AttributeRights>();
    rights.add(new AttributeRights(1, Role.VOADMIN, listOfActions));
    rights.add(new AttributeRights(1, Role.SELF, new ArrayList<ActionType>()));
    perun.getAttributesManager().setAttributeRights(sess, rights);
    // getting rights
    rights.clear();
    rights = perun.getAttributesManager().getAttributeRights(sess, 1);
    assertTrue("list of rights should have 4 items for each role", rights.size() == 4);
    for (AttributeRights attributeRights : rights) {
        if (attributeRights.getRole().equals(Role.VOADMIN)) {
            assertTrue("our attribute 1 should have right READ for VOADMIN", attributeRights.getRights().contains(ActionType.READ));
            assertTrue("our attribute 1 should have right WRITE for VOADMIN", attributeRights.getRights().contains(ActionType.WRITE));
        }
        if (attributeRights.getRole().equals(Role.SELF)) {
            assertTrue("our attribute 1 should not have rights for SELF", attributeRights.getRights().isEmpty());
        }
    }
}
Also used : ActionType(cz.metacentrum.perun.core.api.ActionType) AttributeRights(cz.metacentrum.perun.core.api.AttributeRights) ArrayList(java.util.ArrayList) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 2 with AttributeRights

use of cz.metacentrum.perun.core.api.AttributeRights in project perun by CESNET.

the class AttributesManagerEntryIntegrationTest method setAttributeRights.

@Test
public void setAttributeRights() throws Exception {
    System.out.println(CLASS_NAME + "setAttributeRights");
    List<ActionType> listOfActions = new ArrayList<ActionType>();
    listOfActions.add(ActionType.WRITE);
    listOfActions.add(ActionType.READ);
    List<AttributeRights> rights = new ArrayList<AttributeRights>();
    rights.add(new AttributeRights(1, Role.VOADMIN, listOfActions));
    listOfActions.clear();
    listOfActions.add(ActionType.READ);
    rights.add(new AttributeRights(1, Role.SELF, listOfActions));
    perun.getAttributesManager().setAttributeRights(sess, rights);
    listOfActions.clear();
    rights.clear();
    listOfActions.add(ActionType.WRITE);
    rights.add(new AttributeRights(1, Role.VOADMIN, new ArrayList<ActionType>()));
    rights.add(new AttributeRights(1, Role.SELF, listOfActions));
    perun.getAttributesManager().setAttributeRights(sess, rights);
    rights.clear();
    rights = perun.getAttributesManager().getAttributeRights(sess, 1);
    for (AttributeRights attributeRights : rights) {
        if (attributeRights.getRole().equals(Role.SELF)) {
            assertTrue("our attribute 1 should not have right READ for VOADMIN", !(attributeRights.getRights().contains(ActionType.READ)));
            assertTrue("our attribute 1 should have right WRITE for VOADMIN", attributeRights.getRights().contains(ActionType.WRITE));
        }
        if (attributeRights.getRole().equals(Role.VOADMIN)) {
            assertTrue("our attribute 1 should not have rights for VOADMIN", attributeRights.getRights().isEmpty());
        }
    }
}
Also used : ActionType(cz.metacentrum.perun.core.api.ActionType) AttributeRights(cz.metacentrum.perun.core.api.AttributeRights) ArrayList(java.util.ArrayList) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with AttributeRights

use of cz.metacentrum.perun.core.api.AttributeRights in project perun by CESNET.

the class AttributesManagerBlImpl method setAttributeRights.

@Override
public void setAttributeRights(PerunSession sess, List<AttributeRights> rights) throws InternalErrorException {
    for (AttributeRights right : rights) {
        getAttributesManagerImpl().setAttributeRight(sess, right);
        getPerunBl().getAuditer().log(sess, "Attribute right set : {}", right);
        //If these rights are for VoAdmin, do the same for VoObserver but only for READ privilegies
        if (right.getRole().equals(Role.VOADMIN)) {
            List<ActionType> onlyReadActionType = new ArrayList<ActionType>();
            if (right.getRights().contains(ActionType.READ))
                onlyReadActionType.add(ActionType.READ);
            right.setRights(onlyReadActionType);
            right.setRole(Role.VOOBSERVER);
            //Rights are now set for VoObserver with read privilegies on the same attribute like VoAdmin
            getAttributesManagerImpl().setAttributeRight(sess, right);
            getPerunBl().getAuditer().log(sess, "Attribute right set : {}", right);
        }
    }
}
Also used : ActionType(cz.metacentrum.perun.core.api.ActionType) AttributeRights(cz.metacentrum.perun.core.api.AttributeRights) ArrayList(java.util.ArrayList)

Example 4 with AttributeRights

use of cz.metacentrum.perun.core.api.AttributeRights in project perun by CESNET.

the class AttributesManagerEntry method setAttributeRights.

public void setAttributeRights(PerunSession sess, List<AttributeRights> rights) throws InternalErrorException, PrivilegeException, AttributeNotExistsException {
    Utils.checkPerunSession(sess);
    // so as we can check, if the attributes exist
    for (AttributeRights attributeright : rights) {
        getAttributeDefinitionById(sess, attributeright.getAttributeId());
    }
    if (!AuthzResolver.isAuthorized(sess, Role.PERUNADMIN))
        throw new PrivilegeException("This operation can do only PerunAdmin.");
    getAttributesManagerBl().setAttributeRights(sess, rights);
}
Also used : AttributeRights(cz.metacentrum.perun.core.api.AttributeRights)

Example 5 with AttributeRights

use of cz.metacentrum.perun.core.api.AttributeRights in project perun by CESNET.

the class AttributesManagerImpl method getAttributeRights.

@Override
public List<AttributeRights> getAttributeRights(PerunSession sess, final int attributeId) throws InternalErrorException {
    List<AttributeRights> rights = null;
    try {
        rights = jdbc.query("select " + attributeRightSelectQuery + " from attributes_authz join roles on " + "attributes_authz.role_id=roles.id join action_types on attributes_authz.action_type_id=action_types.id where " + "attributes_authz.attr_id=?", new AttributeRightsExtractor(attributeId), attributeId);
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
    // set also empty rights for other roles (not present in DB)
    boolean roleExists;
    List<Role> listOfRoles = new ArrayList<Role>();
    listOfRoles.add(Role.FACILITYADMIN);
    listOfRoles.add(Role.GROUPADMIN);
    listOfRoles.add(Role.SELF);
    listOfRoles.add(Role.VOADMIN);
    for (Role roleToTry : listOfRoles) {
        roleExists = false;
        Iterator itr = rights.iterator();
        while ((itr.hasNext()) && (!roleExists)) {
            AttributeRights right = (AttributeRights) itr.next();
            if (right.getRole().equals(roleToTry)) {
                roleExists = true;
            }
        }
        if (!roleExists) {
            rights.add(new AttributeRights(attributeId, roleToTry, new ArrayList<ActionType>()));
        }
    }
    return rights;
}
Also used : Role(cz.metacentrum.perun.core.api.Role) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) AttributeRights(cz.metacentrum.perun.core.api.AttributeRights) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

AttributeRights (cz.metacentrum.perun.core.api.AttributeRights)5 ActionType (cz.metacentrum.perun.core.api.ActionType)3 ArrayList (java.util.ArrayList)3 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)2 Test (org.junit.Test)2 Role (cz.metacentrum.perun.core.api.Role)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 ConsistencyErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException)1 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)1