Search in sources :

Example 1 with UserGroupJoin

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin in project irida by phac-nml.

the class GroupsController method getGroupUsers.

/**
 * List the members in the group.
 *
 * @param params
 *            the datatables parameters to search for.
 * @param userGroupId
 *            the group ID to get members for.
 * @return the datatables-formatted response with filtered users.
 */
@RequestMapping("/{userGroupId}/ajax/list")
@ResponseBody
public DataTablesResponse getGroupUsers(@DataTablesRequest DataTablesParams params, @PathVariable Long userGroupId) {
    final UserGroup group = userGroupService.read(userGroupId);
    final Page<UserGroupJoin> page = userGroupService.filterUsersByUsername(params.getSearchValue(), group, params.getCurrentPage(), params.getLength(), params.getSort());
    List<DataTablesResponseModel> members = page.getContent().stream().map(DTGroupMember::new).collect(Collectors.toList());
    return new DataTablesResponse(params, page, members);
}
Also used : DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

Example 2 with UserGroupJoin

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin in project irida by phac-nml.

the class ModifyProjectPermission method customPermissionAllowed.

/**
 * {@inheritDoc}
 */
public boolean customPermissionAllowed(Authentication authentication, Project p) {
    logger.trace("Testing permission for [" + authentication + "] can modify project [" + p + "]");
    // check if the user is a project owner for this project
    User u = userRepository.loadUserByUsername(authentication.getName());
    List<Join<Project, User>> projectUsers = pujRepository.getUsersForProjectByRole(p, ProjectRole.PROJECT_OWNER);
    for (Join<Project, User> projectUser : projectUsers) {
        if (projectUser.getObject().equals(u)) {
            logger.trace("Permission GRANTED for [" + authentication + "] on project [" + p + "]");
            // this user is an owner for the project.
            return true;
        }
    }
    // if we've made it this far, then that means that the user isn't
    // directly added to the project, so check if the user is in any groups
    // added to the project.
    final Collection<UserGroupProjectJoin> groups = ugpjRepository.findGroupsByProject(p);
    for (final UserGroupProjectJoin group : groups) {
        if (group.getProjectRole().equals(ProjectRole.PROJECT_OWNER)) {
            final Collection<UserGroupJoin> groupMembers = ugRepository.findUsersInGroup(group.getObject());
            final boolean inGroup = groupMembers.stream().anyMatch(j -> j.getSubject().equals(u));
            if (inGroup) {
                logger.trace("Permission GRANTED for [" + authentication + "] on project [" + p + "] by group membership in [" + group.getLabel() + "]");
                return true;
            }
        } else {
            logger.trace("Group is not PROJECT_OWNER, checking next project.");
        }
    }
    logger.trace("Permission DENIED for [" + authentication + "] on project [" + p + "]");
    return false;
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) Join(ca.corefacility.bioinformatics.irida.model.joins.Join) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)

Example 3 with UserGroupJoin

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin in project irida by phac-nml.

the class UpdateUserGroupPermission method customPermissionAllowed.

/**
 * {@inheritDoc}
 */
@Override
public boolean customPermissionAllowed(final Authentication authentication, final UserGroup g) {
    logger.trace("Checking if [" + authentication + "] can modify [" + g + "]");
    final User user = userRepository.loadUserByUsername(authentication.getName());
    final Optional<UserGroupJoin> userInGroup = userGroupJoinRepository.findUsersInGroup(g).stream().filter(j -> j.getSubject().equals(user)).findAny();
    if (userInGroup.isPresent()) {
        final UserGroupJoin j = userInGroup.get();
        if (j.getRole().equals(UserGroupRole.GROUP_OWNER)) {
            logger.trace("User [" + user + "] is GROUP_OWNER in group [" + g + "], access is GRANTED.");
            return true;
        } else {
            logger.trace("User [" + user + "] is *not* GROUP_OWNER in group [" + g + "], access is DENIED.");
            return false;
        }
    } else {
        logger.trace("User [" + user + "] is not in group [" + g + "], access is DENIED.");
        return false;
    }
}
Also used : UserRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserRepository) Logger(org.slf4j.Logger) UserGroupJoinRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserGroupJoinRepository) UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) LoggerFactory(org.slf4j.LoggerFactory) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) Autowired(org.springframework.beans.factory.annotation.Autowired) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Component(org.springframework.stereotype.Component) UserGroupRepository(ca.corefacility.bioinformatics.irida.repositories.user.UserGroupRepository) BasePermission(ca.corefacility.bioinformatics.irida.security.permissions.BasePermission) Optional(java.util.Optional) User(ca.corefacility.bioinformatics.irida.model.user.User) Authentication(org.springframework.security.core.Authentication) User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin)

Example 4 with UserGroupJoin

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin in project irida by phac-nml.

the class ReadProjectPermissionTest method testGrantPermissionByGroup.

@Test
public void testGrantPermissionByGroup() {
    final String username = "fbristow";
    final User u = new User();
    u.setUsername(username);
    final Project p = new Project();
    final UserGroup g = new UserGroup("The group");
    final List<UserGroupProjectJoin> projectGroups = new ArrayList<>();
    projectGroups.add(new UserGroupProjectJoin(p, g, ProjectRole.PROJECT_USER));
    when(userRepository.loadUserByUsername(username)).thenReturn(u);
    when(projectRepository.findOne(1L)).thenReturn(p);
    when(pujRepository.getUsersForProject(p)).thenReturn(ImmutableList.of());
    when(ugpjRepository.findGroupsByProject(p)).thenReturn(projectGroups);
    when(ugRepository.findUsersInGroup(g)).thenReturn(ImmutableList.of(new UserGroupJoin(u, g, UserGroupJoin.UserGroupRole.GROUP_MEMBER)));
    Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
    assertTrue("permission should be granted by user group.", readProjectPermission.isAllowed(auth, 1L));
    verify(userRepository).loadUserByUsername(username);
    verify(projectRepository).findOne(1L);
    verify(pujRepository).getUsersForProject(p);
}
Also used : Project(ca.corefacility.bioinformatics.irida.model.project.Project) User(ca.corefacility.bioinformatics.irida.model.user.User) Authentication(org.springframework.security.core.Authentication) UserGroupProjectJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin) ArrayList(java.util.ArrayList) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Test(org.junit.Test)

Example 5 with UserGroupJoin

use of ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin in project irida by phac-nml.

the class UpdateUserGroupPermissionTest method testGrantPermission.

@Test
public void testGrantPermission() {
    final String username = "user";
    final User u = new User();
    final UserGroup ug = new UserGroup("group");
    u.setUsername(username);
    when(userRepository.loadUserByUsername(username)).thenReturn(u);
    when(userRepository.findOne(1L)).thenReturn(u);
    when(userGroupRepository.findOne(1L)).thenReturn(ug);
    when(userGroupJoinRepository.findUsersInGroup(ug)).thenReturn(ImmutableList.of(new UserGroupJoin(u, ug, UserGroupRole.GROUP_OWNER)));
    final Authentication auth = new UsernamePasswordAuthenticationToken(username, "password1");
    assertTrue("permission was not granted.", updateUserPermission.isAllowed(auth, 1L));
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) Authentication(org.springframework.security.core.Authentication) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Test(org.junit.Test)

Aggregations

UserGroupJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin)13 User (ca.corefacility.bioinformatics.irida.model.user.User)10 UserGroup (ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)9 Test (org.junit.Test)5 Authentication (org.springframework.security.core.Authentication)5 UserGroupWithoutOwnerException (ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException)4 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)4 Project (ca.corefacility.bioinformatics.irida.model.project.Project)3 UserGroupRole (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole)3 UserGroupProjectJoin (ca.corefacility.bioinformatics.irida.model.user.group.UserGroupProjectJoin)3 DTUserGroup (ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Join (ca.corefacility.bioinformatics.irida.model.joins.Join)2 DataTablesResponse (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse)2 DataTablesResponseModel (ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel)2 UserGroupService (ca.corefacility.bioinformatics.irida.service.user.UserGroupService)2 UserService (ca.corefacility.bioinformatics.irida.service.user.UserService)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 IridaApiJdbcDataSourceConfig (ca.corefacility.bioinformatics.irida.config.data.IridaApiJdbcDataSourceConfig)1