Search in sources :

Example 1 with AccessControlList

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());
}
Also used : AccessControlList(org.sagebionetworks.repo.model.AccessControlList) IdentifierHolder(org.sagebionetworks.bridge.models.accounts.IdentifierHolder) EntityView(org.sagebionetworks.repo.model.table.EntityView) AppAndUsers(org.sagebionetworks.bridge.models.apps.AppAndUsers) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) Test(org.testng.annotations.Test)

Example 2 with AccessControlList

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);
    }
}
Also used : AccessControlList(org.sagebionetworks.repo.model.AccessControlList) ResourceAccess(org.sagebionetworks.repo.model.ResourceAccess) Node(org.sagebionetworks.repo.model.Node) UserInfo(org.sagebionetworks.repo.model.UserInfo) ACCESS_TYPE(org.sagebionetworks.repo.model.ACCESS_TYPE) NamedAnnotations(org.sagebionetworks.repo.model.NamedAnnotations)

Example 3 with AccessControlList

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);
    }
}
Also used : AccessControlList(org.sagebionetworks.repo.model.AccessControlList) ACLInheritanceException(org.sagebionetworks.repo.model.ACLInheritanceException) Entity(org.sagebionetworks.repo.model.Entity) Test(org.junit.Test)

Example 4 with AccessControlList

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);
    }
}
Also used : AccessControlList(org.sagebionetworks.repo.model.AccessControlList) ACLInheritanceException(org.sagebionetworks.repo.model.ACLInheritanceException) Entity(org.sagebionetworks.repo.model.Entity) Test(org.junit.Test)

Example 5 with AccessControlList

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;
}
Also used : AccessControlList(org.sagebionetworks.repo.model.AccessControlList) ResourceAccess(org.sagebionetworks.repo.model.ResourceAccess) ACCESS_TYPE(org.sagebionetworks.repo.model.ACCESS_TYPE) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

AccessControlList (org.sagebionetworks.repo.model.AccessControlList)86 Test (org.junit.Test)59 ResourceAccess (org.sagebionetworks.repo.model.ResourceAccess)35 ACCESS_TYPE (org.sagebionetworks.repo.model.ACCESS_TYPE)30 UserInfo (org.sagebionetworks.repo.model.UserInfo)26 Node (org.sagebionetworks.repo.model.Node)19 HashSet (java.util.HashSet)18 UserGroup (org.sagebionetworks.repo.model.UserGroup)16 Project (org.sagebionetworks.repo.model.Project)13 Annotations (org.sagebionetworks.repo.model.Annotations)12 Date (java.util.Date)11 Study (org.sagebionetworks.repo.model.Study)10 ACLInheritanceException (org.sagebionetworks.repo.model.ACLInheritanceException)9 EntityBundle (org.sagebionetworks.repo.model.EntityBundle)8 UserEntityPermissions (org.sagebionetworks.repo.model.auth.UserEntityPermissions)7 Transactional (org.springframework.transaction.annotation.Transactional)7 EntityPath (org.sagebionetworks.repo.model.EntityPath)6 ArrayList (java.util.ArrayList)5 Before (org.junit.Before)5 Entity (org.sagebionetworks.repo.model.Entity)5