小编Vla*_*ich的帖子

无法在自定义 Spring Boot 启动器中使用 WebSecurityConfigurerAdapter

我正在尝试通过定义从WebSecurityConfigurerAdapter. 然而,当我用这个启动器启动我的应用程序时,我得到:

IllegalStateException: Found WebSecurityConfigurerAdapter as well as SecurityFilterChain.
Please select just one.
Run Code Online (Sandbox Code Playgroud)

我发现由于spring security 的这个问题,不可能再这样做了。spring的WebSecurityConfiguration中有一个断言:

WebSecurityConfiguration.java 的快照

我解决了这个问题,在启动器中添加了以下内容(根据问题):

@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...以防万一: 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)

这是我的依赖项列表:

  1. 具有初学者使用的模型的模块(名称:my-ldap-security-model):
dependencies {
    compileOnly …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-boot

6
推荐指数
1
解决办法
1万
查看次数

无法部署到 Heroku。at=错误代码=H10 desc="应用程序崩溃"

我正在尝试将我的应用程序部署到 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)

我的课程和页面的屏幕截图在这里

java spring heroku

5
推荐指数
1
解决办法
7623
查看次数

标签 统计

java ×2

spring ×2

heroku ×1

spring-boot ×1

spring-security ×1