Skip to content

Commit

Permalink
Forby innkommende STS unntatt spesielt annoterte endepunkt
Browse files Browse the repository at this point in the history
  • Loading branch information
jolarsen committed Aug 22, 2024
1 parent 2afe408 commit e966b40
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public static void validerTokenSetKontekst(ResourceInfo resourceInfo, ContainerR
var expiresAt = Optional.ofNullable(JwtUtil.getExpirationTime(claims)).orElseGet(() -> Instant.now().plusSeconds(300));
var token = new OpenIDToken(configuration.type(), OpenIDToken.OIDC_DEFAULT_TOKEN_TYPE, tokenString, null, expiresAt.toEpochMilli());

if (OpenIDProvider.STS.equals(configuration.type()) && getAnnotation(resourceInfo, TillatSTS.class).isEmpty()) {
throw new ValideringsFeil("Kall med STS til endepunkt som ikke eksplisitt tillater STS");
}

// Valider
var tokenValidator = OidcTokenValidatorConfig.instance().getValidator(token.provider());
var validateResult = tokenValidator.validate(token.primary());
Expand All @@ -131,22 +135,8 @@ public static void validerTokenSetKontekst(ResourceInfo resourceInfo, ContainerR
} else {
throw new ValideringsFeil("Ugyldig token");
}
logStsUsage(configuration.type(), resourceInfo, resourceInfo.getResourceMethod().getName());
}

private static void logStsUsage(OpenIDProvider type, ResourceInfo resourceInfo, String metodenavn) {
if (OpenIDProvider.STS.equals(type)) {
var annotertTillatSts = getAnnotation(resourceInfo, TillatSTS.class).isPresent();
if (annotertTillatSts) {
LOG.info("Innkommende STS - metode {} har annotering TillatSTS", metodenavn);
} else {
LOG.info("Innkommende STS - metode {} mangler annotering TillatSTS", metodenavn);
}
}
}



private static class TokenFeil extends RuntimeException {
TokenFeil(String message) {
super(message);
Expand Down

0 comments on commit e966b40

Please sign in to comment.