Search in sources :

Example 6 with Admin

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);
}
Also used : AdminLog(com.itrus.portal.db.AdminLog) Admin(com.itrus.portal.db.Admin) AdminExample(com.itrus.portal.db.AdminExample) Date(java.util.Date)

Example 7 with Admin

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);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) ArrayList(java.util.ArrayList) AdminRoleExample(com.itrus.portal.db.AdminRoleExample) RoleAndResources(com.itrus.portal.db.RoleAndResources) Admin(com.itrus.portal.db.Admin) InitSystemData(com.itrus.portal.utils.InitSystemData) Date(java.util.Date) PortalUser(com.itrus.portal.utils.PortalUser) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) SysResources(com.itrus.portal.db.SysResources) Collection(java.util.Collection) AdminRole(com.itrus.portal.db.AdminRole) AdminExample(com.itrus.portal.db.AdminExample) RoleAndResourcesExample(com.itrus.portal.db.RoleAndResourcesExample) HashSet(java.util.HashSet)

Example 8 with Admin

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;
}
Also used : Admin(com.itrus.portal.db.Admin) AdminExample(com.itrus.portal.db.AdminExample)

Example 9 with 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();
}
Also used : Admin(com.itrus.portal.db.Admin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Admin

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";
}
Also used : Project(com.itrus.portal.db.Project) ProjectExample(com.itrus.portal.db.ProjectExample) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Admin(com.itrus.portal.db.Admin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Admin (com.itrus.portal.db.Admin)16 AdminExample (com.itrus.portal.db.AdminExample)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 Project (com.itrus.portal.db.Project)4 ProjectExample (com.itrus.portal.db.ProjectExample)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 SecurityContext (org.springframework.security.core.context.SecurityContext)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 AdminRole (com.itrus.portal.db.AdminRole)2 List (java.util.List)2 Map (java.util.Map)2 AdminLog (com.itrus.portal.db.AdminLog)1 AdminLogExample (com.itrus.portal.db.AdminLogExample)1 AdminRoleExample (com.itrus.portal.db.AdminRoleExample)1 Agent (com.itrus.portal.db.Agent)1 BusinessLicense (com.itrus.portal.db.BusinessLicense)1 Certification (com.itrus.portal.db.Certification)1 DigitalCert (com.itrus.portal.db.DigitalCert)1 Enterprise (com.itrus.portal.db.Enterprise)1