Skip to content

Commit

Permalink
adjust jwt security meter.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Feb 26, 2024
1 parent 57f8fd6 commit 127bc90
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import com.nimbusds.jose.jwk.source.ImmutableSecret;
import com.nimbusds.jose.util.Base64;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -46,6 +48,8 @@ import org.springframework.security.oauth2.server.resource.web.DefaultBearerToke
@Configuration
public class SecurityJwtConfiguration {
private final Logger log = LoggerFactory.getLogger(SecurityJwtConfiguration.class);
@Value("${jhipster.security.authentication.jwt.base64-secret}")
private String jwtKey;
Expand All @@ -62,13 +66,22 @@ public class SecurityJwtConfiguration {
metersService.trackTokenExpired();
} else if (e.getMessage().contains("Failed to validate the token")) {
metersService.trackTokenInvalidSignature();
} else if (
e.getMessage().contains("Invalid JWT serialization:") ||
e.getMessage().contains("Invalid unsecured/JWS/JWE header:")
) {
metersService.trackTokenMalformed();
} else {
log.error("Unknown JWT reactive error {}", e.getMessage());
}
});
} catch (Exception e) {
if (e.getMessage().contains("An error occurred while attempting to decode the Jwt")) {
metersService.trackTokenMalformed();
} else if (e.getMessage().contains("Failed to validate the token")) {
metersService.trackTokenInvalidSignature();
} else {
log.error("Unknown JWT error {}", e.getMessage());
}
throw e;
}
Expand All @@ -86,6 +99,8 @@ public class SecurityJwtConfiguration {
e.getMessage().contains("Invalid unsecured/JWS/JWE")
) {
metersService.trackTokenMalformed();
} else {
log.error("Unknown JWT error {}", e.getMessage());
}
throw e;
}
Expand Down

0 comments on commit 127bc90

Please sign in to comment.