【问题标题】:apache shiro filter authc and user in the case /**apache shiro 过滤 authc 和用户案例 /**
【发布时间】:2018-05-28 08:59:18
【问题描述】:

这是我的代码的一部分。

...
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();

filterChainDefinitionMap.put("/favicon.ico", "anon");
filterChainDefinitionMap.put("/css/**", "anon");
filterChainDefinitionMap.put("/js/**", "anon");

filterChainDefinitionMap.put("/logout", "logout");

filterChainDefinitionMap.put("/**", "authc");
...

我在过滤器链的末尾将/** 设置为authc,但是当我尝试访问ip:port/favicon.ico 时,它会将我重定向到/login 页面。之前的所有anon 定义都不起作用。

但是,当我将 /** 更改为 user 时,现在一切正常。

filterChainDefinitionMap.put("/**", "user");

依赖

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.BUILD-SNAPSHOT</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
...
<dependency>
    <groupId>org.apache.shiro</groupId>
    <artifactId>shiro-spring</artifactId>
    <version>1.4.0</version>
</dependency>
...

【问题讨论】:

  • 你有示例项目(在 GitHub 上吗?)我们可以看看。您还有哪些其他 spring 依赖项?

标签: spring-boot shiro


【解决方案1】:

这是您的问题所忽略的,并且是问题的原因。 https://github.com/zymint/shiro-example/blob/master/tp/src/main/java/tp/softfly/config/shiro/ShiroConfig.java#L25-L27

表单过滤器只需要用于您的 /login 路由。不是为您的所有路线自定义定义的。删除这些行可以解决问题

【讨论】:

    猜你喜欢
    • 2012-12-28
    • 2015-08-08
    • 2014-06-17
    • 2017-03-17
    • 2014-02-19
    • 2015-11-17
    • 2014-02-26
    • 2018-01-25
    相关资源
    最近更新 更多