Skip to content

Commit

Permalink
Export census : json and csv format (#2)
Browse files Browse the repository at this point in the history
* refactor: json output

* build: update spring version

* test: fix bug temporary

* build: change finalName

* style: delete comments and imports

* feat: add csv exports (survey and supplement)

* Update BusinessConstant.java

* fix: bad constant

* fix: bad constant

* feat: change column name

* fix: change output

* fix: bug when birthMonth or BirthDay empty

* perf: optimising the recovery of individuals

* refactor: deprecated old controller

* fix: replace empty days and months with 31 and 12 only for comparisons

* delete truncate

* release: 0.1.0-RC

* fix: majorityDate <= startYear

* release: 0.1.0
  • Loading branch information
mbergonzini authored Jan 3, 2024
1 parent 331e421 commit 5bb02a6
Show file tree
Hide file tree
Showing 52 changed files with 1,726 additions and 530 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/src/main/resources/application-*.properties
/target/
.idea
.idea
*.iml
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<version>3.1.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>fr.insee</groupId>
<artifactId>era</artifactId>
<version>0.0.6</version>
<version>0.1.0</version>
<name>ERA</name>
<description>API permettant de générer des JSON pour coleman</description>
<description>API permettant de générer des JSON pour REM</description>
<properties>
<java.version>17</java.version>
<opencsv.version>5.7.1</opencsv.version>
<springdoc.version>2.0.0</springdoc.version>
<springdoc.version>2.1.0</springdoc.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -107,6 +107,7 @@


<build>
<finalName>era-erabo-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/fr/insee/era/EraApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@

import fr.insee.era.configuration.PropertiesLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;

import java.util.Arrays;
import java.util.stream.StreamSupport;

@SpringBootApplication
@Slf4j
Expand Down
125 changes: 66 additions & 59 deletions src/main/java/fr/insee/era/configuration/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,73 +26,80 @@
public class SecurityConfig {


@Value("${fr.insee.era.admin.role.rp}")
private String administrateurRPRole;
@Value("${fr.insee.era.admin.role.hors-rp}")
private String administrateurHorsRPRole;
@Value("${fr.insee.era.admin.role.rp}")
private String administrateurRPRole;
@Value("${fr.insee.era.admin.role.hors-rp}")
private String administrateurHorsRPRole;


//Par défaut, spring sécurity prefixe les rôles avec cette chaine
private String ROLE_PREFIX = "ROLE_";
//Par défaut, spring sécurity prefixe les rôles avec cette chaine
private static final String ROLE_PREFIX = "ROLE_";

@Autowired InseeSecurityTokenProperties inseeSecurityTokenProperties;
@Autowired
InseeSecurityTokenProperties inseeSecurityTokenProperties;

//Liste d'URL sur lesquels on n'applique pas de sécurité (swagger; actuator...)
@Value("#{'${fr.insee.sndil.starter.security.whitelist-matchers}'.split(',')}")
private String[] whiteList;
//Liste d'URL sur lesquels on n'applique pas de sécurité (swagger; actuator...)
@Value("#{'${fr.insee.sndil.starter.security.whitelist-matchers}'.split(',')}")
private String[] whiteList;

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

http.csrf().disable()
.authorizeHttpRequests(authorize ->
http.csrf(csrf -> csrf.disable()) //NOSONAR
.authorizeHttpRequests(authorize ->
authorize.requestMatchers(whiteList).permitAll()
.requestMatchers("/extraction-survey-unit/**").hasRole(administrateurRPRole)
)
.formLogin(AbstractAuthenticationFilterConfigurer::permitAll)
.oauth2ResourceServer(oauth2 -> oauth2.jwt().jwtAuthenticationConverter(jwtAuthenticationConverter()));
return http.build();
}
@Bean
JwtAuthenticationConverter jwtAuthenticationConverter() {
JwtAuthenticationConverter jwtAuthenticationConverter = new JwtAuthenticationConverter();
jwtAuthenticationConverter.setPrincipalClaimName(inseeSecurityTokenProperties.getOidcClaimUsername());
jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(jwtGrantedAuthoritiesConverter());
return jwtAuthenticationConverter;
}

Converter<Jwt, Collection<GrantedAuthority>> jwtGrantedAuthoritiesConverter() {
return new Converter<Jwt, Collection<GrantedAuthority>>() {
@Override @SuppressWarnings({ "unchecked" }) public Collection<GrantedAuthority> convert(Jwt source) {

String[] claimPath = inseeSecurityTokenProperties.getOidcClaimRole().split("\\.");
Map<String, Object> claims = source.getClaims();
try {

for (int i = 0; i < claimPath.length - 1; i++) {
claims = (Map<String, Object>) claims.get(claimPath[i]);
}

List<String> roles = (List<String>) claims.getOrDefault(claimPath[claimPath.length - 1], new ArrayList<>());
//if we need to add customs roles to every connected user we could define this variable (static or from properties)
//roles.addAll(defaultRolesForUsers);
return roles.stream().map(s -> new GrantedAuthority() {
@Override public String getAuthority() {
return ROLE_PREFIX + s;
}

@Override public String toString() {
return getAuthority();
}
}).collect(Collectors.toList());
}
catch (ClassCastException e) {
// role path not correctly found, assume that no role for this user
return new ArrayList<>();
}
.requestMatchers("/extraction-survey-unit/**").hasRole(administrateurRPRole)
.requestMatchers("/census-extraction/**").hasRole(administrateurRPRole)
)
.formLogin(AbstractAuthenticationFilterConfigurer::permitAll)
.oauth2ResourceServer(oauth2 -> oauth2.jwt(jwt -> jwt.jwtAuthenticationConverter(jwtAuthenticationConverter())));
return http.build();
}

@Bean
JwtAuthenticationConverter jwtAuthenticationConverter() {
JwtAuthenticationConverter jwtAuthenticationConverter = new JwtAuthenticationConverter();
jwtAuthenticationConverter.setPrincipalClaimName(inseeSecurityTokenProperties.getOidcClaimUsername());
jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(jwtGrantedAuthoritiesConverter());
return jwtAuthenticationConverter;
}

Converter<Jwt, Collection<GrantedAuthority>> jwtGrantedAuthoritiesConverter() {
return new Converter<Jwt, Collection<GrantedAuthority>>() {
@Override
@SuppressWarnings({"unchecked"})
public Collection<GrantedAuthority> convert(Jwt source) {

String[] claimPath = inseeSecurityTokenProperties.getOidcClaimRole().split("\\.");
Map<String, Object> claims = source.getClaims();
try {

for (int i = 0; i < claimPath.length - 1; i++) {
claims = (Map<String, Object>) claims.get(claimPath[i]);
}

List<String> roles = (List<String>) claims.getOrDefault(claimPath[claimPath.length - 1],
new ArrayList<>());
//if we need to add customs roles to every connected user we could define this variable (static
// or from properties)
return roles.stream().map(s -> new GrantedAuthority() {
@Override
public String getAuthority() {
return ROLE_PREFIX + s;
}
};
}

@Override
public String toString() {
return getAuthority();
}
}).collect(Collectors.toCollection(ArrayList::new));
} catch (ClassCastException e) {
// role path not correctly found, assume that no role for this user
return new ArrayList<>();
}
}
};
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,12 @@ public class SpringDocConfiguration {


public static final String OAUTHSCHEME = "oAuth";
//public final String SCHEMEBASIC = "basic";

@Bean
public OpenAPI customOpenAPIBasicAndOIDC() {
final OpenAPI openapi = createOpenAPI();
openapi.components(
new Components()
/*.addSecuritySchemes(
SCHEMEBASIC,
new SecurityScheme()
.type(SecurityScheme.Type.HTTP)
.scheme(SCHEMEBASIC)
.in(SecurityScheme.In.HEADER)
.description("Authentification Basic"))*/
.addSecuritySchemes(
OAUTHSCHEME,
new SecurityScheme()
Expand Down
Loading

0 comments on commit 5bb02a6

Please sign in to comment.