Search in sources :

Example 1 with UserRole

use of org.gluu.model.user.UserRole in project oxTrust by GluuFederation.

the class Authenticator method postLogin.

/**
 * Set session variables after user login
 *
 * @throws Exception
 */
private void postLogin(User user) {
    identity.login();
    log.debug("Configuring application after user '{}' login", user.getUid());
    GluuCustomPerson person = findPersonByDn(user.getDn());
    identity.setUser(person);
    // Set user roles
    UserRole[] userRoles = securityService.getUserRoles(user);
    if (ArrayHelper.isNotEmpty(userRoles)) {
        log.debug("Get '{}' user roles", Arrays.toString(userRoles));
    } else {
        log.debug("Get 0 user roles");
    }
    for (UserRole userRole : userRoles) {
        identity.addRole(userRole.getRoleName());
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) UserRole(org.gluu.model.user.UserRole)

Example 2 with UserRole

use of org.gluu.model.user.UserRole in project oxTrust by GluuFederation.

the class SecurityService method getUserRoles.

/**
 * Get person user roles
 *
 * @param user
 *            Person
 * @return List of roles
 * @throws Exception
 *             exception
 */
public UserRole[] getUserRoles(User user) {
    GluuOrganization organization = organizationService.getOrganization();
    // String ownerGroupDn = organization.getOwnerGroup();
    String managerGroupDn = organization.getManagerGroup();
    String personDN = user.getDn();
    Set<UserRole> userRoles = new HashSet<UserRole>();
    if (groupService.isMemberOrOwner(managerGroupDn, personDN)) {
        userRoles.add(UserRole.MANAGER);
    }
    if ((userRoles.size() == 0)) /*
									 * &&
									 * (GluuStatus.ACTIVE.equals(person.getStatus
									 * ()))
									 */
    {
        userRoles.add(UserRole.USER);
    }
    return userRoles.toArray(new UserRole[userRoles.size()]);
}
Also used : UserRole(org.gluu.model.user.UserRole) GluuOrganization(org.gluu.oxtrust.model.GluuOrganization) HashSet(java.util.HashSet)

Example 3 with UserRole

use of org.gluu.model.user.UserRole in project oxTrust by GluuFederation.

the class SecurityService method isUseAdminUser.

public boolean isUseAdminUser(String userName) {
    try {
        User user = personService.getUserByUid(userName);
        UserRole[] roles = getUserRoles(user);
        for (UserRole role : roles) {
            if (UserRole.MANAGER.equals(role)) {
                return true;
            }
        }
    } catch (Exception ex) {
        log.error("Failed to find user '{}' in ldap", userName, ex);
    }
    return false;
}
Also used : User(org.gluu.oxtrust.model.User) UserRole(org.gluu.model.user.UserRole)

Aggregations

UserRole (org.gluu.model.user.UserRole)3 HashSet (java.util.HashSet)1 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)1 GluuOrganization (org.gluu.oxtrust.model.GluuOrganization)1 User (org.gluu.oxtrust.model.User)1