我正在尝试通过定义从WebSecurityConfigurerAdapter. 然而,当我用这个启动器启动我的应用程序时,我得到:
IllegalStateException: Found WebSecurityConfigurerAdapter as well as SecurityFilterChain.
Please select just one.
Run Code Online (Sandbox Code Playgroud)
我发现由于spring security 的这个问题,不可能再这样做了。spring的WebSecurityConfiguration中有一个断言:
我解决了这个问题,在启动器中添加了以下内容(根据问题):
@Bean
@Order(1) //Explanation for this below
open fun filterChain(http: HttpSecurity, jwtHelper: JwtHelper): SecurityFilterChain {
return http.authorizeRequests()
...
.addFilterBefore(JwtAuthenticationFilter(jwtHelper), UsernamePasswordAuthenticationFilter::class.java)
.and().build()
}
@Bean
open fun authenticationProvider(ldapConfig: LdapConfig): ActiveDirectoryLdapAuthenticationProvider {
return ActiveDirectoryLdapAuthenticationProvider(...)
}
Run Code Online (Sandbox Code Playgroud)
我添加是@Order(1)因为有两个securityFilterChains:我的(在上面的配置中定义)和另一个来自未知来源的。我想,后者是无法使用的原因WebSecurityConfigurerAdapter。
断点来自WebSecurityConfiguration...以防万一:

我想,因此我@EnableGlobalMethodSecurity(prePostEnabled = true)
也无法使用。它说:
Cannot apply org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration$EnableGlobalAuthenticationAutowiredConfigurer
to already built object
Run Code Online (Sandbox Code Playgroud)
这是我的依赖项列表:
dependencies {
compileOnly …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的应用程序部署到 Heroku。我的应用程序崩溃了。这是错误:
at=error code=H10 desc="App crashed" method=GET path="/"
host=smartmed2017.herokuapp.com request_id=3e8cc17e-320b-4230-bdbb-
3a751e3477de fwd="195.19.247.73" dyno= connect= service= status=503
bytes= protocol=https
2017-06-01T11:17:42.380548+00:00 heroku[router]: at=error code=H10
desc="App crashed" method=GET path="/favicon.ico"
host=smartmed2017.herokuapp.com request_id=9ab6574e-3fed-4af3-9cae-
0651e13d9112 fwd="195.19.247.73" dyno= connect= service= status=503
bytes= protocol=https
Run Code Online (Sandbox Code Playgroud)
像往常一样,但我这个问题的原因可能有所不同。
这是Main.class
@Controller
@SpringBootApplication
public class Main
{
public static void main(String[] args) throws Exception {
SpringApplication.run(Main.class, args);
}
@RequestMapping("/")
String index() {
return "index";
}
}
Run Code Online (Sandbox Code Playgroud)
过程文件:
web: java -Dserver.port=$PORT -jar target/untitled-1.0-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud)