Skip to content

Commit

Permalink
Merge pull request #3318 from navikt/feature/krr-forbedring-frontend
Browse files Browse the repository at this point in the history
Feature/krr forbedring frontend
  • Loading branch information
stigus committed Oct 27, 2023
2 parents df4e84b + 53ccd53 commit 8e71bd9
Show file tree
Hide file tree
Showing 100 changed files with 1,303 additions and 789 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;

Expand All @@ -20,7 +21,7 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {

httpSecurity.sessionManagement(sessionConfig -> sessionConfig.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.csrf(csrfSpec -> csrfSpec.disable())
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authorizeConfig -> authorizeConfig.requestMatchers(
"/internal/**",
"/webjars/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SecurityConfig {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity httpSecurity) {
return httpSecurity
.csrf(csrfSpec -> csrfSpec.disable())
.csrf(ServerHttpSecurity.CsrfSpec::disable)
.authorizeExchange(authorizeConfig -> authorizeConfig.pathMatchers(
"/internal/**",
"/webjars/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SecurityConfig {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity httpSecurity) {
return httpSecurity
.csrf(csrfSpec -> csrfSpec.disable())
.csrf(ServerHttpSecurity.CsrfSpec::disable)
.authorizeExchange(authorizeConfig -> authorizeConfig.pathMatchers(
"/internal/**",
"/webjars/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;

Expand All @@ -18,7 +19,7 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {

httpSecurity.sessionManagement(sessionConfig -> sessionConfig.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.csrf(csrfSpec -> csrfSpec.disable())
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authorizeConfig -> authorizeConfig.requestMatchers(
"/internal/**",
"/webjars/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;

Expand All @@ -21,7 +22,7 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {

httpSecurity.sessionManagement(sessionConfig -> sessionConfig.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.csrf(csrfSpec -> csrfSpec.disable())
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authorizeConfig -> authorizeConfig.requestMatchers(
"/internal/**",
"/webjars/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;

Expand All @@ -18,7 +19,7 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {

httpSecurity.sessionManagement(sessionConfig -> sessionConfig.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.csrf(csrfSpec -> csrfSpec.disable())
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authorizeConfig -> authorizeConfig.requestMatchers(
"/internal/**",
"/webjars/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SecurityConfig {
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity httpSecurity) {
return httpSecurity
.csrf(csrfSpec -> csrfSpec.disable())
.csrf(ServerHttpSecurity.CsrfSpec::disable)
.authorizeExchange(authorizeConfig -> authorizeConfig.pathMatchers(
"/internal/**",
"/webjars/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,6 @@
@Component
public class DigitalKontaktMappingStrategy implements MappingStrategy {

private static void kobleMaalformTilSpraak(RsDollyUtvidetBestilling bestilling, DigitalKontaktdata digitalKontaktdata) {

String maalform = null;

if (nonNull(bestilling.getTpsMessaging()) && isKrrMaalform(bestilling.getTpsMessaging().getSpraakKode())) {
maalform = bestilling.getTpsMessaging().getSpraakKode();
}

if (isNotBlank(maalform) && isBlank(digitalKontaktdata.getSpraak())) {

digitalKontaktdata.setSpraak(isNotBlank(maalform) ? maalform.toLowerCase() : maalform); //NOSONAR
digitalKontaktdata.setSpraakOppdatert(ZonedDateTime.now());
digitalKontaktdata.setRegistrert(true);
}
}

private static boolean isKrrMaalform(String spraak) {

return isNotBlank(spraak) && Stream.of("NB", "NN", "EN", "SE").anyMatch(spraak::equalsIgnoreCase);
}

@Override
public void register(MapperFactory factory) {
factory.classMap(RsDigitalKontaktdata.class, DigitalKontaktdata.class)
Expand All @@ -52,21 +31,30 @@ public void mapAtoB(RsDigitalKontaktdata digitalKontaktdata, DigitalKontaktdata

kontaktdataRequest.setGyldigFra(getDato(digitalKontaktdata));

if (nonNull(digitalKontaktdata.getMobil())) {
if (isNotBlank(digitalKontaktdata.getMobil())) {
kontaktdataRequest.setMobilOppdatert(getDato(digitalKontaktdata));
kontaktdataRequest.setMobilVerifisert(getDato(digitalKontaktdata));
kontaktdataRequest.setMobil(digdirFormatertTlfNummer(digitalKontaktdata.getMobil()));
}
if (nonNull(digitalKontaktdata.getEpost())) {
if (isNotBlank(digitalKontaktdata.getEpost())) {
kontaktdataRequest.setEpostOppdatert(getDato(digitalKontaktdata));
kontaktdataRequest.setEpostVerifisert(getDato(digitalKontaktdata));
}
if (nonNull(digitalKontaktdata.getSpraak())) {
if (isNotBlank(digitalKontaktdata.getSpraak())) {
kontaktdataRequest.setSpraakOppdatert(getDato(digitalKontaktdata));
}

kobleMaalformTilSpraak((RsDollyUtvidetBestilling) context.getProperty("bestilling"), kontaktdataRequest);
}

private String digdirFormatertTlfNummer(String mobil) {
if (isBlank(mobil)) {
return null;
}
var nummerUtenSpace = mobil.replace(" ", "");
return nummerUtenSpace.contains("+47") ? nummerUtenSpace : "+47%s".formatted(nummerUtenSpace);
}

private ZonedDateTime getDato(RsDigitalKontaktdata digitalKontaktdata) {
return nonNull(digitalKontaktdata.getGyldigFra()) ?
ZonedDateTime.of(digitalKontaktdata.getGyldigFra(), ZoneId.systemDefault()) :
Expand All @@ -77,4 +65,25 @@ private ZonedDateTime getDato(RsDigitalKontaktdata digitalKontaktdata) {
.byDefault()
.register();
}

private static void kobleMaalformTilSpraak(RsDollyUtvidetBestilling bestilling, DigitalKontaktdata digitalKontaktdata) {

String maalform = null;

if (nonNull(bestilling.getTpsMessaging()) && isKrrMaalform(bestilling.getTpsMessaging().getSpraakKode())) {
maalform = bestilling.getTpsMessaging().getSpraakKode();
}

if (isNotBlank(maalform) && isBlank(digitalKontaktdata.getSpraak())) {

digitalKontaktdata.setSpraak(isNotBlank(maalform) ? maalform.toLowerCase() : maalform); //NOSONAR
digitalKontaktdata.setSpraakOppdatert(ZonedDateTime.now());
digitalKontaktdata.setRegistrert(true);
}
}

private static boolean isKrrMaalform(String spraak) {

return isNotBlank(spraak) && Stream.of("NB", "NN", "EN", "SE").anyMatch(spraak::equalsIgnoreCase);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
class DigitalKontaktMappingStrategyTest {

private static final String EPOST = "test@nav.no";
private static final String MOBIL = "99990000";
private static final String MOBIL_INCORRECT = "99990000";
private static final String MOBIL_INCORRECT_SPACE = "+47 99990000";
private static final String MOBIL_CORRECT = "+4799990000";
private static final String SPRAAK = "NO";
private static final boolean RESERVERT = true;
private static final LocalDateTime GYLDIG_FRA = LocalDateTime.of(2018, 1, 1, 0, 0);
Expand Down Expand Up @@ -59,14 +61,27 @@ void mapReservert_OK() {
}

@Test
void mapMobil_OK() {
void mapMobil_Incorrect_OK() {

var result = mapperFacade.map(RsDigitalKontaktdata.builder()
.gyldigFra(GYLDIG_FRA)
.mobil(MOBIL)
.mobil(MOBIL_INCORRECT)
.build(), DigitalKontaktdata.class, context);

assertThat(result.getMobil(), is(equalTo(MOBIL)));
assertThat(result.getMobil(), is(equalTo(MOBIL_CORRECT)));
assertThat(result.getMobilOppdatert(), is(equalTo(Z_GYLDIG_FRA)));
assertThat(result.getMobilVerifisert(), is(equalTo(Z_GYLDIG_FRA)));
}

@Test
void mapMobil_WithSpace_OK() {

var result = mapperFacade.map(RsDigitalKontaktdata.builder()
.gyldigFra(GYLDIG_FRA)
.mobil(MOBIL_INCORRECT_SPACE)
.build(), DigitalKontaktdata.class, context);

assertThat(result.getMobil(), is(equalTo(MOBIL_CORRECT)));
assertThat(result.getMobilOppdatert(), is(equalTo(Z_GYLDIG_FRA)));
assertThat(result.getMobilVerifisert(), is(equalTo(Z_GYLDIG_FRA)));
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dolly-frontend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencyManagement {
applyMavenExclusions = false
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2022.0.4'
mavenBom 'org.springframework.session:spring-session-bom:2021.2.0'
mavenBom 'org.springframework.session:spring-session-bom:2021.2.3'

}
}
Expand Down
1 change: 1 addition & 0 deletions apps/dolly-frontend/config.idporten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ spec:
- host: testnav-pensjon-testdata-facade-proxy.dev-fss-pub.nais.io
- host: testnav-sigrunstub-proxy.dev-fss-pub.nais.io
- host: testnav-krrstub-proxy.dev-fss-pub.nais.io
- host: testnav-udistub-proxy.dev-fss-pub.nais.io
- host: testnav-inst-proxy.dev-fss-pub.nais.io
- host: testnav-aareg-proxy.dev-fss-pub.nais.io
- host: testnav-medl-proxy.dev-fss-pub.nais.io
Expand Down
1 change: 1 addition & 0 deletions apps/dolly-frontend/config.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ spec:
- host: testnav-pensjon-testdata-facade-proxy.dev-fss-pub.nais.io
- host: testnav-sigrunstub-proxy.dev-fss-pub.nais.io
- host: testnav-krrstub-proxy.dev-fss-pub.nais.io
- host: testnav-udistub-proxy.dev-fss-pub.nais.io
- host: testnav-inst-proxy.dev-fss-pub.nais.io
- host: testnav-histark-proxy.dev-fss-pub.nais.io
- host: testnav-aareg-proxy.dev-fss-pub.nais.io
Expand Down
1 change: 1 addition & 0 deletions apps/dolly-frontend/config.unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ spec:
- host: testnav-pensjon-testdata-facade-proxy.dev-fss-pub.nais.io
- host: testnav-sigrunstub-proxy.dev-fss-pub.nais.io
- host: testnav-krrstub-proxy.dev-fss-pub.nais.io
- host: testnav-udistub-proxy.dev-fss-pub.nais.io
- host: testnav-inst-proxy.dev-fss-pub.nais.io
- host: testnav-aareg-proxy.dev-fss-pub.nais.io
- host: testnav-medl-proxy.dev-fss-pub.nais.io
Expand Down
1 change: 1 addition & 0 deletions apps/dolly-frontend/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ spec:
- host: testnav-pensjon-testdata-facade-proxy.dev-fss-pub.nais.io
- host: testnav-sigrunstub-proxy.dev-fss-pub.nais.io
- host: testnav-krrstub-proxy.dev-fss-pub.nais.io
- host: testnav-udistub-proxy.dev-fss-pub.nais.io
- host: testnav-inst-proxy.dev-fss-pub.nais.io
- host: testnav-aareg-proxy.dev-fss-pub.nais.io
- host: testnav-medl-proxy.dev-fss-pub.nais.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class DollyFrontendApplicationStarter {
private final TestnavBrregstubProxyProperties testnavBrregstubProxyProperties;
private final TestnavInstProxyProperties testnavInstProxyProperties;
private final TestnavAaregProxyProperties testnavAaregProxyProperties;
private final TestnavUdistubProxyProperties testnavUdistubProxyProperties;
private final TestnavArenaForvalterenProxyProperties testnavArenaForvalterenProxyProperties;
private final TestnavKrrstubProxyProperties testnavKrrstubProxyProperties;
private final TestnavMedlProxyProperties testnavMedlProxyProperties;
Expand Down Expand Up @@ -97,6 +98,7 @@ public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
.route(createRoute(testnavInntektstubProxyProperties))
.route(createRoute(testnavBrregstubProxyProperties))
.route(createRoute(testnavAaregProxyProperties))
.route(createRoute(testnavUdistubProxyProperties, "testnav-udistub-proxy"))
.route(createRoute(testnavArenaForvalterenProxyProperties))
.route(createRoute(testnavKrrstubProxyProperties, "testnav-krrstub-proxy"))
.route(createRoute(testnavMedlProxyProperties, "testnav-medl-proxy"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,32 @@ public SecurityWebFilterChain configure(ServerHttpSecurity http) {
var logoutSuccessHandler = new LogoutSuccessHandler();
logoutSuccessHandler.applyOn("idporten", new IdportenOcidLogoutUrlResolver(wellKnownUrl, postLogoutRedirectUri));

return http.cors()
.and().csrf().disable()
.authorizeExchange()
.pathMatchers(
"/internal/isReady",
"/internal/isAlive",
"/assets/*",
"/internal/metrics",
"/oauth2/callback",
"/favicon.ico",
LOGIN,
LOGOUT,
"/oauth2/logout",
"/*.css",
"/*.js",
"/*.mjs",
"/*.png"
).permitAll()
.anyExchange().authenticated()
.and().oauth2Login(oAuth2LoginSpec -> oAuth2LoginSpec
return http.cors(ServerHttpSecurity.CorsSpec::disable)
.csrf(ServerHttpSecurity.CsrfSpec::disable)
.authorizeExchange(authorizeExchangeSpec -> authorizeExchangeSpec.pathMatchers(
"/internal/isReady",
"/internal/isAlive",
"/assets/*",
"/internal/metrics",
"/oauth2/callback",
"/favicon.ico",
LOGIN,
LOGOUT,
"/oauth2/logout",
"/*.css",
"/*.js",
"/*.mjs",
"/*.png"
).permitAll()
.anyExchange().authenticated())
.oauth2Login(oAuth2LoginSpec -> oAuth2LoginSpec
.authenticationManager(authenticationManger)
.authenticationSuccessHandler(authenticationSuccessHandler))
.formLogin().loginPage(LOGIN)
.and().logout(logoutSpec -> logoutSpec
.formLogin(formLoginSpec -> formLoginSpec.loginPage(LOGIN))
.logout(logoutSpec -> logoutSpec
.logoutUrl(LOGOUT)
.requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, LOGOUT))
.logoutSuccessHandler(logoutSuccessHandler))
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,28 @@ public SecurityWebFilterChain configure(ServerHttpSecurity http) {
var authenticationSuccessHandler = new DollyAuthenticationSuccessHandler();
var logoutSuccessHandler = new LogoutSuccessHandler();

return http.cors()
.and().csrf().disable()
.authorizeExchange()
.pathMatchers(
"/internal/isReady",
"/internal/isAlive",
"/assets/*",
"/internal/metrics",
"/oauth2/callback",
"/favicon.ico",
LOGIN,
LOGOUT,
"/oauth2/logout",
"/*.css",
"/*.js",
"/*.mjs",
"/*.png"
).permitAll()
.anyExchange().authenticated()
.and().oauth2Login(oAuth2LoginSpec -> oAuth2LoginSpec
return http.cors(ServerHttpSecurity.CorsSpec::disable)
.csrf(ServerHttpSecurity.CsrfSpec::disable)
.authorizeExchange(authorizeExchangeSpec -> authorizeExchangeSpec.pathMatchers(
"/internal/isReady",
"/internal/isAlive",
"/assets/*",
"/internal/metrics",
"/oauth2/callback",
"/favicon.ico",
LOGIN,
LOGOUT,
"/oauth2/logout",
"/*.css",
"/*.js",
"/*.mjs",
"/*.png"
).permitAll()
.anyExchange().authenticated())
.oauth2Login(oAuth2LoginSpec -> oAuth2LoginSpec
.authenticationSuccessHandler(authenticationSuccessHandler))
.formLogin().loginPage(LOGIN)
.and().logout(logoutSpec -> logoutSpec
.formLogin(formLoginSpec -> formLoginSpec.loginPage(LOGIN))
.logout(logoutSpec -> logoutSpec
.logoutUrl(LOGOUT)
.requiresLogout(ServerWebExchangeMatchers.pathMatchers(HttpMethod.GET, LOGOUT))
.logoutSuccessHandler(logoutSuccessHandler))
Expand Down
Loading

0 comments on commit 8e71bd9

Please sign in to comment.