Git Product home page Git Product logo

Comments (7)

springboot-plus avatar springboot-plus commented on September 7, 2024
  1. addDefaultFilterDefinition方法添加RequestPathFilter目的,1是可打印请求路径,2.示范shiro方式配置filter
  2. cacheLoginInfo方法的generate参数删除,新增refreshLoginInfo方法
  3. LoginUtil登陆工具类是用来业务模块使用的,获取当前登陆信息
  4. LoginServiceImpl类的refreshToken方法,已优化
    代码更改:https://github.com/geekidea/spring-boot-plus/commit/766f02f6ea8f049ec411359503a2dadddcc7a19a

from spring-boot-plus.

nita22 avatar nita22 commented on September 7, 2024
  1. addDefaultFilterDefinition方法添加RequestPathFilter目的,1是可打印请求路径,2.示范shiro方式配置filter
  2. cacheLoginInfo方法的generate参数删除,新增refreshLoginInfo方法
  3. LoginUtil登陆工具类是用来业务模块使用的,获取当前登陆信息
  4. LoginServiceImpl类的refreshToken方法,已优化
    代码更改:https://github.com/geekidea/spring-boot-plus/commit/766f02f6ea8f049ec411359503a2dadddcc7a19a

刚看了refreshLoginInfo的实现,首先会调用deleteLoginInfo删除redis中的记录,那getLoginSysUserRedisVo应该取不到对应的value了吧。
应该是先getLoginSysUserRedisVo再deleteLoginInfo吧

from spring-boot-plus.

nita22 avatar nita22 commented on September 7, 2024

LoginUtil的getUserId()、getUsername()方法有问题:1、loginSysUserRedisVo为空依然调用getId()、getUsername()方法,容易出现NullPointer异常

from spring-boot-plus.

nita22 avatar nita22 commented on September 7, 2024

JwtFilter中的createToken()方法中的token过期时间可能早于redis中的过期时间,可能出现token到期但redis中仍存在对应key-value的情况。
image
另外还有一个小疑问:Shiro模块中抛出的AuthenticationException是没有进行捕获处理吗?

from spring-boot-plus.

springboot-plus avatar springboot-plus commented on September 7, 2024

Redis缓存时间是获取的JwtToken的失效时间,所以是一致的。 @nita22
LoginRedisServiceImpl > cacheLoginInfo

// Redis过期时间与JwtToken过期时间一致
Duration expireDuration = Duration.ofSeconds(jwtToken.getExpireSecond());

from spring-boot-plus.

springboot-plus avatar springboot-plus commented on September 7, 2024

当抛出AuthenticationException等校验异常时,会进入失败方法处理
JwtFilter

 /**
     * 访问失败处理
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
        HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
        HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
        // 返回401
        httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        // 设置响应码为401或者直接输出消息
        String url = httpServletRequest.getRequestURI();
        log.error("onAccessDenied url:{}", url);
        ApiResult apiResult = ApiResult.fail(ApiCode.UNAUTHORIZED);
        HttpServletResponseUtil.printJSON(httpServletResponse, apiResult);
        return false;
    }

前端响应结果

{
  "code": 401,
  "msg": "非法访问",
  "time": "2019-10-22 10:06:16"
}

from spring-boot-plus.

springboot-plus avatar springboot-plus commented on September 7, 2024

refreshToken方法和LoginUtil工具类方法问题已修复
8e3192e7b2c78521f4f122e064ef38bbd8212762

from spring-boot-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.