Created
October 2, 2019 15:17
-
-
Save akoserwal/3648953f708d1a036a7b8c3ad9b410a9 to your computer and use it in GitHub Desktop.
keycloak-spring-boot-config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@KeycloakConfiguration | |
class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter { | |
/** | |
* Registers the KeycloakAuthenticationProvider with the authentication manager. | |
*/ | |
@Autowired | |
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { | |
KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider(); | |
auth.authenticationProvider(keycloakAuthenticationProvider); | |
} | |
/** | |
* Provide a session authentication strategy bean which should be of type | |
* RegisterSessionAuthenticationStrategy for public or confidential applications | |
* and NullAuthenticatedSessionStrategy for bearer-only applications. | |
*/ | |
@Bean | |
@Override | |
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() { | |
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl()); | |
} | |
/** | |
* Use properties in application.properties instead of keycloak.json | |
*/ | |
@Bean | |
@Primary | |
public KeycloakConfigResolver keycloakConfigResolver(KeycloakSpringBootProperties properties) { | |
return new CustomKeycloakSpringBootConfigResolver(properties); | |
} | |
/** | |
* Secure appropriate endpoints | |
*/ | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
super.configure(http); | |
http.authorizeRequests() | |
.antMatchers("/**").authenticated() | |
.anyRequest().authenticated(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment