Skip to content

Commit

Permalink
Småopprydning som ble til Spring Boot 3 og java 21
Browse files Browse the repository at this point in the history
Ryddet litt i kode og imports, og fjernet en del ubrukte pakker fra pom.
Kort tid etter hadde vi plutselig migrert til Spring Boot 3.

Hovedendring er kanskje at EhCache har blitt byttet ut med Caffeine.
  • Loading branch information
Oddsor authored May 23, 2024
1 parent e24c2b0 commit a82a407
Show file tree
Hide file tree
Showing 105 changed files with 548 additions and 774 deletions.
6 changes: 0 additions & 6 deletions .dockerignore

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Java JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: temurin
cache: maven

Expand Down
3 changes: 0 additions & 3 deletions .sonarcloud.properties

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM ghcr.io/navikt/baseimages/temurin:17
FROM ghcr.io/navikt/baseimages/temurin:21
COPY import-vault-token.sh /init-scripts
COPY /target/tiltaksgjennomforing-api-1.0.0-SNAPSHOT.jar app.jar
40 changes: 16 additions & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.16</version>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>17</java.version>
<swagger.version>2.9.2</swagger.version>
<java.version>21</java.version>
<avro.version>1.11.3</avro.version>
<lombok.version>1.18.30</lombok.version>
</properties>
Expand All @@ -40,11 +39,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
Expand All @@ -57,14 +51,6 @@
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand Down Expand Up @@ -103,7 +89,7 @@
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.2</version>
<version>7.4</version>
</dependency>
<dependency>
<groupId>no.nav</groupId>
Expand All @@ -113,7 +99,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
Expand All @@ -131,12 +117,12 @@
<dependency>
<groupId>no.nav.security</groupId>
<artifactId>token-validation-spring</artifactId>
<version>2.1.9</version>
<version>4.1.5</version>
</dependency>
<dependency>
<groupId>no.nav.security</groupId>
<artifactId>token-client-spring</artifactId>
<version>2.1.9</version>
<version>4.1.5</version>
</dependency>

<!-- Swagger -->
Expand Down Expand Up @@ -168,7 +154,7 @@
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>7.4.0</version>
<version>7.6.0</version>
</dependency>

<dependency>
Expand All @@ -190,9 +176,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.27.2</version>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>3.5.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,18 @@ public static class BrukerOgIssuer {

public Optional<BrukerOgIssuer> hentBrukerOgIssuer() {
return hentClaim(ISSUER_SYSTEM, "sub").map(sub -> new BrukerOgIssuer(ISSUER_SYSTEM, sub))
.or(() -> hentClaim(ISSUER_AAD, "NAVident").map(sub -> new BrukerOgIssuer(ISSUER_AAD, sub)))
.or(() -> hentClaim(ISSUER_TOKENX, "pid").map(it -> new BrukerOgIssuer(ISSUER_TOKENX, it)));
.or(() -> hentClaim(ISSUER_AAD, "NAVident").map(sub -> new BrukerOgIssuer(ISSUER_AAD, sub)))
.or(() -> hentClaim(ISSUER_TOKENX, "pid").map(it -> new BrukerOgIssuer(ISSUER_TOKENX, it)));
}

public boolean harAdGruppe(UUID gruppeAD) {
Optional<List<String>> groupsClaim = hentClaims(ISSUER_AAD, "groups");
if (!groupsClaim.isPresent()) {
return false;
}
return groupsClaim.get().contains(gruppeAD.toString());
return groupsClaim.map(strings -> strings.contains(gruppeAD.toString())).orElse(false);
}

public boolean harAdRolle(String rolle) {
Optional<List<String>> roller = hentClaims(ISSUER_AAD, "roles");
if (!roller.isPresent()) {
return false;
}
return roller.get().contains(rolle.toString());
return roller.map(strings -> strings.contains(rolle)).orElse(false);
}

private Optional<List<String>> hentClaims(Issuer issuer, String claim) {
Expand Down Expand Up @@ -90,9 +84,11 @@ private Optional<JwtTokenClaims> hentClaimSet(Issuer issuer) {
// Er ikke i kontekst av en request
return Optional.empty();
}
JwtTokenClaims claims = tokenValidationContext.getClaims(issuer.issuerName);
return Optional.ofNullable(claims);

try {
return Optional.of(tokenValidationContext.getClaims(issuer.issuerName));
} catch (IllegalArgumentException e) {
return Optional.empty();
}
}

public String hentTokenx() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package no.nav.tag.tiltaksgjennomforing.autorisasjon.abac.adapter;

import no.nav.tag.tiltaksgjennomforing.infrastruktur.cache.EhCacheConfig;
import no.nav.tag.tiltaksgjennomforing.infrastruktur.cache.CacheConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
Expand All @@ -27,10 +27,10 @@ public class AbacAdapter {

private final Cache cache;

public AbacAdapter(RestTemplate stsRestTemplate, AbacProperties abacProperties, EhCacheCacheManager cacheManager) {
public AbacAdapter(RestTemplate stsRestTemplate, AbacProperties abacProperties, CacheManager cacheManager) {
this.restTemplate = stsRestTemplate;
this.abacProperties = abacProperties;
this.cache = cacheManager.getCache(EhCacheConfig.ABAC_CACHE);
this.cache = cacheManager.getCache(CacheConfig.ABAC_CACHE);
}

Map<String, String> cacheKey(String navIdent, String deltakerFnr) {
Expand Down Expand Up @@ -77,7 +77,7 @@ private HttpEntity getHttpEntity(String body) {
return new HttpEntity<>(body, headers);
}

@CacheEvict(cacheNames = EhCacheConfig.ABAC_CACHE, allEntries = true)
@CacheEvict(cacheNames = CacheConfig.ABAC_CACHE, allEntries = true)
public void cacheEvict() {
log.info("Tømmer abac cache for data");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package no.nav.tag.tiltaksgjennomforing.autorisasjon.abac.adapter;

import static java.util.Optional.ofNullable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import no.nav.tag.tiltaksgjennomforing.Miljø;
import no.nav.tag.tiltaksgjennomforing.featuretoggles.enhet.AxsysService;
Expand All @@ -13,7 +11,7 @@
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

;
import static java.util.Optional.ofNullable;

@Component
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import no.nav.security.token.support.client.core.oauth2.OAuth2AccessTokenService;
import no.nav.security.token.support.client.spring.ClientConfigurationProperties;
import no.nav.tag.tiltaksgjennomforing.Miljø;
import no.nav.tag.tiltaksgjennomforing.autorisasjon.TokenUtils;
import no.nav.tag.tiltaksgjennomforing.autorisasjon.TokenUtils.Issuer;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
Expand All @@ -13,17 +12,14 @@
@Component
@Profile(value = { Miljø.PROD_FSS, Miljø.DEV_FSS })
public class ArbeidsgiverTokenStrategyFactoryImpl implements ArbeidsgiverTokenStrategyFactory {
private final TokenUtils tokenUtils;
private final OAuth2AccessTokenService oAuth2AccessTokenService;
private final ClientConfigurationProperties clientConfigurationProperties;

public HentArbeidsgiverToken create(Issuer issuer) {
switch (issuer) {
case ISSUER_TOKENX:
return new HentArbeidsgiverTokenxImpl(oAuth2AccessTokenService, clientConfigurationProperties);
default:
throw new RuntimeException();
if (issuer == Issuer.ISSUER_TOKENX) {
return new HentArbeidsgiverTokenxImpl(oAuth2AccessTokenService, clientConfigurationProperties);
}
throw new RuntimeException();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package no.nav.tag.tiltaksgjennomforing.autorisasjon.altinntilgangsstyring;

public interface HentArbeidsgiverToken {
public String hentArbeidsgiverToken ();
String hentArbeidsgiverToken();
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,14 @@ public void finnTilskuddsperioderMedFeilDatoer() {
midlertidige.removeIf(a -> a.getGjeldendeInnhold().getAvtaleInngått() == null);
midlertidige.removeIf(a -> a.getTilskuddPeriode().isEmpty());

midlertidige.forEach(avtale -> {
avtale.getTilskuddPeriode().forEach(tp -> {
if (tp.getLøpenummer() > 1) {
TilskuddPeriode forrigePeriode = avtale.getTilskuddPeriode().stream().filter(t -> t.getLøpenummer() == tp.getLøpenummer() - 1).toList().stream().findFirst().orElseThrow();
if (tp.getStartDato().isBefore(forrigePeriode.getStartDato())) {
log.warn("Tilskuddsperiode med id {} har startDato før startDatoen til forrige løpenummer!", tp.getId());
}
midlertidige.forEach(avtale -> avtale.getTilskuddPeriode().forEach(tp -> {
if (tp.getLøpenummer() > 1) {
TilskuddPeriode forrigePeriode = avtale.getTilskuddPeriode().stream().filter(t -> t.getLøpenummer() == tp.getLøpenummer() - 1).toList().stream().findFirst().orElseThrow();
if (tp.getStartDato().isBefore(forrigePeriode.getStartDato())) {
log.warn("Tilskuddsperiode med id {} har startDato før startDatoen til forrige løpenummer!", tp.getId());
}
});
});
}
}));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import lombok.*;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import java.time.LocalDate;
import java.util.UUID;

Expand Down

This file was deleted.

Loading

0 comments on commit a82a407

Please sign in to comment.