-
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.
Add FakedingsConsumer and switch to TokenX authentication
Introduced FakedingsConsumer for generating fake tokens. Replaced TrygdeetatenAzureAdTokenService with TokenXService for authentication. Cleaned up unused dependencies and old configuration references.
- Loading branch information
Showing
7 changed files
with
94 additions
and
32 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
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
25 changes: 25 additions & 0 deletions
25
...roxy/src/main/java/no/nav/testnav/proxies/yrkesskadeproxy/consumer/FakedingsConsumer.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,25 @@ | ||
package no.nav.testnav.proxies.yrkesskadeproxy.consumer; | ||
|
||
import no.nav.testnav.proxies.yrkesskadeproxy.consumer.command.FakedingsGetCommand; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Service | ||
public class FakedingsConsumer { | ||
|
||
private static final String FAKE_TOKENDINGS_URL = "https://fakedings.intern.dev.nav.no"; | ||
private final WebClient webClient; | ||
|
||
public FakedingsConsumer(WebClient.Builder webClientBuilder) { | ||
|
||
this.webClient = webClientBuilder | ||
.baseUrl(FAKE_TOKENDINGS_URL) | ||
.build(); | ||
} | ||
|
||
public Mono<String> getFakeToken(String ident) { | ||
|
||
return new FakedingsGetCommand(webClient, ident).call(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ain/java/no/nav/testnav/proxies/yrkesskadeproxy/consumer/command/FakedingsGetCommand.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,28 @@ | ||
package no.nav.testnav.proxies.yrkesskadeproxy.consumer.command; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
@RequiredArgsConstructor | ||
public class FakedingsGetCommand implements Callable<Mono<String>> { | ||
|
||
private static final String FAKEDINGS_URL = "/fake/idporten"; | ||
|
||
private final WebClient webClient; | ||
private final String ident; | ||
|
||
@Override | ||
public Mono<String> call() { | ||
|
||
return webClient.get() | ||
.uri(uriBuilder -> uriBuilder.path(FAKEDINGS_URL) | ||
.queryParam("pid", ident) | ||
.queryParam("acr", "Level4") | ||
.build()) | ||
.retrieve() | ||
.bodyToMono(String.class); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../testnav/proxies/yrkesskadeproxy/filter/AddAuthenticationRequestGatewayFilterFactory.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,31 @@ | ||
package no.nav.testnav.proxies.yrkesskadeproxy.filter; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import lombok.extern.slf4j.Slf4j; | ||
import no.nav.testnav.libs.reactivesecurity.exchange.tokenx.TokenXService; | ||
import no.nav.testnav.libs.securitycore.domain.ServerProperties; | ||
import no.nav.testnav.proxies.yrkesskadeproxy.consumer.FakedingsConsumer; | ||
import org.springframework.cloud.gateway.filter.GatewayFilter; | ||
import org.springframework.http.HttpHeaders; | ||
|
||
@Slf4j | ||
@UtilityClass | ||
public class AddAuthenticationRequestGatewayFilterFactory { | ||
public static GatewayFilter bearerIdportenHeaderFilter(FakedingsConsumer fakedingsConsumer, | ||
TokenXService tokenXService, | ||
ServerProperties serverProperties) { | ||
|
||
return (exchange, chain) -> { | ||
var httpRequest = exchange.getRequest(); | ||
var ident = httpRequest.getHeaders().getFirst("ident"); | ||
return fakedingsConsumer.getFakeToken(ident) | ||
.flatMap(faketoken -> tokenXService.exchange(serverProperties, faketoken) | ||
.flatMap(tokenX -> { | ||
exchange.mutate() | ||
.request(builder -> builder.header(HttpHeaders.AUTHORIZATION, | ||
"Bearer " + tokenX.getTokenValue()).build()); | ||
return chain.filter(exchange); | ||
})); | ||
}; | ||
} | ||
} |