Spring Boot-如何禁用Keycloak? [英] Spring Boot - How to disable Keycloak?

查看:282
本文介绍了Spring Boot-如何禁用Keycloak?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集成了keycloak的Spring Boot项目.现在,我想出于测试目的禁用密钥斗篷.

I have a Spring Boot project with keycloak integrated. Now I want to disable keycloak for testing purposes.

我尝试将keycloak.enabled=false添加到application.properties中,如Keycloak 文档,但是没有用.

I tried by adding keycloak.enabled=false to application.properties as mentioned in Keycloak documentation but it didnt work.

那我怎么禁用它呢?

推荐答案

对于可能遇到相同麻烦的任何人,这就是我所做的.

For anyone who might have the same trouble, here is what I did.

我没有禁用Keycloak,但出于测试目的,我单独制作了一个Keycloak配置文件.

I didn't disable Keycloak but I made a separate a Keycloak config file for testing purposes.

这是我的配置文件

@Profile("test")
@Configuration
@EnableWebSecurity
public class SecurityTestConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/**").permitAll();
        http.headers().frameOptions().disable();
        http.csrf().disable();

    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/**");
    }

    @Bean
    @Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
    public AccessToken accessToken() {
        AccessToken accessToken = new AccessToken();
        accessToken.setSubject("abc");
        accessToken.setName("Tester");

        return accessToken;

    }

}

请注意,仅在测试环境中使用此选项很重要,因此我已将配置注释为@Profile("test").我还添加了AccessToken bean,因为应用程序中的某些审核功能依赖于它.

Please note it is important to use this only in a test environment and therefore I have annotated the config as @Profile("test"). I have also added an AccessToken bean since some of the auditing features in my application depend on it.

这篇关于Spring Boot-如何禁用Keycloak?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆