Search in sources :

Example 26 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.

the class DataverseRoleServiceBean method save.

public DataverseRole save(DataverseRole aRole) {
    if (aRole.getId() == null) {
        em.persist(aRole);
        /**
         * @todo Why would getId be null? Should we call
         * indexDefinitionPoint here too?
         * A: it's null for new roles.
         */
        return aRole;
    } else {
        DataverseRole merged = em.merge(aRole);
        /**
         * @todo update permissionModificationTime here.
         */
        IndexResponse indexDefinitionPountResult = indexDefinitionPoint(merged.getOwner());
        logger.info("aRole getId was not null. Indexing result: " + indexDefinitionPountResult);
        return merged;
    }
}
Also used : IndexResponse(edu.harvard.iq.dataverse.search.IndexResponse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 27 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.

the class DataverseRoleServiceBean method getDataverseRolesByPermission.

public List<DataverseRole> getDataverseRolesByPermission(Permission permissionIn, Long ownerId) {
    /*
         For a given permission and dataverse Id get all of the roles (built-in or owned by the dataverse)            
         that contain that permission
         */
    List<DataverseRole> rolesToCheck = findBuiltinRoles();
    List<DataverseRole> retVal = new ArrayList<>();
    rolesToCheck.addAll(findByOwnerId(ownerId));
    for (DataverseRole role : rolesToCheck) {
        if (role.permissions().contains(permissionIn)) {
            retVal.add(role);
        }
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 28 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.

the class DataverseRoleServiceBean method revoke.

public void revoke(Set<DataverseRole> roles, RoleAssignee assignee, DvObject defPoint) {
    for (DataverseRole role : roles) {
        em.createNamedQuery("RoleAssignment.deleteByAssigneeIdentifier_RoleIdDefinition_PointId").setParameter("assigneeIdentifier", assignee.getIdentifier()).setParameter("roleId", role.getId()).setParameter("definitionPointId", defPoint.getId()).executeUpdate();
        em.refresh(role);
    }
    em.refresh(assignee);
}
Also used : DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 29 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.

the class Roles method viewRole.

@GET
@Path("{id}")
public Response viewRole(@PathParam("id") Long id) {
    return response(() -> {
        final User user = findUserOrDie();
        final DataverseRole role = findRoleOrDie(id);
        return (permissionSvc.userOn(user, role.getOwner()).has(Permission.ManageDataversePermissions)) ? ok(json(role)) : permissionError("Permission required to view roles.");
    });
}
Also used : User(edu.harvard.iq.dataverse.authorization.users.User) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 30 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.

the class RoleDTO method asRole.

public DataverseRole asRole() {
    DataverseRole r = new DataverseRole();
    r.setAlias(alias);
    r.setDescription(description);
    r.setName(name);
    if (permissions != null) {
        if (permissions.length > 0) {
            if (permissions[0].trim().toLowerCase().equals("all")) {
                r.addPermissions(EnumSet.allOf(Permission.class));
            } else {
                for (String ps : permissions) {
                    r.addPermission(Permission.valueOf(ps));
                }
            }
        }
    }
    return r;
}
Also used : Permission(edu.harvard.iq.dataverse.authorization.Permission) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Aggregations

DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)44 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)23 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)19 Test (org.junit.Test)19 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)18 Dataset (edu.harvard.iq.dataverse.Dataset)16 DvObject (edu.harvard.iq.dataverse.DvObject)12 Dataverse (edu.harvard.iq.dataverse.Dataverse)9 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)6 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)6 ArrayList (java.util.ArrayList)5 User (edu.harvard.iq.dataverse.authorization.users.User)4 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)3 Permission (edu.harvard.iq.dataverse.authorization.Permission)3 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)3 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)3 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)3 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)3 Timestamp (java.sql.Timestamp)3