use of com.goku.demo.entity.SysUser in project springBoot-learn-demo by nbfujx.
the class ShiroRealm method doGetAuthenticationInfo.
/**
* 登录验证
* *
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
String userName = token.getUsername();
SysUser user = sysUserService.getSysUserByUsername(token.getUsername());
if (user != null) {
// 设置用户session
Session session = SecurityUtils.getSubject().getSession();
session.setAttribute("user", user);
return new SimpleAuthenticationInfo(userName, user.getPassword(), getName());
} else {
return null;
}
}
use of com.goku.demo.entity.SysUser 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.entity.SysUser in project springBoot-learn-demo by nbfujx.
the class SysUserExtRepositoryImpl method getSysUserWithRoleAndMenu.
@Override
public SysUser getSysUserWithRoleAndMenu(String userid) {
String sql = "SELECT u FROM SysUser u " + "left join fetch u.sysRoles s left join fetch s.sysMenus rm " + "left join fetch u.sysMenus m where u.id=:userid";
Query query = entityManager.createQuery(sql).setParameter("userid", userid);
SysUser sysUser = (SysUser) query.getSingleResult();
return sysUser;
}
use of com.goku.demo.entity.SysUser in project springBoot-learn-demo by nbfujx.
the class TestUserRepositroy method getSysUserInfo.
@Test
public void getSysUserInfo() {
SysUser sysUser = sysUserService.getSysUser("999");
System.out.print(JSON.toJSONString(sysUserService.listUserPermissionPO(sysUser)));
System.out.print(JSON.toJSONString(sysUserService.listUserRolePO(sysUser)));
}
Aggregations