【发布时间】:2018-08-12 23:20:03
【问题描述】:
我们正在将 Spring Boot 1.5.7 应用程序迁移到 Spring Boot 2,我注意到 SecurityProperties.ACCESS_OVERRIDE_ORDER 不再可用。
我们使用@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)) 来强制使用特定顺序的安全配置过滤器,如果没有此注释,它就无法工作(由于安全过滤器的顺序错误,因此会出现不同的状态)。是否有一些替换或配置更改以使其以旧方式工作?
我们有基本的身份验证 + OAuth2。
这是我们使用的 OAuth2 依赖:
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.1.0.RELEASE'
编辑:这是我的网络安全属性:
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
private static final String LOGIN = "/login";
private static final String LOGOUT_SUCCESS = "/login?logout";
private final UserDetailsService userDetailsService;
private final AuthenticationManager authenticationManager;
public WebSecurityConfig(UserDetailsService userDetailsService, @Lazy AuthenticationManager authenticationManager) {
this.userDetailsService = userDetailsService;
this.authenticationManager = authenticationManager;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
// enable cors
.cors().and()
.requestMatchers().antMatchers("/oauth/**", "/*").and()
// These from the above are secured by the following way
.authorizeRequests().antMatchers("/").permitAll()
// These from the rest are secured by the following way
.anyRequest().authenticated().and()
// Set login page
.formLogin().loginPage(LOGIN).permitAll().defaultSuccessUrl(PROFILE)
// Set logout handling
.and().logout().logoutSuccessUrl(LOGOUT_SUCCESS);
// @formatter:on
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(HttpMethod.OPTIONS, "/**");
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.parentAuthenticationManager(authenticationManager);
auth.userDetailsService(userDetailsService);
}
}
当通过 REST 访问 /user 时,我希望在没有有效令牌的情况下获得 401 - Unauthorized。相反,我得到302 - Redirect to /login,这意味着基本身份验证具有更高的优先级。我不知道如何解决这个问题,因为我尝试使用的任何命令都不起作用。
【问题讨论】:
标签: java spring-boot spring-security