Search in sources :

Example 11 with PrivateUrlUser

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

the class PrivateUrlUtilTest method testIdentifier2roleAssignee.

@Test
public void testIdentifier2roleAssignee() {
    RoleAssignee returnValueFromEmptyString = null;
    try {
        returnValueFromEmptyString = PrivateUrlUtil.identifier2roleAssignee("");
    } catch (Exception ex) {
        assertEquals(ex.getClass(), IllegalArgumentException.class);
        assertEquals(ex.getMessage(), "Could not find dataset id in ''");
    }
    assertNull(returnValueFromEmptyString);
    RoleAssignee returnValueFromNonColon = null;
    String peteIdentifier = "@pete";
    try {
        returnValueFromNonColon = PrivateUrlUtil.identifier2roleAssignee(peteIdentifier);
    } catch (Exception ex) {
        assertEquals(ex.getClass(), IllegalArgumentException.class);
        assertEquals(ex.getMessage(), "Could not find dataset id in '" + peteIdentifier + "'");
    }
    assertNull(returnValueFromNonColon);
    RoleAssignee returnValueFromNonNumber = null;
    String nonNumberIdentifier = PrivateUrlUser.PREFIX + "nonNumber";
    try {
        returnValueFromNonNumber = PrivateUrlUtil.identifier2roleAssignee(nonNumberIdentifier);
    } catch (Exception ex) {
        assertEquals(ex.getClass(), IllegalArgumentException.class);
        assertEquals(ex.getMessage(), "Could not find dataset id in '" + nonNumberIdentifier + "'");
    }
    assertNull(returnValueFromNonNumber);
    RoleAssignee returnFromValidIdentifier = null;
    String validIdentifier = PrivateUrlUser.PREFIX + 42;
    returnFromValidIdentifier = PrivateUrlUtil.identifier2roleAssignee(validIdentifier);
    assertNotNull(returnFromValidIdentifier);
    assertEquals("#42", returnFromValidIdentifier.getIdentifier());
    assertEquals("Private URL Enabled", returnFromValidIdentifier.getDisplayInfo().getTitle());
    Assert.assertTrue(returnFromValidIdentifier instanceof PrivateUrlUser);
    PrivateUrlUser privateUrlUser42 = (PrivateUrlUser) returnFromValidIdentifier;
    assertEquals(42, privateUrlUser42.getDatasetId());
}
Also used : PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 12 with PrivateUrlUser

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

the class PrivateUrlUtilTest method testGetDatasetFromRoleAssignmentNonDataset.

@Test
public void testGetDatasetFromRoleAssignmentNonDataset() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    DvObject nonDataset = new Dataverse();
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, nonDataset, privateUrlToken);
    assertNull(PrivateUrlUtil.getDatasetFromRoleAssignment(ra));
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 13 with PrivateUrlUser

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

the class PrivateUrlUtilTest method testGetUserFromRoleAssignmentSucess.

@Test
public void testGetUserFromRoleAssignmentSucess() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUserIn;
    DvObject dataset = new Dataset();
    dataset.setId(123l);
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrlUserOut = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(ra);
    assertNotNull(privateUrlUserOut);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 14 with PrivateUrlUser

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

the class PrivateUrlUtilTest method testGetPrivateUrlUserFromRoleAssignmentAndAssigneeSuccess.

@Test
public void testGetPrivateUrlUserFromRoleAssignmentAndAssigneeSuccess() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee assignee = privateUrlUser;
    DvObject dataset = new Dataset();
    dataset.setId(42l);
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment assignment = new RoleAssignment(aRole, assignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrl = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(assignment, assignee);
    assertNotNull(privateUrl);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 15 with PrivateUrlUser

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

the class LazyRef method findUserOrDie.

/**
 * Returns the user of pointed by the API key, or the guest user
 * @return a user, may be a guest user.
 * @throws edu.harvard.iq.dataverse.api.AbstractApiBean.WrappedResponse iff there is an api key present, but it is invalid.
 */
protected User findUserOrDie() throws WrappedResponse {
    final String requestApiKey = getRequestApiKey();
    if (requestApiKey == null) {
        return GuestUser.get();
    }
    PrivateUrlUser privateUrlUser = privateUrlSvc.getPrivateUrlUserFromToken(requestApiKey);
    if (privateUrlUser != null) {
        return privateUrlUser;
    }
    return findAuthenticatedUserOrDie(requestApiKey);
}
Also used : PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)

Aggregations

PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)33 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)22 Test (org.junit.Test)21 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)18 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)18 Dataset (edu.harvard.iq.dataverse.Dataset)14 DvObject (edu.harvard.iq.dataverse.DvObject)11 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)6 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)5 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)4 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)4 ArrayList (java.util.ArrayList)3 JsonObject (javax.json.JsonObject)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)2 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 GuestUser (edu.harvard.iq.dataverse.authorization.users.GuestUser)2 User (edu.harvard.iq.dataverse.authorization.users.User)2 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)2