Search in sources :

Example 1 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class ReturnDatasetToAuthorCommandTest method setUp.

@Before
public void setUp() {
    dataset = new Dataset();
    HttpServletRequest aHttpServletRequest = null;
    dataverseRequest = new DataverseRequest(MocksFactory.makeAuthenticatedUser("First", "Last"), aHttpServletRequest);
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public AuthenticationServiceBean authentication() {
            return new AuthenticationServiceBean() {

                @Override
                public AuthenticatedUser getAuthenticatedUser(String id) {
                    return MocksFactory.makeAuthenticatedUser("First", "Last");
                }
            };
        }

        @Override
        public IndexServiceBean index() {
            return new IndexServiceBean() {

                @Override
                public Future<String> indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) {
                    return null;
                }
            };
        }

        @Override
        public EntityManager em() {
            return new NoOpTestEntityManager();
        }

        @Override
        public DatasetServiceBean datasets() {
            return new DatasetServiceBean() {

                {
                    em = new NoOpTestEntityManager();
                }

                @Override
                public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
                    return null;
                }

                @Override
                public WorkflowComment addWorkflowComment(WorkflowComment comment) {
                    return comment;
                }

                @Override
                public void removeDatasetLocks(Long datasetId, DatasetLock.Reason aReason) {
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public DataverseRole findBuiltinRoleByAlias(String alias) {
                    return new DataverseRole();
                }

                @Override
                public RoleAssignment save(RoleAssignment assignment) {
                    // no-op
                    return assignment;
                }
            };
        }

        @Override
        public PermissionServiceBean permissions() {
            return new PermissionServiceBean() {

                @Override
                public List<AuthenticatedUser> getUsersWithPermissionOn(Permission permission, DvObject dvo) {
                    // We only need permissions for notifications, which we are testing in InReviewWorkflowIT.
                    return Collections.emptyList();
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) PermissionServiceBean(edu.harvard.iq.dataverse.PermissionServiceBean) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) WorkflowComment(edu.harvard.iq.dataverse.workflows.WorkflowComment) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) NoOpTestEntityManager(edu.harvard.iq.dataverse.engine.NoOpTestEntityManager) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) AuthenticationServiceBean(edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) Permission(edu.harvard.iq.dataverse.authorization.Permission) IndexServiceBean(edu.harvard.iq.dataverse.search.IndexServiceBean) Before(org.junit.Before)

Example 2 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class CreatePrivateUrlCommandTest method setUp.

@Before
public void setUp() {
    dataset = new Dataset();
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public PrivateUrlServiceBean privateUrl() {
            return new PrivateUrlServiceBean() {

                @Override
                public PrivateUrl getPrivateUrlFromDatasetId(long datasetId) {
                    if (datasetId == privateUrlAlreadyExists) {
                        Dataset dataset = new Dataset();
                        dataset.setId(privateUrlAlreadyExists);
                        String token = null;
                        PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
                        RoleAssignment roleAssignment = new RoleAssignment(null, privateUrlUser, dataset, token);
                        return new PrivateUrl(roleAssignment, dataset, "FIXME");
                    } else if (datasetId == latestVersionIsNotDraft) {
                        return null;
                    } else {
                        return null;
                    }
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public DataverseRole findBuiltinRoleByAlias(String alias) {
                    return new DataverseRole();
                }

                @Override
                public RoleAssignment save(RoleAssignment assignment) {
                    // no-op
                    return assignment;
                }
            };
        }

        @Override
        public SystemConfig systemConfig() {
            return new SystemConfig() {

                @Override
                public String getDataverseSiteUrl() {
                    return "https://dataverse.example.edu";
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) SystemConfig(edu.harvard.iq.dataverse.util.SystemConfig) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlServiceBean(edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) Before(org.junit.Before)

Example 3 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class CreateDataverseCommandTest method testDefaultOptions.

@Test
public void testDefaultOptions() throws CommandException {
    Dataverse dv = makeDataverse();
    dv.setCreateDate(null);
    dv.setId(null);
    dv.setCreator(null);
    dv.setDefaultContributorRole(null);
    dv.setOwner(makeDataverse());
    final DataverseRequest request = makeRequest(makeAuthenticatedUser("jk", "rollin'"));
    CreateDataverseCommand sut = new CreateDataverseCommand(dv, request, null, null);
    Dataverse result = engine.submit(sut);
    assertNotNull(result.getCreateDate());
    assertNotNull(result.getId());
    assertEquals(result.getCreator(), request.getUser());
    assertEquals(Dataverse.DataverseType.UNCATEGORIZED, result.getDataverseType());
    assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.EDITOR), result.getDefaultContributorRole());
    // Assert that the creator is admin.
    final RoleAssignment roleAssignment = roles.directRoleAssignments(dv).get(0);
    assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.ADMIN), roleAssignment.getRole());
    assertEquals(dv, roleAssignment.getDefinitionPoint());
    assertEquals(roleAssignment.getAssigneeIdentifier(), request.getUser().getIdentifier());
    // The following is a pretty wierd way to test that the create date defaults to
    // now, but it works across date changes.
    assertTrue("When the supplied creation date is null, date shuld default to command execution time", Math.abs(System.currentTimeMillis() - result.getCreateDate().toInstant().toEpochMilli()) < 1000);
    assertTrue(result.isPermissionRoot());
    assertTrue(result.isThemeRoot());
    assertTrue(indexCalled);
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Example 4 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class ShibGroupServiceBean method delete.

public boolean delete(ShibGroup doomed) throws Exception {
    ActionLogRecord alr = new ActionLogRecord(ActionLogRecord.ActionType.GlobalGroups, "shibDelete");
    alr.setInfo(doomed.getName() + ":" + doomed.getIdentifier());
    List<RoleAssignment> assignments = roleAssigneeSvc.getAssignmentsFor(doomed.getIdentifier());
    if (assignments.isEmpty()) {
        em.remove(doomed);
        actionLogSvc.log(alr);
        return true;
    } else {
        /**
         * @todo Delete role assignments that match this Shib group.
         */
        List<String> assignmentIds = new ArrayList<>();
        for (RoleAssignment assignment : assignments) {
            assignmentIds.add(assignment.getId().toString());
        }
        String message = "Could not delete Shibboleth group id " + doomed.getId() + " due to existing role assignments: " + assignmentIds;
        logger.info(message);
        actionLogSvc.log(alr.setActionResult(ActionLogRecord.Result.BadRequest).setInfo(alr.getInfo() + "// " + message));
        throw new Exception(message);
    }
}
Also used : ActionLogRecord(edu.harvard.iq.dataverse.actionlogging.ActionLogRecord) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException) NonUniqueResultException(javax.persistence.NonUniqueResultException)

Example 5 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class PrivateUrlServiceBean method getPrivateUrlRoleAssignmentFromDataset.

/**
 * @param dataset A non-null dataset;
 * @return A role assignment for a Private URL, if found, or null.
 *
 * @todo This might be a good place for Optional.
 */
private RoleAssignment getPrivateUrlRoleAssignmentFromDataset(Dataset dataset) {
    if (dataset == null) {
        return null;
    }
    TypedQuery<RoleAssignment> query = em.createNamedQuery("RoleAssignment.listByAssigneeIdentifier_DefinitionPointId", RoleAssignment.class);
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(dataset.getId());
    query.setParameter("assigneeIdentifier", privateUrlUser.getIdentifier());
    query.setParameter("definitionPointId", dataset.getId());
    try {
        return query.getSingleResult();
    } catch (NoResultException | NonUniqueResultException ex) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) NoResultException(javax.persistence.NoResultException)

Aggregations

RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)38 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)23 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)22 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)19 Test (org.junit.Test)19 Dataset (edu.harvard.iq.dataverse.Dataset)16 DvObject (edu.harvard.iq.dataverse.DvObject)14 Dataverse (edu.harvard.iq.dataverse.Dataverse)8 ArrayList (java.util.ArrayList)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)7 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)6 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)5 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)4 User (edu.harvard.iq.dataverse.authorization.users.User)4 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)4 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)4 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)4 Before (org.junit.Before)4 DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)3