diff --git a/.github/workflows/app.ereg-batch-status-service.yml b/.github/workflows/app.ereg-batch-status-service.yml index f9f8e2ac8fd..3547091010a 100644 --- a/.github/workflows/app.ereg-batch-status-service.yml +++ b/.github/workflows/app.ereg-batch-status-service.yml @@ -14,7 +14,7 @@ jobs: workflow: uses: ./.github/workflows/common.workflow.backend.yml with: - cluster: "dev-fss" + cluster: "dev-gcp" working-directory: "apps/ereg-batch-status-service" deploy-tag: "#deploy-ereg-batch-status-service" permissions: diff --git a/.github/workflows/proxy.modapp-ereg-proxy.yml b/.github/workflows/proxy.modapp-ereg-proxy.yml new file mode 100644 index 00000000000..ec4b0b6bdb9 --- /dev/null +++ b/.github/workflows/proxy.modapp-ereg-proxy.yml @@ -0,0 +1,23 @@ +name: modapp-ereg-proxy + +on: + push: + paths: + - libs/reactive-core + - libs/reactive-proxy + - libs/reactive-security + - libs/security-core + - proxies/modapp-ereg-proxy/** + - .github/workflows/proxy.modapp-ereg-proxy.yml + +jobs: + workflow: + uses: ./.github/workflows/common.workflow.backend.yml + with: + cluster: "dev-fss" + working-directory: "proxies/modapp-ereg-proxy" + deploy-tag: "#deploy-proxy" + permissions: + contents: read + id-token: write + secrets: inherit diff --git a/.gitignore b/.gitignore index 88695f9e761..82bf724a9e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.idea/ *target/ *.iml +*.http # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. diff --git a/apps/ereg-batch-status-service/README.md b/apps/ereg-batch-status-service/README.md index b258606b430..030a76d60dc 100644 --- a/apps/ereg-batch-status-service/README.md +++ b/apps/ereg-batch-status-service/README.md @@ -2,7 +2,7 @@ App for å hente ut batch status. ## Swagger -Swagger finnes under [/swagger](https://ereg-batch-status-service.dev.intern.nav.no/swagger) -endepunktet til applikasjonen. +Swagger finnes under [/swagger](https://testnav-ereg-batch-status-service.intern.dev.nav.no/swagger) -endepunktet til applikasjonen. ## Lokal kjøring Ha naisdevice kjørende og kjør EregBatchServiceServiceApplicationStarter med følgende argumenter: diff --git a/apps/ereg-batch-status-service/build.gradle b/apps/ereg-batch-status-service/build.gradle index ac3f1fb375e..c5aa01d3aaa 100644 --- a/apps/ereg-batch-status-service/build.gradle +++ b/apps/ereg-batch-status-service/build.gradle @@ -44,21 +44,21 @@ dependencies { implementation 'no.nav.testnav.libs:data-transfer-objects' implementation 'no.nav.testnav.libs:reactive-core' - implementation 'no.nav.testnav.libs:servlet-core' - implementation 'no.nav.testnav.libs:servlet-security' + implementation 'no.nav.testnav.libs:reactive-security' + implementation 'no.nav.testnav.libs:security-core' implementation 'org.springframework.boot:spring-boot-starter-webflux' - implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' + implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.cloud:spring-cloud-starter-gateway' implementation 'org.springframework.cloud:spring-cloud-starter-vault-config' - implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap' // TODO remove legacy bootstrap config implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.micrometer:micrometer-registry-prometheus' - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' + implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.3.0' implementation 'io.swagger.core.v3:swagger-annotations-jakarta:2.2.20' implementation 'net.logstash.logback:logstash-logback-encoder:7.4' diff --git a/apps/ereg-batch-status-service/config.yml b/apps/ereg-batch-status-service/config.yml index 23f5416dc3e..5e1b25b8980 100644 --- a/apps/ereg-batch-status-service/config.yml +++ b/apps/ereg-batch-status-service/config.yml @@ -18,6 +18,9 @@ spec: cluster: dev-gcp - application: organisasjon-bestilling-service cluster: dev-gcp + outbound: + external: + - host: testnav-modapp-ereg-proxy.dev-fss-pub.nais.io tokenx: enabled: true azure: @@ -48,4 +51,4 @@ spec: limits: memory: 2048Mi ingresses: - - "https://ereg-batch-status-service.dev-fss-pub.nais.io" \ No newline at end of file + - "https://testnav-ereg-batch-status-service.intern.dev.nav.no" \ No newline at end of file diff --git a/apps/ereg-batch-status-service/settings.gradle b/apps/ereg-batch-status-service/settings.gradle index 5b9f453200b..8c37d66ba90 100644 --- a/apps/ereg-batch-status-service/settings.gradle +++ b/apps/ereg-batch-status-service/settings.gradle @@ -6,8 +6,8 @@ rootProject.name = 'ereg-batch-status-service' includeBuild '../../libs/data-transfer-objects' includeBuild '../../libs/reactive-core' -includeBuild '../../libs/servlet-core' -includeBuild '../../libs/servlet-security' +includeBuild '../../libs/reactive-security' +includeBuild '../../libs/security-core' gradleEnterprise { buildScan { diff --git a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/ApplicationConfig.java b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/ApplicationConfig.java index 67f13c87191..6e6b082290c 100644 --- a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/ApplicationConfig.java +++ b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/ApplicationConfig.java @@ -1,14 +1,17 @@ package no.nav.registre.testnorge.eregbatchstatusservice.config; +import no.nav.testnav.libs.reactivecore.config.CoreConfig; +import no.nav.testnav.libs.reactivesecurity.config.SecureOAuth2ServerToServerConfiguration; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.web.reactive.config.EnableWebFlux; -import no.nav.testnav.libs.servletcore.config.ApplicationCoreConfig; -import no.nav.testnav.libs.servletsecurity.config.SecureOAuth2ServerToServerConfiguration; @Configuration +@EnableWebFlux @Import({ - ApplicationCoreConfig.class, + CoreConfig.class, + SecurityConfig.class, SecureOAuth2ServerToServerConfiguration.class }) public class ApplicationConfig { diff --git a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/Consumers.java b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/Consumers.java new file mode 100644 index 00000000000..a39eadfc259 --- /dev/null +++ b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.registre.testnorge.eregbatchstatusservice.config; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + *

+ * Husk at Spring Boot bruker relaxed binding + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties modappEregProxy; + +} diff --git a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/EregProperties.java b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/EregProperties.java deleted file mode 100644 index 4b3c4647e47..00000000000 --- a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/EregProperties.java +++ /dev/null @@ -1,16 +0,0 @@ -package no.nav.registre.testnorge.eregbatchstatusservice.config; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -import java.util.Map; - -@Getter -@Setter -@Configuration -@ConfigurationProperties(prefix = "ereg") -public class EregProperties { - private Map envHostMap; -} diff --git a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/OpenApiConfig.java b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/OpenApiConfig.java index 49734eadc21..d72806f2a12 100644 --- a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/OpenApiConfig.java +++ b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/OpenApiConfig.java @@ -7,17 +7,15 @@ import io.swagger.v3.oas.models.info.License; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; +import no.nav.testnav.libs.reactivecore.config.ApplicationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.http.HttpHeaders; import java.util.Arrays; -import no.nav.testnav.libs.servletcore.config.ApplicationProperties; - @Configuration -public class OpenApiConfig implements WebMvcConfigurer { +public class OpenApiConfig { @Bean public OpenAPI openApi(ApplicationProperties applicationProperties) { @@ -27,7 +25,7 @@ public OpenAPI openApi(ApplicationProperties applicationProperties) { .scheme("bearer") .bearerFormat("JWT") .in(SecurityScheme.In.HEADER) - .name("Authorization") + .name(HttpHeaders.AUTHORIZATION) )) .addSecurityItem( new SecurityRequirement().addList("bearer-jwt", Arrays.asList("read", "write"))) @@ -47,9 +45,4 @@ public OpenAPI openApi(ApplicationProperties applicationProperties) { ) ); } - - @Override - public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/swagger").setViewName("redirect:/swagger-ui.html"); - } } \ No newline at end of file diff --git a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/SecurityConfig.java b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/SecurityConfig.java index 11037bdd77f..8edc18ab66e 100644 --- a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/SecurityConfig.java +++ b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/config/SecurityConfig.java @@ -1,26 +1,30 @@ package no.nav.registre.testnorge.eregbatchstatusservice.config; +import lombok.RequiredArgsConstructor; +import no.nav.testnav.libs.reactivesecurity.manager.JwtReactiveAuthenticationManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; -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.config.annotation.method.configuration.EnableReactiveMethodSecurity; +import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.web.server.SecurityWebFilterChain; -@EnableWebSecurity @Configuration +@EnableWebFluxSecurity +@EnableReactiveMethodSecurity +@RequiredArgsConstructor @Profile({ "prod", "dev" }) public class SecurityConfig { + private final JwtReactiveAuthenticationManager jwtReactiveAuthenticationManager; + @Bean - public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception { + public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity httpSecurity) { - httpSecurity.sessionManagement(sessionConfig -> sessionConfig.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) - .csrf(AbstractHttpConfigurer::disable) - .authorizeHttpRequests(authorizeConfig -> authorizeConfig.requestMatchers( + return httpSecurity + .csrf(ServerHttpSecurity.CsrfSpec::disable) + .authorizeExchange(authorizeConfig -> authorizeConfig.pathMatchers( "/internal/**", "/webjars/**", "/swagger-resources/**", @@ -29,10 +33,9 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti "/swagger", "/error", "/swagger-ui.html" - ).permitAll().requestMatchers("/api/**").fullyAuthenticated()) - .oauth2ResourceServer(oauth2RSConfig -> oauth2RSConfig.jwt(Customizer.withDefaults())); - - return httpSecurity.build(); + ).permitAll().anyExchange().authenticated()) + .oauth2ResourceServer(oauth2RSConfig -> oauth2RSConfig.jwt(jwtSpec -> jwtSpec.authenticationManager(jwtReactiveAuthenticationManager))) + .build(); } } diff --git a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/consumer/EregConsumer.java b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/consumer/EregConsumer.java index 5a9164c9ca2..b5ed69cfced 100644 --- a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/consumer/EregConsumer.java +++ b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/consumer/EregConsumer.java @@ -1,38 +1,37 @@ package no.nav.registre.testnorge.eregbatchstatusservice.consumer; import lombok.extern.slf4j.Slf4j; -import no.nav.registre.testnorge.eregbatchstatusservice.config.EregProperties; +import no.nav.registre.testnorge.eregbatchstatusservice.config.Consumers; import no.nav.registre.testnorge.eregbatchstatusservice.consumer.command.GetBatchStatusCommand; +import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; - -import java.util.Map; -import java.util.stream.Collectors; +import reactor.core.publisher.Mono; @Slf4j @Component public class EregConsumer { - private final Map envWebClientMap; + private final ServerProperties serverProperties; + private final WebClient webClient; + private final TokenExchange tokenService; + - public EregConsumer(EregProperties eregProperties) { + public EregConsumer(TokenExchange tokenService, + Consumers consumers + ) { - this.envWebClientMap = eregProperties - .getEnvHostMap() - .entrySet() - .stream() - .collect(Collectors.toMap( - Map.Entry::getKey, - entry -> WebClient.builder() - .baseUrl(entry.getValue()) - .build() - )); + this.tokenService = tokenService; + this.serverProperties = consumers.getModappEregProxy(); + this.webClient = WebClient.builder() + .baseUrl(consumers.getModappEregProxy().getUrl()) + .build(); } - public Long getStatusKode(String miljo, Long id) { - if (!envWebClientMap.containsKey(miljo)) { - throw new RuntimeException("Stotter ikke miljo: " + miljo + " i EREG."); - } else { - return new GetBatchStatusCommand(envWebClientMap.get(miljo), id).call(); - } + public Mono getStatusKode(String miljo, Long id) { + return tokenService + .exchange(serverProperties) + .flatMap(accessToken -> + new GetBatchStatusCommand(webClient, miljo, id, accessToken.getTokenValue()).call()); } -} +} \ No newline at end of file diff --git a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/consumer/command/GetBatchStatusCommand.java b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/consumer/command/GetBatchStatusCommand.java index fbbf9ec1e25..cf5cc38f465 100644 --- a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/consumer/command/GetBatchStatusCommand.java +++ b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/consumer/command/GetBatchStatusCommand.java @@ -1,27 +1,45 @@ package no.nav.registre.testnorge.eregbatchstatusservice.consumer.command; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import no.nav.registre.testnorge.eregbatchstatusservice.util.WebClientFilter; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.server.ResponseStatusException; +import reactor.core.publisher.Mono; import reactor.util.retry.Retry; import java.time.Duration; import java.util.concurrent.Callable; +import static org.springframework.http.HttpHeaders.AUTHORIZATION; + @RequiredArgsConstructor -public class GetBatchStatusCommand implements Callable { +@Slf4j +public class GetBatchStatusCommand implements Callable> { private final WebClient webClient; + private final String miljoe; private final Long id; + private final String token; @Override - public Long call() { + public Mono call() { return webClient .get() - .uri(builder -> builder.path("/ereg/internal/batch/poll/{id}").build(id)) + .uri(builder -> builder.path("/{miljoe}/ereg/internal/batch/poll/{id}").build(miljoe, id)) + .header(AUTHORIZATION, "Bearer " + token) .retrieve() + .onStatus(HttpStatusCode::is4xxClientError, clientResponse -> { + if (clientResponse.statusCode().equals(HttpStatus.UNAUTHORIZED)) { + log.error("Unauthorized error occurred when calling modapp-ereg-proxy"); + return Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found")); + } + log.error("Client error occurred when calling modapp-ereg-proxy"); + return Mono.error(new ResponseStatusException(clientResponse.statusCode(), "Client error occurred")); + }) .bodyToMono(Long.class) .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) - .filter(WebClientFilter::is5xxException)) - .block(); + .filter(WebClientFilter::is5xxException)); } } diff --git a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/filter/SwaggerWebFilter.java b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/filter/SwaggerWebFilter.java new file mode 100644 index 00000000000..6141d2e2409 --- /dev/null +++ b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/filter/SwaggerWebFilter.java @@ -0,0 +1,23 @@ +package no.nav.registre.testnorge.eregbatchstatusservice.filter; + +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.server.WebFilter; +import org.springframework.web.server.WebFilterChain; +import reactor.core.publisher.Mono; + +@Component +public class SwaggerWebFilter implements WebFilter { + @Override + public Mono filter(ServerWebExchange exchange, WebFilterChain chain) { + if (exchange.getRequest().getURI().getPath().equals("/swagger")) { + return chain + .filter(exchange.mutate() + .request(exchange.getRequest() + .mutate().path("/swagger-ui.html").build()) + .build()); + } + + return chain.filter(exchange); + } +} \ No newline at end of file diff --git a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/provider/BatchStatusController.java b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/provider/BatchStatusController.java index f886c3ed961..4086e65f040 100644 --- a/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/provider/BatchStatusController.java +++ b/apps/ereg-batch-status-service/src/main/java/no/nav/registre/testnorge/eregbatchstatusservice/provider/BatchStatusController.java @@ -1,6 +1,7 @@ package no.nav.registre.testnorge.eregbatchstatusservice.provider; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import no.nav.registre.testnorge.eregbatchstatusservice.consumer.EregConsumer; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -9,7 +10,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.function.client.WebClientResponseException; +import reactor.core.publisher.Mono; +@Slf4j @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/batch/items") @@ -17,11 +20,12 @@ public class BatchStatusController { private final EregConsumer eregConsumer; @GetMapping("/{id}") - public ResponseEntity getStatusKode(@RequestHeader("miljoe") String miljo, @PathVariable("id") Long id) { + public ResponseEntity> getStatusKode(@RequestHeader("miljoe") String miljo, @PathVariable("id") Long id) { try { var status = eregConsumer.getStatusKode(miljo, id); return ResponseEntity.ok(status); - } catch (WebClientResponseException.NotFound e) { + } catch (WebClientResponseException e) { + log.error(e.getMessage(), e); return ResponseEntity.notFound().build(); } } diff --git a/apps/ereg-batch-status-service/src/main/resources/application-dev.yml b/apps/ereg-batch-status-service/src/main/resources/application-dev.yml new file mode 100644 index 00000000000..f05debbd219 --- /dev/null +++ b/apps/ereg-batch-status-service/src/main/resources/application-dev.yml @@ -0,0 +1 @@ +TOKEN_X_ISSUER: dummy \ No newline at end of file diff --git a/apps/ereg-batch-status-service/src/main/resources/application.yml b/apps/ereg-batch-status-service/src/main/resources/application.yml index ede2e74d146..dbdd87a98e5 100644 --- a/apps/ereg-batch-status-service/src/main/resources/application.yml +++ b/apps/ereg-batch-status-service/src/main/resources/application.yml @@ -1,11 +1,14 @@ AAD_ISSUER_URI: https://login.microsoftonline.com/62366534-1ec3-4962-8869-9b5535279d0b spring: + cloud: + vault: + enabled: false main: banner-mode: off application: name: ereg-batch-status-service - version: application.version.todo #TODO Finn ut hvordan denne kan settes fra gradle + version: application.version.todo description: Tjeneste for å hente ut batch status fra EREG. security: oauth2: @@ -15,7 +18,7 @@ spring: jwk-set-uri: ${AAD_ISSUER_URI}/discovery/v2.0/keys accepted-audience: ${azure.app.client.id}, api://${azure.app.client.id} tokenx: - issuer-uri: ${TOKEN_X_ISSUER} + issuer-uri: ${TOKEN_X_ISSUER} jwk-set-uri: ${TOKEN_X_JWKS_URI} accepted-audience: ${TOKEN_X_CLIENT_ID} @@ -24,13 +27,12 @@ springdoc: disable-swagger-default-url: true url: /v3/api-docs -ereg: - envHostMap: - q1: https://ereg-services-q1.dev.intern.nav.no - q2: https://ereg-services-q2.dev.intern.nav.no - q4: https://ereg-services-q4.dev.intern.nav.no - q5: https://ereg-services-q5.dev.intern.nav.no - t3: https://ereg-services-t3.dev.intern.nav.no +consumers: + modapp-ereg-proxy: + name: testnav-modapp-ereg-proxy + namespace: dolly + url: https://testnav-modapp-ereg-proxy.dev-fss-pub.nais.io + cluster: dev-fss management: endpoints: diff --git a/apps/ereg-batch-status-service/src/main/resources/bootstrap.yml b/apps/ereg-batch-status-service/src/main/resources/bootstrap.yml deleted file mode 100644 index 0451449ca23..00000000000 --- a/apps/ereg-batch-status-service/src/main/resources/bootstrap.yml +++ /dev/null @@ -1,4 +0,0 @@ -spring: - cloud: - vault: - enabled: false \ No newline at end of file diff --git a/apps/organisasjon-bestilling-service/config.yml b/apps/organisasjon-bestilling-service/config.yml index aac16e21e70..085a993d852 100644 --- a/apps/organisasjon-bestilling-service/config.yml +++ b/apps/organisasjon-bestilling-service/config.yml @@ -33,8 +33,10 @@ spec: - application: testnav-organisasjon-mottak-service cluster: dev-gcp outbound: + rules: + - application: ereg-batch-status-service + cluster: dev-gcp external: - - host: ereg-batch-status-service.dev-fss-pub.nais.io - host: testnorge-batch-adeo-proxy.dev-fss-pub.nais.io gcp: sqlInstances: diff --git a/apps/organisasjon-bestilling-service/src/main/java/no/nav/testnav/apps/organisasjonbestillingservice/consumer/command/GetEregBatchStatusCommand.java b/apps/organisasjon-bestilling-service/src/main/java/no/nav/testnav/apps/organisasjonbestillingservice/consumer/command/GetEregBatchStatusCommand.java index 1efac7ce2b5..e480b8ab753 100644 --- a/apps/organisasjon-bestilling-service/src/main/java/no/nav/testnav/apps/organisasjonbestillingservice/consumer/command/GetEregBatchStatusCommand.java +++ b/apps/organisasjon-bestilling-service/src/main/java/no/nav/testnav/apps/organisasjonbestillingservice/consumer/command/GetEregBatchStatusCommand.java @@ -1,14 +1,18 @@ package no.nav.testnav.apps.organisasjonbestillingservice.consumer.command; import lombok.RequiredArgsConstructor; -import no.nav.testnav.libs.commands.utils.WebClientFilter; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientResponseException; +import org.springframework.web.server.ResponseStatusException; import reactor.util.retry.Retry; import java.time.Duration; import java.util.concurrent.Callable; +@Slf4j @RequiredArgsConstructor public class GetEregBatchStatusCommand implements Callable { private final WebClient webClient; @@ -18,14 +22,19 @@ public class GetEregBatchStatusCommand implements Callable { @Override public Long call() { - return webClient.get() - .uri(uriBuilder -> uriBuilder.path("/api/v1/batch/items/{id}").build(batchId)) - .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) - .header("miljoe", miljo) - .retrieve() - .bodyToMono(Long.class) - .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) - .filter(WebClientFilter::is5xxException)) - .block(); + try { + return webClient.get() + .uri(uriBuilder -> uriBuilder.path("/api/v1/batch/items/{id}").build(batchId)) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + token) + .header("miljoe", miljo) + .retrieve() + .bodyToMono(Long.class) + .retryWhen(Retry.backoff(3, Duration.ofSeconds(5)) + .filter(throwable -> throwable instanceof WebClientResponseException.GatewayTimeout)) + .block(); + } catch (Exception e) { + log.error("Failed to get status for batch with id: " + batchId, e); + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Resource not found", e); + } } } \ No newline at end of file diff --git a/apps/organisasjon-bestilling-service/src/main/resources/application.yml b/apps/organisasjon-bestilling-service/src/main/resources/application.yml index 3d3df5fd455..805ee2e6965 100644 --- a/apps/organisasjon-bestilling-service/src/main/resources/application.yml +++ b/apps/organisasjon-bestilling-service/src/main/resources/application.yml @@ -16,7 +16,7 @@ spring: jwk-set-uri: ${AAD_ISSUER_URI}/discovery/v2.0/keys accepted-audience: ${azure.app.client.id}, api://${azure.app.client.id} tokenx: - issuer-uri: ${TOKEN_X_ISSUER} + issuer-uri: ${TOKEN_X_ISSUER} jwk-set-uri: ${TOKEN_X_JWKS_URI} accepted-audience: ${TOKEN_X_CLIENT_ID} @@ -27,8 +27,8 @@ springdoc: consumers: ereg-batch-status-service: - url: https://ereg-batch-status-service.dev-fss-pub.nais.io - cluster: dev-fss + url: http://ereg-batch-status-service.dolly.svc.cluster.local + cluster: dev-gcp namespace: dolly name: ereg-batch-status-service jenkins: diff --git a/apps/organisasjon-mottak-service/src/main/java/no/nav/registre/testnorge/organisasjonmottak/domain/Record.java b/apps/organisasjon-mottak-service/src/main/java/no/nav/registre/testnorge/organisasjonmottak/domain/Record.java index 0d1f11a0c4e..cecc9238ecc 100644 --- a/apps/organisasjon-mottak-service/src/main/java/no/nav/registre/testnorge/organisasjonmottak/domain/Record.java +++ b/apps/organisasjon-mottak-service/src/main/java/no/nav/registre/testnorge/organisasjonmottak/domain/Record.java @@ -4,21 +4,36 @@ import java.util.Date; import java.util.List; +import static java.util.Objects.nonNull; + public class Record { private final StringBuilder builder = new StringBuilder(); private int record = 0; - public static Record create(List lines, String orgnummer, String enhetstype, boolean update) { + public void append(String value) { + record++; + builder.append(value); + } + + public int getRecord() { + return record; + } + + public String build() { + return builder.toString(); + } + + public static Record create(List lines, String orgnummer, String enhetstype, Date regDato, boolean update) { Record record = new Record(); - record.append(createEHN(update, orgnummer, enhetstype)); + record.append(createEHN(update, orgnummer, enhetstype, regDato)); lines.forEach(line -> record.append(line.getValue())); return record; } - private static String createEHN(boolean update, String orgnummer, String enhetstype) { + private static String createEHN(boolean update, String orgnummer, String enhetstype, Date regDato) { StringBuilder stringBuilder = createStringBuilderWithReplacement(49, ' '); - String dateNowFormatted = getDateNowFormatted(); + String dateNowFormatted = getDateNowFormatted(regDato); String undersakstype = update ? "EN" : "NY"; stringBuilder.replace(0, "ENH".length(), "ENH") @@ -41,21 +56,8 @@ private static StringBuilder createStringBuilderWithReplacement(int size, char r return stringBuilder; } - private static String getDateNowFormatted() { + private static String getDateNowFormatted(Date regDato) { SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); - return format.format(new Date()); - } - - public void append(String value) { - record++; - builder.append(value); - } - - public int getRecord() { - return record; - } - - public String build() { - return builder.toString(); + return format.format(nonNull(regDato) ? regDato : new Date()); } } diff --git a/apps/organisasjon-mottak-service/src/main/java/no/nav/registre/testnorge/organisasjonmottak/listener/OrganisasjonMottakListener.java b/apps/organisasjon-mottak-service/src/main/java/no/nav/registre/testnorge/organisasjonmottak/listener/OrganisasjonMottakListener.java index 92ac3f4e787..a20a58ca856 100644 --- a/apps/organisasjon-mottak-service/src/main/java/no/nav/registre/testnorge/organisasjonmottak/listener/OrganisasjonMottakListener.java +++ b/apps/organisasjon-mottak-service/src/main/java/no/nav/registre/testnorge/organisasjonmottak/listener/OrganisasjonMottakListener.java @@ -29,13 +29,18 @@ import org.springframework.kafka.annotation.KafkaListener; import org.springframework.stereotype.Component; +import java.time.LocalDate; +import java.time.ZoneOffset; import java.util.ArrayList; import java.util.Collection; +import java.util.Date; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import static java.util.Objects.nonNull; + @Slf4j @Profile("prod") @Component @@ -95,11 +100,20 @@ private void createRecords(List records, Organisasjon organisasjon, Orga Optional.ofNullable(organisasjon.getFormaal()).ifPresent(value -> list.add(new Formaal(value))); Optional.ofNullable(parent).ifPresent(value -> list.add(new Knytning(value, organisasjon))); + var stiftelsesDato = (nonNull(organisasjon.getStiftelsesdato()) && nonNull(organisasjon.getStiftelsesdato().getDato()) ? organisasjon.getStiftelsesdato().getDato() : null); + var regDato = (nonNull(organisasjon.getStiftelsesdato()) + //Registreringsdato settes til dagen etter stiftelsesdato hvis den er satt + ? Date.from(LocalDate.of(stiftelsesDato.getAar(), stiftelsesDato.getMaaned(), stiftelsesDato.getDag()) + .plusDays(1).atStartOfDay() + .toInstant(ZoneOffset.UTC)) + : null); + var record = Record.create( list.stream().map(ToLine::toLine) .toList(), organisasjon.getOrgnummer(), organisasjon.getEnhetstype(), + regDato, update ); diff --git a/apps/organisasjon-mottak-service/src/test/java/no/nav/registre/testnorge/organisasjonmottak/domain/RecordTest.java b/apps/organisasjon-mottak-service/src/test/java/no/nav/registre/testnorge/organisasjonmottak/domain/RecordTest.java new file mode 100644 index 00000000000..2db6ce7748c --- /dev/null +++ b/apps/organisasjon-mottak-service/src/test/java/no/nav/registre/testnorge/organisasjonmottak/domain/RecordTest.java @@ -0,0 +1,42 @@ +package no.nav.registre.testnorge.organisasjonmottak.domain; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; + +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.util.Collections; +import java.util.Date; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + +class RecordTest { + + @InjectMocks + Record record; + + @BeforeEach + void setUp() { + MockitoAnnotations.openMocks(this); + } + + @Test + void testCreate() { + // Create mock objects + var line = mock(Line.class); + var orgnummer = "123456789"; + var enhetstype = "AS"; + var regDato = Date.from(LocalDate.of(2022, 1, 1).atStartOfDay().toInstant(ZoneOffset.UTC)); + var update = false; + + // Call method under test + var result = Record.create(Collections.singletonList(line), orgnummer, enhetstype, regDato, update); + + // Verify that the StringBuilder contains the correct date + var expectedDate = "20220101"; + assertTrue(result.build().contains(expectedDate)); + } +} \ No newline at end of file diff --git a/proxies/ereg-proxy/src/main/java/no/nav/testnav/proxies/eregproxy/EregProxyApplicationStarter.java b/proxies/ereg-proxy/src/main/java/no/nav/testnav/proxies/eregproxy/EregProxyApplicationStarter.java index 4ec7582870a..b5f7b4f5d37 100644 --- a/proxies/ereg-proxy/src/main/java/no/nav/testnav/proxies/eregproxy/EregProxyApplicationStarter.java +++ b/proxies/ereg-proxy/src/main/java/no/nav/testnav/proxies/eregproxy/EregProxyApplicationStarter.java @@ -12,6 +12,7 @@ import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Import; +import org.springframework.http.HttpHeaders; import java.util.function.Function; @@ -29,8 +30,6 @@ public RouteLocator customRouteLocator(RouteLocatorBuilder builder) { .route(createRoute("q1")) .route(createRoute("q2")) .route(createRoute("q4")) - .route(createRoute("q5")) - .route(createRoute("t3")) .build(); } @@ -43,6 +42,7 @@ private Function> createRoute(String miljo) { .path("/api/" + miljo + "/**") .filters(filterSpec -> filterSpec .rewritePath("/api/" + miljo + "/(?.*)", "/${segment}") + .removeRequestHeader(HttpHeaders.AUTHORIZATION) ).uri("https://ereg-services-" + miljo + ".dev.intern.nav.no/"); } } diff --git a/proxies/modapp-ereg-proxy/Dockerfile b/proxies/modapp-ereg-proxy/Dockerfile new file mode 100644 index 00000000000..4a36f93546f --- /dev/null +++ b/proxies/modapp-ereg-proxy/Dockerfile @@ -0,0 +1,8 @@ +FROM ghcr.io/navikt/baseimages/temurin:21 +LABEL maintainer="Team Dolly" + +ENV JAVA_OPTS="-Dspring.profiles.active=prod" + +ADD /build/libs/app.jar /app/app.jar + +EXPOSE 8080 diff --git a/proxies/modapp-ereg-proxy/build.gradle b/proxies/modapp-ereg-proxy/build.gradle new file mode 100644 index 00000000000..5f8425ba179 --- /dev/null +++ b/proxies/modapp-ereg-proxy/build.gradle @@ -0,0 +1,71 @@ +plugins { + id 'java' + id "org.sonarqube" version "4.4.1.3373" + id 'org.springframework.boot' version "3.2.1" + id 'io.spring.dependency-management' version "1.1.4" + id "jacoco" +} + +test { + useJUnitPlatform() +} + +sonarqube { + properties { + property "sonar.dynamicAnalysis", "reuseReports" + property "sonar.host.url", "https://sonarcloud.io" + property "sonar.java.coveragePlugin", "jacoco" + property "sonar.language", "java" + property "sonar.token", System.getenv("SONAR_TOKEN") + property "sonar.organization", "navikt" + property "sonar.project.monorepo.enabled", true + property "sonar.projectKey", "testnav-modapp-ereg-proxy" + property "sonar.projectName", "testnav-modapp-ereg-proxy" + property "sonar.sourceEncoding", "UTF-8" + } +} +bootJar { + archiveFileName = "app.jar" +} + +dependencyManagement { + applyMavenExclusions = false + imports { + mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2023.0.0' + } +} + +repositories { + mavenCentral() + mavenLocal() +} + +dependencies { + + implementation 'no.nav.testnav.libs:security-core' + implementation 'no.nav.testnav.libs:reactive-core' + implementation 'no.nav.testnav.libs:reactive-proxy' + implementation 'no.nav.testnav.libs:reactive-security' + + implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' + implementation 'org.springframework.boot:spring-boot-starter-webflux' + + implementation 'org.springframework.cloud:spring-cloud-starter-vault-config' + implementation 'org.springframework.cloud:spring-cloud-starter-gateway' + + + implementation 'net.logstash.logback:logstash-logback-encoder:7.4' + implementation 'org.hibernate.validator:hibernate-validator' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock' + + annotationProcessor 'org.projectlombok:lombok' + implementation 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' +} +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} diff --git a/proxies/modapp-ereg-proxy/config.yml b/proxies/modapp-ereg-proxy/config.yml new file mode 100644 index 00000000000..be0933c0b8c --- /dev/null +++ b/proxies/modapp-ereg-proxy/config.yml @@ -0,0 +1,66 @@ +--- +apiVersion: nais.io/v1 +kind: AzureAdApplication +metadata: + name: testnav-modapp-ereg-proxy-trygdeetaten + namespace: dolly + labels: + team: dolly +spec: + secretName: azure-trygdeetaten-testnav-modapp-ereg-proxy-trygdeetaten + secretKeyPrefix: "AZURE_TRYGDEETATEN" + tenant: trygdeetaten.no +--- +apiVersion: "nais.io/v1alpha1" +kind: "Application" +metadata: + name: testnav-modapp-ereg-proxy + namespace: dolly + labels: + team: dolly +spec: + image: "{{image}}" + port: 8080 + webproxy: true + tokenx: + enabled: true + azure: + application: + allowAllUsers: true + enabled: true + tenant: nav.no + accessPolicy: + inbound: + rules: + - application: team-dolly-lokal-app + cluster: dev-gcp + - application: testnav-oversikt-frontend + cluster: dev-gcp + - application: ereg-batch-status-service + cluster: dev-gcp + - application: app-1 + namespace: plattformsikkerhet + cluster: dev-gcp + liveness: + path: /internal/isAlive + initialDelay: 4 + periodSeconds: 5 + failureThreshold: 500 + readiness: + path: /internal/isReady + initialDelay: 4 + periodSeconds: 5 + failureThreshold: 500 + replicas: + min: 1 + max: 1 + resources: + requests: + cpu: 200m + memory: 1025Mi + limits: + memory: 2048Mi + envFrom: + - secret: azure-trygdeetaten-testnav-modapp-ereg-proxy-trygdeetaten + ingresses: + - "https://testnav-modapp-ereg-proxy.dev-fss-pub.nais.io" diff --git a/proxies/modapp-ereg-proxy/gradle/wrapper/gradle-wrapper.jar b/proxies/modapp-ereg-proxy/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..7454180f2ae Binary files /dev/null and b/proxies/modapp-ereg-proxy/gradle/wrapper/gradle-wrapper.jar differ diff --git a/proxies/modapp-ereg-proxy/gradle/wrapper/gradle-wrapper.properties b/proxies/modapp-ereg-proxy/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..a5952066425 --- /dev/null +++ b/proxies/modapp-ereg-proxy/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/proxies/modapp-ereg-proxy/gradlew b/proxies/modapp-ereg-proxy/gradlew new file mode 100755 index 00000000000..3da45c161b0 --- /dev/null +++ b/proxies/modapp-ereg-proxy/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright ? 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions ?$var?, ?${var}?, ?${var:-default}?, ?${var+SET}?, +# ?${var#prefix}?, ?${var%suffix}?, and ?$( cmd )?; +# * compound commands having a testable exit status, especially ?case?; +# * various built-in commands including ?command?, ?set?, and ?ulimit?. +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/proxies/modapp-ereg-proxy/gradlew.bat b/proxies/modapp-ereg-proxy/gradlew.bat new file mode 100644 index 00000000000..107acd32c4e --- /dev/null +++ b/proxies/modapp-ereg-proxy/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/proxies/modapp-ereg-proxy/gradlewUpdate.sh b/proxies/modapp-ereg-proxy/gradlewUpdate.sh new file mode 100755 index 00000000000..e5ee6361152 --- /dev/null +++ b/proxies/modapp-ereg-proxy/gradlewUpdate.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gradle wrapper \ No newline at end of file diff --git a/proxies/modapp-ereg-proxy/settings.gradle b/proxies/modapp-ereg-proxy/settings.gradle new file mode 100644 index 00000000000..ef5b8a957cb --- /dev/null +++ b/proxies/modapp-ereg-proxy/settings.gradle @@ -0,0 +1,18 @@ +plugins { + id "com.gradle.enterprise" version "3.12.3" +} + +rootProject.name = 'modapp-ereg-proxy' + + +includeBuild '../../libs/reactive-core' +includeBuild '../../libs/reactive-proxy' +includeBuild '../../libs/security-core' +includeBuild '../../libs/reactive-security' + +gradleEnterprise { + buildScan { + termsOfServiceUrl = "https://gradle.com/terms-of-service" + termsOfServiceAgree = "yes" + } +} diff --git a/proxies/modapp-ereg-proxy/src/main/java/no/nav/testnav/proxies/modapperegproxy/Consumers.java b/proxies/modapp-ereg-proxy/src/main/java/no/nav/testnav/proxies/modapperegproxy/Consumers.java new file mode 100644 index 00000000000..32e25c534b9 --- /dev/null +++ b/proxies/modapp-ereg-proxy/src/main/java/no/nav/testnav/proxies/modapperegproxy/Consumers.java @@ -0,0 +1,29 @@ +package no.nav.testnav.proxies.modapperegproxy; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import static lombok.AccessLevel.PACKAGE; + +/** + * Samler alle placeholders for ulike {@code consumers.*}-konfigurasjon her, dvs. subklasser av {@code ServerProperties}. + *

+ * Husk at Spring Boot bruker relaxed binding + * mellom configuration properties og field names. + * + * @see ServerProperties + */ +@Configuration +@ConfigurationProperties(prefix = "consumers") +@NoArgsConstructor(access = PACKAGE) +@Getter +@Setter(PACKAGE) +public class Consumers { + + private ServerProperties eregAura; + +} diff --git a/proxies/modapp-ereg-proxy/src/main/java/no/nav/testnav/proxies/modapperegproxy/ModappEregProxyApplicationStarter.java b/proxies/modapp-ereg-proxy/src/main/java/no/nav/testnav/proxies/modapperegproxy/ModappEregProxyApplicationStarter.java new file mode 100644 index 00000000000..4e3b05118bd --- /dev/null +++ b/proxies/modapp-ereg-proxy/src/main/java/no/nav/testnav/proxies/modapperegproxy/ModappEregProxyApplicationStarter.java @@ -0,0 +1,73 @@ +package no.nav.testnav.proxies.modapperegproxy; + +import no.nav.testnav.libs.reactivecore.config.CoreConfig; +import no.nav.testnav.libs.reactiveproxy.config.DevConfig; +import no.nav.testnav.libs.reactiveproxy.config.SecurityConfig; +import no.nav.testnav.libs.securitycore.domain.ServerProperties; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.gateway.route.Route; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.Buildable; +import org.springframework.cloud.gateway.route.builder.PredicateSpec; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; + +import java.util.Arrays; +import java.util.Map; +import java.util.function.Function; + +@Import({ + CoreConfig.class, + DevConfig.class, + SecurityConfig.class +}) +@SpringBootApplication +public class ModappEregProxyApplicationStarter { + + private static final String[] miljoer = new String[]{ "q1", "q2", "q4" }; + private static final Map miljoeUrlSegment = Map.of( + "q1", "05", + "q2", "10", + "q4", "09" + ); + + @Bean + public RouteLocator customRouteLocator( + RouteLocatorBuilder builder, + Consumers consumers + ) { + var routes = builder.routes(); + Arrays + .asList(miljoer) + .forEach( + miljoe -> { + var properties = forEnvironment(consumers.getEregAura(), miljoeUrlSegment.get(miljoe)); + routes + .route(createRoute(miljoe, properties.getUrl())); + }); + return routes.build(); + } + + public static void main(String[] args) { + SpringApplication.run(ModappEregProxyApplicationStarter.class, args); + } + + private Function> createRoute(String miljo, String url) { + return spec -> spec + .path("/" + miljo + "/**") + .filters(filterSpec -> filterSpec + .rewritePath("/" + miljo + "/(?.*)", "/${segment}") + ).uri(url); + } + + private static ServerProperties forEnvironment(ServerProperties original, String urlSegment) { + return ServerProperties.of( + original.getCluster(), + original.getNamespace(), + original.getName(), + original.getUrl().replace("-MILJOE", urlSegment) + ); + } +} \ No newline at end of file diff --git a/proxies/modapp-ereg-proxy/src/main/resources/application.yml b/proxies/modapp-ereg-proxy/src/main/resources/application.yml new file mode 100644 index 00000000000..4842e668d2b --- /dev/null +++ b/proxies/modapp-ereg-proxy/src/main/resources/application.yml @@ -0,0 +1,30 @@ +AAD_ISSUER_URI: https://login.microsoftonline.com/62366534-1ec3-4962-8869-9b5535279d0b + +spring: + application: + name: testnav-modapp-ereg-proxy + desciption: Proxy for ereg appen i modapp som legger på sikkerhet og redirecter til riktig miljø. + security: + oauth2: + resourceserver: + aad: + issuer-uri: ${AAD_ISSUER_URI}/v2.0 + jwk-set-uri: ${AAD_ISSUER_URI}/discovery/v2.0/keys + accepted-audience: ${azure.app.client.id}, api://${azure.app.client.id} + tokenx: + issuer-uri: ${TOKEN_X_ISSUER} + jwk-set-uri: ${TOKEN_X_JWKS_URI} + accepted-audience: ${TOKEN_X_CLIENT_ID} + cloud: + gateway: + httpclient: + response-timeout: 1200s + vault: + enabled: false + +consumers: + ereg-aura: + name: ereg-aura + namespace: arbeidsforhold + url: https://b27jbsl016-MILJOE.preprod.local:8443 + cluster: dev-fss \ No newline at end of file diff --git a/proxies/modapp-ereg-proxy/src/main/resources/logback-spring.xml b/proxies/modapp-ereg-proxy/src/main/resources/logback-spring.xml new file mode 100644 index 00000000000..52c15597b3c --- /dev/null +++ b/proxies/modapp-ereg-proxy/src/main/resources/logback-spring.xml @@ -0,0 +1,40 @@ + + + + + + + true + 256 + 10280 + 20 + ^sun\.reflect\..*\.invoke + ^net\.sf\.cglib\.proxy\.MethodProxy\.invoke + java\.util\.concurrent\..* + org\.apache\.catalina\..* + org\.apache\.coyote\..* + org\.apache\.tomcat\..* + + + + + + + + + + + + + %d{HH:mm:ss.SSS} | %5p | %logger{25} | %m%n + + utf8 + + + + + + + + + \ No newline at end of file diff --git a/proxies/modapp-ereg-proxy/src/test/java/no/nav/testnav/proxies/modapperegproxy/ApplicationContextTest.java b/proxies/modapp-ereg-proxy/src/test/java/no/nav/testnav/proxies/modapperegproxy/ApplicationContextTest.java new file mode 100644 index 00000000000..315981c5591 --- /dev/null +++ b/proxies/modapp-ereg-proxy/src/test/java/no/nav/testnav/proxies/modapperegproxy/ApplicationContextTest.java @@ -0,0 +1,20 @@ +package no.nav.testnav.proxies.modapperegproxy; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder; +import org.springframework.test.context.ActiveProfiles; + +@SpringBootTest +@ActiveProfiles("test") +class ApplicationContextTest { + + @MockBean + public ReactiveJwtDecoder reactiveJwtDecoder; + + @Test + @SuppressWarnings("java:S2699") + void load_app_context() { + } +} diff --git a/proxies/modapp-ereg-proxy/src/test/resources/application-test.yml b/proxies/modapp-ereg-proxy/src/test/resources/application-test.yml new file mode 100644 index 00000000000..905697c5bae --- /dev/null +++ b/proxies/modapp-ereg-proxy/src/test/resources/application-test.yml @@ -0,0 +1,11 @@ +TOKEN_X_ISSUER: dummy +consumers: + ereg-aura: + url: http://ereg-dummy.dummy.no + cluster: dev-fss + name: ereg-dummy + namespace: dummy +spring: + cloud: + vault: + enabled: false diff --git a/settings.gradle b/settings.gradle index 1a3d42dbd11..c1a87b24977 100644 --- a/settings.gradle +++ b/settings.gradle @@ -25,6 +25,7 @@ includeBuild './proxies/udistub-proxy' includeBuild './proxies/skjermingsregister-proxy' includeBuild './proxies/batch-adeo-proxy' includeBuild './proxies/saf-proxy' +includeBuild './proxies/modapp-ereg-proxy' includeBuild './proxies/dokarkiv-proxy' includeBuild './proxies/tps-forvalteren-proxy' includeBuild './proxies/aareg-synt-services-proxy'