Spring-Boot-Shiro icon indicating copy to clipboard operation
Spring-Boot-Shiro copied to clipboard

敏感资源如果没有携带TOKEN

Open GeXyu opened this issue 5 years ago • 4 comments

通过URL方式配置,敏感资源如果没有携带TOKEN,是不是就能访问了呢? 因为isAccessAllowed方法没有携带则直接通过了

或者说,这种方式只适用于注解的形式?URL配置只是为了拦截并转发到JWTFilter处理。

GeXyu avatar Apr 17 '20 11:04 GeXyu

这和URL配置还是注解配置没有关系。敏感资源不带token照样不能访问。URL配置和注解配置只是两种不同的配置方式而已,这两种配置方式最后都能拦截转发到JWTFilter处理。

Smith-Cruise avatar Apr 17 '20 11:04 Smith-Cruise

@GeXyu 哥们 有解决方案了吗

qiqingfu avatar Apr 18 '20 16:04 qiqingfu

https://github.com/Smith-Cruise/Spring-Boot-Shiro/blob/master/src/main/java/org/inlighting/shiro/JWTFilter.java 如果没有携带Token, isLoginAttempt会一直返回true,isAccessAllowed也会返回true,即不会执行executeLogin方法,不会执行Relam方法。此时如果没有携带TOKEN,访问到敏感资源 代码如下:

protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
        if (isLoginAttempt(request, response)) {
            try {
                executeLogin(request, response);
            } catch (Exception e) {
                response401(request, response);
            }
        }
        return true;
    }

GeXyu avatar Apr 24 '20 06:04 GeXyu

@GeXyu 哥们 有解决方案了吗

在url如果配置了该过滤器 ,说明是需要进行Token校验的,所以必须携带token,如果没有携带则认为无效请求,如果想匿名访问,则配置anno过滤器 代码配置如下:

//必须登录且具有admin角色
 filterRuleMap.put("/**", "jwt,roles[admin]"); 
//必须登录
filterRuleMap.put("/**", "jwt"); 
//匿名访问
filterRuleMap.put("/login", "anon"); 

GeXyu avatar Apr 24 '20 06:04 GeXyu