Search in sources :

Example 11 with UserGroup

use of gemma.gsec.model.UserGroup in project Gemma by PavlidisLab.

the class UserManagerImpl method findGroupsForUser.

@Override
@Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "RUN_AS_USER" })
public Collection<String> findGroupsForUser(String userName) {
    Collection<String> result = new HashSet<>();
    if (!this.loggedIn()) {
        return result;
    }
    User u = this.loadUser(userName);
    Collection<UserGroup> groups = userService.findGroupsForUser(u);
    for (UserGroup g : groups) {
        result.add(g.getName());
    }
    return result;
}
Also used : User(gemma.gsec.model.User) UserGroup(gemma.gsec.model.UserGroup) Secured(org.springframework.security.access.annotation.Secured)

Example 12 with UserGroup

use of gemma.gsec.model.UserGroup in project Gemma by PavlidisLab.

the class UserManagerImpl method findUsersInGroup.

@Override
public List<String> findUsersInGroup(String groupName) {
    UserGroup group = this.loadGroup(groupName);
    Collection<gemma.gsec.model.User> groupMembers = group.getGroupMembers();
    List<String> result = new ArrayList<>();
    for (gemma.gsec.model.User u : groupMembers) {
        result.add(u.getUserName());
    }
    return result;
}
Also used : User(gemma.gsec.model.User) User(gemma.gsec.model.User) UserGroup(gemma.gsec.model.UserGroup)

Example 13 with UserGroup

use of gemma.gsec.model.UserGroup in project Gemma by PavlidisLab.

the class UserManagerImpl method findAllGroups.

@Override
public List<String> findAllGroups() {
    Collection<UserGroup> groups = userService.listAvailableGroups();
    List<String> result = new ArrayList<>();
    for (UserGroup group : groups) {
        result.add(group.getName());
    }
    return result;
}
Also used : UserGroup(gemma.gsec.model.UserGroup)

Example 14 with UserGroup

use of gemma.gsec.model.UserGroup in project Gemma by PavlidisLab.

the class UserManagerImpl method addGroupAuthority.

@Override
public void addGroupAuthority(String groupName, GrantedAuthority authority) {
    UserGroup g = this.loadGroup(groupName);
    for (gemma.gsec.model.GroupAuthority ga : g.getAuthorities()) {
        if (ga.getAuthority().equals(authority.getAuthority())) {
            logger.warn("Group already has authority" + authority.getAuthority());
            return;
        }
    }
    GroupAuthority auth = ubic.gemma.model.common.auditAndSecurity.GroupAuthority.Factory.newInstance();
    auth.setAuthority(authority.getAuthority());
    g.getAuthorities().add(auth);
    userService.update(g);
}
Also used : GroupAuthority(gemma.gsec.model.GroupAuthority) GroupAuthority(gemma.gsec.model.GroupAuthority) UserGroup(gemma.gsec.model.UserGroup)

Example 15 with UserGroup

use of gemma.gsec.model.UserGroup in project Gemma by PavlidisLab.

the class UserManagerImpl method findGroupAuthorities.

@Override
public List<GrantedAuthority> findGroupAuthorities(String groupName) {
    String groupToSearch = groupName;
    if (groupName.startsWith(rolePrefix)) {
        groupToSearch = groupToSearch.replaceFirst(rolePrefix, "");
    }
    UserGroup group = this.loadGroup(groupToSearch);
    List<GrantedAuthority> result = new ArrayList<>();
    for (gemma.gsec.model.GroupAuthority ga : group.getAuthorities()) {
        result.add(new SimpleGrantedAuthority(ga.getAuthority()));
    }
    return result;
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) GroupAuthority(gemma.gsec.model.GroupAuthority) UserGroup(gemma.gsec.model.UserGroup)

Aggregations

UserGroup (gemma.gsec.model.UserGroup)15 User (gemma.gsec.model.User)5 GrantedAuthority (org.springframework.security.core.GrantedAuthority)4 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)4 GroupAuthority (gemma.gsec.model.GroupAuthority)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Secured (org.springframework.security.access.annotation.Secured)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2 UserDetailsImpl (gemma.gsec.authentication.UserDetailsImpl)1 UserExistsException (gemma.gsec.authentication.UserExistsException)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 Transactional (org.springframework.transaction.annotation.Transactional)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1