use of org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider in project vboard by voyages-sncf-technologies.
the class WebSecurityConfig method configure.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionAuthenticationStrategy(SESSION_AUTH_STRATEGY).sessionCreationPolicy(SessionCreationPolicy.ALWAYS);
http.csrf().disable();
http.authorizeRequests().antMatchers("/pins/vblog").permitAll();
if (KeycloakEnabledInEnv.evaluate()) {
http.authenticationProvider(new KeycloakAuthenticationProvider());
configureKeycloakSecurity(http);
} else if (awsCognitoConfig.isEnabled()) {
http.authenticationProvider(new AwsCognitoAuthenticationProvider(awsCognitoConfig)).securityContext().securityContextRepository(new AwsCognitoSecurityContextRepository(awsCognitoConfig));
}
if (isAuthEnabled()) {
http.authorizeRequests().requestMatchers(new AntPathRequestMatcher("/**", "OPTIONS")).permitAll().requestMatchers(new AntPathRequestMatcher("/**", "GET")).permitAll().requestMatchers(new AntPathRequestMatcher("/pins/url", "POST")).permitAll().antMatchers("/**").authenticated();
} else {
http.authorizeRequests().antMatchers("/**").permitAll();
}
}
use of org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider in project tutorials by eugenp.
the class SecurityConfig method configureGlobal.
// Submits the KeycloakAuthenticationProvider to the AuthenticationManager
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
auth.authenticationProvider(keycloakAuthenticationProvider);
}
use of org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider in project shinyproxy by openanalytics.
the class KeycloakAuthenticationBackend method keycloakAuthenticationProvider.
protected KeycloakAuthenticationProvider keycloakAuthenticationProvider() {
return new KeycloakAuthenticationProvider() {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
KeycloakAuthenticationToken token = (KeycloakAuthenticationToken) super.authenticate(authentication);
List<GrantedAuthority> auth = token.getAuthorities().stream().map(t -> t.getAuthority().toUpperCase()).map(a -> a.startsWith("ROLE_") ? a : "ROLE_" + a).map(a -> new KeycloakRole(a)).collect(Collectors.toList());
return new KeycloakAuthenticationToken2(token.getAccount(), auth);
}
};
}
Aggregations