Skip to content

Commit 50a75fd

Browse files
committed
Forenklet pdl-pip-dto for tilgangsformål
1 parent 4c628b3 commit 50a75fd

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

felles/tilgang/src/main/java/no/nav/vedtak/sikkerhet/tilgang/TilgangPersondata.java

+8
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55

66
public interface TilgangPersondata {
77

8+
// Full respons
89
// ident er aktørId eller personident
910
TilgangPersondataDto hentTilgangPersondata(String ident);
1011

1112
// identer er aktørId eller personident. Respons er map fra personident til responsobjekt
1213
Map<String, TilgangPersondataDto> hentTilgangPersondataBolk(List<String> identer);
1314

15+
// Enklere respons - for tilgangskontroll
16+
// ident er aktørId eller personident
17+
TilgangPersondataEnkelDto hentEnkelTilgangPersondata(String ident);
18+
19+
// identer er aktørId eller personident. Respons er map fra personident til responsobjekt
20+
Map<String, TilgangPersondataEnkelDto> hentEnkelTilgangPersondataBolk(List<String> identer);
21+
1422
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package no.nav.vedtak.sikkerhet.tilgang;
2+
3+
import java.time.LocalDate;
4+
import java.util.List;
5+
import java.util.Optional;
6+
7+
import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
8+
9+
public record TilgangPersondataEnkelDto(String aktoerId, Person person, Identer identer) {
10+
11+
public record Person(List<Adressebeskyttelse> adressebeskyttelse) {
12+
}
13+
14+
public record Adressebeskyttelse(Gradering gradering) { }
15+
16+
public record Identer(List<Ident> identer) { }
17+
18+
public record Ident(String ident, Boolean historisk, IdentGruppe gruppe) { }
19+
20+
public enum Gradering { STRENGT_FORTROLIG_UTLAND, STRENGT_FORTROLIG, FORTROLIG, @JsonEnumDefaultValue UDEFINERT }
21+
22+
public enum IdentGruppe { AKTORID, FOLKEREGISTERIDENT, NPID, @JsonEnumDefaultValue UDEFINERT }
23+
24+
public boolean harStrengAdresseBeskyttelse() {
25+
return Optional.ofNullable(person()).map(Person::adressebeskyttelse).orElse(List.of()).stream()
26+
.map(Adressebeskyttelse::gradering)
27+
.anyMatch(g -> Gradering.STRENGT_FORTROLIG.equals(g) || Gradering.STRENGT_FORTROLIG_UTLAND.equals(g));
28+
}
29+
30+
public boolean harAdresseBeskyttelse() {
31+
return Optional.ofNullable(person()).map(Person::adressebeskyttelse).orElse(List.of()).stream()
32+
.map(Adressebeskyttelse::gradering)
33+
.anyMatch(g -> g != null && !Gradering.UDEFINERT.equals(g));
34+
}
35+
36+
public String personIdent() {
37+
return Optional.ofNullable(identer()).map(Identer::identer).orElse(List.of()).stream()
38+
.filter(i -> IdentGruppe.FOLKEREGISTERIDENT.equals(i.gruppe()))
39+
.filter(i -> !i.historisk())
40+
.map(Ident::ident)
41+
.findFirst().orElse(null);
42+
}
43+
44+
public List<String> personIdenter(boolean medHistoriske) {
45+
return Optional.ofNullable(identer()).map(Identer::identer).orElse(List.of()).stream()
46+
.filter(i -> IdentGruppe.FOLKEREGISTERIDENT.equals(i.gruppe()))
47+
.filter(i -> medHistoriske || !i.historisk())
48+
.map(Ident::ident)
49+
.toList();
50+
}
51+
52+
public String aktørId(boolean medHistoriske) {
53+
return Optional.ofNullable(identer()).map(Identer::identer).orElse(List.of()).stream()
54+
.filter(i -> IdentGruppe.AKTORID.equals(i.gruppe()))
55+
.filter(i -> medHistoriske || !i.historisk())
56+
.map(Ident::ident)
57+
.findFirst().orElse(null);
58+
}
59+
60+
public List<String> alleIdenter(boolean medHistoriske) {
61+
return Optional.ofNullable(identer()).map(Identer::identer).orElse(List.of()).stream()
62+
.filter(i -> medHistoriske || !i.historisk())
63+
.map(Ident::ident)
64+
.toList();
65+
}
66+
}

felles/tilgang/src/main/java/no/nav/vedtak/sikkerhet/tilgang/TilgangPersondataKlient.java

+29
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,35 @@ public Map<String, TilgangPersondataDto> hentTilgangPersondataBolk(List<String>
7575
return response != null ? DefaultJsonMapper.mapFromJson(response, TilgangPersondataDto.class) : Map.of();
7676
}
7777

78+
@Override
79+
public TilgangPersondataEnkelDto hentEnkelTilgangPersondata(String ident) {
80+
var builder = HttpRequest.newBuilder(personURI)
81+
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
82+
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
83+
.header(HttpHeaders.AUTHORIZATION, OIDC_AUTH_HEADER_PREFIX + TokenProvider.getTokenForSystem(personScopes).token())
84+
.header("ident", ident)
85+
.timeout(Duration.ofSeconds(5))
86+
.GET();
87+
var request = new PersondataRequest(builder);
88+
89+
var response = DefaultHttpClient.client().send(request);
90+
return response != null ? DefaultJsonMapper.fromJson(response, TilgangPersondataEnkelDto.class) : null;
91+
}
92+
93+
@Override
94+
public Map<String, TilgangPersondataEnkelDto> hentEnkelTilgangPersondataBolk(List<String> identer) {
95+
var builder = HttpRequest.newBuilder(personBolkURI)
96+
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
97+
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON)
98+
.header(HttpHeaders.AUTHORIZATION, OIDC_AUTH_HEADER_PREFIX + TokenProvider.getTokenForSystem(personScopes).token())
99+
.timeout(Duration.ofSeconds(5))
100+
.POST(HttpRequest.BodyPublishers.ofString(DefaultJsonMapper.toJson(identer)));
101+
var request = new PersondataRequest(builder);
102+
103+
var response = DefaultHttpClient.client().send(request);
104+
return response != null ? DefaultJsonMapper.mapFromJson(response, TilgangPersondataEnkelDto.class) : Map.of();
105+
}
106+
78107

79108
private static class PersondataRequest extends HttpClientRequest {
80109
public PersondataRequest(HttpRequest.Builder builder) {

0 commit comments

Comments
 (0)