Search in sources :

Example 1 with AdminRole

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

Example 2 with AdminRole

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);
}
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)

Aggregations

Admin (com.itrus.portal.db.Admin)2 AdminRole (com.itrus.portal.db.AdminRole)2 AdminExample (com.itrus.portal.db.AdminExample)1 AdminRoleExample (com.itrus.portal.db.AdminRoleExample)1 Project (com.itrus.portal.db.Project)1 RoleAndResources (com.itrus.portal.db.RoleAndResources)1 RoleAndResourcesExample (com.itrus.portal.db.RoleAndResourcesExample)1 SysResources (com.itrus.portal.db.SysResources)1 InitSystemData (com.itrus.portal.utils.InitSystemData)1 PortalUser (com.itrus.portal.utils.PortalUser)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1