Search in sources :

Example 11 with UserGroupJoin

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

the class ReadProjectPermission method customPermissionAllowed.

/**
 * {@inheritDoc}
 */
@Override
public boolean customPermissionAllowed(final Authentication authentication, final Project p) {
    logger.trace("Testing permission for [" + authentication + "] on project [" + p + "]");
    if (authentication.getAuthorities().stream().anyMatch(g -> g.getAuthority().equals(ROLE_SEQUENCER))) {
        logger.trace("Fast pass for sequencer role.");
        return true;
    }
    // if not an administrator, then we need to figure out if the
    // authenticated user is participating in the project.
    final User u = userRepository.loadUserByUsername(authentication.getName());
    final List<Join<Project, User>> projectUsers = pujRepository.getUsersForProject(p);
    for (final Join<Project, User> projectUser : projectUsers) {
        if (projectUser.getObject().equals(u)) {
            logger.trace("Permission GRANTED for [" + authentication + "] on project [" + p + "]");
            // this user is participating in 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) {
        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;
        }
    }
    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 12 with UserGroupJoin

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

the class GroupsController method isGroupOwner.

/**
 * Convenience method for checking whether or not the specified user is an
 * owner of the group.
 *
 * @param user
 *            the {@link User} to check.
 * @param group
 *            the {@link UserGroup} to check.
 * @return true if owner, false otherwise.
 */
private boolean isGroupOwner(final User user, final UserGroup group) {
    final Collection<UserGroupJoin> groupUsers = userGroupService.getUsersForGroup(group);
    final Optional<UserGroupJoin> currentUserGroup = groupUsers.stream().filter(j -> j.getSubject().equals(user)).findAny();
    if (currentUserGroup.isPresent()) {
        final UserGroupJoin j = currentUserGroup.get();
        return j.getRole().equals(UserGroupRole.GROUP_OWNER);
    } else {
        return false;
    }
}
Also used : UserGroupWithoutOwnerException(ca.corefacility.bioinformatics.irida.exceptions.UserGroupWithoutOwnerException) java.util(java.util) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroupSpecification(ca.corefacility.bioinformatics.irida.repositories.specification.UserGroupSpecification) EntityExistsException(ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) Model(org.springframework.ui.Model) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ImmutableList(com.google.common.collect.ImmutableList) DataTablesResponseModel(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.models.DataTablesResponseModel) DataTablesResponse(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesResponse) ConstraintViolation(javax.validation.ConstraintViolation) DTGroupMember(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTGroupMember) MessageSource(org.springframework.context.MessageSource) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Role(ca.corefacility.bioinformatics.irida.model.user.Role) DataTablesRequest(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.config.DataTablesRequest) UserGroupRole(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin.UserGroupRole) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) PageRequest(org.springframework.data.domain.PageRequest) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) UserGroupService(ca.corefacility.bioinformatics.irida.service.user.UserGroupService) Principal(java.security.Principal) ConstraintViolationException(javax.validation.ConstraintViolationException) UserService(ca.corefacility.bioinformatics.irida.service.user.UserService) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) User(ca.corefacility.bioinformatics.irida.model.user.User) DataTablesParams(ca.corefacility.bioinformatics.irida.ria.web.components.datatables.DataTablesParams) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin)

Example 13 with UserGroupJoin

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

the class GroupsController method getDetailsPage.

/**
 * Get the details page for a {@link UserGroup}.
 *
 * @param userGroupId
 *            the {@link UserGroup} to retrieve.
 * @param principal
 *            the user that's currently logged in.
 * @param model
 *            the model to write attributes to.
 * @return the route to the group details page.
 */
@RequestMapping("/{userGroupId}")
public String getDetailsPage(@PathVariable final Long userGroupId, final Principal principal, final Model model) {
    final UserGroup group = userGroupService.read(userGroupId);
    final Collection<UserGroupJoin> groupUsers = userGroupService.getUsersForGroup(group);
    final User currentUser = userService.getUserByUsername(principal.getName());
    final boolean isOwner = isGroupOwner(currentUser, group);
    model.addAttribute("group", group);
    model.addAttribute("isAdmin", currentUser.getSystemRole().equals(Role.ROLE_ADMIN));
    model.addAttribute("isOwner", isOwner);
    model.addAttribute("users", groupUsers);
    model.addAttribute("groupRoles", ImmutableList.of(UserGroupRole.GROUP_MEMBER, UserGroupRole.GROUP_OWNER));
    return GROUP_DETAILS;
}
Also used : User(ca.corefacility.bioinformatics.irida.model.user.User) UserGroupJoin(ca.corefacility.bioinformatics.irida.model.user.group.UserGroupJoin) DTUserGroup(ca.corefacility.bioinformatics.irida.ria.web.models.datatables.DTUserGroup) UserGroup(ca.corefacility.bioinformatics.irida.model.user.group.UserGroup)

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