AnA*_*ser 12 java spring-security
我有一些麻烦使我的登录始终重定向到同一个地方.我做过这样的事情
<http auto-config="true" use-expressions="true" entry-point-ref="gaeEntryPoint" >
<intercept-url pattern="/_ah/login" access="permitAll"/>
<intercept-url pattern="/**" access="isAuthenticated()"/>
<custom-filter position="PRE_AUTH_FILTER" ref="gaeFilter"/>
<form-login authentication-success-handler-ref="authSuccessHandler"/>
</http>
<beans:bean id="authSuccessHandler"
class="dk.lindhardt.arbejdsfordeling.server.security.AuthenticationSuccessHandlerImpl"/>
Run Code Online (Sandbox Code Playgroud)
和
public class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHandler {
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
if (authentication != null && authentication.isAuthenticated()) {
response.sendRedirect(OrganizationListServlet.URL);
}
}
}
Run Code Online (Sandbox Code Playgroud)
它永远不会进入上述方法.我怎么做到这一点?
编辑:我按照本指南http://blog.springsource.com/2010/08/02/spring-security-in-google-app-engine/
您不应该在那里拥有那个然后执行重定向的servlet.您可以在配置中进行重定向.
<http auto-config="true">
<intercept-url pattern="/app/login" filters="none" />
<form-login
login-page="/app/login"
login-processing-url="/app/dologin"
authentication-failure-url="/app/login?login_error=1"
default-target-url="/app/home"/>
</http>
Run Code Online (Sandbox Code Playgroud)
我想我们可以扩展SimpleUrlAuthenticationSuccessHandler并调用 super.onAuthenticationSuccess()方法来使用DefaultRedirectStrategy.修改后的代码将是:
public class AuthenticationSuccessHandlerImpl extends SimpleUrlAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
throws IOException, ServletException {
if (authentication != null) {
setDefaultTargetUrl(OrganizationListServlet.URL);
super.onAuthenticationSuccess(request, response, authentication);
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可以在没有处理程序的情况下通过向表单登录设置添加"always-use-default-target"来完成此操作
<form-login default-target-url='/your/target/url.htm' always-use-default-target='true' />
Run Code Online (Sandbox Code Playgroud)
请参阅"设置默认的登录后目的地"下的http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ns-form-and-basic
| 归档时间: |
|
| 查看次数: |
15899 次 |
| 最近记录: |