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());
}
}
}
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());
}
}
}
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);
}
}
}
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);
}
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;
}
Aggregations