Spring boot 弹簧靴&x2B;部署到tomcat时KeyClope应用程序不工作
我已经将KeyClope与我的spring boot应用程序集成。当我使用spring boot run运行它时,它正在工作。但当我创建一个war并部署到tomcat时,我得到了一个例外:Spring boot 弹簧靴&x2B;部署到tomcat时KeyClope应用程序不工作,spring-boot,keycloak,Spring Boot,Keycloak,我已经将KeyClope与我的spring boot应用程序集成。当我使用spring boot run运行它时,它正在工作。但当我创建一个war并部署到tomcat时,我得到了一个例外: java.lang.NullPointerException: null at org.keycloak.adapters.KeycloakDeploymentBuilder.internalBuild(KeycloakDeploymentBuilder.java:57) ~[keycloak-ada
java.lang.NullPointerException: null
at org.keycloak.adapters.KeycloakDeploymentBuilder.internalBuild(KeycloakDeploymentBuilder.java:57) ~[keycloak-adapter-core-9.0.2.jar:9.0.2]
要将此部署到tomcat,我需要做什么
这是我的应用程序.properties
文件:
# keycloak configuration
keycloak.realm=salary-plus
keycloak.auth-server-url=http://localhost:8080/auth
keycloak.ssl-required=external
keycloak.resource=salary-plus-api
keycloak.credentials.secret=8dd03031-60ac-4ef5-9ae5-19a2e3460da2
keycloak.use-resource-role-mappings = true
下面是我的spring安全配置类:
@Configuration
@EnableWebSecurity
@ComponentScan(basePackageClasses = KeycloakSecurityComponents.class)
class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(
AuthenticationManagerBuilder auth) throws Exception {
KeycloakAuthenticationProvider keycloakAuthenticationProvider
= keycloakAuthenticationProvider();
keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(
new SimpleAuthorityMapper());
auth.authenticationProvider(keycloakAuthenticationProvider);
}
@Bean
public KeycloakSpringBootConfigResolver KeycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
@Bean
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new NullAuthenticatedSessionStrategy();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http
.csrf()
.disable();
http.authorizeRequests()
.antMatchers(HttpMethod.GET, "/api/disbursement/**").hasAnyRole(
"disbursement_maker", "disbursement_checker")
.antMatchers(HttpMethod.POST, "/api/disbursement/request").hasRole("disbursement_maker")
.antMatchers(HttpMethod.PUT, "/api/disbursement/item/*").hasRole("disbursement_maker")
.antMatchers(HttpMethod.PATCH, "/api/disbursement/request/update/*").hasRole("disbursement_maker")
.antMatchers("/api/auth/**").permitAll()
.anyRequest()
.denyAll();
}
}
要部署为WAR文件,您需要使用KeyClope Spring安全适配器或Tomcat适配器,而不是Spring引导适配器。从: 如果您计划将Spring应用程序部署为WAR,那么您应该 不要使用Spring Boot适配器,而应使用专用适配器 您正在使用的应用程序服务器或servlet容器。你的春天 引导还应包含一个web.xml文件