use of org.sagebionetworks.repo.model.AccessControlList in project BridgeServer2 by Sage-Bionetworks.
the class AppServiceTest method createAppAndUsersDefaultsPasswordPolicy.
@Test
public void createAppAndUsersDefaultsPasswordPolicy() throws SynapseException {
app.setPasswordPolicy(null);
app.setExternalIdRequiredOnSignup(false);
app.setSynapseDataAccessTeamId(null);
app.setSynapseProjectId(null);
List<StudyParticipant> participants = ImmutableList.of(new StudyParticipant.Builder().withEmail(TEST_USER_EMAIL).withSynapseUserId(TEST_USER_SYNAPSE_ID).withRoles(ImmutableSet.of(DEVELOPER)).build());
IdentifierHolder holder = new IdentifierHolder("user-id");
when(mockParticipantService.createParticipant(any(), any(), anyBoolean())).thenReturn(holder);
AccessControlList acl = new AccessControlList();
acl.setResourceAccess(new HashSet<>());
when(mockSynapseClient.createTeam(any())).thenReturn(team);
when(mockSynapseClient.createEntity(any())).thenReturn(project);
when(mockSynapseClient.getACL(any())).thenReturn(acl);
EntityView view = new EntityView();
view.setScopeIds(new ArrayList<>());
when(mockSynapseClient.getEntity(SYNAPSE_TRACKING_VIEW_ID, EntityView.class)).thenReturn(view);
AppAndUsers mockAppAndUsers = new AppAndUsers(ImmutableList.of("12345678"), app, participants);
service.createAppAndUsers(mockAppAndUsers);
verify(mockAppDao).createApp(appCaptor.capture());
assertNotNull(appCaptor.getValue().getPasswordPolicy());
}
use of org.sagebionetworks.repo.model.AccessControlList in project Synapse-Repository-Services by Sage-Bionetworks.
the class JDONodeQueryAuthorizationTest method afterPropertiesSet.
/**
* The setup for this test is expensive so we only do it once after all of the
* beans are ready.
*/
@Override
public void afterPropertiesSet() throws Exception {
Long creatorUserGroupId = Long.parseLong(userGroupDAO.findGroup(AuthorizationConstants.BOOTSTRAP_USER_GROUP_NAME, false).getId());
if (instance != null) {
return;
}
instance = this;
// Keeps track of the users to delete
nodesToDelete = new ArrayList<String>();
groupsToDelete = new ArrayList<String>();
// Create some users
adminUser = createUser("admin@JDONodeQueryAuthorizationTest.org", true);
// Create two groups
groupA = createGroup("groupA@JDONodeQueryAuthorizationTest.org");
groupB = createGroup("groupB@JDONodeQueryAuthorizationTest.org");
// Create users in each group
usersInGroupA = new HashMap<String, UserInfo>();
for (int i = 0; i < 10; i++) {
// Create all of the users
String userId = "userInA" + i + "@JDONodeQueryAuthorizationTest.org";
UserInfo info = createUser(userId, false);
info.getGroups().add(groupA);
usersInGroupA.put(userId, info);
}
// Create group b users
usersInGroupB = new HashMap<String, UserInfo>();
for (int i = 0; i < 7; i++) {
// Create all of the users
String userId = "userInB" + i + "@JDONodeQueryAuthorizationTest.org";
UserInfo info = createUser(userId, false);
info.getGroups().add(groupB);
usersInGroupB.put(userId, info);
}
// Create users in both groups
usersInBothGroups = new HashMap<String, UserInfo>();
for (int i = 0; i < 7; i++) {
// Create all of the users
String userId = "userInBothA&B" + i + "@JDONodeQueryAuthorizationTest.org";
UserInfo info = createUser(userId, false);
info.getGroups().add(groupB);
info.getGroups().add(groupA);
usersInBothGroups.put(userId, info);
}
// Now create the two projects
// Project A
projectA = NodeTestUtils.createNew("projectA", creatorUserGroupId);
projectA.setNodeType(EntityType.project.name());
String id = nodeDao.createNew(projectA);
nodesToDelete.add(id);
projectA = nodeDao.getNode(id);
// Create the ACL for this node.
AccessControlList acl = AccessControlListUtil.createACLToGrantAll(id, adminUser);
// Make sure group A can read from this node
ResourceAccess access = new ResourceAccess();
access.setPrincipalId(Long.parseLong(groupA.getId()));
access.setAccessType(new HashSet<ACCESS_TYPE>());
access.getAccessType().add(ACCESS_TYPE.READ);
acl.getResourceAccess().add(access);
accessControlListDAO.create(acl);
// Project B
projectB = NodeTestUtils.createNew("projectB", creatorUserGroupId);
projectB.setNodeType(EntityType.project.name());
id = nodeDao.createNew(projectB);
nodesToDelete.add(id);
projectB = nodeDao.getNode(id);
// Create the ACL for this node.
acl = AccessControlListUtil.createACLToGrantAll(id, adminUser);
// Make sure group B can read from this node
access = new ResourceAccess();
access.setPrincipalId(Long.parseLong(groupB.getId()));
access.setAccessType(new HashSet<ACCESS_TYPE>());
access.getAccessType().add(ACCESS_TYPE.READ);
acl.getResourceAccess().add(access);
accessControlListDAO.create(acl);
// Now add some nodes to each project.
nodesInProjectA = new HashMap<String, Node>();
for (int i = 0; i < 25; i++) {
Node node = NodeTestUtils.createNew("nodeInProjectA" + i, creatorUserGroupId);
node.setNodeType(EntityType.dataset.name());
node.setParentId(projectA.getId());
id = nodeDao.createNew(node);
// nodesToDelete.add(id);
node = nodeDao.getNode(id);
nodesInProjectA.put(node.getId(), node);
}
// Now add some nodes to each project.
nodesInProjectB = new HashMap<String, Node>();
for (int i = 0; i < 25; i++) {
Node node = NodeTestUtils.createNew("nodeInProjectB" + i, creatorUserGroupId);
node.setNodeType(EntityType.dataset.name());
node.setParentId(projectB.getId());
id = nodeDao.createNew(node);
// nodesToDelete.add(id);
node = nodeDao.getNode(id);
nodesInProjectB.put(node.getId(), node);
// Add an attribute to nodes in group B
NamedAnnotations annos = nodeDao.getAnnotations(id);
assertNotNull(annos);
// fieldTypeDao.addNewType(attributeName, FieldType.LONG_ATTRIBUTE);
annos.getAdditionalAnnotations().addAnnotation(attributeName, new Long(i));
nodeDao.updateAnnotations(id, annos);
}
}
use of org.sagebionetworks.repo.model.AccessControlList in project Synapse-Repository-Services by Sage-Bionetworks.
the class DefaultControllerAutowiredAllTypesTest method testUpdateEntityAcl.
@Test
public void testUpdateEntityAcl() throws Exception {
// First create one of each type
List<Entity> created = createEntitesOfEachType(1);
assertNotNull(created);
assertTrue(created.size() >= EntityType.values().length);
// Now update each
for (Entity entity : created) {
AccessControlList acl = null;
try {
acl = ServletTestHelper.getEntityACL(dispatchServlet, entity.getId(), userName);
} catch (ACLInheritanceException e) {
acl = ServletTestHelper.getEntityACL(dispatchServlet, e.getBenefactorId(), userName);
}
assertNotNull(acl);
ServletTestHelper.updateEntityAcl(dispatchServlet, acl.getId(), acl, userName);
}
}
use of org.sagebionetworks.repo.model.AccessControlList in project Synapse-Repository-Services by Sage-Bionetworks.
the class DefaultControllerAutowiredAllTypesTest method testGetEntityAcl.
@Test
public void testGetEntityAcl() throws Exception {
// First create one of each type
List<Entity> created = createEntitesOfEachType(1);
assertNotNull(created);
assertTrue(created.size() >= EntityType.values().length);
// Now update each
for (Entity entity : created) {
AccessControlList acl = null;
try {
acl = ServletTestHelper.getEntityACL(dispatchServlet, entity.getId(), userName);
} catch (ACLInheritanceException e) {
acl = ServletTestHelper.getEntityACL(dispatchServlet, e.getBenefactorId(), userName);
}
assertNotNull(acl);
}
}
use of org.sagebionetworks.repo.model.AccessControlList in project Synapse-Repository-Services by Sage-Bionetworks.
the class EntityBootstrapperImpl method createAcl.
/**
* Build up an ACL from List<AccessBootstrapData> list.
* @param nodeId
* @param list
* @param groupIdMap
* @return
*/
public static AccessControlList createAcl(String nodeId, String creatorPrincipalId, List<AccessBootstrapData> list) throws DatastoreException {
if (nodeId == null)
throw new IllegalArgumentException("NodeId cannot be null");
AccessControlList acl = new AccessControlList();
acl.setCreationDate(new Date(System.currentTimeMillis()));
acl.setId(nodeId);
Set<ResourceAccess> set = new HashSet<ResourceAccess>();
acl.setResourceAccess(set);
for (AccessBootstrapData data : list) {
// For each group add the types requested.
ResourceAccess access = new ResourceAccess();
set.add(access);
Set<ACCESS_TYPE> typeSet = new HashSet<ACCESS_TYPE>();
access.setAccessType(typeSet);
access.setPrincipalId(data.getGroupId());
// Add each type to the set
List<ACCESS_TYPE> types = data.getAccessTypeList();
for (ACCESS_TYPE type : types) {
typeSet.add(type);
}
}
return acl;
}
Aggregations