【问题标题】:Why doesn't Apache Shiro's [anon] Filter work correctly?为什么 Apache Shiro 的 [anon] 过滤器不能正常工作?
【发布时间】:2019-02-26 22:24:33
【问题描述】:

我尝试在我的项目中使用 Apache Shiro 身份验证,但没有成功。我无法发现问题出在哪里。我只需要用户直接访问 /pages/principal/products.xhtml 页面,选择要购买的产品,然后重定向到 /purchase.xhtml 以完成购买,但在我的情况下,我尝试的所有请求都重定向到/login.xhtml 页面。有没有人有什么建议?下面的代码。谢谢!

shiro.ini    
[main]
authc.loginUrl = /login.xhtml
authc.successUrl = /index.xhtml

[users]
admin@faces.com = adminfaces, admin
user@faces.com = user, customer


[roles]
admin = *
customer = purchases

[urls]

/index.xhtml = anon
/pages/principal/products = anon
/login.xhtml = authc
/javax.faces.resource/** = anon
/logout = logout
/pages/purchase/** = authc
/protected/** = authc, roles[admin]

web.xml

...
<listener>
    <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener
    </listener-class>
</listener>

<filter>
    <filter-name>ShiroFilter</filter-name>
    <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ShiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>
...

【问题讨论】:

    标签: apache jsf-2 shiro adminfaces


    【解决方案1】:

    我能够解决我的问题。我现在正在使用 redhat PicketLink 解决方案。它使用流利的 java 语言来配置安全路径,并且学习曲线较低。我认为 Apache Shiro 是一个很好的安全 API,但我有一点时间来学习它。感谢您的帮助@Brian Demers。

    【讨论】:

      【解决方案2】:

      我猜你需要换行: /pages/principal/products = anon/pages/principal/products.xhtml = anon

      您也可以使用permissive 过滤器

      【讨论】:

      • 嗨@Brian,我将 shiro.ini 修改为:
      • /pages/principal/products.xhtml = anon,我包括 [main] authcBasic.enabled = true [urls] /pages/principal/produtcts.xhtml = authcBasic [permissive],但没有成功。还有其他帮助吗?谢谢大家。
      • 去掉shiro过滤器后可以访问页面吗?
      • 如果我在 web.xml 中对 ShiroFilter 进行注释,则不再有效。如果我排除 shiro.ini [main] [users] admin@faces.com = adminfaces [roles] [urls] 中的所有信息为空白,则任何请求都将重定向到 login.xhtml。
      • 您是否尝试过一次添加一条过滤线来隔离问题所在?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 2023-02-20
      • 1970-01-01
      • 2014-02-19
      • 2016-07-16
      • 2019-01-04
      • 2020-09-03
      相关资源
      最近更新 更多