Search in sources :

Example 1 with AuthRole

use of com.github.liuweijw.core.beans.system.AuthRole in project fw-cloud-framework by liuweijw.

the class TokenArgumentResolver method generatorByToken.

private AuthUser generatorByToken(HttpServletRequest request, String token) {
    String username = JwtUtil.getUserName(request);
    List<String> roles = JwtUtil.getRole(request);
    AuthUser authUser = new AuthUser();
    authUser.setUsername(username);
    if (null != roles) {
        List<AuthRole> roleList = new ArrayList<AuthRole>();
        roles.stream().forEach(role -> {
            AuthRole authRole = new AuthRole();
            authRole.setRoleCode(role);
            roleList.add(authRole);
        });
        authUser.setRoleList(roleList);
        cacheManager.getCache(SecurityConstant.TOKEN_USER_DETAIL).put(token, authUser);
    }
    return authUser;
}
Also used : AuthRole(com.github.liuweijw.core.beans.system.AuthRole) ArrayList(java.util.ArrayList) AuthUser(com.github.liuweijw.core.beans.system.AuthUser)

Example 2 with AuthRole

use of com.github.liuweijw.core.beans.system.AuthRole in project fw-cloud-framework by liuweijw.

the class UserServiceImpl method buildAuthUserByUser.

private AuthUser buildAuthUserByUser(User user) {
    if (null == user)
        return null;
    AuthUser authUser = new AuthUser();
    authUser.setPicUrl(user.getPicUrl());
    authUser.setStatu(user.getStatu());
    authUser.setPassword(user.getPassword());
    authUser.setUserId(user.getUserId());
    authUser.setUsername(user.getUsername());
    if (null == user.getRoleList() || user.getRoleList().size() == 0)
        return authUser;
    List<AuthRole> rList = new ArrayList<AuthRole>();
    for (Role r : user.getRoleList()) {
        AuthRole aRole = new AuthRole();
        aRole.setStatu(r.getStatu());
        aRole.setRoleCode(r.getRoleCode());
        aRole.setRoleDesc(r.getRoleDesc());
        aRole.setRoleId(r.getRoleId());
        aRole.setRoleName(r.getRoleName());
        rList.add(aRole);
    }
    authUser.setRoleList(rList);
    return authUser;
}
Also used : QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) Role(com.github.liuweijw.business.admin.domain.Role) AuthRole(com.github.liuweijw.core.beans.system.AuthRole) QRole(com.github.liuweijw.business.admin.domain.QRole) UserRole(com.github.liuweijw.business.admin.domain.UserRole) AuthRole(com.github.liuweijw.core.beans.system.AuthRole) ArrayList(java.util.ArrayList) AuthUser(com.github.liuweijw.core.beans.system.AuthUser)

Example 3 with AuthRole

use of com.github.liuweijw.core.beans.system.AuthRole in project fw-cloud-framework by liuweijw.

the class UserServiceImpl method findUserInfo.

@Override
public UserBean findUserInfo(AuthUser user) {
    User dbUser = findUserByUsername(user.getUsername(), false);
    UserBean userInfo = new UserBean();
    // 过滤关键信息
    dbUser.setPassword("");
    dbUser.setCreateTime(null);
    dbUser.setUpdateTime(null);
    userInfo.setUser(dbUser);
    // 设置角色列表
    List<AuthRole> roleList = user.getRoleList();
    List<String> roleCodes = new ArrayList<>();
    roleList.stream().forEach(r -> {
        roleCodes.add(r.getRoleCode());
    });
    String[] roles = roleCodes.toArray(new String[roleCodes.size()]);
    userInfo.setRoles(roles);
    // 设置权限列表(menu.permission)
    Set<String> permissions = new HashSet<String>();
    for (String roleCode : roles) {
        permissions.addAll(menuService.findMenuPermissions(roleCode));
    }
    userInfo.setPermissions(permissions.toArray(new String[permissions.size()]));
    return userInfo;
}
Also used : User(com.github.liuweijw.business.admin.domain.User) QUser(com.github.liuweijw.business.admin.domain.QUser) AuthUser(com.github.liuweijw.core.beans.system.AuthUser) UserBean(com.github.liuweijw.business.admin.beans.UserBean) AuthRole(com.github.liuweijw.core.beans.system.AuthRole) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

AuthRole (com.github.liuweijw.core.beans.system.AuthRole)3 AuthUser (com.github.liuweijw.core.beans.system.AuthUser)3 ArrayList (java.util.ArrayList)3 UserBean (com.github.liuweijw.business.admin.beans.UserBean)1 QRole (com.github.liuweijw.business.admin.domain.QRole)1 QUser (com.github.liuweijw.business.admin.domain.QUser)1 QUserRole (com.github.liuweijw.business.admin.domain.QUserRole)1 Role (com.github.liuweijw.business.admin.domain.Role)1 User (com.github.liuweijw.business.admin.domain.User)1 UserRole (com.github.liuweijw.business.admin.domain.UserRole)1 HashSet (java.util.HashSet)1