Skip to content

Commit

Permalink
Oppdatert håndtering for Token-X
Browse files Browse the repository at this point in the history
  • Loading branch information
krharum committed Jan 22, 2025
1 parent a65d05f commit 8b626ad
Showing 1 changed file with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,7 @@ public class ProfilService {

public Profil getProfile() {
if (isTokenX()) {
return getUserInfo.call()
.map(userInfo ->
organisasjonTilgangConsumer
.getOrganisasjon(userInfo.organisasjonsnummer())
.map(dto -> new Profil(
userInfo.brukernavn(),
UKJENT,
UKJENT,
dto.getNavn(),
dto.getOrganisasjonsnummer(),
BANK_ID)
).block()
).orElse(new Profil(
BANK_ID,
UKJENT,
UKJENT,
UKJENT,
UKJENT,
BANK_ID
));
return getTokenXAttributes();
}
return azureAdProfileConsumer.getProfil();
}
Expand All @@ -56,25 +37,40 @@ public Optional<byte[]> getImage() {
return isTokenX() ? Optional.empty() : azureAdProfileConsumer.getProfilImage();
}

private JwtAuthenticationToken getJwtAuthenticationToken() {
private Optional<JwtAuthenticationToken> getJwtAuthenticationToken() {
return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication())
.filter(JwtAuthenticationToken.class::isInstance)
.map(JwtAuthenticationToken.class::cast)
.map(t -> {
log.info("JwtAuthenticationToken, attributes: {}",
t.getTokenAttributes().entrySet().stream()
.map(entry -> entry.getKey() + ":" + entry.getValue())
.collect(Collectors.joining(",")));
.map(entry -> entry.getKey() + ":" + entry.getValue())
.collect(Collectors.joining(",")));
return t;
})
.orElseThrow();
});
}

private boolean isTokenX() {

return getJwtAuthenticationToken()
.getTokenAttributes()
.get(JwtClaimNames.ISS)
.equals(tokenXResourceServerProperties.getIssuerUri());
.map(token -> token
.getTokenAttributes()
.get(JwtClaimNames.ISS)
.equals(tokenXResourceServerProperties.getIssuerUri()))
.orElseThrow();
}

private Profil getTokenXAttributes() {

return getJwtAuthenticationToken()
.map(JwtAuthenticationToken::getTokenAttributes)
.map(attribs -> new Profil(
(String) attribs.get("brukernavn"),
UKJENT,
UKJENT,
UKJENT,
(String) attribs.get("org"),
BANK_ID))
.orElseThrow();
}
}

0 comments on commit 8b626ad

Please sign in to comment.