use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetPrivateUrlFromRoleAssignmentDatasetNull.
@Test
public void testGetPrivateUrlFromRoleAssignmentDatasetNull() {
String dataverseSiteUrl = "https://dataverse.example.edu";
DataverseRole aRole = null;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUser;
DvObject dataset = null;
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
PrivateUrl privateUrl = PrivateUrlUtil.getPrivateUrlFromRoleAssignment(ra, dataverseSiteUrl);
assertNull(privateUrl);
}
use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetDatasetFromRoleAssignmentSuccess.
@Test
public void testGetDatasetFromRoleAssignmentSuccess() {
DataverseRole aRole = null;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUser;
DvObject dataset = new Dataset();
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
assertNotNull(PrivateUrlUtil.getDatasetFromRoleAssignment(ra));
assertEquals("#42", ra.getAssigneeIdentifier());
}
use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetPrivateUrlRedirectDataSuccess.
@Test
public void testGetPrivateUrlRedirectDataSuccess() {
DataverseRole aRole = null;
long datasetId = 42;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
RoleAssignee anAssignee = privateUrlUser;
Dataset dataset = new Dataset();
dataset.setProtocol("doi");
dataset.setAuthority("10.5072/FK2");
dataset.setIdentifier("3L33T");
dataset.setId(datasetId);
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
PrivateUrlRedirectData privateUrlRedirectData = PrivateUrlUtil.getPrivateUrlRedirectData(ra);
assertNotNull(privateUrlRedirectData);
assertEquals("/dataset.xhtml?persistentId=doi:10.5072/FK2/3L33T&version=DRAFT", privateUrlRedirectData.getDraftDatasetPageToBeRedirectedTo());
assertEquals(privateUrlUser.getIdentifier(), privateUrlRedirectData.getPrivateUrlUser().getIdentifier());
}
use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class DeletePrivateUrlCommandTest method setUp.
@Before
public void setUp() {
testEngine = new TestDataverseEngine(new TestCommandContext() {
@Override
public PrivateUrlServiceBean privateUrl() {
return new PrivateUrlServiceBean() {
@Override
public PrivateUrl getPrivateUrlFromDatasetId(long datasetId) {
if (datasetId == noPrivateUrlToDelete) {
return null;
} else if (datasetId == hasPrivateUrlToDelete) {
Dataset dataset = new Dataset();
dataset.setId(hasPrivateUrlToDelete);
String token = null;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
RoleAssignment roleAssignment = new RoleAssignment(null, privateUrlUser, dataset, token);
return new PrivateUrl(roleAssignment, dataset, "FIXME");
} else {
return null;
}
}
};
}
@Override
public DataverseRoleServiceBean roles() {
return new DataverseRoleServiceBean() {
@Override
public List<RoleAssignment> directRoleAssignments(RoleAssignee roas, DvObject dvo) {
RoleAssignment roleAssignment = new RoleAssignment();
List<RoleAssignment> list = new ArrayList<>();
list.add(roleAssignment);
return list;
}
@Override
public void revoke(RoleAssignment ra) {
// no-op
}
};
}
});
}
use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class AddRoleAssigneesToExplicitGroupCommand method execute.
@Override
public ExplicitGroup execute(CommandContext ctxt) throws CommandException {
List<String> nonexistentRAs = new LinkedList<>();
for (String rai : roleAssigneeIdentifiers) {
RoleAssignee ra = null;
try {
ra = ctxt.roleAssignees().getRoleAssignee(rai);
} catch (EJBException iae) {
if (iae.getCausedByException() instanceof IllegalArgumentException) {
throw new IllegalCommandException("Bad role assignee name:" + rai, this);
}
}
if (ra == null) {
nonexistentRAs.add(rai);
} else {
try {
explicitGroup.add(ra);
} catch (GroupException ex) {
Logger.getLogger(AddRoleAssigneesToExplicitGroupCommand.class.getName()).log(Level.WARNING, "Error adding role assignee " + rai + " to group" + " " + explicitGroup.getIdentifier(), ex);
throw new IllegalCommandException("Error adding " + rai + " to group " + explicitGroup.getIdentifier() + ": " + ex.getMessage(), this);
}
}
}
if (nonexistentRAs.isEmpty()) {
return ctxt.explicitGroups().persist(explicitGroup);
} else {
StringBuilder sb = new StringBuilder();
for (String s : nonexistentRAs) {
sb.append(s).append(", ");
}
sb.setLength(sb.length() - 2);
throw new IllegalCommandException("The following role assignees were not found: " + sb.toString(), this);
}
}
Aggregations