Search in sources :

Example 1 with AdapterDeploymentContextFactoryBean

use of org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean in project vboard by voyages-sncf-technologies.

the class WebSecurityConfig method adapterDeploymentContext.

// Also injected in `KeycloakPreAuthActionsFilter` as the `deploymentContext` property through the `initFilterBean` method.
// !BEWARE! if this `deploymentContext` property ends up null, it will lead to a NullPointerException in `org.keycloak.adapters.PreAuthActionsHandler.preflightCors:107`
@Bean
@Conditional(KeycloakEnabledInEnv.class)
public static AdapterDeploymentContext adapterDeploymentContext() throws Exception {
    AdapterDeploymentContextFactoryBean factoryBean = new AdapterDeploymentContextFactoryBean(new KeycloakSpringBootConfigResolver());
    // creates the AdapterDeploymentContext
    factoryBean.afterPropertiesSet();
    return factoryBean.getObject();
}
Also used : KeycloakSpringBootConfigResolver(org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver) AdapterDeploymentContextFactoryBean(org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean) Conditional(org.springframework.context.annotation.Conditional) AdapterDeploymentContextFactoryBean(org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with AdapterDeploymentContextFactoryBean

use of org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean in project shinyproxy by openanalytics.

the class KeycloakAuthenticationBackend method adapterDeploymentContext.

@Bean
@ConditionalOnProperty(name = "shiny.proxy.authentication", havingValue = "keycloak")
protected AdapterDeploymentContext adapterDeploymentContext() throws Exception {
    AdapterConfig cfg = new AdapterConfig();
    cfg.setRealm(environment.getProperty("shiny.proxy.keycloak.realm"));
    cfg.setAuthServerUrl(environment.getProperty("shiny.proxy.keycloak.auth-server-url"));
    cfg.setResource(environment.getProperty("shiny.proxy.keycloak.resource"));
    Map<String, Object> credentials = new HashMap<>();
    credentials.put("secret", environment.getProperty("shiny.proxy.keycloak.credentials-secret"));
    cfg.setCredentials(credentials);
    KeycloakDeployment dep = KeycloakDeploymentBuilder.build(cfg);
    AdapterDeploymentContextFactoryBean factoryBean = new AdapterDeploymentContextFactoryBean(new KeycloakConfigResolver() {

        @Override
        public KeycloakDeployment resolve(Request facade) {
            return dep;
        }
    });
    factoryBean.afterPropertiesSet();
    return factoryBean.getObject();
}
Also used : HashMap(java.util.HashMap) KeycloakConfigResolver(org.keycloak.adapters.KeycloakConfigResolver) AdapterConfig(org.keycloak.representations.adapters.config.AdapterConfig) KeycloakDeployment(org.keycloak.adapters.KeycloakDeployment) Request(org.keycloak.adapters.spi.HttpFacade.Request) AdapterDeploymentContextFactoryBean(org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean) AdapterDeploymentContextFactoryBean(org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Aggregations

AdapterDeploymentContextFactoryBean (org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean)2 Bean (org.springframework.context.annotation.Bean)2 HashMap (java.util.HashMap)1 KeycloakConfigResolver (org.keycloak.adapters.KeycloakConfigResolver)1 KeycloakDeployment (org.keycloak.adapters.KeycloakDeployment)1 Request (org.keycloak.adapters.spi.HttpFacade.Request)1 KeycloakSpringBootConfigResolver (org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver)1 AdapterConfig (org.keycloak.representations.adapters.config.AdapterConfig)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1 Conditional (org.springframework.context.annotation.Conditional)1