-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from InseeFr/devAuth
Add OIDC Authentication
- Loading branch information
Showing
10 changed files
with
241 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
25 changes: 25 additions & 0 deletions
25
...-api/src/main/java/fr/insee/kraftwerk/api/configuration/security/NoAuthConfiguration.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package fr.insee.kraftwerk.api.configuration.security; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@ConditionalOnProperty(name = "fr.insee.kraftwerk.authentication", havingValue = "NONE") | ||
@Configuration | ||
@EnableWebSecurity | ||
@Slf4j | ||
@AllArgsConstructor | ||
public class NoAuthConfiguration { | ||
|
||
@Bean | ||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | ||
http.csrf(AbstractHttpConfigurer::disable).authorizeHttpRequests(auth -> auth.anyRequest().permitAll()); | ||
return http.build(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...pi/src/main/java/fr/insee/kraftwerk/api/configuration/security/OIDCAuthConfiguration.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package fr.insee.kraftwerk.api.configuration.security; | ||
|
||
import fr.insee.kraftwerk.api.configuration.ConfigProperties; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.Customizer; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@Slf4j | ||
@ConditionalOnProperty(name = "fr.insee.kraftwerk.authentication", havingValue = "OIDC") | ||
public class OIDCAuthConfiguration { | ||
|
||
ConfigProperties config; | ||
@Autowired | ||
public OIDCAuthConfiguration(ConfigProperties config) { | ||
this.config = config; | ||
} | ||
|
||
@Bean | ||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | ||
http | ||
.csrf(AbstractHttpConfigurer::disable) | ||
.sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS)); | ||
for (var pattern : config.getWhiteList()) { | ||
http.authorizeHttpRequests(authorize -> | ||
authorize | ||
.requestMatchers(AntPathRequestMatcher.antMatcher(pattern)).permitAll() | ||
); | ||
} | ||
http | ||
.authorizeHttpRequests(configurer -> configurer | ||
.anyRequest().authenticated() | ||
) | ||
.oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults())); | ||
return http.build(); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ [email protected]@ | |
springdoc.swagger-ui.path=/index.html | ||
springdoc.api-docs.resolve-schema-properties=true | ||
springdoc.swagger-ui.tagsSorter=alpha | ||
springdoc.swagger-ui.oauth2RedirectUrl=${fr.insee.kraftwerk.application.host.url}/swagger-ui/oauth2-redirect.html | ||
|
||
|
||
fr.insee.postcollecte.csv.output.quote =" | ||
|
@@ -46,3 +47,10 @@ logging.pattern.rolling-file-name= C:\\Temp\\kraftwerk\\kraftwerk-%d{yyyy-MM-dd} | |
|
||
# Genesis API | ||
fr.insee.postcollecte.genesis.api.url= http://api-reponses-enquetes.insee.fr/ | ||
|
||
#Auth | ||
fr.insee.kraftwerk.authentication = OIDC | ||
fr.insee.kraftwerk.security.token.oidc-claim-role=realm_access.roles | ||
fr.insee.kraftwerk.security.token.oidc-claim-username=name | ||
spring.security.oauth2.resourceserver.jwt.issuer-uri=${fr.insee.kraftwerk.oidc.auth-server-url}/realms/${fr.insee.kraftwerk.oidc.realm} | ||
fr.insee.kraftwerk.security.whitelist-matchers=/v3/api-docs/**,/swagger-ui/**,/swagger-ui.html,/actuator/**,/error,/,/health-check/** |
Oops, something went wrong.