Search in sources :

Example 1 with User

use of com.alibaba.otter.shared.common.model.user.User in project otter by alibaba.

the class UserServiceImpl method doToModel.

private User doToModel(UserDO userDo) {
    User user = new User();
    user.setId(userDo.getId());
    user.setName(userDo.getName());
    user.setDepartment(userDo.getDepartment());
    user.setRealName(userDo.getRealName());
    user.setAuthorizeType(userDo.getAuthorizeType());
    user.setGmtCreate(userDo.getGmtCreate());
    user.setGmtModified(userDo.getGmtModified());
    return user;
}
Also used : User(com.alibaba.otter.shared.common.model.user.User)

Example 2 with User

use of com.alibaba.otter.shared.common.model.user.User in project otter by alibaba.

the class AuthContextValve method invoke.

public void invoke(PipelineContext pipelineContext) throws Exception {
    TurbineRunData rundata = getTurbineRunData(request);
    // TODO 走 api 的验证
    if (isAPI(rundata)) {
        if (apiAuthService.auth(rundata)) {
            pipelineContext.invokeNext();
        } else {
            // TODO 需要转跳到 json 格式的 link
            redirect(pipelineContext, rundata, forbiddenLink);
        }
        return;
    }
    // 得到请求URL相对路径(不包含域名/端口信息)
    String requestUrl = rundata.getRequest().getRequestURI();
    List<AuthorizeType> result = urlAnalyze.check(requestUrl);
    String action = StringUtil.toCamelCase(trimToNull(rundata.getParameters().getString(actionParam)));
    String eventName = getEventName();
    // 首先判断是否登录
    User user = (User) rundata.getRequest().getSession().getAttribute(WebConstant.USER_SESSION_KEY);
    if (StringUtils.isNotEmpty(action)) {
        result.addAll(urlAnalyze.check(action, eventName));
    }
    if (result.isEmpty()) {
        // 访问的连接不符合权限匹配规则,跳转到登录页面
        redirect(pipelineContext, rundata, forbiddenLink);
    } else {
        if (null == user) {
            // 2.如果集合中只包含匿名权限,则通过。
            if (result.contains(AuthorizeType.OPERATOR) || result.contains(AuthorizeType.ADMIN)) {
                redirect(pipelineContext, rundata, loginLink);
            } else {
                pipelineContext.invokeNext();
            }
        } else {
            // 2.如果权限集合有高于用户权限,则跳转到登录页面。
            if (compareAuth(user.getAuthorizeType(), result)) {
                pipelineContext.invokeNext();
            } else {
                redirect(pipelineContext, rundata, forbiddenLink);
            }
        }
    }
}
Also used : AuthorizeType(com.alibaba.otter.shared.common.model.user.AuthorizeType) User(com.alibaba.otter.shared.common.model.user.User) TurbineRunData(com.alibaba.citrus.turbine.TurbineRunData) TurbineUtil.getTurbineRunData(com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData)

Example 3 with User

use of com.alibaba.otter.shared.common.model.user.User in project otter by alibaba.

the class UserManager method execute.

public void execute(@Param("pageIndex") int pageIndex, @Param("searchKey") String searchKey, Context context) throws Exception {
    @SuppressWarnings("unchecked") Map<String, Object> condition = new HashMap<String, Object>();
    if ("支持ID、用户名、真实姓名、部门搜索".equals(searchKey)) {
        searchKey = "";
    }
    condition.put("searchKey", searchKey);
    int count = userService.getCount(condition);
    Paginator paginator = new Paginator();
    paginator.setItems(count);
    paginator.setPage(pageIndex);
    condition.put("offset", paginator.getOffset());
    condition.put("length", paginator.getLength());
    List<User> users = userService.listByCondition(condition);
    context.put("users", users);
    context.put("paginator", paginator);
    context.put("searchKey", searchKey);
}
Also used : User(com.alibaba.otter.shared.common.model.user.User) HashMap(java.util.HashMap) Paginator(com.alibaba.citrus.util.Paginator)

Example 4 with User

use of com.alibaba.otter.shared.common.model.user.User in project otter by alibaba.

the class UserAction method doAdd.

public void doAdd(@FormGroup("addUserInfo") Group userInfo, Navigator nav, @FormField(name = "formUserError", group = "addUserInfo") CustomErrors err) {
    User user = new User();
    userInfo.setProperties(user);
    user.setPassword(SecurityUtils.getPassword(user.getPassword()));
    try {
        userService.createUser(user);
    } catch (RepeatConfigureException rce) {
        err.setMessage("invalidUser");
        return;
    }
    nav.redirectTo(WebConstant.USER_MANAGER_LINK);
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) User(com.alibaba.otter.shared.common.model.user.User)

Example 5 with User

use of com.alibaba.otter.shared.common.model.user.User in project otter by alibaba.

the class UserAction method doEdit.

public void doEdit(@FormGroup("editUserInfo") Group userInfo, @Param("pageIndex") int pageIndex, @Param("searchKey") String searchKey, Navigator nav, @FormField(name = "formUserError", group = "editUserInfo") CustomErrors err) {
    User user = new User();
    userInfo.setProperties(user);
    if (null != user.getPassword()) {
        if (user.getPassword().length() < 6) {
            err.setMessage("passwordTooLess");
            return;
        }
        user.setPassword(SecurityUtils.getPassword(user.getPassword()));
    }
    try {
        userService.updataUser(user);
    } catch (RepeatConfigureException rce) {
        err.setMessage("invalidUser");
        return;
    }
    nav.redirectToLocation("userManager.htm?pageIndex=" + pageIndex + "&searchKey=" + urlEncode(searchKey));
}
Also used : RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException) User(com.alibaba.otter.shared.common.model.user.User)

Aggregations

User (com.alibaba.otter.shared.common.model.user.User)8 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)2 UserDO (com.alibaba.otter.manager.biz.user.dal.dataobject.UserDO)2 ArrayList (java.util.ArrayList)2 TurbineRunData (com.alibaba.citrus.turbine.TurbineRunData)1 TurbineUtil.getTurbineRunData (com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData)1 Paginator (com.alibaba.citrus.util.Paginator)1 AuthorizeType (com.alibaba.otter.shared.common.model.user.AuthorizeType)1 HashMap (java.util.HashMap)1