Skip to content
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 @@ -65,6 +65,7 @@ private static class AttestationHandler {

public void handle(RoutingContext rc) {
boolean success = false;
boolean isJwtValid = false;

final IAuthorizable profile = AuthMiddleware.getAuthClient(rc);
if (profile instanceof OperatorKey) {
Expand All @@ -85,32 +86,37 @@ public void handle(RoutingContext rc) {
if (jwt != null && !jwt.isBlank()) {
try {
JwtValidationResponse response = jwtService.validateJwt(jwt, this.jwtAudience, this.jwtIssuer);
success = response.getIsValid();
if (success) {
isJwtValid = response.getIsValid();
if (isJwtValid) {
if (!this.roleBasedJwtClaimValidator.hasRequiredRoles(response)) {
success = false;
isJwtValid = false;
LOGGER.info("JWT missing required role. Required roles: {}, JWT Presented Roles: {}, SiteId: {}, Name: {}, Contact: {}", this.roleBasedJwtClaimValidator.getRequiredRoles(), response.getRoles(), operatorKey.getSiteId(), operatorKey.getName(), operatorKey.getContact());
}

String subject = calculateSubject(operatorKey);
if (!validateSubject(response, subject)) {
success = false;
isJwtValid = false;
LOGGER.info("JWT failed validation of Subject. JWT Presented Roles: {}, SiteId: {}, Name: {}, Contact: {}, JWT Subject: {}, Operator Subject: {}", response.getRoles(), operatorKey.getSiteId(), operatorKey.getName(), operatorKey.getContact(), response.getSubject(), subject);
}
}
} catch (JwtService.ValidationException e) {
LOGGER.info("Error validating JWT. Attestation validation failed. SiteId: {}, Name: {}, Contact: {}. Error: {}", operatorKey.getSiteId(), operatorKey.getName(), operatorKey.getContact(), e);
success = false;
}
} else {
if (this.enforceJwt) {
LOGGER.info("JWT is required, but was not received. Attestation validation failed. SiteId: {}, Name: {}, Contact: {}", operatorKey.getSiteId(), operatorKey.getName(), operatorKey.getContact());
success = false;
}
}
}
}

if (!isJwtValid && this.enforceJwt) {
LOGGER.info("JWT validation has failed.");
success = false;
} else if (!isJwtValid && !this.enforceJwt) {
LOGGER.info("JWT validation has failed, but JWTs are not being enforced.");
}

if (success) {
next.handle(rc);
} else {
Expand Down
Loading