use of com.itrus.portal.db.AdminExample 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);
}
use of com.itrus.portal.db.AdminExample in project portal by ixinportal.
the class AbstractController method getAdmin.
/**
* 获得当前管理员
*
* @return
*/
public Admin getAdmin() {
String adminName = getNameOfAdmin();
// 查询管理员信息
AdminExample adminex = new AdminExample();
adminex.or().andAccountEqualTo(adminName);
Admin admin = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByExample", adminex);
return admin;
}
use of com.itrus.portal.db.AdminExample in project portal by ixinportal.
the class AdminController method list.
// 列表所有信息
@RequestMapping(produces = "text/html")
public String list(@Valid Admin admin, @RequestParam(value = "project", required = false) Long project, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
uiModel.addAttribute("project", project);
uiModel.addAttribute("adminRole", admin.getAdminRole());
uiModel.addAttribute("status", admin.getStatus());
uiModel.addAttribute("account", admin.getAccount());
uiModel.addAttribute("name", admin.getName());
// page,size
if (page == null || page < 1)
page = 1;
if (size == null || size < 1)
size = 10;
AdminExample adminex = new AdminExample();
AdminExample.Criteria criteria = adminex.or();
if (project != null && project > 0)
criteria.andProjectEqualTo(project);
if (admin.getAdminRole() != null && admin.getAdminRole() > 0) {
criteria.andAdminRoleEqualTo(admin.getAdminRole());
}
if (admin.getStatus() != null && admin.getStatus().length() > 0)
criteria.andStatusEqualTo(admin.getStatus());
if (admin.getAccount() != null && admin.getAccount().length() > 0)
criteria.andAccountLike("%" + admin.getAccount() + "%");
if (admin.getName() != null && admin.getName().length() > 0)
criteria.andNameLike("%" + admin.getName() + "%");
// count,pages
Integer count = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.countByExample", adminex);
uiModel.addAttribute("count", count);
uiModel.addAttribute("pages", (count + size - 1) / size);
// page, size
if (page > 1 && size * (page - 1) >= count) {
page = (count + size - 1) / size;
}
uiModel.addAttribute("page", page);
uiModel.addAttribute("size", size);
// query data
Integer offset = size * (page - 1);
adminex.setOffset(offset);
adminex.setLimit(size);
List<Admin> adminall = sqlSession.selectList("com.itrus.portal.db.AdminMapper.selectByExample", adminex);
List<Admin> adminList = new ArrayList<Admin>();
boolean flag = false;
for (Admin admini : adminall) {
if (admini.getProjects().contains(",")) {
String[] strs = admini.getProjects().split(",");
for (String s : strs) {
if (s.equals("0")) {
// 包含所有项目
flag = true;
break;
} else {
flag = false;
}
}
}
String projectName = getProjectNameByAdminId(admini.getId());
admini.setProjects(projectName);
if (flag)
admini.setProjects("所有项目");
adminList.add(admini);
flag = false;
}
uiModel.addAttribute("admins", adminList);
// itemcount
uiModel.addAttribute("itemcount", adminall.size());
Map<Long, Admin> adminmap = sqlSession.selectMap("com.itrus.portal.db.AdminMapper.selectByExample", adminex, "id");
for (Long adminid : adminmap.keySet()) adminmap.get(adminid).setPassword(null);
uiModel.addAttribute("adminmap", adminmap);
ProjectExample projectex = new ProjectExample();
Map projectmap = sqlSession.selectMap("com.itrus.portal.db.ProjectMapper.selectByExample", projectex, "id");
uiModel.addAttribute("projectmap", projectmap);
List projects = sqlSession.selectList("com.itrus.portal.db.ProjectMapper.selectByExample", projectex);
uiModel.addAttribute("projects", projects);
Map adminroles = sqlSession.selectMap("com.itrus.portal.db.AdminRoleMapper.selectByExample", "id");
uiModel.addAttribute("adminroles", adminroles);
return "admins/list";
}
use of com.itrus.portal.db.AdminExample in project portal by ixinportal.
the class AdminPinController method modify.
// 修改处理
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String modify(AdminPinModify adminpinmodify, Model uiModel) {
SecurityContext securityContext = SecurityContextHolder.getContext();
String adminName = securityContext.getAuthentication().getName();
// 新口令和确认口令不能为空
if (adminpinmodify.getNewpass() == null || adminpinmodify.getNewpass1() == null) {
uiModel.addAttribute("errormsg", "新口令和确认口令不能为空");
String oper = "修改口令失败";
String info = "修改口令失败,管理员账号: " + adminName + ",新口令和确认口令不能为空";
LogUtil.adminlog(sqlSession, oper, info);
return "adminpin/modifyerror";
}
// 验证新口令和确认口令是否相同
if (adminpinmodify.getNewpass().compareTo(adminpinmodify.getNewpass1()) != 0l) {
uiModel.addAttribute("errormsg", "新口令和确认口令不一致");
String oper = "修改口令失败";
String info = "修改口令失败,管理员账号: " + adminName + ",新口令和确认口令不一致";
LogUtil.adminlog(sqlSession, oper, info);
return "adminpin/modifyerror";
}
// 查询管理员信息
AdminExample adminex = new AdminExample();
adminex.or().andAccountEqualTo(adminName);
Admin admin0 = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByExample", adminex);
// 验证员口令是否匹配
String oldpass0 = admin0.getPassword();
if (oldpass0 != null && oldpass0.length() != 40) {
// 原口令为非加密口令
if (oldpass0.compareTo(adminpinmodify.getOldpass()) != 0) {
uiModel.addAttribute("errormsg", "旧口令不正确");
String oper = "修改口令失败";
String info = "修改口令失败,管理员账号: " + adminName + ",旧口令不正确";
LogUtil.adminlog(sqlSession, oper, info);
return "adminpin/modifyerror";
}
} else if (oldpass0 != null && oldpass0.length() == 40) {
// 原口令为加密口令
// String oldpasssha = new String(PassUtil.doDigestSHA1(adminpinmodify.getOldpass(), adminName));
String oldpasssha = passwordEncoder.encodePassword(adminpinmodify.getOldpass(), adminName);
if (oldpass0.compareTo(oldpasssha) != 0) {
uiModel.addAttribute("errormsg", "旧口令不正确");
String oper = "修改口令失败";
String info = "修改口令失败,管理员账号: " + adminName + ",旧口令不正确";
LogUtil.adminlog(sqlSession, oper, info);
return "adminpin/modifyerror";
}
}
// 修改口令
// String newpasssha = new String(PassUtil.doDigestSHA1(adminpinmodify.getNewpass(), adminName));
String newpasssha = passwordEncoder.encodePassword(adminpinmodify.getNewpass(), adminName);
admin0.setPassword(newpasssha);
sqlSession.update("com.itrus.portal.db.AdminMapper.updateByPrimaryKey", admin0);
String oper = "修改口令";
String info = "修改口令,管理员账号: " + admin0.getAccount();
LogUtil.adminlog(sqlSession, oper, info);
return "adminpin/modifyok";
}
use of com.itrus.portal.db.AdminExample in project portal by ixinportal.
the class AdminServiceImpl method getAdminByName.
/**
* 根据用户名查询帐号
*
* @param adminName
* @return
*/
public Admin getAdminByName(String adminName) {
AdminExample adminExample = new AdminExample();
AdminExample.Criteria criteria = adminExample.or();
criteria.andAccountEqualTo(adminName);
adminExample.setLimit(1);
Admin admin = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByExample", adminExample);
return admin;
}
Aggregations