Java Code Examples for com.zhazhapan.util.Checker#isNull()

The following examples show how to use com.zhazhapan.util.Checker#isNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserController.java    From efo with MIT License 6 votes vote down vote up
@ApiOperation(value = "登录(用户名密码和token必须有一个输入)")
@ApiImplicitParams({@ApiImplicitParam(name = "username", value = "用户名"), @ApiImplicitParam(name
        = "password", value = "密码"), @ApiImplicitParam(name = "auto", value = "是否自动登录", dataType = "Boolean"),
        @ApiImplicitParam(name = "token", value = "用于自动登录")})
@AuthInterceptor(InterceptorLevel.NONE)
@RequestMapping(value = "/login", method = RequestMethod.PUT)
public String login(String username, String password, boolean auto, String token) {
    //使用密码登录
    User user = userService.login(username, password, ValueConsts.NULL_STRING, ValueConsts.NULL_RESPONSE);
    if (Checker.isNull(user) || user.getPermission() < 1) {
        jsonObject.put("status", "failed");
    } else {
        request.getSession().setAttribute(ValueConsts.USER_STRING, user);
        jsonObject.put("status", "success");
        if (auto) {
            jsonObject.put("token", TokenConfig.generateToken(token, user.getId()));
        } else {
            jsonObject.put("token", "");
            TokenConfig.removeTokenByValue(user.getId());
        }
    }
    return jsonObject.toString();
}
 
Example 2
Source File: FileController.java    From efo with MIT License 6 votes vote down vote up
@ApiOperation(value = "获取文件记录")
@ApiImplicitParams({@ApiImplicitParam(name = "offset", value = "偏移量", required = true), @ApiImplicitParam(name =
        "categoryId", value = "分类ID", required = true), @ApiImplicitParam(name = "orderBy", value = "排序方式",
        required = true, example = "id desc"), @ApiImplicitParam(name = "search", value = "记录匹配(允许为空)")})
@AuthInterceptor(InterceptorLevel.NONE)
@RequestMapping(value = "/all", method = RequestMethod.GET)
public String getAll(int offset, int categoryId, String orderBy, String search) {
    User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
    boolean canGet = EfoApplication.settings.getBooleanUseEval(ConfigConsts.ANONYMOUS_VISIBLE_OF_SETTING) ||
            (Checker.isNotNull(user) && user.getIsVisible() == 1);
    if (canGet) {
        int userId = Checker.isNull(user) ? 0 : user.getId();
        return Formatter.listToJson(fileService.listAll(userId, offset, categoryId, orderBy, search));
    } else {
        jsonObject.put("error", "权限被限制,无法获取资源,请联系管理员");
        return jsonObject.toString();
    }
}
 
Example 3
Source File: FileController.java    From efo with MIT License 6 votes vote down vote up
@ApiOperation(value = "删除指定文件")
@AuthInterceptor(InterceptorLevel.USER)
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public String removeFile(@PathVariable("id") long id) {
    User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
    jsonObject.put("status", "error");
    if (Checker.isNull(user)) {
        jsonObject.put("message", "请先登录");
    } else if (id < 1) {
        jsonObject.put("message", "格式不合法");
    } else if (fileService.removeFile(user, id)) {
        jsonObject.put("status", "success");
    } else {
        jsonObject.put("message", "删除失败,权限不够,请联系管理员");
    }
    return jsonObject.toString();
}
 
Example 4
Source File: UserServiceImpl.java    From efo with MIT License 6 votes vote down vote up
@Override
public User login(String loginName, String password, String token, HttpServletResponse response) {
    boolean allowLogin = settings.getBooleanUseEval(ConfigConsts.ALLOW_LOGIN_OF_SETTINGS);
    User user = null;
    if (allowLogin) {
        if (Checker.isNotEmpty(token) && EfoApplication.tokens.containsKey(token)) {
            user = userDAO.getUserById(EfoApplication.tokens.get(token));
            if (Checker.isNotNull(response)) {
                Cookie cookie = new Cookie(ValueConsts.TOKEN_STRING, TokenConfig.generateToken(token, user.getId
                        ()));
                cookie.setMaxAge(30 * 24 * 60 * 60);
                response.addCookie(cookie);
            }
        }
        if (Checker.isNull(user) && Checker.isNotEmpty(loginName) && Checker.isNotEmpty(password)) {
            user = userDAO.login(loginName, password);
            if (Checker.isNotNull(user)) {
                TokenConfig.removeTokenByValue(user.getId());
            }
        }
        updateUserLoginTime(user);
    }
    return user;
}
 
Example 5
Source File: AuthServiceImpl.java    From efo with MIT License 6 votes vote down vote up
@Override
public boolean addAuth(String files, String users, String auths) {
    if (Checker.isNotEmpty(files) && Checker.isNotEmpty(users) && Checker.isNotEmpty(auths)) {
        String[] file = files.split(ValueConsts.COMMA_SIGN);
        String[] user = users.split(ValueConsts.COMMA_SIGN);
        for (String f : file) {
            long fileId = Formatter.stringToLong(f);
            for (String u : user) {
                int userId = Formatter.stringToInt(u);
                if (Checker.isNull(authDAO.exists(userId, fileId))) {
                    Auth auth = new Auth(userId, fileId);
                    auth.setAuth(BeanUtils.getAuth(auths));
                    authDAO.insertAuth(auth);
                }
            }
        }
    }
    return true;
}
 
Example 6
Source File: CategoryController.java    From efo with MIT License 5 votes vote down vote up
@ApiOperation(value = "获取一个分类")
@AuthInterceptor(InterceptorLevel.NONE)
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String getById(@PathVariable("id") int id) {
    Category category = categoryService.getById(id);
    if (Checker.isNull(category)) {
        return ControllerUtils.getResponse(ValueConsts.FALSE);
    } else {
        return category.toString();
    }
}
 
Example 7
Source File: VsController.java    From visual-spider with MIT License 5 votes vote down vote up
/**
 * 启动爬虫
 *
 * @return 是否启动成功
 */
public boolean start() {
    if (Checker.isNull(controller)) {
        return false;
    } else {
        controller.start(Crawler.class, numberOfCrawlers);
        return true;
    }
}
 
Example 8
Source File: WebInterceptor.java    From efo with MIT License 4 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws
        Exception {
    String url = request.getServletPath();
    InterceptorLevel level = InterceptorLevel.NONE;
    if (handler instanceof HandlerMethod) {
        AuthInterceptor interceptor = ((HandlerMethod) handler).getMethodAnnotation(AuthInterceptor.class);
        //注解到类上面的注解,无法直接获取,只能通过扫描
        if (Checker.isNull(interceptor)) {
            for (Class<?> type : EfoApplication.controllers) {
                RequestMapping mapping = type.getAnnotation(RequestMapping.class);
                if (Checker.isNotNull(mapping)) {
                    for (String path : mapping.value()) {
                        if (url.startsWith(path)) {
                            interceptor = type.getAnnotation(AuthInterceptor.class);
                            break;
                        }
                    }
                    break;
                }
            }
        }
        if (Checker.isNotNull(interceptor)) {
            level = interceptor.value();
        }
    }
    User user = (User) request.getSession().getAttribute(ValueConsts.USER_STRING);
    if (Checker.isNull(user)) {
        //读取token,自动登录
        Cookie cookie = HttpUtils.getCookie(ValueConsts.TOKEN_STRING, request.getCookies());
        if (Checker.isNotNull(cookie)) {
            user = userService.login(ValueConsts.EMPTY_STRING, ValueConsts.EMPTY_STRING, cookie.getValue(),
                    response);
            if (Checker.isNotNull(user)) {
                request.getSession().setAttribute(ValueConsts.USER_STRING, user);
            }
        }
    }
    if (level != InterceptorLevel.NONE) {
        boolean isRedirect = Checker.isNull(user) || (level == InterceptorLevel.ADMIN && user.getPermission() <
                2) || (level == InterceptorLevel.SYSTEM && user.getPermission() < 3);
        if (isRedirect) {
            response.sendRedirect(DefaultValues.SIGNIN_PAGE);
            return false;
        }
    }
    return true;
}