diff --git a/extensions/guacamole-auth-nextcloud/src/main/java/org/apache/guacamole/auth/nextcloud/NextcloudJwtAuthenticationProvider.java b/extensions/guacamole-auth-nextcloud/src/main/java/org/apache/guacamole/auth/nextcloud/NextcloudJwtAuthenticationProvider.java index bb20171f07..1bb470d2d3 100644 --- a/extensions/guacamole-auth-nextcloud/src/main/java/org/apache/guacamole/auth/nextcloud/NextcloudJwtAuthenticationProvider.java +++ b/extensions/guacamole-auth-nextcloud/src/main/java/org/apache/guacamole/auth/nextcloud/NextcloudJwtAuthenticationProvider.java @@ -194,6 +194,28 @@ private void validateJwt(DecodedJWT decodedJWT) throws GuacamoleException { } } + /** + * Decodes a JSON Web Token (JWT) using the public key configured in the service. + * + *

This method decodes a JWT by verifying it with an elliptic curve public key + * fetched from the configuration service. The public key is decoded from Base64 + * and used to create a verifier instance which then verifies and decodes the JWT. + * + * @param token + * The JWT token to decode. + * + * @return + * The decoded JWT. + * + * @throws GuacamoleException + * If there is an error in the configuration service. + * + * @throws NoSuchAlgorithmException + * If the algorithm for the key factory is not available. + * + * @throws InvalidKeySpecException + * If the provided key specification is invalid. + */ private DecodedJWT getDecodedJWT(String token) throws GuacamoleException, NoSuchAlgorithmException, InvalidKeySpecException { @@ -269,6 +291,21 @@ private boolean isUserAllowed(String uid) throws GuacamoleException { return confService.getAllowedUser().contains(uid); } + /** + * Decodes a Base64 encoded JSON payload and extracts the uid + * + *

This method takes a Base64 encoded string as input, decodes it to a JSON string, + * parses the JSON to extract the user ID from the "userdata" object. + * + * @param payload + * The Base64 encoded JSON string containing user data. + * + * @return + * The user ID extracted from the decoded JSON payload. + * + * @throws JsonProcessingException + * If there is an error processing the JSON payload. + */ private String getUserId(String payload) throws JsonProcessingException { byte[] decodedBytes = Base64.getDecoder().decode(payload); String decodedPayload = new String(decodedBytes, StandardCharsets.UTF_8);