use of com.itrus.portal.db.AdminRole in project portal by ixinportal.
the class AdminController method show.
// 显示详情
@RequestMapping(value = "/{id}", produces = "text/html")
public String show(@PathVariable("id") Long id, Model uiModel) {
Admin admin = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByPrimaryKey", id);
admin.setPassword("");
uiModel.addAttribute("admin", admin);
if (admin.getAdminRole() != null) {
AdminRole adminRole = sqlSession.selectOne("com.itrus.portal.db.AdminRoleMapper.selectByPrimaryKey", admin.getAdminRole());
uiModel.addAttribute("adminRole", adminRole);
}
uiModel.addAttribute("hasAllProject", 0);
if (admin.getProjects().contains(",")) {
String[] strs = admin.getProjects().split(",");
for (String s : strs) {
if (s.equals("0")) {
// 包含所有项目
uiModel.addAttribute("hasAllProject", 1);
break;
}
}
}
uiModel.addAttribute("projectMap", adminService.getProjectByAdminId(id));
Project project = sqlSession.selectOne("com.itrus.portal.db.ProjectMapper.selectByPrimaryKey", admin.getProject());
uiModel.addAttribute("project", project);
return "admins/show";
}
use of com.itrus.portal.db.AdminRole 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