Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redirect Shiro不';t重定向到未经授权的durl w/无效登录-带Spring和Tiles的Shiro_Redirect_Spring Mvc_Tiles_Shiro - Fatal编程技术网

Redirect Shiro不';t重定向到未经授权的durl w/无效登录-带Spring和Tiles的Shiro

Redirect Shiro不';t重定向到未经授权的durl w/无效登录-带Spring和Tiles的Shiro,redirect,spring-mvc,tiles,shiro,Redirect,Spring Mvc,Tiles,Shiro,我正在使用SpringMVC、Tiles和Shiro 以下是我的unauthorizedUrl属性的配置方式: 我的期望是,当MyAuthorizingRealm发现无效凭据时,Shiro将重定向到/unauthorized 但是,我在提交表格时没有这样做。我有一个登录名@Controller,它被映射为处理/login的GET和POST操作。要访问url/列表,将显示登录表单。因此,它似乎在一种情况下有效,但在另一种情况下无效 @控制器 @请求映射(value=“/login”) 公共类登录

我正在使用SpringMVC、Tiles和Shiro

以下是我的unauthorizedUrl属性的配置方式:

我的期望是,当
MyAuthorizingRealm
发现无效凭据时,Shiro将重定向到
/unauthorized

但是,我在提交表格时没有这样做。我有一个登录名
@Controller
,它被映射为处理
/login
的GET和POST操作。要访问url
/列表
,将显示登录表单。因此,它似乎在一种情况下有效,但在另一种情况下无效

@控制器
@请求映射(value=“/login”)
公共类登录控制器{
@RequestMapping(method=RequestMethod.GET)
公共字符串getLoginFormView(模型){
返回“登录”;
}
//如果此方法不存在,将引发Post not SUPPORED异常
@RequestMapping(method=RequestMethod.POST)
公共字符串handlePost(){
返回“此视图不存在”;
}
}
即使我从
myauthorizationrealm.dogeAuthenticationInfo()
抛出
AuthenticationException
,我仍然无法让Shiro重定向到
/unauthorized
。它总是继续使用过滤器链,并在
@Controller
中执行POST方法;当然,我希望改为重定向

这是我的
webapp context.xml

这是我的
web.xml

下面是Shiro的一些跟踪日志输出。Shiro在您尝试访问
/列表时工作。但是,当提交登录表单时,将不会重定向到
/unauthorized
。注意,检测到登录提交:

因此,检测到登录提交,但仍会执行原始筛选链,而不是重定向到
/unauthorized


我被难住了。非常感谢您的帮助,如果您需要更多信息,请告诉我。

我想我发现了两个问题:

1) SpringXML的粘贴库不显示SecurityManager 正在配置您的领域。也就是说,它需要如下所示:

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <property name="realm" ref="myRealm"/>
</bean>
另外,作为提示,您可能希望使用Shiro的WebUtils将最终用户重定向到他们在重定向到登录之前最初尝试的url。Shiro的
FormAuthenticationFilter
会自动执行此操作,但当您自己执行登录时,如果需要,您将负责执行此重定向

例如,在您的
LoginController
的handlePost方法中:

subject.login(authcToken);
WebUtils.redirectToSavedRequest(request, response, yourFallbackUrlIfThereIsntASavedRequest);
return null; //tells Spring MVC you've handled the response, and not to render a view

对不起,我的安全管理器在我的配置中;我只是不知怎么把它从帖子里漏掉了。从您所说的听起来,不可能同时使用Spring MVC设施和Shiro。换句话说,我想同时使用FormAuthenticationFilter和Spring MVC与Tile。如果我使用FormAuthenticationFilter,您是说我无法通过mvc控制器运行它,因此我失去了mvc框架中的很多功能。如果是这样的话,也许我真的需要使用直通过滤器,自己处理登录过程。另外,谢谢你的反馈,我真的很感激。
subject.login(authcToken);
WebUtils.redirectToSavedRequest(request, response, yourFallbackUrlIfThereIsntASavedRequest);
return null; //tells Spring MVC you've handled the response, and not to render a view