use of com.goku.demo.common.po.UserRolePO 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;
}
use of com.goku.demo.common.po.UserRolePO in project springBoot-learn-demo by nbfujx.
the class SysUserServiceImpl method listUserRolePO.
@Override
public Set<UserRolePO> listUserRolePO(SysUser sysUser) {
// SysUser sysUser = sysUserRepository.findById(userId);
Set<UserRolePO> userRolePOS = new HashSet<UserRolePO>();
Set<SysRole> sysRoles = sysUser.getSysRoles();
Iterator<SysRole> it = sysRoles.iterator();
while (it.hasNext()) {
SysRole sysRole = it.next();
UserRolePO urpo = new UserRolePO();
urpo.setUserId(sysUser.getId());
urpo.setRoleId(sysRole.getKey());
urpo.setRoleName(sysRole.getName());
userRolePOS.add(urpo);
}
return userRolePOS;
}
Aggregations