我们正在将Spring Boot 1.5.7应用迁移到Spring Boot 2,我发现
我们使用
我们已经实现了基本身份验证+OAuth2。
这是我们使用的OAuth2依赖项:
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'
编辑:这是我的WebSecurity属性:
@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 - 未授权
。然而实际上,我得到了302 - 重定向到 /login
,这意味着基本身份验证优先级更高。我不确定如何解决这个问题,因为无论我尝试使用的顺序都不起作用。