Search in sources :

Example 21 with XXPortalUserRole

use of org.apache.ranger.entity.XXPortalUserRole in project ranger by apache.

the class UserMgr method createUser.

public XXPortalUser createUser(XXPortalUser user, int userStatus, Collection<String> userRoleList) {
    user.setStatus(userStatus);
    String saltEncodedpasswd = encrypt(user.getLoginId(), user.getPassword());
    user.setPassword(saltEncodedpasswd);
    user = daoManager.getXXPortalUser().create(user);
    // Create the UserRole for this user
    List<XXPortalUserRole> gjUserRoleList = new ArrayList<XXPortalUserRole>();
    if (userRoleList != null) {
        for (String userRole : userRoleList) {
            XXPortalUserRole gjUserRole = addUserRole(user.getId(), userRole);
            if (gjUserRole != null) {
                gjUserRoleList.add(gjUserRole);
            }
        }
    }
    return user;
}
Also used : ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole)

Example 22 with XXPortalUserRole

use of org.apache.ranger.entity.XXPortalUserRole in project ranger by apache.

the class UserMgr method gjUserToUserProfile.

private void gjUserToUserProfile(XXPortalUser user, VXPortalUser userProfile) {
    UserSessionBase sess = ContextUtil.getCurrentUserSession();
    if (sess == null) {
        return;
    }
    // Admin
    if (sess.isUserAdmin() || sess.isKeyAdmin() || sess.getXXPortalUser().getId().equals(user.getId())) {
        userProfile.setLoginId(user.getLoginId());
        userProfile.setStatus(user.getStatus());
        userProfile.setUserRoleList(new ArrayList<String>());
        String emailAddress = user.getEmailAddress();
        if (emailAddress != null && stringUtil.validateEmail(emailAddress)) {
            userProfile.setEmailAddress(user.getEmailAddress());
        }
        userProfile.setUserSource(sess.getAuthProvider());
        List<XXPortalUserRole> gjUserRoleList = daoManager.getXXPortalUserRole().findByParentId(user.getId());
        for (XXPortalUserRole gjUserRole : gjUserRoleList) {
            userProfile.getUserRoleList().add(gjUserRole.getUserRole());
        }
        userProfile.setId(user.getId());
        List<XXUserPermission> xUserPermissions = daoManager.getXXUserPermission().findByUserPermissionIdAndIsAllowed(userProfile.getId());
        List<XXGroupPermission> xxGroupPermissions = daoManager.getXXGroupPermission().findbyVXPortalUserId(userProfile.getId());
        List<VXGroupPermission> groupPermissions = new ArrayList<VXGroupPermission>();
        List<VXUserPermission> vxUserPermissions = new ArrayList<VXUserPermission>();
        for (XXGroupPermission xxGroupPermission : xxGroupPermissions) {
            VXGroupPermission groupPermission = xGroupPermissionService.populateViewBean(xxGroupPermission);
            groupPermission.setModuleName(daoManager.getXXModuleDef().findByModuleId(groupPermission.getModuleId()).getModule());
            groupPermissions.add(groupPermission);
        }
        for (XXUserPermission xUserPermission : xUserPermissions) {
            VXUserPermission vXUserPermission = xUserPermissionService.populateViewBean(xUserPermission);
            vXUserPermission.setModuleName(daoManager.getXXModuleDef().findByModuleId(vXUserPermission.getModuleId()).getModule());
            vxUserPermissions.add(vXUserPermission);
        }
        userProfile.setGroupPermissions(groupPermissions);
        userProfile.setUserPermList(vxUserPermissions);
        userProfile.setFirstName(user.getFirstName());
        userProfile.setLastName(user.getLastName());
        userProfile.setPublicScreenName(user.getPublicScreenName());
    }
}
Also used : XXGroupPermission(org.apache.ranger.entity.XXGroupPermission) ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXUserPermission(org.apache.ranger.entity.XXUserPermission) VXUserPermission(org.apache.ranger.view.VXUserPermission) UserSessionBase(org.apache.ranger.common.UserSessionBase) VXGroupPermission(org.apache.ranger.view.VXGroupPermission) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole)

Example 23 with XXPortalUserRole

use of org.apache.ranger.entity.XXPortalUserRole in project ranger by apache.

the class UserMgr method getRolesForUser.

@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public Collection<String> getRolesForUser(XXPortalUser user) {
    Collection<String> roleList = new ArrayList<String>();
    Collection<XXPortalUserRole> roleCollection = daoManager.getXXPortalUserRole().findByUserId(user.getId());
    for (XXPortalUserRole role : roleCollection) {
        roleList.add(role.getUserRole());
    }
    return roleList;
}
Also used : ArrayList(java.util.ArrayList) VXString(org.apache.ranger.view.VXString) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with XXPortalUserRole

use of org.apache.ranger.entity.XXPortalUserRole in project ranger by apache.

the class UserMgr method getRolesByLoginId.

public Collection<String> getRolesByLoginId(String loginId) {
    if (loginId == null || loginId.trim().isEmpty()) {
        return DEFAULT_ROLE_LIST;
    }
    XXPortalUser xXPortalUser = daoManager.getXXPortalUser().findByLoginId(loginId);
    if (xXPortalUser == null) {
        return DEFAULT_ROLE_LIST;
    }
    Collection<XXPortalUserRole> xXPortalUserRoles = daoManager.getXXPortalUserRole().findByUserId(xXPortalUser.getId());
    if (xXPortalUserRoles == null) {
        return DEFAULT_ROLE_LIST;
    }
    Collection<String> roleList = new ArrayList<String>();
    for (XXPortalUserRole role : xXPortalUserRoles) {
        if (role != null && VALID_ROLE_LIST.contains(role.getUserRole())) {
            if (!roleList.contains(role.getUserRole())) {
                roleList.add(role.getUserRole());
            }
        }
    }
    if (roleList == null || roleList.size() == 0) {
        return DEFAULT_ROLE_LIST;
    }
    return roleList;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) ArrayList(java.util.ArrayList) XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) VXString(org.apache.ranger.view.VXString)

Example 25 with XXPortalUserRole

use of org.apache.ranger.entity.XXPortalUserRole in project ranger by apache.

the class UserService method mapEntityToViewBean.

@Override
protected VXPortalUser mapEntityToViewBean(VXPortalUser userProfile, XXPortalUser user) {
    userProfile.setId(user.getId());
    userProfile.setLoginId(user.getLoginId());
    userProfile.setFirstName(user.getFirstName());
    userProfile.setLastName(user.getLastName());
    userProfile.setPublicScreenName(user.getPublicScreenName());
    userProfile.setStatus(user.getStatus());
    userProfile.setUserRoleList(new ArrayList<String>());
    String emailAddress = user.getEmailAddress();
    if (emailAddress != null && stringUtil.validateEmail(emailAddress)) {
        userProfile.setEmailAddress(user.getEmailAddress());
    }
    UserSessionBase sess = ContextUtil.getCurrentUserSession();
    if (sess != null) {
        userProfile.setUserSource(sess.getAuthProvider());
    }
    List<XXPortalUserRole> gjUserRoleList = daoManager.getXXPortalUserRole().findByParentId(user.getId());
    for (XXPortalUserRole gjUserRole : gjUserRoleList) {
        userProfile.getUserRoleList().add(gjUserRole.getUserRole());
    }
    return userProfile;
}
Also used : XXPortalUserRole(org.apache.ranger.entity.XXPortalUserRole) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Aggregations

XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)34 ArrayList (java.util.ArrayList)28 XXPortalUser (org.apache.ranger.entity.XXPortalUser)21 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)20 VXString (org.apache.ranger.view.VXString)20 Test (org.junit.Test)19 VXPortalUser (org.apache.ranger.view.VXPortalUser)18 XXUserPermission (org.apache.ranger.entity.XXUserPermission)14 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)12 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)12 Date (java.util.Date)11 XXModuleDef (org.apache.ranger.entity.XXModuleDef)10 VXGroupPermission (org.apache.ranger.view.VXGroupPermission)10 VXUserPermission (org.apache.ranger.view.VXUserPermission)10 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)9 XXGroupPermissionDao (org.apache.ranger.db.XXGroupPermissionDao)7 UserSessionBase (org.apache.ranger.common.UserSessionBase)6 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)5 VXStringList (org.apache.ranger.view.VXStringList)4 VXPasswordChange (org.apache.ranger.view.VXPasswordChange)3