java – spring-security login?logout重定向到登录
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – spring-security login?logout重定向到登录,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2879字,纯文字阅读大概需要5分钟。
内容图文
![java – spring-security login?logout重定向到登录](/upload/InfoBanner/zyjiaocheng/804/b41bf9fbc81245008b2673fb97180b9b.jpg)
我使用spring-security 3.2.0.RC2与java配置和两个HttpSecurity配置.一个用于REST API,一个用于UI.
当我发布到/ logout它重定向到/ login?logout然后(错误地)重定向到/ login.
当我成功输入用户名和密码后,我被重定向到登录?注销并且必须再次输入凭证才能进入主页面.
因此,登录的permitAll似乎没有因登录而受到尊重?注销.
我的安全配置如下所示:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Resource
private MyUserDetailsService userDetailsService;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
StandardPasswordEncoder encoder = new StandardPasswordEncoder();
auth.userDetailsService(userDetailsService).passwordEncoder(encoder);
}
@Configuration
@Order(1)
public static class RestSecurityConfig
extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/v1/**").authorizeRequests()
.antMatchers("/v1/admin/**").hasRole("admin")
.antMatchers("/v1/account/**").hasRole("admin")
.antMatchers("/v1/plant/**").access("hasRole('admin') or hasRole('dataProvider')")
.antMatchers("/v1/upload/**").access("hasRole('admin') or hasRole('dataProvider')")
.antMatchers("/v1/**").authenticated()
.and().httpBasic();
}
}
@Configuration
@Order(2)
public static class UiSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/account/**").hasRole("admin")
.antMatchers("/admin/**").hasRole("admin")
.antMatchers("/plant/**").access("hasRole('admin') or hasRole('dataProvider')")
.antMatchers("/upload/**").access("hasRole('admin') or hasRole('dataProvider')")
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll();
}
}
}
谁能解释为什么会发生这种情况或者我的配置有什么问题?
我在这个配置中看到的第二个问题是jsp标签sec:authorize url = …不起作用,尽管sec:authorize access = …确实有效.
在url = …情况下,即使用户未获得授权,它也始终显示内容.
我知道用户没有被授权,因为命中应该被sec:authorize标签隐藏的链接导致403 Forbidden.
对此的任何帮助非常感谢!
解决方法:
我找到了这个明显错误的解决方法.
我在/ login / **上添加了permitAll(),如下所示:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/account/request/**").permitAll()
.antMatchers("/login/**").permitAll()
.antMatchers("/account/change_password/**").authenticated()
.antMatchers("/account/**").hasAuthority("admin")
.antMatchers("/admin/**").hasAuthority("admin")
.antMatchers("/plant/**").hasAnyAuthority("admin", "dataProvider")
.antMatchers("/upload/**").hasAnyAuthority("admin", "dataProvider")
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll();
}
回答我自己的问题,以防它遇到任何碰到这个bug的人.
内容总结
以上是互联网集市为您收集整理的java – spring-security login?logout重定向到登录全部内容,希望文章能够帮你解决java – spring-security login?logout重定向到登录所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。