Search in sources :

Example 1 with SysResources

use of com.itrus.portal.db.SysResources in project portal by ixinportal.

the class HomeController method getRes.

/**
 * 获取菜单资源集合
 *
 * @param resNums
 * @return
 */
private Map<SysResources, Set<SysResources>> getRes(Collection<Integer> resNums) {
    Comparator<SysResources> sysResCom = new Comparator<SysResources>() {

        @Override
        public int compare(SysResources o1, SysResources o2) {
            return o1.getResOrder() - o2.getResOrder();
        }
    };
    Map<SysResources, Set<SysResources>> sysResMap = new TreeMap<SysResources, Set<SysResources>>(sysResCom);
    // 获得用户资源集合list
    for (Integer rNum : resNums) {
        SysResources res = cacheCustomer.getResByResNum(rNum);
        if (res.getParentNum() == null)
            continue;
        SysResources rootRes = cacheCustomer.getResByResNum(res.getParentNum());
        Set<SysResources> childRes = sysResMap.get(rootRes);
        if (childRes == null) {
            childRes = new TreeSet<SysResources>(sysResCom);
        }
        childRes.add(res);
        sysResMap.put(rootRes, childRes);
    }
    return sysResMap;
}
Also used : SysResources(com.itrus.portal.db.SysResources)

Example 2 with SysResources

use of com.itrus.portal.db.SysResources 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 3 with SysResources

use of com.itrus.portal.db.SysResources in project portal by ixinportal.

the class LicenseData method loadResNums.

void loadResNums(SqlSession sqlSession) {
    SysResourcesExample resEx = new SysResourcesExample();
    resEx.or().andResRoleNameIn(roleTitle);
    List<SysResources> sysResources = sqlSession.selectList("com.itrus.ukey.db.SysResourcesMapper.selectByExample", resEx);
    if (sysResources != null && !sysResources.isEmpty())
        resNums = new HashSet<Integer>();
    for (SysResources res : sysResources) {
        resNums.add(res.getResNum());
    }
}
Also used : SysResources(com.itrus.portal.db.SysResources) SysResourcesExample(com.itrus.portal.db.SysResourcesExample)

Aggregations

SysResources (com.itrus.portal.db.SysResources)3 Admin (com.itrus.portal.db.Admin)1 AdminExample (com.itrus.portal.db.AdminExample)1 AdminRole (com.itrus.portal.db.AdminRole)1 AdminRoleExample (com.itrus.portal.db.AdminRoleExample)1 RoleAndResources (com.itrus.portal.db.RoleAndResources)1 RoleAndResourcesExample (com.itrus.portal.db.RoleAndResourcesExample)1 SysResourcesExample (com.itrus.portal.db.SysResourcesExample)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