Search in sources :

Example 11 with AuthenticatedUser

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

the class GroupUtilTest method testGetAllIdentifiersForUserWithNoGroups.

@Test
public void testGetAllIdentifiersForUserWithNoGroups() {
    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    authenticatedUser.setUserIdentifier("pete");
    Set<Group> groups = new LinkedHashSet<>();
    String expected = "'@pete'";
    String actual = GroupUtil.getAllIdentifiersForUser(authenticatedUser, groups);
    assertEquals(expected, actual);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Test(org.junit.Test)

Example 12 with AuthenticatedUser

use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser 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 13 with AuthenticatedUser

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

the class MocksFactory method makeAuthenticatedUser.

public static AuthenticatedUser makeAuthenticatedUser(String firstName, String lastName) {
    AuthenticatedUser user = new AuthenticatedUser();
    user.setId(nextId());
    user.setAffiliation("UnitTester");
    user.setEmail(firstName + "." + lastName + "@someU.edu");
    user.setLastName(lastName);
    user.setFirstName(firstName);
    user.setPosition("In-Memory user");
    user.setUserIdentifier("unittest" + user.getId());
    user.setCreatedTime(new Timestamp(new Date().getTime()));
    user.setLastLoginTime(user.getCreatedTime());
    return user;
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Timestamp(java.sql.Timestamp) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 14 with AuthenticatedUser

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

the class DataCaptureModuleUtilTest method testGenerateJsonForUploadRequest.

@Test
public void testGenerateJsonForUploadRequest() {
    System.out.println("generateJsonForUploadRequest");
    AuthenticatedUser user = makeAuthenticatedUser("Ralph", "Rsync");
    Dataset dataset = new Dataset();
    dataset.setIdentifier("42");
    JsonObject result = DataCaptureModuleUtil.generateJsonForUploadRequest(user, dataset);
    assertEquals("42", result.getString("datasetIdentifier"));
    int userId = result.getInt("userId");
    assertTrue(Integer.MIN_VALUE <= userId && userId <= Integer.MAX_VALUE);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) JsonObject(javax.json.JsonObject) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) MocksFactory.makeAuthenticatedUser(edu.harvard.iq.dataverse.mocks.MocksFactory.makeAuthenticatedUser) Test(org.junit.Test)

Example 15 with AuthenticatedUser

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

the class CreateRoleCommandTest method testNonSuperUsersCantAddRoles.

@Test(expected = IllegalCommandException.class)
public void testNonSuperUsersCantAddRoles() throws CommandException {
    DataverseRole dvr = new DataverseRole();
    dvr.setAlias("roleTest");
    dvr.setName("Tester Role");
    dvr.addPermission(Permission.AddDataset);
    Dataverse dv = MocksFactory.makeDataverse();
    dvr.setOwner(dv);
    AuthenticatedUser normalUser = new AuthenticatedUser();
    normalUser.setSuperuser(false);
    CreateRoleCommand sut = new CreateRoleCommand(dvr, new DataverseRequest(normalUser, IpAddress.valueOf("89.17.33.33")), dv);
    engine.submit(sut);
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Dataverse(edu.harvard.iq.dataverse.Dataverse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) Test(org.junit.Test)

Aggregations

AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)125 Dataverse (edu.harvard.iq.dataverse.Dataverse)24 Timestamp (java.sql.Timestamp)24 Date (java.util.Date)24 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)23 Dataset (edu.harvard.iq.dataverse.Dataset)22 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)21 Path (javax.ws.rs.Path)19 EJBException (javax.ejb.EJBException)16 ArrayList (java.util.ArrayList)14 User (edu.harvard.iq.dataverse.authorization.users.User)13 DataFile (edu.harvard.iq.dataverse.DataFile)11 IOException (java.io.IOException)11 JsonObjectBuilder (javax.json.JsonObjectBuilder)11 POST (javax.ws.rs.POST)11 Test (org.junit.Test)11 BuiltinUser (edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser)10 SwordError (org.swordapp.server.SwordError)10 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)8 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)8