Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forby innkommende STS unntatt spesielt annoterte endepunkt #1379

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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