Skip to content

Commit 6b5480d

Browse files
author
pp7en
committed
GUACAMOLE-1949: Add Javadoc for getDecodedJWT and getUserId method
1 parent 26cc2cd commit 6b5480d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

extensions/guacamole-auth-nextcloud/src/main/java/org/apache/guacamole/auth/nextcloud/NextcloudJwtAuthenticationProvider.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,28 @@ private void validateJwt(DecodedJWT decodedJWT) throws GuacamoleException {
194194
}
195195
}
196196

197+
/**
198+
* Decodes a JSON Web Token (JWT) using the public key configured in the service.
199+
*
200+
* <p>This method decodes a JWT by verifying it with an elliptic curve public key
201+
* fetched from the configuration service. The public key is decoded from Base64
202+
* and used to create a verifier instance which then verifies and decodes the JWT.
203+
*
204+
* @param token
205+
* The JWT token to decode.
206+
*
207+
* @return
208+
* The decoded JWT.
209+
*
210+
* @throws GuacamoleException
211+
* If there is an error in the configuration service.
212+
*
213+
* @throws NoSuchAlgorithmException
214+
* If the algorithm for the key factory is not available.
215+
*
216+
* @throws InvalidKeySpecException
217+
* If the provided key specification is invalid.
218+
*/
197219
private DecodedJWT getDecodedJWT(String token) throws GuacamoleException, NoSuchAlgorithmException,
198220
InvalidKeySpecException {
199221

@@ -269,6 +291,21 @@ private boolean isUserAllowed(String uid) throws GuacamoleException {
269291
return confService.getAllowedUser().contains(uid);
270292
}
271293

294+
/**
295+
* Decodes a Base64 encoded JSON payload and extracts the uid
296+
*
297+
* <p>This method takes a Base64 encoded string as input, decodes it to a JSON string,
298+
* parses the JSON to extract the user ID from the "userdata" object.
299+
*
300+
* @param payload
301+
* The Base64 encoded JSON string containing user data.
302+
*
303+
* @return
304+
* The user ID extracted from the decoded JSON payload.
305+
*
306+
* @throws JsonProcessingException
307+
* If there is an error processing the JSON payload.
308+
*/
272309
private String getUserId(String payload) throws JsonProcessingException {
273310
byte[] decodedBytes = Base64.getDecoder().decode(payload);
274311
String decodedPayload = new String(decodedBytes, StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)