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