-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to use Altinn3 API for user access management #deploy-bruker-service Replaced Person-Organisasjon-Tilgang API with Altinn3 API across the application. Deprecated `OrganisasjonDTO` and updated classes to utilize `AltinnBrukerRequest` and Altinn3 DTOs. Adjusted configuration and consumer logic to align with the new API structure for improved functionality. ```
- Loading branch information
Showing
9 changed files
with
67 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 16 additions & 23 deletions
39
...in/java/no/nav/testnav/apps/brukerservice/consumer/PersonOrganisasjonTilgangConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,44 @@ | ||
package no.nav.testnav.apps.brukerservice.consumer; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import no.nav.testnav.apps.brukerservice.config.Consumers; | ||
import no.nav.testnav.apps.brukerservice.consumer.command.GetOrganisasjonCommand; | ||
import no.nav.testnav.apps.brukerservice.consumer.command.GetBrukertilgangCommand; | ||
import no.nav.testnav.apps.brukerservice.domain.Organisasjon; | ||
import no.nav.testnav.libs.reactivesecurity.action.GetAuthenticatedUserId; | ||
import no.nav.testnav.libs.reactivesecurity.exchange.TokenExchange; | ||
import no.nav.testnav.libs.securitycore.domain.ServerProperties; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.codec.json.Jackson2JsonDecoder; | ||
import org.springframework.http.codec.json.Jackson2JsonEncoder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.ExchangeStrategies; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
public class PersonOrganisasjonTilgangConsumer { | ||
|
||
private final WebClient webClient; | ||
private final ServerProperties serverProperties; | ||
private final TokenExchange tokenExchange; | ||
private final GetAuthenticatedUserId getAuthenticatedUserId; | ||
|
||
public PersonOrganisasjonTilgangConsumer( | ||
Consumers consumers, | ||
TokenExchange tokenExchange, | ||
ObjectMapper objectMapper, | ||
WebClient.Builder webClientBuilder) { | ||
serverProperties = consumers.getTestnavPersonOrganisasjonTilgangService(); | ||
WebClient.Builder webClientBuilder, | ||
GetAuthenticatedUserId getAuthenticatedUserId) { | ||
|
||
serverProperties = consumers.getTestnavAltinn3TilgangService(); | ||
this.tokenExchange = tokenExchange; | ||
ExchangeStrategies jacksonStrategy = ExchangeStrategies | ||
.builder() | ||
.codecs( | ||
config -> { | ||
config.defaultCodecs() | ||
.jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); | ||
config.defaultCodecs() | ||
.jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); | ||
}) | ||
.build(); | ||
this.webClient = webClientBuilder | ||
.exchangeStrategies(jacksonStrategy) | ||
.baseUrl(serverProperties.getUrl()) | ||
.build(); | ||
this.getAuthenticatedUserId = getAuthenticatedUserId; | ||
} | ||
|
||
public Mono<Organisasjon> getOrganisasjon(String orgnummer) { | ||
return tokenExchange.exchange(serverProperties) | ||
.flatMap(accessToken -> new GetOrganisasjonCommand(webClient, orgnummer, accessToken.getTokenValue()).call()) | ||
.map(Organisasjon::new); | ||
|
||
return Mono.from(getAuthenticatedUserId.call() | ||
.flatMapMany(userId -> tokenExchange.exchange(serverProperties) | ||
.flatMapMany(accessToken -> | ||
new GetBrukertilgangCommand(webClient, userId, accessToken.getTokenValue()).call())) | ||
.filter(org -> org.getOrganisasjonsnummer().equals(orgnummer)) | ||
.map(Organisasjon::new)); | ||
} | ||
} |
22 changes: 13 additions & 9 deletions
22
...sumer/command/GetOrganisasjonCommand.java → ...umer/command/GetBrukertilgangCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
package no.nav.testnav.apps.brukerservice.consumer.command; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import no.nav.testnav.apps.brukerservice.consumer.dto.OrganisasjonDTO; | ||
import no.nav.testnav.apps.brukerservice.consumer.dto.AltinnBrukerRequest; | ||
import no.nav.testnav.libs.dto.altinn3.v1.OrganisasjonDTO; | ||
import no.nav.testnav.libs.reactivecore.utils.WebClientFilter; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import org.springframework.web.reactive.function.client.WebClientResponseException; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
@RequiredArgsConstructor | ||
public class GetOrganisasjonCommand implements Callable<Mono<OrganisasjonDTO>> { | ||
public class GetBrukertilgangCommand implements Callable<Flux<OrganisasjonDTO>> { | ||
private final WebClient webClient; | ||
private final String organisasjonsnummer; | ||
private final String ident; | ||
private final String token; | ||
|
||
@Override | ||
public Mono<OrganisasjonDTO> call() { | ||
return webClient.get() | ||
.uri(builder -> builder.path("/api/v1/person/organisasjoner/{organisasjonsnummer}").build(organisasjonsnummer)) | ||
public Flux<OrganisasjonDTO> call() { | ||
return webClient.post() | ||
.uri(builder -> builder.path("/api/v1/brukertilgang").build()) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token) | ||
.bodyValue(new AltinnBrukerRequest(ident)) | ||
.retrieve() | ||
.bodyToMono(OrganisasjonDTO.class) | ||
.bodyToFlux(OrganisasjonDTO.class) | ||
.doOnError(WebClientFilter::logErrorMessage) | ||
.onErrorResume( | ||
throwable -> throwable instanceof WebClientResponseException.NotFound, | ||
throwable -> Mono.empty() | ||
); | ||
} | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...ice/src/main/java/no/nav/testnav/apps/brukerservice/consumer/dto/AltinnBrukerRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package no.nav.testnav.apps.brukerservice.consumer.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class AltinnBrukerRequest { | ||
|
||
private String ident; | ||
} |
4 changes: 0 additions & 4 deletions
4
...service/src/main/java/no/nav/testnav/apps/brukerservice/consumer/dto/OrganisasjonDTO.java
This file was deleted.
Oops, something went wrong.
34 changes: 15 additions & 19 deletions
34
apps/bruker-service/src/main/java/no/nav/testnav/apps/brukerservice/domain/Organisasjon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,23 @@ | ||
package no.nav.testnav.apps.brukerservice.domain; | ||
|
||
import no.nav.testnav.apps.brukerservice.consumer.dto.OrganisasjonDTO; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import no.nav.testnav.libs.dto.altinn3.v1.OrganisasjonDTO; | ||
|
||
public class Organisasjon { | ||
private final String navn; | ||
private final String organisasjonsnummer; | ||
private final String organisasjonsform; | ||
|
||
public Organisasjon(OrganisasjonDTO dto) { | ||
this.navn = dto.navn(); | ||
this.organisasjonsnummer = dto.organisasjonsnummer(); | ||
this.organisasjonsform = dto.organisasjonsfrom(); | ||
} | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
|
||
public String getNavn() { | ||
return navn; | ||
} | ||
public class Organisasjon { | ||
|
||
public String getOrganisasjonsnummer() { | ||
return organisasjonsnummer; | ||
} | ||
private String navn; | ||
private String organisasjonsnummer; | ||
private String organisasjonsform; | ||
|
||
public String getOrganisasjonsform() { | ||
return organisasjonsform; | ||
public Organisasjon(OrganisasjonDTO dto) { | ||
this.navn = dto.getNavn(); | ||
this.organisasjonsnummer = dto.getOrganisasjonsnummer(); | ||
this.organisasjonsform = dto.getOrganisasjonsform(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters