use of com.itrus.portal.db.RoleAndResourcesExample in project portal by ixinportal.
the class ItrusPortalUserDetailsService method loadUserByUsername.
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// 资源编号集合
Collection<Integer> resNums = new HashSet<Integer>();
// 查询用户信息
AdminExample adminex = new AdminExample();
adminex.or().andAccountEqualTo(username.toLowerCase());
Admin admin = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByExample", adminex);
boolean isNonLocked = true;
// 用户授权信息
Collection authorities = new ArrayList();
// 用户不存在,异常处理
if (admin == null) {
Integer count = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.countByExample", null);
if (count > 0)
throw new UsernameNotFoundException(username);
admin = new Admin();
admin.setPassword("itrusyes");
admin.setStatus("valid");
admin.setCreateTime(new Date());
InitSystemData license = InitSystemData.getDefault();
resNums = license.getResNums();
for (String title : license.getRoleTitle()) authorities.add(new SimpleGrantedAuthority(title));
} else {
// 项目管理员
AdminRoleExample roleex = new AdminRoleExample();
roleex.or().andIdEqualTo(admin.getAdminRole());
AdminRole adminRole = sqlSession.selectOne("com.itrus.portal.db.AdminRoleMapper.selectByExample", roleex);
RoleAndResourcesExample rarEx = new RoleAndResourcesExample();
rarEx.or().andAdminRoleEqualTo(adminRole.getId());
List<RoleAndResources> roleAndRes = sqlSession.selectList("com.itrus.portal.db.RoleAndResourcesMapper.selectByExample", rarEx);
for (RoleAndResources rar : roleAndRes) {
SysResources res = cacheCustomer.getResById(rar.getSysResources());
resNums.add(res.getResNum());
// 不能为null角色名称
if (res.getResRoleName() != null) {
authorities.add(new SimpleGrantedAuthority(res.getResRoleName()));
}
}
}
String pass = admin.getPassword();
if (pass != null && pass.length() != 40)
// pass = PassUtil.doDigestSHA1(pass,username);
pass = passwordEncoder.encodePassword(pass, username);
isNonLocked = "valid".equalsIgnoreCase(admin.getStatus()) ? true : false;
return new PortalUser(admin.getId(), username, pass, isNonLocked, admin.getProjects(), admin.getProject(), admin.getCreateTime(), resNums, authorities);
}
Aggregations