use of com.itrus.portal.db.Admin in project portal by ixinportal.
the class ItrusPortalUserLoginSucess method onAuthenticationSuccess.
public void onAuthenticationSuccess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Authentication authentication) throws javax.servlet.ServletException, IOException {
// 查询用户信息
AdminExample adminex = new AdminExample();
adminex.or().andAccountEqualTo(authentication.getName().toLowerCase());
Admin admin = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByExample", adminex);
if (admin != null) {
AdminLog adminlog = new AdminLog();
adminlog.setAdmin(admin.getId());
adminlog.setCreateTime(new Date());
adminlog.setType("登录成功");
adminlog.setInfo("登录成功,管理员: " + admin.getAccount());
adminlog.setIp(request.getRemoteAddr());
int ret = sqlSession.insert("com.itrus.portal.db.AdminLogMapper.insert", adminlog);
// System.out.println("insert ret = " + ret);
}
setDefaultTargetUrl("/index");
super.onAuthenticationSuccess(request, response, authentication);
}
use of com.itrus.portal.db.Admin 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.Admin 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.Admin in project portal by ixinportal.
the class AdminController method update.
// 修改处理
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@Valid Admin admin, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest, String[] projectId) {
if (bindingResult.hasErrors()) {
uiModel.addAttribute("admin", admin);
return "admins/update";
}
Admin admin0 = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByPrimaryKey", admin.getId());
if (!admin0.getAccount().equals(admin.getAccount())) {
// 查询帐号是否已经存在
if (null != adminService.getAdminByName(admin.getAccount())) {
uiModel.addAttribute("admin", admin);
return "admins/update";
}
}
admin.setCreateTime(admin0.getCreateTime());
admin.setId(admin0.getId());
String newpass = admin.getPassword();
// 否则进行密码加密,并设置新密码
if (StringUtils.isBlank(newpass)) {
newpass = admin0.getPassword();
} else {
newpass = passwordEncoder.encodePassword(newpass.trim(), admin.getAccount());
}
admin.setPassword(newpass);
if (null != projectId) {
String projectStr = "";
for (int i = 0; i < projectId.length; i++) {
projectStr += projectId[i] + ",";
}
// 判断选择的管理范围中是否包含了所属项目
boolean flag = false;
for (int i = 0; i < projectId.length; i++) {
if (projectId[i].equals(admin.getProject().toString())) {
// 存在
flag = true;
}
}
if (!flag) {
// 不存在则添加
// 设置角色管理的项目
admin.setProjects(projectStr + admin.getProject() + ",");
} else {
// 设置角色管理的项目
admin.setProjects(projectStr);
}
} else {
admin.setProjects(admin.getProject() + ",");
}
sqlSession.update("com.itrus.portal.db.AdminMapper.updateByPrimaryKey", admin);
String oper = "修改管理员";
String info = "管理员账号: " + admin.getAccount();
LogUtil.adminlog(sqlSession, oper, info);
return "redirect:/admins/" + admin.getId();
}
use of com.itrus.portal.db.Admin in project portal by ixinportal.
the class AdminController method updateForm.
// 返回修改页面
@RequestMapping(value = "/{id}", params = "form", produces = "text/html")
public String updateForm(@PathVariable("id") Long id, Model uiModel) {
Admin admin = sqlSession.selectOne("com.itrus.portal.db.AdminMapper.selectByPrimaryKey", id);
admin.setPassword("");
uiModel.addAttribute("admin", admin);
ProjectExample projectex = new ProjectExample();
Map<Long, Project> projects = sqlSession.selectMap("com.itrus.portal.db.ProjectMapper.selectByExample", projectex, "id");
// 所有项目
uiModel.addAttribute("projects", projects);
List<Long> projectList = new ArrayList<Long>();
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;
}
}
}
for (Project project : adminService.getProjectByAdminId(id)) {
projectList.add(project.getId());
}
// 管理员管理的项目id
uiModel.addAttribute("projectList", projectList);
List adminroles = sqlSession.selectList("com.itrus.portal.db.AdminRoleMapper.selectByExample");
uiModel.addAttribute("adminroles", adminroles);
return "admins/update";
}
Aggregations