当前位置: 首页 > 知识库问答 >
问题:

Dropwizard中的Shiro一直将我重定向到登录页面

万俟招
2023-03-14

我正在将Shiro集成到我的dropwizard WebApp中。我已经说到这一点了

    null
[main]
# some other stuff
authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
authc.loginUrl = /auth/login

# NOTE: URLs are evaluated in order, and the first matching pattern is accepted.
[urls]
/static/** = noSessionCreation, anon
/auth/** = authc
/admin/** = authc
/** = anon
0:0:0:0:0:0:0:1%0 - - [10/Oct/2013:18:23:54 +0000] "GET /auth/login;JSESSIONID=65e06b39-30e5-45dd-85f9-b2a1c29fc3af HTTP/1.1" 200 739 4 4
WARN  [2013-10-10 18:24:08,485] com.sun.jersey.spi.container.servlet.WebComponent:
A servlet request, to the URI http://blah:8080/auth/login, contains form
parameters in the request body but the request body has been consumed by the servlet
or a servlet filter accessing the request parameters. Only resource methods using
@FormParam will work as expected. Resource methods consuming the request body by other
means will not work as expected.

并且每次访问/admin都会导致错误302。我不知道还有什么相关的来回答这个问题。我已经探讨了其他几个“Shiro不断将我重定向到登录”的问题,但大多数都直接提到了带有web.xmls的Jetty,Dropwizard不使用它,我也不知道应用了什么过滤器。我的同事用同样的方法让shiro处理他的dropwizard项目。

在决定是否将用户发送到登录页面之前,shiro如何对用户进行身份验证?

共有1个答案

吕胤
2023-03-14

我找到问题了。下面是shiro.ini的更多内容,特别是会话管理部分:

sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
# NOTE: The session ID cookie seems to be required in order for authentication to work as intended.
# If the presence of cookies is a deal-breaker, further investigation will be required.
# Here we enable the Secure attribute (serve over SSL only) for this cookie;
# the HttpOnly attribute (not accessible by JavaScript) is enabled by default.
#sessionManager.sessionIdCookie.secure = true
# enabled Ehcache following advice from Shiro docs
sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
sessionManager.sessionDAO = $sessionDAO
# can optionally add session listeners here if actions need to be performed on session start/stop/expiration
# sessionManager.sessionListeners = $listener_1, $listener_2, ...
securityManager.sessionManager = $sessionManager

我已经注释了SessionIDCookie.Secure(稍后将删除它)结果表明,如果不启用ssl,当该变量设置为true时,将不会存储cookie。这解释了url栏中的JSESSIONID查询参数,但也解释了为什么经过身份验证后,它立即忘记了我,并决定我需要重新登录。

 类似资料:
  • 记录器文件中的日志- org.springframework.Security.Access.event.loggerlistener-安全授权失败,原因是:org.springframework.Security.Access.accessdeniedexception:访问被拒绝;通过身份验证的主体:org.springframework.security.authentication.ano

  • 我在地址栏中输入的任何链接都会将我重定向到登录页面。我该怎么防止呢? 例如如果我加上http://localhost:8080/asdasdsa 我的安全配置:

  • 问题内容: 我一直在寻找解决方案,但无论尝试如何,似乎都无法正确解决。 成功登录后,应该将用户重定向到他来自的页面,假设他一直在浏览帖子,并且想要登录以便可以发表评论,因此应该将他重定向到他正在浏览的帖子。所以这是我所拥有的: login.php 显示登录表单: 在 登录-check.php 检查用户名和传球被输入,的确用户存在,或者如果他已经登录,并且参数发送给login.php中: 然后将参数

  • 问题内容: 我正在尝试建立一个简单的网站,其登录功能与SO上的登录功能非常相似。用户应该能够以匿名用户的身份浏览网站,并且每个页面上都会有一个登录链接。当单击登录链接时,用户将被带到登录表单。成功登录后,应将用户带回到他首先单击登录链接的页面。我猜想我必须以某种方式将当前页面的url传递给处理登录表单的视图,但是我真的无法使其正常工作。 编辑:我想通了。我通过将当前页面作为GET参数传递来链接到登

  • 在Woocommerce for WordPress上,当您在产品页面上单击登录时,当您登录时,您将从您的帐户重定向到仪表板页面,而不是之前阅读的页面。 我正在尝试这样做,在登录前重定向到上一页,如果我的站点上没有上一页,则重定向到主页。 我已经试过了,但每次我都被重定向到主页。 有什么想法吗?

  • 我想在登录后将用户重定向到同一页面。该场景是,如果用户未登录,将重定向到登录页面。在登录页面上,当他单击一个可用的用户选项时,我想存储用户id,然后将他重定向回他来自的同一页面。为此,我使用以下代码: 在应用程序中提供帮助。rb: 在SigninController中: 在登录/索引页中: