Search in sources :

Example 31 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class SystemInterceptor method preHandle.

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (Constant.WEB_ROOT == null) {
        Constant.WEB_ROOT = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
    }
    if (Constant.WORK_DIR == null) {
        Constant.WORK_DIR = request.getSession().getServletContext().getRealPath("/");
        ;
    }
    if (handler.getClass().isAssignableFrom(HandlerMethod.class)) {
        // 方法上是否有身份验证注解
        AuthPassport authPassport = ((HandlerMethod) handler).getMethodAnnotation(AuthPassport.class);
        // 声明不验证权限
        if (authPassport != null && authPassport.validate() == false) {
            return true;
        }
        // 已经登录
        if (request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY) != null || request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY) != null) {
            return true;
        }
        // 根据不同package处理不同身份认证逻辑
        String packageName = ((HandlerMethod) handler).getBeanType().getPackage().getName();
        String token = request.getHeader("token");
        if (token == null) {
            token = request.getParameter("token");
        }
        // client请求鉴权
        if (packageName.startsWith(Constant.API_PACKAGE_FOR_CLIENT)) {
            if (StringUtils.isNotBlank(token)) {
                // 登录验证
                AccountService accountService = SpringContextHolder.getBean(AccountService.class);
                UserService userService = SpringContextHolder.getBean(UserService.class);
                TestUser user = accountService.getByToken(token.trim());
                UserVo userVo = userService.genVo(user);
                if (user != null) {
                    request.getSession().setAttribute(Constant.HTTP_SESSION_USER_KEY, userVo);
                    return true;
                }
            }
            Map<String, Object> result = new HashMap<String, Object>();
            result.put("code", RespCode.NOT_LOGIN.getCode());
            result.put("msg", "not login");
            WebUtils.renderJson(response, JSON.toJSONString(result));
            return false;
        }
    }
    return true;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) UserService(com.ngtesting.platform.service.UserService) HashMap(java.util.HashMap) AccountService(com.ngtesting.platform.service.AccountService) TestUser(com.ngtesting.platform.entity.TestUser) HandlerMethod(org.springframework.web.method.HandlerMethod) AuthPassport(com.ngtesting.platform.util.AuthPassport)

Example 32 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class ProjectServiceImpl method viewPers.

@Override
public TestProjectVo viewPers(Long projectId, UserVo userVo) {
    TestProject project = getDetail(projectId);
    getHistoryPers(project.getOrgId(), userVo.getId(), projectId, project.getName());
    TestUser userPo = (TestUser) get(TestUser.class, userVo.getId());
    userPo.setDefaultPrjId(projectId);
    saveOrUpdate(userPo);
    userVo.setDefaultPrjId(projectId);
    userVo.setDefaultPrjName(project.getName());
    TestProjectVo vo = genVo(project);
    return vo;
}
Also used : TestProject(com.ngtesting.platform.entity.TestProject) TestProjectVo(com.ngtesting.platform.vo.TestProjectVo) TestUser(com.ngtesting.platform.entity.TestUser)

Example 33 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class RelationOrgGroupUserServiceImpl method listAllOrgUsers.

private List<TestUser> listAllOrgUsers(Long orgId) {
    DetachedCriteria dc = DetachedCriteria.forClass(TestUser.class);
    dc.createAlias("orgSet", "orgs");
    dc.add(Restrictions.eq("orgs.id", orgId));
    dc.add(Restrictions.eq("deleted", Boolean.FALSE));
    dc.add(Restrictions.eq("disabled", Boolean.FALSE));
    dc.addOrder(Order.asc("id"));
    List<TestUser> ls = findAllByCriteria(dc);
    return ls;
}
Also used : DetachedCriteria(org.hibernate.criterion.DetachedCriteria) TestUser(com.ngtesting.platform.entity.TestUser)

Example 34 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class OrgRoleUserServiceImpl method saveOrgRoleUsers.

@Override
public boolean saveOrgRoleUsers(Long roleId, List<UserVo> orgUsers) {
    if (orgUsers == null) {
        return false;
    }
    TestOrgRole orgRole = (TestOrgRole) get(TestOrgRole.class, roleId);
    Set<TestUser> userSet = orgRole.getUserSet();
    for (Object obj : orgUsers) {
        UserVo vo = JSON.parseObject(JSON.toJSONString(obj), UserVo.class);
        if (vo.getSelecting() != vo.getSelected()) {
            // 变化了
            TestUser orgUser = (TestUser) get(TestUser.class, vo.getId());
            if (vo.getSelecting() && !userSet.contains(orgUser)) {
                // 勾选
                userSet.add(orgUser);
            } else if (orgUser != null) {
                // 取消
                userSet.remove(orgUser);
            }
        }
    }
    saveOrUpdate(orgRole);
    return true;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) TestOrgRole(com.ngtesting.platform.entity.TestOrgRole) TestUser(com.ngtesting.platform.entity.TestUser)

Example 35 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class OrgRoleUserServiceImpl method listUserByOrgRole.

@Override
public List<UserVo> listUserByOrgRole(Long orgRoleId) {
    List<TestUser> allUsers = listAllOrgUsers();
    List<TestUser> orgRoleUsers;
    if (orgRoleId == null) {
        orgRoleUsers = new LinkedList<>();
    } else {
        orgRoleUsers = listOrgRoleUsers(orgRoleId);
    }
    List<UserVo> vos = new LinkedList<UserVo>();
    for (TestUser po1 : allUsers) {
        UserVo vo = genVo(po1);
        vo.setSelected(false);
        vo.setSelecting(false);
        for (TestUser po2 : orgRoleUsers) {
            if (po1.getId().longValue() == po2.getId().longValue()) {
                vo.setSelected(true);
                vo.setSelecting(true);
            }
        }
        vos.add(vo);
    }
    return vos;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) TestUser(com.ngtesting.platform.entity.TestUser) LinkedList(java.util.LinkedList)

Aggregations

TestUser (com.ngtesting.platform.entity.TestUser)43 HashMap (java.util.HashMap)13 JSONObject (com.alibaba.fastjson.JSONObject)12 AuthPassport (com.ngtesting.platform.util.AuthPassport)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 UserVo (com.ngtesting.platform.vo.UserVo)9 List (java.util.List)9 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)9 TestOrg (com.ngtesting.platform.entity.TestOrg)5 TestVerifyCode (com.ngtesting.platform.entity.TestVerifyCode)5 Date (java.util.Date)5 RelationOrgGroupUserVo (com.ngtesting.platform.vo.RelationOrgGroupUserVo)3 LinkedList (java.util.LinkedList)3 OrgVo (com.ngtesting.platform.vo.OrgVo)2 TestAlert (com.ngtesting.platform.entity.TestAlert)1 TestOrgGroup (com.ngtesting.platform.entity.TestOrgGroup)1 TestOrgRole (com.ngtesting.platform.entity.TestOrgRole)1 TestPlan (com.ngtesting.platform.entity.TestPlan)1 TestProject (com.ngtesting.platform.entity.TestProject)1