Search in sources :

Example 1 with UserPermissionPO

use of com.goku.demo.common.po.UserPermissionPO in project springBoot-learn-demo by nbfujx.

the class ShiroRealm method doGetAuthorizationInfo.

/**
 *权限验证
 * *
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    SysUser user = sysUserService.getSysUserByUsername((String) principalCollection.getPrimaryPrincipal());
    // 把principals放session中 key=userId value=principals
    SecurityUtils.getSubject().getSession().setAttribute(String.valueOf(user.getId()), SecurityUtils.getSubject().getPrincipals());
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    Set<UserRolePO> urpos = sysUserService.listUserRolePO(user);
    Set<UserPermissionPO> uppos = sysUserService.listUserPermissionPO(user);
    // 赋予角色
    for (UserRolePO userRole : urpos) {
        this.logger.info(userRole.getRoleId());
        info.addRole(userRole.getRoleId());
    }
    // 赋予权限
    for (UserPermissionPO userPermission : uppos) {
        this.logger.info(userPermission.getPermission());
        info.addStringPermission(userPermission.getPermission());
    }
    return info;
}
Also used : SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) SysUser(com.goku.demo.entity.SysUser) UserPermissionPO(com.goku.demo.common.po.UserPermissionPO) UserRolePO(com.goku.demo.common.po.UserRolePO)

Example 2 with UserPermissionPO

use of com.goku.demo.common.po.UserPermissionPO in project springBoot-learn-demo by nbfujx.

the class SysUserServiceImpl method listUserPermissionPO.

@Override
public Set<UserPermissionPO> listUserPermissionPO(SysUser sysUser) {
    // SysUser sysUser = sysUserRepository.findById(userId);
    Set<UserPermissionPO> userPermissionPOS = new HashSet<UserPermissionPO>();
    Set<SysMenu> sysMenus = sysUser.getSysMenus();
    Iterator<SysMenu> smit = sysMenus.iterator();
    while (smit.hasNext()) {
        SysMenu sysMenu = smit.next();
        if (sysMenu.getPermission() != null && !sysMenu.getPermission().isEmpty()) {
            UserPermissionPO uppo = new UserPermissionPO();
            uppo.setUserId(sysUser.getId());
            uppo.setPermission(sysMenu.getPermission());
            userPermissionPOS.add(uppo);
        }
    }
    Set<SysRole> sysRoles = sysUser.getSysRoles();
    Iterator<SysRole> srit = sysRoles.iterator();
    while (srit.hasNext()) {
        SysRole sysRole = srit.next();
        Iterator<SysMenu> srmit = sysRole.getSysMenus().iterator();
        while (srmit.hasNext()) {
            SysMenu sysMenu = srmit.next();
            if (sysMenu.getPermission() != null && !sysMenu.getPermission().isEmpty()) {
                UserPermissionPO uppo = new UserPermissionPO();
                uppo.setUserId(sysUser.getId());
                uppo.setPermission(sysMenu.getPermission());
                userPermissionPOS.add(uppo);
            }
        }
    }
    return userPermissionPOS;
}
Also used : SysMenu(com.goku.demo.entity.SysMenu) UserPermissionPO(com.goku.demo.common.po.UserPermissionPO) SysRole(com.goku.demo.entity.SysRole)

Aggregations

UserPermissionPO (com.goku.demo.common.po.UserPermissionPO)2 UserRolePO (com.goku.demo.common.po.UserRolePO)1 SysMenu (com.goku.demo.entity.SysMenu)1 SysRole (com.goku.demo.entity.SysRole)1 SysUser (com.goku.demo.entity.SysUser)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1