-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from Making-Sense-Info/Feat/dependencies
Feat/dependencies
- Loading branch information
Showing
6 changed files
with
102 additions
and
123 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
32 changes: 0 additions & 32 deletions
32
src/main/java/fr/insee/trevas/lab/configuration/security/DefaultSecurityConfiguration.java
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
src/main/java/fr/insee/trevas/lab/configuration/security/OIDCSecurityConfiguration.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
src/main/java/fr/insee/trevas/lab/configuration/security/SecurityConfiguration.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,61 @@ | ||
package fr.insee.trevas.lab.configuration.security; | ||
|
||
import fr.insee.trevas.lab.model.User; | ||
import org.springframework.beans.factory.annotation.Value; | ||
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.oauth2.jwt.Jwt; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class SecurityConfiguration { | ||
|
||
@Value("${app.security.enabled}") | ||
private boolean securityEnabled; | ||
|
||
@Value("${spring.security.oauth2.login-page}") | ||
private String loginPage; | ||
|
||
@Value("${jwt.username-claim}") | ||
private String usernameClaim; | ||
|
||
@Bean | ||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
if (!securityEnabled) { | ||
// Désactive toute sécurité | ||
http.csrf(AbstractHttpConfigurer::disable) | ||
.authorizeHttpRequests(authorize -> authorize | ||
.anyRequest().permitAll() | ||
); | ||
} else { | ||
// Active OIDC | ||
http.csrf(AbstractHttpConfigurer::disable) | ||
.authorizeHttpRequests(authorize -> authorize | ||
.requestMatchers("/public").permitAll() // Endpoint public | ||
.anyRequest().authenticated() | ||
) | ||
.oauth2Login(oauth2 -> oauth2 | ||
.loginPage("/oauth2/authorization/myclient") // Page de login personnalisée, peut être modifiée | ||
); | ||
} | ||
return http.build(); | ||
} | ||
|
||
@Bean | ||
public UserProvider getUserProvider() { | ||
return auth -> { | ||
final User user = new User(); | ||
if (null == auth) { | ||
return user; | ||
} | ||
final Jwt jwt = (Jwt) auth.getPrincipal(); | ||
user.setId(jwt.getClaimAsString(usernameClaim)); | ||
user.setAuthToken(jwt.getTokenValue()); | ||
return user; | ||
}; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,26 @@ | ||
auth: | ||
mode: "NONE" | ||
spark: | ||
master: "local" | ||
|
||
app: | ||
security: | ||
enabled: false | ||
|
||
spring: | ||
security: | ||
oauth2: | ||
resourceserver: | ||
jwt: | ||
issuer-uri: "" | ||
login-page: "/oauth2/authorization/myclient" | ||
client: | ||
registration: | ||
myclient: | ||
client-id: your-client-id | ||
client-secret: your-client-secret | ||
scope: openid,profile,email | ||
redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}" | ||
client-name: My OIDC Client | ||
provider: myprovider | ||
provider: | ||
myprovider: | ||
issuer-uri: https://accounts.google.com # Par exemple Google ou un autre fournisseur OIDC | ||
|
||
jwt: | ||
username-claim: "preferred_username" | ||
username-claim: "preferred_username" |