Skip to content

Commit

Permalink
GUACAMOLE-1949: Add Javadoc for getDecodedJWT and getUserId method
Browse files Browse the repository at this point in the history
  • Loading branch information
pp7en committed Jun 17, 2024
1 parent 26cc2cd commit 6b5480d
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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 {

Expand Down Expand Up @@ -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
*
* <p>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);
Expand Down

0 comments on commit 6b5480d

Please sign in to comment.