186 JWT jwt = JWTParser.parse(jwtString);
188 if (jwt instanceof SignedJWT) {
191 SignedJWT signedJwt = (SignedJWT)jwt;
194 if (request.getClientId() == null) {
195 request.setClientId(signedJwt.getJWTClaimsSet().getStringClaim(CLIENT_ID));
200 if (client == null) {
201 throw new InvalidClientException(
"Client not found: " + request.getClientId());
205 JWSAlgorithm alg = signedJwt.getHeader().getAlgorithm();
207 if (client.getRequestObjectSigningAlg() == null ||
208 !client.getRequestObjectSigningAlg().equals(alg)) {
209 throw new InvalidClientException(
"Client's registered request object signing algorithm (" + client.getRequestObjectSigningAlg() +
") does not match request object's actual algorithm (" + alg.getName() +
")");
214 if (validator == null) {
215 throw new InvalidClientException(
"Unable to create signature validator for client " + client +
" and algorithm " + alg);
218 if (!validator.validateSignature(signedJwt)) {
219 throw new InvalidClientException(
"Signature did not validate for presented JWT request object.");
222 }
else if (jwt instanceof PlainJWT) {
223 PlainJWT plainJwt = (PlainJWT)jwt;
226 if (request.getClientId() == null) {
227 request.setClientId(plainJwt.getJWTClaimsSet().getStringClaim(CLIENT_ID));
232 if (client == null) {
233 throw new InvalidClientException(
"Client not found: " + request.getClientId());
236 if (client.getRequestObjectSigningAlg() == null) {
237 throw new InvalidClientException(
"Client is not registered for unsigned request objects (no request_object_signing_alg registered)");
238 }
else if (!client.getRequestObjectSigningAlg().equals(Algorithm.NONE)) {
239 throw new InvalidClientException(
"Client is not registered for unsigned request objects (request_object_signing_alg is " + client.getRequestObjectSigningAlg() +
")");
244 }
else if (jwt instanceof EncryptedJWT) {
246 EncryptedJWT encryptedJWT = (EncryptedJWT)jwt;
254 if (!encryptedJWT.getState().equals(State.DECRYPTED)) {
255 throw new InvalidClientException(
"Unable to decrypt the request object");
259 if (request.getClientId() == null) {
260 request.setClientId(encryptedJWT.getJWTClaimsSet().getStringClaim(CLIENT_ID));
265 if (client == null) {
266 throw new InvalidClientException(
"Client not found: " + request.getClientId());
279 JWTClaimsSet claims = jwt.getJWTClaimsSet();
281 Set<String> responseTypes = OAuth2Utils.parseParameterList(claims.getStringClaim(RESPONSE_TYPE));
282 if (!responseTypes.isEmpty()) {
283 if (!responseTypes.equals(request.getResponseTypes())) {
284 logger.info(
"Mismatch between request object and regular parameter for response_type, using request object");
286 request.setResponseTypes(responseTypes);
289 String redirectUri = claims.getStringClaim(REDIRECT_URI);
290 if (redirectUri != null) {
291 if (!redirectUri.equals(request.getRedirectUri())) {
292 logger.info(
"Mismatch between request object and regular parameter for redirect_uri, using request object");
294 request.setRedirectUri(redirectUri);
297 String state = claims.getStringClaim(STATE);
299 if (!state.equals(request.getState())) {
300 logger.info(
"Mismatch between request object and regular parameter for state, using request object");
302 request.setState(state);
305 String nonce = claims.getStringClaim(NONCE);
307 if (!nonce.equals(request.getExtensions().get(NONCE))) {
308 logger.info(
"Mismatch between request object and regular parameter for nonce, using request object");
310 request.getExtensions().put(NONCE, nonce);
313 String display = claims.getStringClaim(DISPLAY);
314 if (display != null) {
315 if (!display.equals(request.getExtensions().get(DISPLAY))) {
316 logger.info(
"Mismatch between request object and regular parameter for display, using request object");
318 request.getExtensions().put(DISPLAY, display);
321 String prompt = claims.getStringClaim(PROMPT);
322 if (prompt != null) {
323 if (!prompt.equals(request.getExtensions().get(PROMPT))) {
324 logger.info(
"Mismatch between request object and regular parameter for prompt, using request object");
326 request.getExtensions().put(PROMPT, prompt);
329 Set<String> scope = OAuth2Utils.parseParameterList(claims.getStringClaim(SCOPE));
330 if (!scope.isEmpty()) {
331 if (!scope.equals(request.getScope())) {
332 logger.info(
"Mismatch between request object and regular parameter for scope, using request object");
334 request.setScope(scope);
338 if (claimRequest != null) {
339 Serializable claimExtension = request.getExtensions().get(CLAIMS);
340 if (claimExtension == null || !claimRequest.equals(
parseClaimRequest(claimExtension.toString()))) {
341 logger.info(
"Mismatch between request object and regular parameter for claims, using request object");
344 request.getExtensions().put(CLAIMS, claimRequest.toString());
347 String loginHint = claims.getStringClaim(LOGIN_HINT);
348 if (loginHint != null) {
349 if (!loginHint.equals(request.getExtensions().get(LOGIN_HINT))) {
350 logger.info(
"Mistmatch between request object and regular parameter for login_hint, using requst object");
352 request.getExtensions().put(LOGIN_HINT, loginHint);
355 }
catch (ParseException e) {
356 logger.error(
"ParseException while parsing RequestObject:", e);
ClientDetailsEntityService clientDetailsService
Definition: ConnectOAuth2RequestFactory.java:81
void decryptJwt(JWEObject jwt)
JsonObject parseClaimRequest(String claimRequestString)
Definition: ConnectOAuth2RequestFactory.java:364
static final Logger logger
Definition: ConnectOAuth2RequestFactory.java:79
ClientKeyCacheService validators
Definition: ConnectOAuth2RequestFactory.java:84
JWTSigningAndValidationService getValidator(ClientDetailsEntity client, JWSAlgorithm alg)
Definition: ClientKeyCacheService.java:77
JWTEncryptionAndDecryptionService encryptionService
Definition: ConnectOAuth2RequestFactory.java:87
ClientDetailsEntity loadClientByClientId(String clientId)