英文:
Redirect to previous page Spring Security
问题
我有一个网络应用程序,在单独的页面上有一个登录选项。然而,当我登录时,我被送回主页,而不是回到我之前所在的页面。我正在使用Spring Security提供的默认登录/注销页面。
这是我的HttpSecurity配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/*").hasRole("Admin")
.antMatchers("/manager").hasAnyRole("Admin", "Manager")
.antMatchers("/sales").hasAnyRole("Admin", "Manager", "Sales")
.antMatchers("/checkout").authenticated()
.and().formLogin().permitAll()
.and().logout().permitAll()
.logoutSuccessUrl("/");
}
英文:
I have a web app which has a log-in option on separate pages. However when I log in, I get sent back to the home page instead of going to back to the page I was on. I am using the default login/log-out pages provided by Spring Security.
Here's my HttpSecurity configuration:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/*").hasRole("Admin")
.antMatchers("/manager").hasAnyRole("Admin", "Manager")
.antMatchers("/sales").hasAnyRole("Admin", "Manager", "Sales")
.antMatchers("/checkout").authenticated()
.and().formLogin().permitAll()
.and().logout().permitAll()
.logoutSuccessUrl("/");
}
答案1
得分: 1
主要思路如何实现要求在这篇文章中解释,其中包括了代码示例的源代码。您只需要修改这个方法:
protected void handle(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws IOException {
if (response.isCommitted()) {
logger.debug("Response has already been committed. Unable to redirect to " + request.getRequestURI());
return;
}
redirectStrategy.sendRedirect(request, response, request.getRequestURI());
}
在 MySimpleUrlAuthenticationSuccessHandler
类中。
英文:
Main idea how to implement requirements explain in this article, which include examples source of code. You need only change this method
protected void handle(final HttpServletRequest request, final HttpServletResponse response, final
Authentication authentication) throws IOException {
if (response.isCommitted()) {
logger.debug("Response has already been committed. Unable to redirect to " + request.getRequestURI());
return;
}
redirectStrategy.sendRedirect(request, response, request.getRequestURI());
}`
in MySimpleUrlAuthenticationSuccessHandler
class
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论