From 9299e571675e763acbac8a7f30b6fe411b81afbf Mon Sep 17 00:00:00 2001 From: Hideki Ikeda Date: Wed, 25 Dec 2024 15:55:38 +0900 Subject: [PATCH] Add request options to each API call method. --- pom.xml | 2 +- .../authlete/jakarta/api/AuthleteApiImpl.java | 558 +++++++++++------- .../jakarta/api/AuthleteApiImplV3.java | 552 ++++++++++------- .../jakarta/api/AuthleteApiJaxrsImpl.java | 81 ++- 4 files changed, 731 insertions(+), 462 deletions(-) diff --git a/pom.xml b/pom.xml index f3ad8f8..65b5666 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ UTF-8 - 4.1 + 4.16 2.10.1 9.31 3.1.0 diff --git a/src/main/java/com/authlete/jakarta/api/AuthleteApiImpl.java b/src/main/java/com/authlete/jakarta/api/AuthleteApiImpl.java index 966e18a..68a5be1 100644 --- a/src/main/java/com/authlete/jakarta/api/AuthleteApiImpl.java +++ b/src/main/java/com/authlete/jakarta/api/AuthleteApiImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2023 Authlete, Inc. + * Copyright (C) 2014-2024 Authlete, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,12 @@ import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; import java.util.LinkedHashMap; import java.util.Map; +import jakarta.ws.rs.client.Invocation.Builder; import jakarta.ws.rs.client.WebTarget; import jakarta.ws.rs.core.GenericType; import com.authlete.common.api.AuthleteApi; import com.authlete.common.api.AuthleteApiException; +import com.authlete.common.api.Options; import com.authlete.common.conf.AuthleteApiVersion; import com.authlete.common.conf.AuthleteConfiguration; import com.authlete.common.dto.*; @@ -202,40 +204,40 @@ private String createServiceCredentials(AuthleteConfiguration configuration) private TResponse callServiceOwnerGetApi( - String path, Class responseClass, Map params) + String path, Class responseClass, Map params, Options options) { - return callGetApi(mServiceOwnerAuth, path, responseClass, params); + return callGetApi(mServiceOwnerAuth, path, responseClass, params, options); } private TResponse callServiceGetApi( - String path, Class responseClass, Map params) + String path, Class responseClass, Map params, Options options) { - return callGetApi(mServiceAuth, path, responseClass, params); + return callGetApi(mServiceAuth, path, responseClass, params, options); } - private Void callServiceOwnerDeleteApi(String path) + private Void callServiceOwnerDeleteApi(String path, Options options) { - return callDeleteApi(mServiceOwnerAuth, path); + return callDeleteApi(mServiceOwnerAuth, path, options); } - private Void callServiceDeleteApi(String path) + private Void callServiceDeleteApi(String path, Options options) { - return callDeleteApi(mServiceAuth, path); + return callDeleteApi(mServiceAuth, path, options); } - private TResponse callServiceOwnerPostApi(String path, Object request, Class responseClass) + private TResponse callServiceOwnerPostApi(String path, Object request, Class responseClass, Options options) { - return callPostApi(mServiceOwnerAuth, path, request, responseClass); + return callPostApi(mServiceOwnerAuth, path, request, responseClass, options); } - private TResponse callServicePostApi(String path, Object request, Class responseClass) + private TResponse callServicePostApi(String path, Object request, Class responseClass, Options options) { - return callPostApi(mServiceAuth, path, request, responseClass); + return callPostApi(mServiceAuth, path, request, responseClass, options); } @@ -245,6 +247,7 @@ private static abstract class ApiCaller implements AuthleteApiCall mResponseClass; protected final Map mParams = new LinkedHashMap<>(); + protected Options mOptions; ApiCaller(Class responseClass, Object request, String path) @@ -267,6 +270,14 @@ public ApiCaller addParam(String name, Object... values) return this; } + + + public ApiCaller setOptions(Options options) + { + mOptions = options; + + return this; + } } @@ -287,7 +298,7 @@ private class ServiceOwnerDeleteApiCaller extends ApiCaller @Override public Void call() { - return callServiceOwnerDeleteApi(mPath); + return callServiceOwnerDeleteApi(mPath, mOptions); } } @@ -309,7 +320,7 @@ private class ServiceOwnerGetApiCaller extends ApiCaller @Override public TResponse call() { - return callServiceOwnerGetApi(mPath, mResponseClass, mParams); + return callServiceOwnerGetApi(mPath, mResponseClass, mParams, mOptions); } } @@ -331,7 +342,7 @@ private class ServiceOwnerPostApiCaller extends ApiCaller @Override public TResponse call() { - return callServiceOwnerPostApi(mPath, mRequest, mResponseClass); + return callServiceOwnerPostApi(mPath, mRequest, mResponseClass, mOptions); } } @@ -353,7 +364,7 @@ private class ServiceDeleteApiCaller extends ApiCaller @Override public Void call() { - return callServiceDeleteApi(mPath); + return callServiceDeleteApi(mPath, mOptions); } } @@ -375,7 +386,7 @@ private class ServiceGetApiCaller extends ApiCaller @Override public TResponse call() { - return callServiceGetApi(mPath, mResponseClass, mParams); + return callServiceGetApi(mPath, mResponseClass, mParams, mOptions); } } @@ -397,7 +408,7 @@ private class ServicePostApiCaller extends ApiCaller @Override public TResponse call() { - return callServicePostApi(mPath, mRequest, mResponseClass); + return callServicePostApi(mPath, mRequest, mResponseClass, mOptions); } } @@ -406,11 +417,12 @@ public TResponse call() * Call {@code /api/auth/authorization} API. */ @Override - public AuthorizationResponse authorization(AuthorizationRequest request) throws AuthleteApiException + public AuthorizationResponse authorization(AuthorizationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - AuthorizationResponse.class, request, AUTH_AUTHORIZATION_API_PATH)); + AuthorizationResponse.class, request, AUTH_AUTHORIZATION_API_PATH) + .setOptions(options)); } @@ -418,11 +430,12 @@ public AuthorizationResponse authorization(AuthorizationRequest request) throws * Call {@code /api/auth/authorization/fail} API. */ @Override - public AuthorizationFailResponse authorizationFail(AuthorizationFailRequest request) throws AuthleteApiException + public AuthorizationFailResponse authorizationFail(AuthorizationFailRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - AuthorizationFailResponse.class, request, AUTH_AUTHORIZATION_FAIL_API_PATH)); + AuthorizationFailResponse.class, request, AUTH_AUTHORIZATION_FAIL_API_PATH) + .setOptions(options)); } @@ -430,11 +443,12 @@ public AuthorizationFailResponse authorizationFail(AuthorizationFailRequest requ * Call {@code /api/auth/authorization/issue} API. */ @Override - public AuthorizationIssueResponse authorizationIssue(AuthorizationIssueRequest request) throws AuthleteApiException + public AuthorizationIssueResponse authorizationIssue(AuthorizationIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - AuthorizationIssueResponse.class, request, AUTH_AUTHORIZATION_ISSUE_API_PATH)); + AuthorizationIssueResponse.class, request, AUTH_AUTHORIZATION_ISSUE_API_PATH) + .setOptions(options)); } @@ -442,11 +456,12 @@ public AuthorizationIssueResponse authorizationIssue(AuthorizationIssueRequest r * Call {@code /api/auth/token} API. */ @Override - public TokenResponse token(TokenRequest request) throws AuthleteApiException + public TokenResponse token(TokenRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - TokenResponse.class, request, AUTH_TOKEN_API_PATH)); + TokenResponse.class, request, AUTH_TOKEN_API_PATH) + .setOptions(options)); } @@ -454,11 +469,12 @@ public TokenResponse token(TokenRequest request) throws AuthleteApiException * Call {@code /api/auth/token/create} API. */ @Override - public TokenCreateResponse tokenCreate(TokenCreateRequest request) throws AuthleteApiException + public TokenCreateResponse tokenCreate(TokenCreateRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - TokenCreateResponse.class, request, AUTH_TOKEN_CREATE_API_PATH)); + TokenCreateResponse.class, request, AUTH_TOKEN_CREATE_API_PATH) + .setOptions(options)); } @@ -466,11 +482,12 @@ public TokenCreateResponse tokenCreate(TokenCreateRequest request) throws Authle * Call /api/auth/token/delete/{token} API. */ @Override - public void tokenDelete(String token) throws AuthleteApiException + public void tokenDelete(String token, Options options) throws AuthleteApiException { executeApiCall( new ServiceDeleteApiCaller( - AUTH_TOKEN_DELETE_API_PATH, token)); + AUTH_TOKEN_DELETE_API_PATH, token) + .setOptions(options)); } @@ -478,11 +495,12 @@ public void tokenDelete(String token) throws AuthleteApiException * Call {@code /api/auth/token/fail} API. */ @Override - public TokenFailResponse tokenFail(TokenFailRequest request) throws AuthleteApiException + public TokenFailResponse tokenFail(TokenFailRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - TokenFailResponse.class, request, AUTH_TOKEN_FAIL_API_PATH)); + TokenFailResponse.class, request, AUTH_TOKEN_FAIL_API_PATH) + .setOptions(options)); } @@ -490,11 +508,12 @@ public TokenFailResponse tokenFail(TokenFailRequest request) throws AuthleteApiE * Call {@code /api/auth/token/issue} API. */ @Override - public TokenIssueResponse tokenIssue(TokenIssueRequest request) throws AuthleteApiException + public TokenIssueResponse tokenIssue(TokenIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - TokenIssueResponse.class, request, AUTH_TOKEN_ISSUE_API_PATH)); + TokenIssueResponse.class, request, AUTH_TOKEN_ISSUE_API_PATH) + .setOptions(options)); } @@ -502,11 +521,12 @@ public TokenIssueResponse tokenIssue(TokenIssueRequest request) throws AuthleteA * Call {@code /api/auth/token/revoke} API. */ @Override - public TokenRevokeResponse tokenRevoke(TokenRevokeRequest request) throws AuthleteApiException + public TokenRevokeResponse tokenRevoke(TokenRevokeRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - TokenRevokeResponse.class, request, AUTH_TOKEN_REVOKE_API_PATH)); + TokenRevokeResponse.class, request, AUTH_TOKEN_REVOKE_API_PATH) + .setOptions(options)); } @@ -514,87 +534,88 @@ public TokenRevokeResponse tokenRevoke(TokenRevokeRequest request) throws Authle * Call {@code /api/auth/token/update} API. */ @Override - public TokenUpdateResponse tokenUpdate(TokenUpdateRequest request) throws AuthleteApiException + public TokenUpdateResponse tokenUpdate(TokenUpdateRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - TokenUpdateResponse.class, request, AUTH_TOKEN_UPDATE_API_PATH)); + TokenUpdateResponse.class, request, AUTH_TOKEN_UPDATE_API_PATH) + .setOptions(options)); } @Override - public TokenListResponse getTokenList() throws AuthleteApiException + public TokenListResponse getTokenList(Options options) throws AuthleteApiException { - return getTokenList(null, null, 0, 0, false, TokenStatus.ALL); + return getTokenList(null, null, 0, 0, false, TokenStatus.ALL, options); } @Override - public TokenListResponse getTokenList(TokenStatus tokenStatus) throws AuthleteApiException + public TokenListResponse getTokenList(TokenStatus tokenStatus, Options options) throws AuthleteApiException { - return getTokenList(null, null, 0, 0, false, tokenStatus); + return getTokenList(null, null, 0, 0, false, tokenStatus, options); } @Override - public TokenListResponse getTokenList(String clientIdentifier, String subject) throws AuthleteApiException + public TokenListResponse getTokenList(String clientIdentifier, String subject, Options options) throws AuthleteApiException { - return getTokenList(clientIdentifier, subject, 0, 0, false, TokenStatus.ALL); + return getTokenList(clientIdentifier, subject, 0, 0, false, TokenStatus.ALL, options); } @Override - public TokenListResponse getTokenList(String clientIdentifier, String subject, TokenStatus tokenStatus) throws AuthleteApiException + public TokenListResponse getTokenList(String clientIdentifier, String subject, TokenStatus tokenStatus, Options options) throws AuthleteApiException { - return getTokenList(clientIdentifier, subject, 0, 0, false, tokenStatus); + return getTokenList(clientIdentifier, subject, 0, 0, false, tokenStatus, options); } @Override - public TokenListResponse getTokenList(int start, int end) throws AuthleteApiException + public TokenListResponse getTokenList(int start, int end, Options options) throws AuthleteApiException { - return getTokenList(null, null, start, end, true, TokenStatus.ALL); + return getTokenList(null, null, start, end, true, TokenStatus.ALL, options); } @Override - public TokenListResponse getTokenList(int start, int end, TokenStatus tokenStatus) throws AuthleteApiException + public TokenListResponse getTokenList(int start, int end, TokenStatus tokenStatus, Options options) throws AuthleteApiException { - return getTokenList(null, null, start, end, true, tokenStatus); + return getTokenList(null, null, start, end, true, tokenStatus, options); } @Override - public TokenListResponse getTokenList(String clientIdentifier, String subject, int start, int end) throws AuthleteApiException + public TokenListResponse getTokenList(String clientIdentifier, String subject, int start, int end, Options options) throws AuthleteApiException { - return getTokenList(clientIdentifier, subject, start, end, true, TokenStatus.ALL); + return getTokenList(clientIdentifier, subject, start, end, true, TokenStatus.ALL, options); } @Override - public TokenListResponse getTokenList(String clientIdentifier, String subject, int start, int end, TokenStatus tokenStatus) throws AuthleteApiException + public TokenListResponse getTokenList(String clientIdentifier, String subject, int start, int end, TokenStatus tokenStatus, Options options) throws AuthleteApiException { - return getTokenList(clientIdentifier, subject, start, end, true, tokenStatus); + return getTokenList(clientIdentifier, subject, start, end, true, tokenStatus, options); } private TokenListResponse getTokenList( final String clientIdentifier, final String subject, - final int start, final int end, final boolean rangeGiven, TokenStatus tokenStatus) throws AuthleteApiException + final int start, final int end, final boolean rangeGiven, TokenStatus tokenStatus, Options options) throws AuthleteApiException { return executeApiCall(new AuthleteApiCall() { @Override public TokenListResponse call() { - return callGetTokenList(clientIdentifier, subject, start, end, rangeGiven, tokenStatus); + return callGetTokenList(clientIdentifier, subject, start, end, rangeGiven, tokenStatus, options); } }); } private TokenListResponse callGetTokenList( - String clientIdentifier, String subject, int start, int end, boolean rangeGiven, TokenStatus tokenStatus) + String clientIdentifier, String subject, int start, int end, boolean rangeGiven, TokenStatus tokenStatus, Options options) { WebTarget target = getTarget().path(AUTH_TOKEN_GET_LIST_API_PATH); @@ -615,10 +636,13 @@ private TokenListResponse callGetTokenList( target = target.queryParam("tokenStatus", tokenStatus.toString()); - return wrapWithDpop(target + Builder builder = wrapWithDpop(target .request(APPLICATION_JSON_TYPE), AUTH_TOKEN_GET_LIST_API_PATH, "GET") - .header(AUTHORIZATION, mServiceAuth) - .get(TokenListResponse.class); + .header(AUTHORIZATION, mServiceAuth); + + setCustomRequestHeaders(builder, options); + + return builder.get(TokenListResponse.class); } @@ -626,11 +650,12 @@ private TokenListResponse callGetTokenList( * Call {@code /api/auth/revocation} API. */ @Override - public RevocationResponse revocation(RevocationRequest request) throws AuthleteApiException + public RevocationResponse revocation(RevocationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - RevocationResponse.class, request, AUTH_REVOCATION_API_PATH)); + RevocationResponse.class, request, AUTH_REVOCATION_API_PATH) + .setOptions(options)); } @@ -638,11 +663,12 @@ public RevocationResponse revocation(RevocationRequest request) throws AuthleteA * Call {@code /api/auth/userinfo} API. */ @Override - public UserInfoResponse userinfo(UserInfoRequest request) throws AuthleteApiException + public UserInfoResponse userinfo(UserInfoRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - UserInfoResponse.class, request, AUTH_USERINFO_API_PATH)); + UserInfoResponse.class, request, AUTH_USERINFO_API_PATH) + .setOptions(options)); } @@ -650,11 +676,12 @@ public UserInfoResponse userinfo(UserInfoRequest request) throws AuthleteApiExce * Call {@code /api/auth/userinfo/issue} API. */ @Override - public UserInfoIssueResponse userinfoIssue(UserInfoIssueRequest request) throws AuthleteApiException + public UserInfoIssueResponse userinfoIssue(UserInfoIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - UserInfoIssueResponse.class, request, AUTH_USERINFO_ISSUE_API_PATH)); + UserInfoIssueResponse.class, request, AUTH_USERINFO_ISSUE_API_PATH) + .setOptions(options)); } @@ -662,11 +689,12 @@ public UserInfoIssueResponse userinfoIssue(UserInfoIssueRequest request) throws * Call {@code /api/auth/introspection} API. */ @Override - public IntrospectionResponse introspection(IntrospectionRequest request) throws AuthleteApiException + public IntrospectionResponse introspection(IntrospectionRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - IntrospectionResponse.class, request, AUTH_INTROSPECTION_API_PATH)); + IntrospectionResponse.class, request, AUTH_INTROSPECTION_API_PATH) + .setOptions(options)); } @@ -675,11 +703,12 @@ public IntrospectionResponse introspection(IntrospectionRequest request) throws */ @Override public StandardIntrospectionResponse standardIntrospection( - StandardIntrospectionRequest request) throws AuthleteApiException + StandardIntrospectionRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - StandardIntrospectionResponse.class, request, AUTH_INTROSPECTION_STANDARD_API_PATH)); + StandardIntrospectionResponse.class, request, AUTH_INTROSPECTION_STANDARD_API_PATH) + .setOptions(options)); } @@ -687,11 +716,12 @@ public StandardIntrospectionResponse standardIntrospection( * Call {@code /api/service/create} API. */ @Override - public Service createService(Service service) throws AuthleteApiException + public Service createService(Service service, Options options) throws AuthleteApiException { return executeApiCall( new ServiceOwnerPostApiCaller( - Service.class, service, SERVICE_CREATE_API_PATH)); + Service.class, service, SERVICE_CREATE_API_PATH) + .setOptions(options)); } @@ -710,11 +740,12 @@ public Service createServie(Service service) throws AuthleteApiException * Call /api/service/delete/{serviceApiKey} API. */ @Override - public void deleteService(long apiKey) throws AuthleteApiException + public void deleteService(long apiKey, Options options) throws AuthleteApiException { executeApiCall( new ServiceOwnerDeleteApiCaller( - SERVICE_DELETE_API_PATH, apiKey)); + SERVICE_DELETE_API_PATH, apiKey) + .setOptions(options)); } @@ -722,11 +753,12 @@ public void deleteService(long apiKey) throws AuthleteApiException * Call /api/service/get/{serviceApiKey} API. */ @Override - public Service getService(long apiKey) throws AuthleteApiException + public Service getService(long apiKey, Options options) throws AuthleteApiException { return executeApiCall( new ServiceOwnerGetApiCaller( - Service.class, SERVICE_GET_API_PATH, apiKey)); + Service.class, SERVICE_GET_API_PATH, apiKey) + .setOptions(options)); } @@ -734,28 +766,28 @@ public Service getService(long apiKey) throws AuthleteApiException * Call {@code /api/service/get/list} API. */ @Override - public ServiceListResponse getServiceList() throws AuthleteApiException + public ServiceListResponse getServiceList(Options options) throws AuthleteApiException { - return getServiceList(0, 0, false); + return getServiceList(0, 0, false, options); } @Override - public ServiceListResponse getServiceList(int start, int end) throws AuthleteApiException + public ServiceListResponse getServiceList(int start, int end, Options options) throws AuthleteApiException { - return getServiceList(start, end, true); + return getServiceList(start, end, true, options); } private ServiceListResponse getServiceList( - final int start, final int end, final boolean rangeGiven) throws AuthleteApiException + final int start, final int end, final boolean rangeGiven, Options options) throws AuthleteApiException { return executeApiCall(new AuthleteApiCall() { @Override public ServiceListResponse call() { - return callGetServiceList(start, end, rangeGiven); + return callGetServiceList(start, end, rangeGiven, options); } }); } @@ -764,7 +796,7 @@ public ServiceListResponse call() /** * Call /service/get/list. */ - private ServiceListResponse callGetServiceList(int start, int end, boolean rangeGiven) + private ServiceListResponse callGetServiceList(int start, int end, boolean rangeGiven, Options options) { WebTarget target = getTarget().path(SERVICE_GET_LIST_API_PATH); @@ -773,10 +805,13 @@ private ServiceListResponse callGetServiceList(int start, int end, boolean range target = target.queryParam("start", start).queryParam("end", end); } - return wrapWithDpop(target + Builder builder = wrapWithDpop(target .request(APPLICATION_JSON_TYPE), SERVICE_GET_LIST_API_PATH, "GET") - .header(AUTHORIZATION, mServiceOwnerAuth) - .get(ServiceListResponse.class); + .header(AUTHORIZATION, mServiceOwnerAuth); + + setCustomRequestHeaders(builder, options); + + return builder.get(ServiceListResponse.class); } @@ -784,11 +819,12 @@ private ServiceListResponse callGetServiceList(int start, int end, boolean range * Call /api/service/update/{serviceApiKey} API. */ @Override - public Service updateService(final Service service) throws AuthleteApiException + public Service updateService(final Service service, Options options) throws AuthleteApiException { return executeApiCall( new ServiceOwnerPostApiCaller( - Service.class, service, SERVICE_UPDATE_API_PATH, service.getApiKey())); + Service.class, service, SERVICE_UPDATE_API_PATH, service.getApiKey()) + .setOptions(options)); } @@ -796,11 +832,12 @@ public Service updateService(final Service service) throws AuthleteApiException * Call {@code /api/service/jwks/get} API */ @Override - public String getServiceJwks() throws AuthleteApiException + public String getServiceJwks(Options options) throws AuthleteApiException { return executeApiCall( new ServiceGetApiCaller( - String.class, SERVICE_JWKS_GET_API_PATH)); + String.class, SERVICE_JWKS_GET_API_PATH) + .setOptions(options)); } @@ -808,13 +845,14 @@ public String getServiceJwks() throws AuthleteApiException * Call {@code /api/service/jwks/get} API */ @Override - public String getServiceJwks(boolean pretty, boolean includePrivateKeys) throws AuthleteApiException + public String getServiceJwks(boolean pretty, boolean includePrivateKeys, Options options) throws AuthleteApiException { return executeApiCall( new ServiceGetApiCaller( String.class, SERVICE_JWKS_GET_API_PATH) .addParam("pretty", pretty) - .addParam("includePrivateKeys", includePrivateKeys)); + .addParam("includePrivateKeys", includePrivateKeys) + .setOptions(options)); } @@ -822,11 +860,12 @@ public String getServiceJwks(boolean pretty, boolean includePrivateKeys) throws * Call {@code /api/service/configuration} API */ @Override - public String getServiceConfiguration() throws AuthleteApiException + public String getServiceConfiguration(Options options) throws AuthleteApiException { return executeApiCall( new ServiceGetApiCaller( - String.class, SERVICE_CONFIGURATION_API_PATH)); + String.class, SERVICE_CONFIGURATION_API_PATH) + .setOptions(options)); } @@ -834,12 +873,13 @@ public String getServiceConfiguration() throws AuthleteApiException * Call {@code /api/service/configuration} API */ @Override - public String getServiceConfiguration(boolean pretty) throws AuthleteApiException + public String getServiceConfiguration(boolean pretty, Options options) throws AuthleteApiException { return executeApiCall( new ServiceGetApiCaller( String.class, SERVICE_CONFIGURATION_API_PATH) - .addParam("pretty", pretty)); + .addParam("pretty", pretty) + .setOptions(options)); } @@ -847,11 +887,12 @@ public String getServiceConfiguration(boolean pretty) throws AuthleteApiExceptio * Call {@code /api/service/configuration} API */ @Override - public String getServiceConfiguration(ServiceConfigurationRequest request) throws AuthleteApiException + public String getServiceConfiguration(ServiceConfigurationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - String.class, request, SERVICE_CONFIGURATION_API_PATH)); + String.class, request, SERVICE_CONFIGURATION_API_PATH) + .setOptions(options)); } @@ -859,11 +900,12 @@ public String getServiceConfiguration(ServiceConfigurationRequest request) throw * Call {@code /api/client/create} API. */ @Override - public Client createClient(Client client) throws AuthleteApiException + public Client createClient(Client client, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - Client.class, client, CLIENT_CREATE_API_PATH)); + Client.class, client, CLIENT_CREATE_API_PATH) + .setOptions(options)); } @@ -871,11 +913,12 @@ public Client createClient(Client client) throws AuthleteApiException * Call {@code /api/client/registration} API. */ @Override - public ClientRegistrationResponse dynamicClientRegister(ClientRegistrationRequest request) throws AuthleteApiException + public ClientRegistrationResponse dynamicClientRegister(ClientRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_API_PATH)); + ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_API_PATH) + .setOptions(options)); } @@ -883,11 +926,12 @@ public ClientRegistrationResponse dynamicClientRegister(ClientRegistrationReques * Call {@code /api/client/registration/get} API. */ @Override - public ClientRegistrationResponse dynamicClientGet(ClientRegistrationRequest request) throws AuthleteApiException + public ClientRegistrationResponse dynamicClientGet(ClientRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_GET_API_PATH)); + ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_GET_API_PATH) + .setOptions(options)); } @@ -895,11 +939,12 @@ public ClientRegistrationResponse dynamicClientGet(ClientRegistrationRequest req * Call {@code /api/client/registration/update} API. */ @Override - public ClientRegistrationResponse dynamicClientUpdate(ClientRegistrationRequest request) throws AuthleteApiException + public ClientRegistrationResponse dynamicClientUpdate(ClientRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_UPDATE_API_PATH)); + ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_UPDATE_API_PATH) + .setOptions(options)); } @@ -907,11 +952,12 @@ public ClientRegistrationResponse dynamicClientUpdate(ClientRegistrationRequest * Call {@code /api/client/registration/delete} API. */ @Override - public ClientRegistrationResponse dynamicClientDelete(ClientRegistrationRequest request) throws AuthleteApiException + public ClientRegistrationResponse dynamicClientDelete(ClientRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_DELETE_API_PATH)); + ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_DELETE_API_PATH) + .setOptions(options)); } @@ -919,9 +965,9 @@ public ClientRegistrationResponse dynamicClientDelete(ClientRegistrationRequest * Call /api/client/delete/{clientId} API. */ @Override - public void deleteClient(long clientId) throws AuthleteApiException + public void deleteClient(long clientId, Options options) throws AuthleteApiException { - deleteClient(String.valueOf(clientId)); + deleteClient(String.valueOf(clientId), options); } @@ -929,11 +975,12 @@ public void deleteClient(long clientId) throws AuthleteApiException * Call /api/client/delete/{clientId} API. */ @Override - public void deleteClient(String clientId) throws AuthleteApiException + public void deleteClient(String clientId, Options options) throws AuthleteApiException { executeApiCall( new ServiceDeleteApiCaller( - CLIENT_DELETE_API_PATH, clientId)); + CLIENT_DELETE_API_PATH, clientId) + .setOptions(options)); } @@ -941,9 +988,9 @@ public void deleteClient(String clientId) throws AuthleteApiException * Call /api/client/get/{clientId} API. */ @Override - public Client getClient(long clientId) throws AuthleteApiException + public Client getClient(long clientId, Options options) throws AuthleteApiException { - return getClient(String.valueOf(clientId)); + return getClient(String.valueOf(clientId), options); } @@ -951,11 +998,12 @@ public Client getClient(long clientId) throws AuthleteApiException * Call /api/client/get/{clientId} API. */ @Override - public Client getClient(String clientId) throws AuthleteApiException + public Client getClient(String clientId, Options options) throws AuthleteApiException { return executeApiCall( new ServiceGetApiCaller( - Client.class, CLIENT_GET_API_PATH, clientId)); + Client.class, CLIENT_GET_API_PATH, clientId) + .setOptions(options)); } @@ -963,48 +1011,48 @@ public Client getClient(String clientId) throws AuthleteApiException * Call {@code /api/client/get/list} API. */ @Override - public ClientListResponse getClientList() throws AuthleteApiException + public ClientListResponse getClientList(Options options) throws AuthleteApiException { - return getClientList(null, 0, 0, false); + return getClientList(null, 0, 0, false, options); } @Override - public ClientListResponse getClientList(String developer) throws AuthleteApiException + public ClientListResponse getClientList(String developer, Options options) throws AuthleteApiException { - return getClientList(developer, 0, 0, false); + return getClientList(developer, 0, 0, false, options); } @Override - public ClientListResponse getClientList(int start, int end) throws AuthleteApiException + public ClientListResponse getClientList(int start, int end, Options options) throws AuthleteApiException { - return getClientList(null, start, end, true); + return getClientList(null, start, end, true, options); } @Override - public ClientListResponse getClientList(String developer, int start, int end) throws AuthleteApiException + public ClientListResponse getClientList(String developer, int start, int end, Options options) throws AuthleteApiException { - return getClientList(developer, start, end, true); + return getClientList(developer, start, end, true, options); } private ClientListResponse getClientList( - final String developer, final int start, final int end, final boolean rangeGiven) throws AuthleteApiException + final String developer, final int start, final int end, final boolean rangeGiven, Options options) throws AuthleteApiException { return executeApiCall(new AuthleteApiCall() { @Override public ClientListResponse call() { - return callGetClientList(developer, start, end, rangeGiven); + return callGetClientList(developer, start, end, rangeGiven, options); } }); } - private ClientListResponse callGetClientList(String developer, int start, int end, boolean rangeGiven) + private ClientListResponse callGetClientList(String developer, int start, int end, boolean rangeGiven, Options options) { WebTarget target = getTarget().path(CLIENT_GET_LIST_API_PATH); @@ -1018,10 +1066,13 @@ private ClientListResponse callGetClientList(String developer, int start, int en target = target.queryParam("start", start).queryParam("end", end); } - return wrapWithDpop(target + Builder builder = wrapWithDpop(target .request(APPLICATION_JSON_TYPE), CLIENT_GET_LIST_API_PATH, "GET") - .header(AUTHORIZATION, mServiceAuth) - .get(ClientListResponse.class); + .header(AUTHORIZATION, mServiceAuth); + + setCustomRequestHeaders(builder, options); + + return builder.get(ClientListResponse.class); } @@ -1029,11 +1080,12 @@ private ClientListResponse callGetClientList(String developer, int start, int en * Call /api/client/update/{clientId} API. */ @Override - public Client updateClient(Client client) throws AuthleteApiException + public Client updateClient(Client client, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - Client.class, client, CLIENT_UPDATE_API_PATH, client.getClientId())); + Client.class, client, CLIENT_UPDATE_API_PATH, client.getClientId()) + .setOptions(options)); } @@ -1042,12 +1094,13 @@ public Client updateClient(Client client) throws AuthleteApiException * Call /api/client/extension/requestable_scopes/get/{clientId} API. */ @Override - public String[] getRequestableScopes(long clientId) throws AuthleteApiException + public String[] getRequestableScopes(long clientId, Options options) throws AuthleteApiException { // Call the API. RequestableScopes response = executeApiCall( new ServiceGetApiCaller( - RequestableScopes.class, REQUESTABLE_SCOPES_GET_API_PATH, clientId)); + RequestableScopes.class, REQUESTABLE_SCOPES_GET_API_PATH, clientId) + .setOptions(options)); if (response != null) { @@ -1062,7 +1115,7 @@ public String[] getRequestableScopes(long clientId) throws AuthleteApiException @Override - public String[] setRequestableScopes(long clientId, String[] scopes) throws AuthleteApiException + public String[] setRequestableScopes(long clientId, String[] scopes, Options options) throws AuthleteApiException { // Prepare a request body. RequestableScopes request = new RequestableScopes().setRequestableScopes(scopes); @@ -1088,16 +1141,17 @@ public String[] setRequestableScopes(long clientId, String[] scopes) throws Auth * Call /api/client/extension/requestable_scopes/delete/{clientId} API. */ @Override - public void deleteRequestableScopes(long clientId) throws AuthleteApiException + public void deleteRequestableScopes(long clientId, Options options) throws AuthleteApiException { executeApiCall( new ServiceDeleteApiCaller( - REQUESTABLE_SCOPES_DELETE_API_PATH, clientId)); + REQUESTABLE_SCOPES_DELETE_API_PATH, clientId) + .setOptions(options)); } @Override - public GrantedScopesGetResponse getGrantedScopes(long clientId, String subject) + public GrantedScopesGetResponse getGrantedScopes(long clientId, String subject, Options options) { // Prepare a request body. GrantedScopesRequest request = new GrantedScopesRequest(subject); @@ -1105,19 +1159,21 @@ public GrantedScopesGetResponse getGrantedScopes(long clientId, String subject) // Call the API. return executeApiCall( new ServicePostApiCaller( - GrantedScopesGetResponse.class, request, GRANTED_SCOPES_GET_API_PATH, clientId)); + GrantedScopesGetResponse.class, request, GRANTED_SCOPES_GET_API_PATH, clientId) + .setOptions(options)); } @Override - public void deleteGrantedScopes(long clientId, String subject) + public void deleteGrantedScopes(long clientId, String subject, Options options) { // Prepare a request body. GrantedScopesRequest request = new GrantedScopesRequest(subject); executeApiCall( new ServicePostApiCaller( - ApiResponse.class, request, GRANTED_SCOPES_DELETE_API_PATH, clientId)); + ApiResponse.class, request, GRANTED_SCOPES_DELETE_API_PATH, clientId) + .setOptions(options)); } @@ -1148,61 +1204,69 @@ public void setSubject(String subject) @Override - public void deleteClientAuthorization(long clientId, String subject) throws AuthleteApiException + public void deleteClientAuthorization(long clientId, String subject, Options options) throws AuthleteApiException { // Prepare a request body. ClientAuthorizationDeleteRequest request = new ClientAuthorizationDeleteRequest(subject); executeApiCall( new ServicePostApiCaller( - ApiResponse.class, request, CLIENT_AUTHORIZATION_DELETE_API_PATH, clientId)); + ApiResponse.class, request, CLIENT_AUTHORIZATION_DELETE_API_PATH, clientId) + .setOptions(options)); } @Override - public AuthorizedClientListResponse getClientAuthorizationList(ClientAuthorizationGetListRequest request) throws AuthleteApiException + public AuthorizedClientListResponse getClientAuthorizationList( + ClientAuthorizationGetListRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - AuthorizedClientListResponse.class, request, CLIENT_AUTHORIZATION_GET_LIST_API_PATH)); + AuthorizedClientListResponse.class, request, CLIENT_AUTHORIZATION_GET_LIST_API_PATH) + .setOptions(options)); } @Override - public void updateClientAuthorization(long clientId, ClientAuthorizationUpdateRequest request) throws AuthleteApiException + public void updateClientAuthorization( + long clientId, ClientAuthorizationUpdateRequest request, Options options) throws AuthleteApiException { executeApiCall( new ServicePostApiCaller( - ApiResponse.class, request, CLIENT_AUTHORIZATION_UPDATE_API_PATH, clientId)); + ApiResponse.class, request, CLIENT_AUTHORIZATION_UPDATE_API_PATH, clientId) + .setOptions(options)); } @Override - public ClientSecretRefreshResponse refreshClientSecret(long clientId) throws AuthleteApiException + public ClientSecretRefreshResponse refreshClientSecret(long clientId, Options options) throws AuthleteApiException { - return refreshClientSecret(String.valueOf(clientId)); + return refreshClientSecret(String.valueOf(clientId), options); } @Override - public ClientSecretRefreshResponse refreshClientSecret(String clientIdentifier) throws AuthleteApiException + public ClientSecretRefreshResponse refreshClientSecret(String clientIdentifier, Options options) throws AuthleteApiException { return executeApiCall( new ServiceGetApiCaller( ClientSecretRefreshResponse.class, - CLIENT_SECRET_REFRESH_API_PATH, clientIdentifier)); + CLIENT_SECRET_REFRESH_API_PATH, clientIdentifier) + .setOptions(options)); } @Override - public ClientSecretUpdateResponse updateClientSecret(long clientId, String clientSecret) throws AuthleteApiException + public ClientSecretUpdateResponse updateClientSecret( + long clientId, String clientSecret, Options options) throws AuthleteApiException { - return updateClientSecret(String.valueOf(clientId), clientSecret); + return updateClientSecret(String.valueOf(clientId), clientSecret, options); } @Override - public ClientSecretUpdateResponse updateClientSecret(String clientIdentifier, String clientSecret) throws AuthleteApiException + public ClientSecretUpdateResponse updateClientSecret( + String clientIdentifier, String clientSecret, Options options) throws AuthleteApiException { // Prepare a request body. setClientSecret(String) method // throws IllegalArgumentException if the given client secret @@ -1213,7 +1277,8 @@ public ClientSecretUpdateResponse updateClientSecret(String clientIdentifier, St return executeApiCall( new ServicePostApiCaller( ClientSecretUpdateResponse.class, request, - CLIENT_SECRET_UPDATE_API_PATH, clientIdentifier)); + CLIENT_SECRET_UPDATE_API_PATH, clientIdentifier) + .setOptions(options)); } @@ -1221,11 +1286,12 @@ public ClientSecretUpdateResponse updateClientSecret(String clientIdentifier, St * Call {@code /api/jose/verify} API. */ @Override - public JoseVerifyResponse verifyJose(JoseVerifyRequest request) throws AuthleteApiException + public JoseVerifyResponse verifyJose(JoseVerifyRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - JoseVerifyResponse.class, request, JOSE_VERIFY_API_PATH)); + JoseVerifyResponse.class, request, JOSE_VERIFY_API_PATH) + .setOptions(options)); } @@ -1233,11 +1299,13 @@ public JoseVerifyResponse verifyJose(JoseVerifyRequest request) throws AuthleteA * Call {@code /api/backchannel/authentication} API. */ @Override - public BackchannelAuthenticationResponse backchannelAuthentication(BackchannelAuthenticationRequest request) throws AuthleteApiException + public BackchannelAuthenticationResponse backchannelAuthentication( + BackchannelAuthenticationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - BackchannelAuthenticationResponse.class, request, BACKCHANNEL_AUTHENTICATION_API_PATH)); + BackchannelAuthenticationResponse.class, request, BACKCHANNEL_AUTHENTICATION_API_PATH) + .setOptions(options)); } @@ -1245,11 +1313,13 @@ public BackchannelAuthenticationResponse backchannelAuthentication(BackchannelAu * Call {@code /api/backchannel/authentication/issue} API. */ @Override - public BackchannelAuthenticationIssueResponse backchannelAuthenticationIssue(BackchannelAuthenticationIssueRequest request) throws AuthleteApiException + public BackchannelAuthenticationIssueResponse backchannelAuthenticationIssue( + BackchannelAuthenticationIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - BackchannelAuthenticationIssueResponse.class, request, BACKCHANNEL_AUTHENTICATION_ISSUE_API_PATH)); + BackchannelAuthenticationIssueResponse.class, request, BACKCHANNEL_AUTHENTICATION_ISSUE_API_PATH) + .setOptions(options)); } @@ -1257,11 +1327,13 @@ public BackchannelAuthenticationIssueResponse backchannelAuthenticationIssue(Bac * Call {@code /api/backchannel/authentication/fail} API. */ @Override - public BackchannelAuthenticationFailResponse backchannelAuthenticationFail(BackchannelAuthenticationFailRequest request) throws AuthleteApiException + public BackchannelAuthenticationFailResponse backchannelAuthenticationFail( + BackchannelAuthenticationFailRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - BackchannelAuthenticationFailResponse.class, request, BACKCHANNEL_AUTHENTICATION_FAIL_API_PATH)); + BackchannelAuthenticationFailResponse.class, request, BACKCHANNEL_AUTHENTICATION_FAIL_API_PATH) + .setOptions(options)); } @@ -1269,11 +1341,13 @@ public BackchannelAuthenticationFailResponse backchannelAuthenticationFail(Backc * Call {@code /api/backchannel/authentication/complete} API. */ @Override - public BackchannelAuthenticationCompleteResponse backchannelAuthenticationComplete(BackchannelAuthenticationCompleteRequest request) throws AuthleteApiException + public BackchannelAuthenticationCompleteResponse backchannelAuthenticationComplete( + BackchannelAuthenticationCompleteRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - BackchannelAuthenticationCompleteResponse.class, request, BACKCHANNEL_AUTHENTICATION_COMPLETE_API_PATH)); + BackchannelAuthenticationCompleteResponse.class, request, BACKCHANNEL_AUTHENTICATION_COMPLETE_API_PATH) + .setOptions(options)); } @@ -1281,11 +1355,13 @@ public BackchannelAuthenticationCompleteResponse backchannelAuthenticationComple * Call {@code /api/device/authorization} API. */ @Override - public DeviceAuthorizationResponse deviceAuthorization(DeviceAuthorizationRequest request) throws AuthleteApiException + public DeviceAuthorizationResponse deviceAuthorization( + DeviceAuthorizationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - DeviceAuthorizationResponse.class, request, DEVICE_AUTHORIZATION_API_PATH)); + DeviceAuthorizationResponse.class, request, DEVICE_AUTHORIZATION_API_PATH) + .setOptions(options)); } @@ -1293,11 +1369,13 @@ public DeviceAuthorizationResponse deviceAuthorization(DeviceAuthorizationReques * Call {@code /api/device/complete} API. */ @Override - public DeviceCompleteResponse deviceComplete(DeviceCompleteRequest request) throws AuthleteApiException + public DeviceCompleteResponse deviceComplete( + DeviceCompleteRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - DeviceCompleteResponse.class, request, DEVICE_COMPLETE_API_PATH)); + DeviceCompleteResponse.class, request, DEVICE_COMPLETE_API_PATH) + .setOptions(options)); } @@ -1305,77 +1383,85 @@ public DeviceCompleteResponse deviceComplete(DeviceCompleteRequest request) thro * Call {@code /api/device/verification} API. */ @Override - public DeviceVerificationResponse deviceVerification(DeviceVerificationRequest request) throws AuthleteApiException + public DeviceVerificationResponse deviceVerification( + DeviceVerificationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - DeviceVerificationResponse.class, request, DEVICE_VERIFICATION_API_PATH)); + DeviceVerificationResponse.class, request, DEVICE_VERIFICATION_API_PATH) + .setOptions(options)); } @Override - public PushedAuthReqResponse pushAuthorizationRequest(PushedAuthReqRequest request) throws AuthleteApiException + public PushedAuthReqResponse pushAuthorizationRequest( + PushedAuthReqRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - PushedAuthReqResponse.class, request, PUSHED_AUTH_REQ_API_PATH)); + PushedAuthReqResponse.class, request, PUSHED_AUTH_REQ_API_PATH) + .setOptions(options)); } @Override - public HskResponse hskCreate(HskCreateRequest request) throws AuthleteApiException + public HskResponse hskCreate(HskCreateRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - HskResponse.class, request, HSK_CREATE_API_PATH)); + HskResponse.class, request, HSK_CREATE_API_PATH) + .setOptions(options)); } @Override - public HskResponse hskDelete(String handle) throws AuthleteApiException + public HskResponse hskDelete(String handle, Options options) throws AuthleteApiException { return executeApiCall( new ServiceGetApiCaller( HskResponse.class, - HSK_DELETE_API_PATH, handle)); + HSK_DELETE_API_PATH, handle) + .setOptions(options)); } @Override - public HskResponse hskGet(String handle) throws AuthleteApiException + public HskResponse hskGet(String handle, Options options) throws AuthleteApiException { return executeApiCall( new ServiceGetApiCaller( HskResponse.class, - HSK_GET_API_PATH, handle)); + HSK_GET_API_PATH, handle) + .setOptions(options)); } @Override - public HskListResponse hskGetList() throws AuthleteApiException + public HskListResponse hskGetList(Options options) throws AuthleteApiException { return executeApiCall( new ServiceGetApiCaller( HskListResponse.class, - HSK_GET_LIST_API_PATH)); + HSK_GET_LIST_API_PATH) + .setOptions(options)); } @Override - public Map echo(Map parameters) throws AuthleteApiException + public Map echo(Map parameters, Options options) throws AuthleteApiException { return executeApiCall(new AuthleteApiCall>() { @Override public Map call() { - return callEcho(parameters); + return callEcho(parameters, options); } }); } - private Map callEcho(Map parameters) + private Map callEcho(Map parameters, Options options) { WebTarget target = getTarget().path(ECHO_API_PATH); @@ -1390,24 +1476,27 @@ private Map callEcho(Map parameters) // The API does not require any authentication, so the code below // does not include '.header(AUTHORIZATION, ...)'. - return target - .request(APPLICATION_JSON_TYPE) - .get(new GenericType>(){}); + Builder builder = target.request(APPLICATION_JSON_TYPE); + + setCustomRequestHeaders(builder, options); + + return builder.get(new GenericType>(){}); } @Override - public GMResponse gm(GMRequest request) throws AuthleteApiException + public GMResponse gm(GMRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( - GMResponse.class, request, GM_API_PATH)); + GMResponse.class, request, GM_API_PATH) + .setOptions(options)); } @Override public void updateClientLockFlag( - String clientIdentifier, boolean clientLocked) throws AuthleteApiException + String clientIdentifier, boolean clientLocked, Options options) throws AuthleteApiException { // Prepare a request body. ClientLockFlagUpdateRequest request = @@ -1416,35 +1505,38 @@ public void updateClientLockFlag( executeApiCall( new ServicePostApiCaller( ApiResponse.class, request, - CLIENT_LOCK_FLAG_UPDATE_API_PATH, clientIdentifier)); + CLIENT_LOCK_FLAG_UPDATE_API_PATH, clientIdentifier) + .setOptions(options)); } @Override public FederationConfigurationResponse federationConfiguration( - FederationConfigurationRequest request) throws AuthleteApiException + FederationConfigurationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( FederationConfigurationResponse.class, request, - FEDERATION_CONFIGURATION_API_PATH)); + FEDERATION_CONFIGURATION_API_PATH) + .setOptions(options)); } @Override public FederationRegistrationResponse federationRegistration( - FederationRegistrationRequest request) throws AuthleteApiException + FederationRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( FederationRegistrationResponse.class, request, - FEDERATION_REGISTRATION_API_PATH)); + FEDERATION_REGISTRATION_API_PATH) + .setOptions(options)); } @Override public CredentialIssuerMetadataResponse credentialIssuerMetadata( - CredentialIssuerMetadataRequest request) throws AuthleteApiException + CredentialIssuerMetadataRequest request, Options options) throws AuthleteApiException { // Note that the /vci/metadata API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1452,13 +1544,14 @@ public CredentialIssuerMetadataResponse credentialIssuerMetadata( return executeApiCall( new ServicePostApiCaller( CredentialIssuerMetadataResponse.class, request, - VCI_METADATA_API_PATH)); + VCI_METADATA_API_PATH) + .setOptions(options)); } @Override public CredentialJwtIssuerMetadataResponse credentialJwtIssuerMetadata( - CredentialJwtIssuerMetadataRequest request) throws AuthleteApiException + CredentialJwtIssuerMetadataRequest request, Options options) throws AuthleteApiException { // Note that the /vci/jwtissuer API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1466,13 +1559,14 @@ public CredentialJwtIssuerMetadataResponse credentialJwtIssuerMetadata( return executeApiCall( new ServicePostApiCaller( CredentialJwtIssuerMetadataResponse.class, request, - VCI_JWT_ISSUER_API_PATH)); + VCI_JWT_ISSUER_API_PATH) + .setOptions(options)); } @Override public CredentialIssuerJwksResponse credentialIssuerJwks( - CredentialIssuerJwksRequest request) throws AuthleteApiException + CredentialIssuerJwksRequest request, Options options) throws AuthleteApiException { // Note that the /vci/jwks API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1480,13 +1574,14 @@ public CredentialIssuerJwksResponse credentialIssuerJwks( return executeApiCall( new ServicePostApiCaller( CredentialIssuerJwksResponse.class, request, - VCI_JWKS_API_PATH)); + VCI_JWKS_API_PATH) + .setOptions(options)); } @Override public CredentialOfferCreateResponse credentialOfferCreate( - CredentialOfferCreateRequest request) throws AuthleteApiException + CredentialOfferCreateRequest request, Options options) throws AuthleteApiException { // Note that the /vci/offer/create API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1494,13 +1589,14 @@ public CredentialOfferCreateResponse credentialOfferCreate( return executeApiCall( new ServicePostApiCaller( CredentialOfferCreateResponse.class, request, - VCI_OFFER_CREATE_API_PATH)); + VCI_OFFER_CREATE_API_PATH) + .setOptions(options)); } @Override public CredentialOfferInfoResponse credentialOfferInfo( - CredentialOfferInfoRequest request) throws AuthleteApiException + CredentialOfferInfoRequest request, Options options) throws AuthleteApiException { // Note that the /vci/offer/info API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1508,13 +1604,14 @@ public CredentialOfferInfoResponse credentialOfferInfo( return executeApiCall( new ServicePostApiCaller( CredentialOfferInfoResponse.class, request, - VCI_OFFER_INFO_API_PATH)); + VCI_OFFER_INFO_API_PATH) + .setOptions(options)); } @Override public CredentialSingleParseResponse credentialSingleParse( - CredentialSingleParseRequest request) throws AuthleteApiException + CredentialSingleParseRequest request, Options options) throws AuthleteApiException { // Note that the /vci/single/parse API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1522,13 +1619,14 @@ public CredentialSingleParseResponse credentialSingleParse( return executeApiCall( new ServicePostApiCaller( CredentialSingleParseResponse.class, request, - VCI_SINGLE_PARSE_API_PATH)); + VCI_SINGLE_PARSE_API_PATH) + .setOptions(options)); } @Override public CredentialSingleIssueResponse credentialSingleIssue( - CredentialSingleIssueRequest request) throws AuthleteApiException + CredentialSingleIssueRequest request, Options options) throws AuthleteApiException { // Note that the /vci/single/issue API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1536,13 +1634,14 @@ public CredentialSingleIssueResponse credentialSingleIssue( return executeApiCall( new ServicePostApiCaller( CredentialSingleIssueResponse.class, request, - VCI_SINGLE_ISSUE_API_PATH)); + VCI_SINGLE_ISSUE_API_PATH) + .setOptions(options)); } @Override public CredentialBatchParseResponse credentialBatchParse( - CredentialBatchParseRequest request) throws AuthleteApiException + CredentialBatchParseRequest request, Options options) throws AuthleteApiException { // Note that the /vci/batch/parse API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1550,13 +1649,14 @@ public CredentialBatchParseResponse credentialBatchParse( return executeApiCall( new ServicePostApiCaller( CredentialBatchParseResponse.class, request, - VCI_BATCH_PARSE_API_PATH)); + VCI_BATCH_PARSE_API_PATH) + .setOptions(options)); } @Override public CredentialBatchIssueResponse credentialBatchIssue( - CredentialBatchIssueRequest request) throws AuthleteApiException + CredentialBatchIssueRequest request, Options options) throws AuthleteApiException { // Note that the /vci/batch/issue API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1564,13 +1664,14 @@ public CredentialBatchIssueResponse credentialBatchIssue( return executeApiCall( new ServicePostApiCaller( CredentialBatchIssueResponse.class, request, - VCI_BATCH_ISSUE_API_PATH)); + VCI_BATCH_ISSUE_API_PATH) + .setOptions(options)); } @Override public CredentialDeferredParseResponse credentialDeferredParse( - CredentialDeferredParseRequest request) throws AuthleteApiException + CredentialDeferredParseRequest request, Options options) throws AuthleteApiException { // Note that the /vci/deferred/parse API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1578,13 +1679,14 @@ public CredentialDeferredParseResponse credentialDeferredParse( return executeApiCall( new ServicePostApiCaller( CredentialDeferredParseResponse.class, request, - VCI_DEFERRED_PARSE_API_PATH)); + VCI_DEFERRED_PARSE_API_PATH) + .setOptions(options)); } @Override public CredentialDeferredIssueResponse credentialDeferredIssue( - CredentialDeferredIssueRequest request) throws AuthleteApiException + CredentialDeferredIssueRequest request, Options options) throws AuthleteApiException { // Note that the /vci/deferred/issue API is not available in Authlete 2.x, // so the executeApiCall below will throw an exception. @@ -1592,24 +1694,26 @@ public CredentialDeferredIssueResponse credentialDeferredIssue( return executeApiCall( new ServicePostApiCaller( CredentialDeferredIssueResponse.class, request, - VCI_DEFERRED_ISSUE_API_PATH)); + VCI_DEFERRED_ISSUE_API_PATH) + .setOptions(options)); } @Override public IDTokenReissueResponse idTokenReissue( - IDTokenReissueRequest request) throws AuthleteApiException + IDTokenReissueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new ServicePostApiCaller( IDTokenReissueResponse.class, request, - ID_TOKEN_REISSUE_API_PATH)); + ID_TOKEN_REISSUE_API_PATH) + .setOptions(options)); } @Override public AuthorizationTicketInfoResponse authorizationTicketInfo( - AuthorizationTicketInfoRequest request) throws AuthleteApiException + AuthorizationTicketInfoRequest request, Options options) throws AuthleteApiException { // Note that the /auth/authorization/ticket/info API is not available // in Authlete 2.x, so the executeApiCall below will throw an exception. @@ -1617,13 +1721,14 @@ public AuthorizationTicketInfoResponse authorizationTicketInfo( return executeApiCall( new ServicePostApiCaller( AuthorizationTicketInfoResponse.class, request, - AUTH_AUTHORIZATION_TICKET_INFO_API_PATH)); + AUTH_AUTHORIZATION_TICKET_INFO_API_PATH) + .setOptions(options)); } @Override public AuthorizationTicketUpdateResponse authorizationTicketUpdate( - AuthorizationTicketUpdateRequest request) throws AuthleteApiException + AuthorizationTicketUpdateRequest request, Options options) throws AuthleteApiException { // Note that the /auth/authorization/ticket/update API is not available // in Authlete 2.x, so the executeApiCall below will throw an exception. @@ -1631,13 +1736,14 @@ public AuthorizationTicketUpdateResponse authorizationTicketUpdate( return executeApiCall( new ServicePostApiCaller( AuthorizationTicketUpdateResponse.class, request, - AUTH_AUTHORIZATION_TICKET_UPDATE_API_PATH)); + AUTH_AUTHORIZATION_TICKET_UPDATE_API_PATH) + .setOptions(options)); } @Override public TokenCreateBatchResponse tokenCreateBatch( - TokenCreateRequest[] tokenCreateRequests, boolean dryRun) throws AuthleteApiException + TokenCreateRequest[] tokenCreateRequests, boolean dryRun, Options options) throws AuthleteApiException { throw new AuthleteApiException( "This method can't be invoked since the corresponding API is not supported."); @@ -1646,7 +1752,7 @@ public TokenCreateBatchResponse tokenCreateBatch( @Override public TokenCreateBatchStatusResponse getTokenCreateBatchStatus( - String requestId) throws AuthleteApiException + String requestId, Options options) throws AuthleteApiException { throw new AuthleteApiException( "This method can't be invoked since the corresponding API is not supported."); diff --git a/src/main/java/com/authlete/jakarta/api/AuthleteApiImplV3.java b/src/main/java/com/authlete/jakarta/api/AuthleteApiImplV3.java index 0972cce..3628c91 100644 --- a/src/main/java/com/authlete/jakarta/api/AuthleteApiImplV3.java +++ b/src/main/java/com/authlete/jakarta/api/AuthleteApiImplV3.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2023 Authlete, Inc. + * Copyright (C) 2014-2024 Authlete, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,12 @@ import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; import java.util.LinkedHashMap; import java.util.Map; +import jakarta.ws.rs.client.Invocation.Builder; import jakarta.ws.rs.client.WebTarget; import jakarta.ws.rs.core.GenericType; import com.authlete.common.api.AuthleteApi; import com.authlete.common.api.AuthleteApiException; +import com.authlete.common.api.Options; import com.authlete.common.conf.AuthleteApiVersion; import com.authlete.common.conf.AuthleteConfiguration; import com.authlete.common.dto.*; @@ -181,21 +183,21 @@ private String createCredentials(AuthleteConfiguration configuration) private TResponse callGetApi( - String path, Class responseClass, Map params) + String path, Class responseClass, Map params, Options options) { - return callGetApi(mAuth, path, responseClass, params); + return callGetApi(mAuth, path, responseClass, params, options); } - private Void callDeleteApi(String path) + private Void callDeleteApi(String path, Options options) { - return callDeleteApi(mAuth, path); + return callDeleteApi(mAuth, path, options); } - private TResponse callPostApi(String path, Object request, Class responseClass) + private TResponse callPostApi(String path, Object request, Class responseClass, Options options) { - return callPostApi(mAuth, path, request, responseClass); + return callPostApi(mAuth, path, request, responseClass, options); } @@ -205,6 +207,7 @@ private static abstract class ApiCaller implements AuthleteApiCall mResponseClass; protected final Map mParams = new LinkedHashMap<>(); + protected Options mOptions; ApiCaller(Class responseClass, Object request, String path) @@ -227,6 +230,14 @@ public ApiCaller addParam(String name, Object... values) return this; } + + + public ApiCaller setOptions(Options options) + { + mOptions = options; + + return this; + } } @@ -247,7 +258,7 @@ private class DeleteApiCaller extends ApiCaller @Override public Void call() { - return callDeleteApi(mPath); + return callDeleteApi(mPath, mOptions); } } @@ -269,7 +280,7 @@ private class GetApiCaller extends ApiCaller @Override public TResponse call() { - return callGetApi(mPath, mResponseClass, mParams); + return callGetApi(mPath, mResponseClass, mParams, mOptions); } } @@ -291,7 +302,7 @@ private class PostApiCaller extends ApiCaller @Override public TResponse call() { - return callPostApi(mPath, mRequest, mResponseClass); + return callPostApi(mPath, mRequest, mResponseClass, mOptions); } } @@ -300,11 +311,12 @@ public TResponse call() * Call {@code /api/{serviceId}/auth/authorization} API. */ @Override - public AuthorizationResponse authorization(AuthorizationRequest request) throws AuthleteApiException + public AuthorizationResponse authorization(AuthorizationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - AuthorizationResponse.class, request, AUTH_AUTHORIZATION_API_PATH, mServiceId)); + AuthorizationResponse.class, request, AUTH_AUTHORIZATION_API_PATH, mServiceId) + .setOptions(options)); } @@ -312,11 +324,12 @@ public AuthorizationResponse authorization(AuthorizationRequest request) throws * Call {@code /api/{serviceId}/auth/authorization/fail} API. */ @Override - public AuthorizationFailResponse authorizationFail(AuthorizationFailRequest request) throws AuthleteApiException + public AuthorizationFailResponse authorizationFail(AuthorizationFailRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - AuthorizationFailResponse.class, request, AUTH_AUTHORIZATION_FAIL_API_PATH, mServiceId)); + AuthorizationFailResponse.class, request, AUTH_AUTHORIZATION_FAIL_API_PATH, mServiceId) + .setOptions(options)); } @@ -324,11 +337,12 @@ public AuthorizationFailResponse authorizationFail(AuthorizationFailRequest requ * Call {@code /api/{serviceId}/auth/authorization/issue} API. */ @Override - public AuthorizationIssueResponse authorizationIssue(AuthorizationIssueRequest request) throws AuthleteApiException + public AuthorizationIssueResponse authorizationIssue(AuthorizationIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - AuthorizationIssueResponse.class, request, AUTH_AUTHORIZATION_ISSUE_API_PATH, mServiceId)); + AuthorizationIssueResponse.class, request, AUTH_AUTHORIZATION_ISSUE_API_PATH, mServiceId) + .setOptions(options)); } @@ -336,11 +350,12 @@ public AuthorizationIssueResponse authorizationIssue(AuthorizationIssueRequest r * Call {@code /api/{serviceId}/auth/token} API. */ @Override - public TokenResponse token(TokenRequest request) throws AuthleteApiException + public TokenResponse token(TokenRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - TokenResponse.class, request, AUTH_TOKEN_API_PATH, mServiceId)); + TokenResponse.class, request, AUTH_TOKEN_API_PATH, mServiceId) + .setOptions(options)); } @@ -348,11 +363,12 @@ public TokenResponse token(TokenRequest request) throws AuthleteApiException * Call {@code /api/{serviceId}/auth/token/create} API. */ @Override - public TokenCreateResponse tokenCreate(TokenCreateRequest request) throws AuthleteApiException + public TokenCreateResponse tokenCreate(TokenCreateRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - TokenCreateResponse.class, request, AUTH_TOKEN_CREATE_API_PATH, mServiceId)); + TokenCreateResponse.class, request, AUTH_TOKEN_CREATE_API_PATH, mServiceId) + .setOptions(options)); } @@ -360,11 +376,12 @@ public TokenCreateResponse tokenCreate(TokenCreateRequest request) throws Authle * Call /api/{serviceId}/auth/token/delete/{token} API. */ @Override - public void tokenDelete(String token) throws AuthleteApiException + public void tokenDelete(String token, Options options) throws AuthleteApiException { executeApiCall( new DeleteApiCaller( - AUTH_TOKEN_DELETE_API_PATH, mServiceId, token)); + AUTH_TOKEN_DELETE_API_PATH, mServiceId, token) + .setOptions(options)); } @@ -372,11 +389,12 @@ public void tokenDelete(String token) throws AuthleteApiException * Call {@code /api/{serviceId}/auth/token/fail} API. */ @Override - public TokenFailResponse tokenFail(TokenFailRequest request) throws AuthleteApiException + public TokenFailResponse tokenFail(TokenFailRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - TokenFailResponse.class, request, AUTH_TOKEN_FAIL_API_PATH, mServiceId)); + TokenFailResponse.class, request, AUTH_TOKEN_FAIL_API_PATH, mServiceId) + .setOptions(options)); } @@ -384,11 +402,12 @@ public TokenFailResponse tokenFail(TokenFailRequest request) throws AuthleteApiE * Call {@code /api/{serviceId}/auth/token/issue} API. */ @Override - public TokenIssueResponse tokenIssue(TokenIssueRequest request) throws AuthleteApiException + public TokenIssueResponse tokenIssue(TokenIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - TokenIssueResponse.class, request, AUTH_TOKEN_ISSUE_API_PATH, mServiceId)); + TokenIssueResponse.class, request, AUTH_TOKEN_ISSUE_API_PATH, mServiceId) + .setOptions(options)); } @@ -396,11 +415,12 @@ public TokenIssueResponse tokenIssue(TokenIssueRequest request) throws AuthleteA * Call {@code /api/{serviceId}/auth/token/revoke} API. */ @Override - public TokenRevokeResponse tokenRevoke(TokenRevokeRequest request) throws AuthleteApiException + public TokenRevokeResponse tokenRevoke(TokenRevokeRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - TokenRevokeResponse.class, request, AUTH_TOKEN_REVOKE_API_PATH, mServiceId)); + TokenRevokeResponse.class, request, AUTH_TOKEN_REVOKE_API_PATH, mServiceId) + .setOptions(options)); } @@ -408,87 +428,90 @@ public TokenRevokeResponse tokenRevoke(TokenRevokeRequest request) throws Authle * Call {@code /api/{serviceId}/auth/token/update} API. */ @Override - public TokenUpdateResponse tokenUpdate(TokenUpdateRequest request) throws AuthleteApiException + public TokenUpdateResponse tokenUpdate(TokenUpdateRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - TokenUpdateResponse.class, request, AUTH_TOKEN_UPDATE_API_PATH, mServiceId)); + TokenUpdateResponse.class, request, AUTH_TOKEN_UPDATE_API_PATH, mServiceId) + .setOptions(options)); } @Override - public TokenListResponse getTokenList() throws AuthleteApiException + public TokenListResponse getTokenList(Options options) throws AuthleteApiException { - return getTokenList(null, null, 0, 0, false, TokenStatus.ALL); + return getTokenList(null, null, 0, 0, false, TokenStatus.ALL, options); } @Override - public TokenListResponse getTokenList(TokenStatus tokenStatus) throws AuthleteApiException + public TokenListResponse getTokenList(TokenStatus tokenStatus, Options options) throws AuthleteApiException { - return getTokenList(null, null, 0, 0, false, tokenStatus); + return getTokenList(null, null, 0, 0, false, tokenStatus, options); } @Override - public TokenListResponse getTokenList(String clientIdentifier, String subject) throws AuthleteApiException + public TokenListResponse getTokenList(String clientIdentifier, String subject, Options options) throws AuthleteApiException { - return getTokenList(clientIdentifier, subject, 0, 0, false, TokenStatus.ALL); + return getTokenList(clientIdentifier, subject, 0, 0, false, TokenStatus.ALL, options); } @Override - public TokenListResponse getTokenList(String clientIdentifier, String subject, TokenStatus tokenStatus) throws AuthleteApiException + public TokenListResponse getTokenList(String clientIdentifier, String subject, TokenStatus tokenStatus, Options options) throws AuthleteApiException { - return getTokenList(clientIdentifier, subject, 0, 0, false, tokenStatus); + return getTokenList(clientIdentifier, subject, 0, 0, false, tokenStatus, options); } @Override - public TokenListResponse getTokenList(int start, int end) throws AuthleteApiException + public TokenListResponse getTokenList(int start, int end, Options options) throws AuthleteApiException { - return getTokenList(null, null, start, end, true, TokenStatus.ALL); + return getTokenList(null, null, start, end, true, TokenStatus.ALL, options); } @Override - public TokenListResponse getTokenList(int start, int end, TokenStatus tokenStatus) throws AuthleteApiException + public TokenListResponse getTokenList(int start, int end, TokenStatus tokenStatus, Options options) throws AuthleteApiException { - return getTokenList(null, null, start, end, true, tokenStatus); + return getTokenList(null, null, start, end, true, tokenStatus, options); } @Override - public TokenListResponse getTokenList(String clientIdentifier, String subject, int start, int end) throws AuthleteApiException + public TokenListResponse getTokenList(String clientIdentifier, String subject, int start, int end, Options options) throws AuthleteApiException { - return getTokenList(clientIdentifier, subject, start, end, true, TokenStatus.ALL); + return getTokenList(clientIdentifier, subject, start, end, true, TokenStatus.ALL, options); } @Override - public TokenListResponse getTokenList(String clientIdentifier, String subject, int start, int end, TokenStatus tokenStatus) throws AuthleteApiException + public TokenListResponse getTokenList(String clientIdentifier, String subject, int start, int end, TokenStatus tokenStatus, Options options) throws AuthleteApiException { - return getTokenList(clientIdentifier, subject, start, end, true, tokenStatus); + return getTokenList(clientIdentifier, subject, start, end, true, tokenStatus, options); } private TokenListResponse getTokenList( final String clientIdentifier, final String subject, - final int start, final int end, final boolean rangeGiven, TokenStatus tokenStatus) throws AuthleteApiException + final int start, final int end, final boolean rangeGiven, TokenStatus tokenStatus, + Options options) throws AuthleteApiException { return executeApiCall(new AuthleteApiCall() { @Override public TokenListResponse call() { - return callGetTokenList(clientIdentifier, subject, start, end, rangeGiven, tokenStatus); + return callGetTokenList(clientIdentifier, subject, start, end, rangeGiven, tokenStatus, options); } }); } private TokenListResponse callGetTokenList( - String clientIdentifier, String subject, int start, int end, boolean rangeGiven, TokenStatus tokenStatus) + String clientIdentifier, String subject, int start, int end, boolean rangeGiven, + TokenStatus tokenStatus, Options options) { String path = String.format(AUTH_TOKEN_GET_LIST_API_PATH, mServiceId); @@ -512,10 +535,13 @@ private TokenListResponse callGetTokenList( target = target.queryParam("tokenStatus", tokenStatus.toString()); // FIXME: it feels weird that this is in its own space instead of the caller classes, is there a reason for that? - return wrapWithDpop(target + Builder builder = wrapWithDpop(target .request(APPLICATION_JSON_TYPE), AUTH_TOKEN_GET_LIST_API_PATH, "GET") - .header(AUTHORIZATION, mAuth) - .get(TokenListResponse.class); + .header(AUTHORIZATION, mAuth); + + setCustomRequestHeaders(builder, options); + + return builder.get(TokenListResponse.class); } @@ -523,11 +549,12 @@ private TokenListResponse callGetTokenList( * Call {@code /api/{serviceId}/auth/revocation} API. */ @Override - public RevocationResponse revocation(RevocationRequest request) throws AuthleteApiException + public RevocationResponse revocation(RevocationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - RevocationResponse.class, request, AUTH_REVOCATION_API_PATH, mServiceId)); + RevocationResponse.class, request, AUTH_REVOCATION_API_PATH, mServiceId) + .setOptions(options)); } @@ -535,11 +562,12 @@ public RevocationResponse revocation(RevocationRequest request) throws AuthleteA * Call {@code /api/{serviceId}/auth/userinfo} API. */ @Override - public UserInfoResponse userinfo(UserInfoRequest request) throws AuthleteApiException + public UserInfoResponse userinfo(UserInfoRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - UserInfoResponse.class, request, AUTH_USERINFO_API_PATH, mServiceId)); + UserInfoResponse.class, request, AUTH_USERINFO_API_PATH, mServiceId) + .setOptions(options)); } @@ -547,11 +575,12 @@ public UserInfoResponse userinfo(UserInfoRequest request) throws AuthleteApiExce * Call {@code /api/{serviceId}/auth/userinfo/issue} API. */ @Override - public UserInfoIssueResponse userinfoIssue(UserInfoIssueRequest request) throws AuthleteApiException + public UserInfoIssueResponse userinfoIssue(UserInfoIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - UserInfoIssueResponse.class, request, AUTH_USERINFO_ISSUE_API_PATH, mServiceId)); + UserInfoIssueResponse.class, request, AUTH_USERINFO_ISSUE_API_PATH, mServiceId) + .setOptions(options)); } @@ -559,11 +588,12 @@ public UserInfoIssueResponse userinfoIssue(UserInfoIssueRequest request) throws * Call {@code /api/{serviceId}/auth/introspection} API. */ @Override - public IntrospectionResponse introspection(IntrospectionRequest request) throws AuthleteApiException + public IntrospectionResponse introspection(IntrospectionRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - IntrospectionResponse.class, request, AUTH_INTROSPECTION_API_PATH, mServiceId)); + IntrospectionResponse.class, request, AUTH_INTROSPECTION_API_PATH, mServiceId) + .setOptions(options)); } @@ -572,11 +602,12 @@ public IntrospectionResponse introspection(IntrospectionRequest request) throws */ @Override public StandardIntrospectionResponse standardIntrospection( - StandardIntrospectionRequest request) throws AuthleteApiException + StandardIntrospectionRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - StandardIntrospectionResponse.class, request, AUTH_INTROSPECTION_STANDARD_API_PATH, mServiceId)); + StandardIntrospectionResponse.class, request, AUTH_INTROSPECTION_STANDARD_API_PATH, mServiceId) + .setOptions(options)); } @@ -584,11 +615,12 @@ public StandardIntrospectionResponse standardIntrospection( * Call {@code /api/service/create} API. */ @Override - public Service createService(Service service) throws AuthleteApiException + public Service createService(Service service, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - Service.class, service, SERVICE_CREATE_API_PATH)); + Service.class, service, SERVICE_CREATE_API_PATH) + .setOptions(options)); } @@ -607,11 +639,11 @@ public Service createServie(Service service) throws AuthleteApiException * Call /api/{serviceId}/service/delete/ API. */ @Override - public void deleteService(long apiKey) throws AuthleteApiException + public void deleteService(long apiKey, Options options) throws AuthleteApiException { executeApiCall( - new DeleteApiCaller( - SERVICE_DELETE_API_PATH, apiKey)); + new DeleteApiCaller(SERVICE_DELETE_API_PATH, apiKey) + .setOptions(options)); } @@ -619,11 +651,12 @@ public void deleteService(long apiKey) throws AuthleteApiException * Call /api/{serviceId}/service/get API. */ @Override - public Service getService(long apiKey) throws AuthleteApiException + public Service getService(long apiKey, Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( - Service.class, SERVICE_GET_API_PATH, apiKey)); + Service.class, SERVICE_GET_API_PATH, apiKey) + .setOptions(options)); } @@ -631,28 +664,28 @@ public Service getService(long apiKey) throws AuthleteApiException * Call {@code /api/service/get/list} API. */ @Override - public ServiceListResponse getServiceList() throws AuthleteApiException + public ServiceListResponse getServiceList(Options options) throws AuthleteApiException { - return getServiceList(0, 0, false); + return getServiceList(0, 0, false, options); } @Override - public ServiceListResponse getServiceList(int start, int end) throws AuthleteApiException + public ServiceListResponse getServiceList(int start, int end, Options options) throws AuthleteApiException { - return getServiceList(start, end, true); + return getServiceList(start, end, true, options); } private ServiceListResponse getServiceList( - final int start, final int end, final boolean rangeGiven) throws AuthleteApiException + final int start, final int end, final boolean rangeGiven, Options options) throws AuthleteApiException { return executeApiCall(new AuthleteApiCall() { @Override public ServiceListResponse call() { - return callGetServiceList(start, end, rangeGiven); + return callGetServiceList(start, end, rangeGiven, options); } }); } @@ -661,7 +694,7 @@ public ServiceListResponse call() /** * Call /service/get/list. */ - private ServiceListResponse callGetServiceList(int start, int end, boolean rangeGiven) + private ServiceListResponse callGetServiceList(int start, int end, boolean rangeGiven, Options options) { WebTarget target = getTarget().path(SERVICE_GET_LIST_API_PATH); @@ -671,10 +704,13 @@ private ServiceListResponse callGetServiceList(int start, int end, boolean range } // FIXME: it feels strange that this doesn't use the caller structures above - return wrapWithDpop(target + Builder builder = wrapWithDpop(target .request(APPLICATION_JSON_TYPE), SERVICE_GET_LIST_API_PATH, "GET") - .header(AUTHORIZATION, mAuth) - .get(ServiceListResponse.class); + .header(AUTHORIZATION, mAuth); + + setCustomRequestHeaders(builder, options); + + return builder.get(ServiceListResponse.class); } @@ -682,11 +718,12 @@ private ServiceListResponse callGetServiceList(int start, int end, boolean range * Call /api/{serviceId}/service/update/ API. */ @Override - public Service updateService(final Service service) throws AuthleteApiException + public Service updateService(final Service service, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - Service.class, service, SERVICE_UPDATE_API_PATH, service.getApiKey())); + Service.class, service, SERVICE_UPDATE_API_PATH, service.getApiKey()) + .setOptions(options)); } @@ -694,11 +731,12 @@ public Service updateService(final Service service) throws AuthleteApiException * Call {@code /api/{serviceId}/service/jwks/get} API */ @Override - public String getServiceJwks() throws AuthleteApiException + public String getServiceJwks(Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( - String.class, SERVICE_JWKS_GET_API_PATH, mServiceId)); + String.class, SERVICE_JWKS_GET_API_PATH, mServiceId) + .setOptions(options)); } @@ -706,13 +744,14 @@ public String getServiceJwks() throws AuthleteApiException * Call {@code /api/{serviceId}/service/jwks/get} API */ @Override - public String getServiceJwks(boolean pretty, boolean includePrivateKeys) throws AuthleteApiException + public String getServiceJwks(boolean pretty, boolean includePrivateKeys, Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( String.class, SERVICE_JWKS_GET_API_PATH, mServiceId) .addParam("pretty", pretty) - .addParam("includePrivateKeys", includePrivateKeys)); + .addParam("includePrivateKeys", includePrivateKeys) + .setOptions(options)); } @@ -720,11 +759,12 @@ public String getServiceJwks(boolean pretty, boolean includePrivateKeys) throws * Call {@code /api/{serviceId}/service/configuration} API */ @Override - public String getServiceConfiguration() throws AuthleteApiException + public String getServiceConfiguration(Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( - String.class, SERVICE_CONFIGURATION_API_PATH, mServiceId)); + String.class, SERVICE_CONFIGURATION_API_PATH, mServiceId) + .setOptions(options)); } @@ -732,12 +772,13 @@ public String getServiceConfiguration() throws AuthleteApiException * Call {@code /api/{serviceId}/service/configuration} API */ @Override - public String getServiceConfiguration(boolean pretty) throws AuthleteApiException + public String getServiceConfiguration(boolean pretty, Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( String.class, SERVICE_CONFIGURATION_API_PATH, mServiceId) - .addParam("pretty", pretty)); + .addParam("pretty", pretty) + .setOptions(options)); } @@ -745,11 +786,12 @@ public String getServiceConfiguration(boolean pretty) throws AuthleteApiExceptio * Call {@code /api/{serviceId}/service/configuration} API */ @Override - public String getServiceConfiguration(ServiceConfigurationRequest request) throws AuthleteApiException + public String getServiceConfiguration(ServiceConfigurationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - String.class, request, SERVICE_CONFIGURATION_API_PATH, mServiceId)); + String.class, request, SERVICE_CONFIGURATION_API_PATH, mServiceId) + .setOptions(options)); } @@ -757,11 +799,12 @@ public String getServiceConfiguration(ServiceConfigurationRequest request) throw * Call {@code /api/{serviceId}/client/create} API. */ @Override - public Client createClient(Client client) throws AuthleteApiException + public Client createClient(Client client, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - Client.class, client, CLIENT_CREATE_API_PATH, mServiceId)); + Client.class, client, CLIENT_CREATE_API_PATH, mServiceId) + .setOptions(options)); } @@ -769,11 +812,12 @@ public Client createClient(Client client) throws AuthleteApiException * Call {@code /api/{serviceId}/client/registration} API. */ @Override - public ClientRegistrationResponse dynamicClientRegister(ClientRegistrationRequest request) throws AuthleteApiException + public ClientRegistrationResponse dynamicClientRegister(ClientRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_API_PATH, mServiceId)); + ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_API_PATH, mServiceId) + .setOptions(options)); } @@ -781,11 +825,12 @@ public ClientRegistrationResponse dynamicClientRegister(ClientRegistrationReques * Call {@code /api/{serviceId}/client/registration/get} API. */ @Override - public ClientRegistrationResponse dynamicClientGet(ClientRegistrationRequest request) throws AuthleteApiException + public ClientRegistrationResponse dynamicClientGet(ClientRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_GET_API_PATH, mServiceId)); + ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_GET_API_PATH, mServiceId) + .setOptions(options)); } @@ -793,11 +838,12 @@ public ClientRegistrationResponse dynamicClientGet(ClientRegistrationRequest req * Call {@code /api/{serviceId}/client/registration/update} API. */ @Override - public ClientRegistrationResponse dynamicClientUpdate(ClientRegistrationRequest request) throws AuthleteApiException + public ClientRegistrationResponse dynamicClientUpdate(ClientRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_UPDATE_API_PATH, mServiceId)); + ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_UPDATE_API_PATH, mServiceId) + .setOptions(options)); } @@ -805,11 +851,12 @@ public ClientRegistrationResponse dynamicClientUpdate(ClientRegistrationRequest * Call {@code /api/{serviceId}/client/registration/delete} API. */ @Override - public ClientRegistrationResponse dynamicClientDelete(ClientRegistrationRequest request) throws AuthleteApiException + public ClientRegistrationResponse dynamicClientDelete(ClientRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_DELETE_API_PATH, mServiceId)); + ClientRegistrationResponse.class, request, CLIENT_REGISTRATION_DELETE_API_PATH, mServiceId) + .setOptions(options)); } @@ -817,9 +864,9 @@ public ClientRegistrationResponse dynamicClientDelete(ClientRegistrationRequest * Call /api/{serviceId}/client/delete/{clientId} API. */ @Override - public void deleteClient(long clientId) throws AuthleteApiException + public void deleteClient(long clientId, Options options) throws AuthleteApiException { - deleteClient(String.valueOf(clientId)); + deleteClient(String.valueOf(clientId), options); } @@ -827,11 +874,12 @@ public void deleteClient(long clientId) throws AuthleteApiException * Call /api/{serviceId}/client/delete/{clientId} API. */ @Override - public void deleteClient(String clientId) throws AuthleteApiException + public void deleteClient(String clientId, Options options) throws AuthleteApiException { executeApiCall( new DeleteApiCaller( - CLIENT_DELETE_API_PATH, mServiceId, clientId)); + CLIENT_DELETE_API_PATH, mServiceId, clientId) + .setOptions(options)); } @@ -839,9 +887,9 @@ public void deleteClient(String clientId) throws AuthleteApiException * Call /api/{serviceId}/client/get/{clientId} API. */ @Override - public Client getClient(long clientId) throws AuthleteApiException + public Client getClient(long clientId, Options options) throws AuthleteApiException { - return getClient(String.valueOf(clientId)); + return getClient(String.valueOf(clientId), options); } @@ -849,11 +897,12 @@ public Client getClient(long clientId) throws AuthleteApiException * Call /api/{serviceId}/client/get/{clientId} API. */ @Override - public Client getClient(String clientId) throws AuthleteApiException + public Client getClient(String clientId, Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( - Client.class, CLIENT_GET_API_PATH, mServiceId, clientId)); + Client.class, CLIENT_GET_API_PATH, mServiceId, clientId) + .setOptions(options)); } @@ -861,48 +910,48 @@ public Client getClient(String clientId) throws AuthleteApiException * Call {@code /api/{serviceId}/client/get/list} API. */ @Override - public ClientListResponse getClientList() throws AuthleteApiException + public ClientListResponse getClientList(Options options) throws AuthleteApiException { - return getClientList(null, 0, 0, false); + return getClientList(null, 0, 0, false, options); } @Override - public ClientListResponse getClientList(String developer) throws AuthleteApiException + public ClientListResponse getClientList(String developer, Options options) throws AuthleteApiException { - return getClientList(developer, 0, 0, false); + return getClientList(developer, 0, 0, false, options); } @Override - public ClientListResponse getClientList(int start, int end) throws AuthleteApiException + public ClientListResponse getClientList(int start, int end, Options options) throws AuthleteApiException { - return getClientList(null, start, end, true); + return getClientList(null, start, end, true, options); } @Override - public ClientListResponse getClientList(String developer, int start, int end) throws AuthleteApiException + public ClientListResponse getClientList(String developer, int start, int end, Options options) throws AuthleteApiException { - return getClientList(developer, start, end, true); + return getClientList(developer, start, end, true, options); } private ClientListResponse getClientList( - final String developer, final int start, final int end, final boolean rangeGiven) throws AuthleteApiException + final String developer, final int start, final int end, final boolean rangeGiven, Options options) throws AuthleteApiException { return executeApiCall(new AuthleteApiCall() { @Override public ClientListResponse call() { - return callGetClientList(developer, start, end, rangeGiven); + return callGetClientList(developer, start, end, rangeGiven, options); } }); } - private ClientListResponse callGetClientList(String developer, int start, int end, boolean rangeGiven) + private ClientListResponse callGetClientList(String developer, int start, int end, boolean rangeGiven, Options options) { String path = String.format(CLIENT_GET_LIST_API_PATH, mServiceId); @@ -919,10 +968,13 @@ private ClientListResponse callGetClientList(String developer, int start, int en } // FIXME: this seems weird that it's not the same caller structure as others - return wrapWithDpop(target + Builder builder = wrapWithDpop(target .request(APPLICATION_JSON_TYPE), CLIENT_GET_LIST_API_PATH, "GET") - .header(AUTHORIZATION, mAuth) - .get(ClientListResponse.class); + .header(AUTHORIZATION, mAuth); + + setCustomRequestHeaders(builder, options); + + return builder.get(ClientListResponse.class); } @@ -930,25 +982,26 @@ private ClientListResponse callGetClientList(String developer, int start, int en * Call /api/{serviceId}/client/update/{clientId} API. */ @Override - public Client updateClient(Client client) throws AuthleteApiException + public Client updateClient(Client client, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - Client.class, client, CLIENT_UPDATE_API_PATH, mServiceId, client.getClientId())); + Client.class, client, CLIENT_UPDATE_API_PATH, mServiceId, client.getClientId()) + .setOptions(options)); } - /** * Call /api/{serviceId}/client/extension/requestable_scopes/get/{clientId} API. */ @Override - public String[] getRequestableScopes(long clientId) throws AuthleteApiException + public String[] getRequestableScopes(long clientId, Options options) throws AuthleteApiException { // Call the API. RequestableScopes response = executeApiCall( new GetApiCaller( - RequestableScopes.class, REQUESTABLE_SCOPES_GET_API_PATH, mServiceId, clientId)); + RequestableScopes.class, REQUESTABLE_SCOPES_GET_API_PATH, mServiceId, clientId) + .setOptions(options)); if (response != null) { @@ -963,7 +1016,7 @@ public String[] getRequestableScopes(long clientId) throws AuthleteApiException @Override - public String[] setRequestableScopes(long clientId, String[] scopes) throws AuthleteApiException + public String[] setRequestableScopes(long clientId, String[] scopes, Options options) throws AuthleteApiException { // Prepare a request body. RequestableScopes request = new RequestableScopes().setRequestableScopes(scopes); @@ -971,7 +1024,8 @@ public String[] setRequestableScopes(long clientId, String[] scopes) throws Auth // Call the API. RequestableScopes response = executeApiCall( new PostApiCaller( - RequestableScopes.class, request, REQUESTABLE_SCOPES_UPDATE_API_PATH, mServiceId, clientId)); + RequestableScopes.class, request, REQUESTABLE_SCOPES_UPDATE_API_PATH, mServiceId, clientId) + .setOptions(options)); if (response != null) { @@ -989,16 +1043,17 @@ public String[] setRequestableScopes(long clientId, String[] scopes) throws Auth * Call /api/{serviceId}/client/extension/requestable_scopes/delete/{clientId} API. */ @Override - public void deleteRequestableScopes(long clientId) throws AuthleteApiException + public void deleteRequestableScopes(long clientId, Options options) throws AuthleteApiException { executeApiCall( new DeleteApiCaller( - REQUESTABLE_SCOPES_DELETE_API_PATH, mServiceId, clientId)); + REQUESTABLE_SCOPES_DELETE_API_PATH, mServiceId, clientId) + .setOptions(options)); } @Override - public GrantedScopesGetResponse getGrantedScopes(long clientId, String subject) + public GrantedScopesGetResponse getGrantedScopes(long clientId, String subject, Options options) { // Prepare a request body. GrantedScopesRequest request = new GrantedScopesRequest(subject); @@ -1006,19 +1061,21 @@ public GrantedScopesGetResponse getGrantedScopes(long clientId, String subject) // Call the API. return executeApiCall( new PostApiCaller( - GrantedScopesGetResponse.class, request, GRANTED_SCOPES_GET_API_PATH, mServiceId, clientId)); + GrantedScopesGetResponse.class, request, GRANTED_SCOPES_GET_API_PATH, mServiceId, clientId) + .setOptions(options)); } @Override - public void deleteGrantedScopes(long clientId, String subject) + public void deleteGrantedScopes(long clientId, String subject, Options options) { // Prepare a request body. GrantedScopesRequest request = new GrantedScopesRequest(subject); executeApiCall( new PostApiCaller( - ApiResponse.class, request, GRANTED_SCOPES_DELETE_API_PATH, mServiceId, clientId)); + ApiResponse.class, request, GRANTED_SCOPES_DELETE_API_PATH, mServiceId, clientId) + .setOptions(options)); } @@ -1049,61 +1106,68 @@ public void setSubject(String subject) @Override - public void deleteClientAuthorization(long clientId, String subject) throws AuthleteApiException + public void deleteClientAuthorization(long clientId, String subject, Options options) throws AuthleteApiException { // Prepare a request body. ClientAuthorizationDeleteRequest request = new ClientAuthorizationDeleteRequest(subject); executeApiCall( new PostApiCaller( - ApiResponse.class, request, CLIENT_AUTHORIZATION_DELETE_API_PATH, mServiceId, clientId)); + ApiResponse.class, request, CLIENT_AUTHORIZATION_DELETE_API_PATH, mServiceId, clientId) + .setOptions(options)); } @Override - public AuthorizedClientListResponse getClientAuthorizationList(ClientAuthorizationGetListRequest request) throws AuthleteApiException + public AuthorizedClientListResponse getClientAuthorizationList( + ClientAuthorizationGetListRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - AuthorizedClientListResponse.class, request, CLIENT_AUTHORIZATION_GET_LIST_API_PATH, mServiceId)); + AuthorizedClientListResponse.class, request, CLIENT_AUTHORIZATION_GET_LIST_API_PATH, mServiceId) + .setOptions(options)); } @Override - public void updateClientAuthorization(long clientId, ClientAuthorizationUpdateRequest request) throws AuthleteApiException + public void updateClientAuthorization( + long clientId, ClientAuthorizationUpdateRequest request, Options options) throws AuthleteApiException { executeApiCall( new PostApiCaller( - ApiResponse.class, request, CLIENT_AUTHORIZATION_UPDATE_API_PATH, mServiceId, clientId)); + ApiResponse.class, request, CLIENT_AUTHORIZATION_UPDATE_API_PATH, mServiceId, clientId) + .setOptions(options)); } @Override - public ClientSecretRefreshResponse refreshClientSecret(long clientId) throws AuthleteApiException + public ClientSecretRefreshResponse refreshClientSecret(long clientId, Options options) throws AuthleteApiException { - return refreshClientSecret(String.valueOf(clientId)); + return refreshClientSecret(String.valueOf(clientId), options); } @Override - public ClientSecretRefreshResponse refreshClientSecret(String clientIdentifier) throws AuthleteApiException + public ClientSecretRefreshResponse refreshClientSecret(String clientIdentifier, Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( ClientSecretRefreshResponse.class, - CLIENT_SECRET_REFRESH_API_PATH, mServiceId, clientIdentifier)); + CLIENT_SECRET_REFRESH_API_PATH, mServiceId, clientIdentifier) + .setOptions(options)); } @Override - public ClientSecretUpdateResponse updateClientSecret(long clientId, String clientSecret) throws AuthleteApiException + public ClientSecretUpdateResponse updateClientSecret(long clientId, String clientSecret, Options options) throws AuthleteApiException { - return updateClientSecret(String.valueOf(clientId), clientSecret); + return updateClientSecret(String.valueOf(clientId), clientSecret, options); } @Override - public ClientSecretUpdateResponse updateClientSecret(String clientIdentifier, String clientSecret) throws AuthleteApiException + public ClientSecretUpdateResponse updateClientSecret( + String clientIdentifier, String clientSecret, Options options) throws AuthleteApiException { // Prepare a request body. setClientSecret(String) method // throws IllegalArgumentException if the given client secret @@ -1114,7 +1178,8 @@ public ClientSecretUpdateResponse updateClientSecret(String clientIdentifier, St return executeApiCall( new PostApiCaller( ClientSecretUpdateResponse.class, request, - CLIENT_SECRET_UPDATE_API_PATH, mServiceId, clientIdentifier)); + CLIENT_SECRET_UPDATE_API_PATH, mServiceId, clientIdentifier) + .setOptions(options)); } @@ -1122,11 +1187,12 @@ public ClientSecretUpdateResponse updateClientSecret(String clientIdentifier, St * Call {@code /api/{serviceId}/jose/verify} API. */ @Override - public JoseVerifyResponse verifyJose(JoseVerifyRequest request) throws AuthleteApiException + public JoseVerifyResponse verifyJose(JoseVerifyRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - JoseVerifyResponse.class, request, JOSE_VERIFY_API_PATH, mServiceId)); + JoseVerifyResponse.class, request, JOSE_VERIFY_API_PATH, mServiceId) + .setOptions(options)); } @@ -1134,11 +1200,13 @@ public JoseVerifyResponse verifyJose(JoseVerifyRequest request) throws AuthleteA * Call {@code /api/{serviceId}/backchannel/authentication} API. */ @Override - public BackchannelAuthenticationResponse backchannelAuthentication(BackchannelAuthenticationRequest request) throws AuthleteApiException + public BackchannelAuthenticationResponse backchannelAuthentication( + BackchannelAuthenticationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - BackchannelAuthenticationResponse.class, request, BACKCHANNEL_AUTHENTICATION_API_PATH, mServiceId)); + BackchannelAuthenticationResponse.class, request, BACKCHANNEL_AUTHENTICATION_API_PATH, mServiceId) + .setOptions(options)); } @@ -1146,11 +1214,13 @@ public BackchannelAuthenticationResponse backchannelAuthentication(BackchannelAu * Call {@code /api/{serviceId}/backchannel/authentication/issue} API. */ @Override - public BackchannelAuthenticationIssueResponse backchannelAuthenticationIssue(BackchannelAuthenticationIssueRequest request) throws AuthleteApiException + public BackchannelAuthenticationIssueResponse backchannelAuthenticationIssue( + BackchannelAuthenticationIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - BackchannelAuthenticationIssueResponse.class, request, BACKCHANNEL_AUTHENTICATION_ISSUE_API_PATH, mServiceId)); + BackchannelAuthenticationIssueResponse.class, request, BACKCHANNEL_AUTHENTICATION_ISSUE_API_PATH, mServiceId) + .setOptions(options)); } @@ -1158,11 +1228,13 @@ public BackchannelAuthenticationIssueResponse backchannelAuthenticationIssue(Bac * Call {@code /api/{serviceId}/backchannel/authentication/fail} API. */ @Override - public BackchannelAuthenticationFailResponse backchannelAuthenticationFail(BackchannelAuthenticationFailRequest request) throws AuthleteApiException + public BackchannelAuthenticationFailResponse backchannelAuthenticationFail( + BackchannelAuthenticationFailRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - BackchannelAuthenticationFailResponse.class, request, BACKCHANNEL_AUTHENTICATION_FAIL_API_PATH, mServiceId)); + BackchannelAuthenticationFailResponse.class, request, BACKCHANNEL_AUTHENTICATION_FAIL_API_PATH, mServiceId) + .setOptions(options)); } @@ -1170,11 +1242,13 @@ public BackchannelAuthenticationFailResponse backchannelAuthenticationFail(Backc * Call {@code /api/{serviceId}/backchannel/authentication/complete} API. */ @Override - public BackchannelAuthenticationCompleteResponse backchannelAuthenticationComplete(BackchannelAuthenticationCompleteRequest request) throws AuthleteApiException + public BackchannelAuthenticationCompleteResponse backchannelAuthenticationComplete( + BackchannelAuthenticationCompleteRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - BackchannelAuthenticationCompleteResponse.class, request, BACKCHANNEL_AUTHENTICATION_COMPLETE_API_PATH, mServiceId)); + BackchannelAuthenticationCompleteResponse.class, request, BACKCHANNEL_AUTHENTICATION_COMPLETE_API_PATH, mServiceId) + .setOptions(options)); } @@ -1182,11 +1256,13 @@ public BackchannelAuthenticationCompleteResponse backchannelAuthenticationComple * Call {@code /api/{serviceId}/device/authorization} API. */ @Override - public DeviceAuthorizationResponse deviceAuthorization(DeviceAuthorizationRequest request) throws AuthleteApiException + public DeviceAuthorizationResponse deviceAuthorization( + DeviceAuthorizationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - DeviceAuthorizationResponse.class, request, DEVICE_AUTHORIZATION_API_PATH, mServiceId)); + DeviceAuthorizationResponse.class, request, DEVICE_AUTHORIZATION_API_PATH, mServiceId) + .setOptions(options)); } @@ -1194,11 +1270,13 @@ public DeviceAuthorizationResponse deviceAuthorization(DeviceAuthorizationReques * Call {@code /api/{serviceId}/device/complete} API. */ @Override - public DeviceCompleteResponse deviceComplete(DeviceCompleteRequest request) throws AuthleteApiException + public DeviceCompleteResponse deviceComplete( + DeviceCompleteRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - DeviceCompleteResponse.class, request, DEVICE_COMPLETE_API_PATH, mServiceId)); + DeviceCompleteResponse.class, request, DEVICE_COMPLETE_API_PATH, mServiceId) + .setOptions(options)); } @@ -1206,77 +1284,85 @@ public DeviceCompleteResponse deviceComplete(DeviceCompleteRequest request) thro * Call {@code /api/{serviceId}/device/verification} API. */ @Override - public DeviceVerificationResponse deviceVerification(DeviceVerificationRequest request) throws AuthleteApiException + public DeviceVerificationResponse deviceVerification( + DeviceVerificationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - DeviceVerificationResponse.class, request, DEVICE_VERIFICATION_API_PATH, mServiceId)); + DeviceVerificationResponse.class, request, DEVICE_VERIFICATION_API_PATH, mServiceId) + .setOptions(options)); } @Override - public PushedAuthReqResponse pushAuthorizationRequest(PushedAuthReqRequest request) throws AuthleteApiException + public PushedAuthReqResponse pushAuthorizationRequest( + PushedAuthReqRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - PushedAuthReqResponse.class, request, PUSHED_AUTH_REQ_API_PATH, mServiceId)); + PushedAuthReqResponse.class, request, PUSHED_AUTH_REQ_API_PATH, mServiceId) + .setOptions(options)); } @Override - public HskResponse hskCreate(HskCreateRequest request) throws AuthleteApiException + public HskResponse hskCreate(HskCreateRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - HskResponse.class, request, HSK_CREATE_API_PATH, mServiceId)); + HskResponse.class, request, HSK_CREATE_API_PATH, mServiceId) + .setOptions(options)); } @Override - public HskResponse hskDelete(String handle) throws AuthleteApiException + public HskResponse hskDelete(String handle, Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( HskResponse.class, - HSK_DELETE_API_PATH, mServiceId, handle)); + HSK_DELETE_API_PATH, mServiceId, handle) + .setOptions(options)); } @Override - public HskResponse hskGet(String handle) throws AuthleteApiException + public HskResponse hskGet(String handle, Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( HskResponse.class, - HSK_GET_API_PATH, mServiceId, handle)); + HSK_GET_API_PATH, mServiceId, handle) + .setOptions(options)); } @Override - public HskListResponse hskGetList() throws AuthleteApiException + public HskListResponse hskGetList(Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( HskListResponse.class, - HSK_GET_LIST_API_PATH, mServiceId)); + HSK_GET_LIST_API_PATH, mServiceId) + .setOptions(options)); } @Override - public Map echo(Map parameters) throws AuthleteApiException + public Map echo(Map parameters, Options options) throws AuthleteApiException { return executeApiCall(new AuthleteApiCall>() { @Override public Map call() { - return callEcho(parameters); + return callEcho(parameters, options); } }); } - private Map callEcho(Map parameters) + private Map callEcho(Map parameters, Options options) { WebTarget target = getTarget().path(ECHO_API_PATH); @@ -1291,229 +1377,251 @@ private Map callEcho(Map parameters) // The API does not require any authentication, so the code below // does not include '.header(AUTHORIZATION, ...)'. - return target - .request(APPLICATION_JSON_TYPE) - .get(new GenericType>(){}); + Builder builder = target.request(APPLICATION_JSON_TYPE); + + setCustomRequestHeaders(builder, options); + + return builder.get(new GenericType>(){}); } @Override - public GMResponse gm(GMRequest request) throws AuthleteApiException + public GMResponse gm(GMRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( - GMResponse.class, request, GM_API_PATH, mServiceId)); + GMResponse.class, request, GM_API_PATH, mServiceId) + .setOptions(options)); } @Override public void updateClientLockFlag( - String clientIdentifier, boolean clientLocked) throws AuthleteApiException + String clientIdentifier, boolean clientLocked, Options options) throws AuthleteApiException { // Prepare a request body. ClientLockFlagUpdateRequest request = new ClientLockFlagUpdateRequest().setClientLocked(clientLocked); executeApiCall( new PostApiCaller( - ApiResponse.class, request, CLIENT_LOCK_FLAG_UPDATE_API_PATH, mServiceId, clientIdentifier)); + ApiResponse.class, request, CLIENT_LOCK_FLAG_UPDATE_API_PATH, mServiceId, clientIdentifier) + .setOptions(options)); } @Override public FederationConfigurationResponse federationConfiguration( - FederationConfigurationRequest request) throws AuthleteApiException + FederationConfigurationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( FederationConfigurationResponse.class, request, - FEDERATION_CONFIGURATION_API_PATH, mServiceId)); + FEDERATION_CONFIGURATION_API_PATH, mServiceId) + .setOptions(options)); } @Override public FederationRegistrationResponse federationRegistration( - FederationRegistrationRequest request) throws AuthleteApiException + FederationRegistrationRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( FederationRegistrationResponse.class, request, - FEDERATION_REGISTRATION_API_PATH, mServiceId)); + FEDERATION_REGISTRATION_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialIssuerMetadataResponse credentialIssuerMetadata( - CredentialIssuerMetadataRequest request) throws AuthleteApiException + CredentialIssuerMetadataRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialIssuerMetadataResponse.class, request, - VCI_METADATA_API_PATH, mServiceId)); + VCI_METADATA_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialJwtIssuerMetadataResponse credentialJwtIssuerMetadata( - CredentialJwtIssuerMetadataRequest request) throws AuthleteApiException + CredentialJwtIssuerMetadataRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialJwtIssuerMetadataResponse.class, request, - VCI_JWT_ISSUER_API_PATH, mServiceId)); + VCI_JWT_ISSUER_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialIssuerJwksResponse credentialIssuerJwks( - CredentialIssuerJwksRequest request) throws AuthleteApiException + CredentialIssuerJwksRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialIssuerJwksResponse.class, request, - VCI_JWKS_API_PATH, mServiceId)); + VCI_JWKS_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialOfferCreateResponse credentialOfferCreate( - CredentialOfferCreateRequest request) throws AuthleteApiException + CredentialOfferCreateRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialOfferCreateResponse.class, request, - VCI_OFFER_CREATE_API_PATH, mServiceId)); + VCI_OFFER_CREATE_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialOfferInfoResponse credentialOfferInfo( - CredentialOfferInfoRequest request) throws AuthleteApiException + CredentialOfferInfoRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialOfferInfoResponse.class, request, - VCI_OFFER_INFO_API_PATH, mServiceId)); + VCI_OFFER_INFO_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialSingleParseResponse credentialSingleParse( - CredentialSingleParseRequest request) throws AuthleteApiException + CredentialSingleParseRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialSingleParseResponse.class, request, - VCI_SINGLE_PARSE_API_PATH, mServiceId)); + VCI_SINGLE_PARSE_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialSingleIssueResponse credentialSingleIssue( - CredentialSingleIssueRequest request) throws AuthleteApiException + CredentialSingleIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialSingleIssueResponse.class, request, - VCI_SINGLE_ISSUE_API_PATH, mServiceId)); + VCI_SINGLE_ISSUE_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialBatchParseResponse credentialBatchParse( - CredentialBatchParseRequest request) throws AuthleteApiException + CredentialBatchParseRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialBatchParseResponse.class, request, - VCI_BATCH_PARSE_API_PATH, mServiceId)); + VCI_BATCH_PARSE_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialBatchIssueResponse credentialBatchIssue( - CredentialBatchIssueRequest request) throws AuthleteApiException + CredentialBatchIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialBatchIssueResponse.class, request, - VCI_BATCH_ISSUE_API_PATH, mServiceId)); + VCI_BATCH_ISSUE_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialDeferredParseResponse credentialDeferredParse( - CredentialDeferredParseRequest request) throws AuthleteApiException + CredentialDeferredParseRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialDeferredParseResponse.class, request, - VCI_DEFERRED_PARSE_API_PATH, mServiceId)); + VCI_DEFERRED_PARSE_API_PATH, mServiceId) + .setOptions(options)); } @Override public CredentialDeferredIssueResponse credentialDeferredIssue( - CredentialDeferredIssueRequest request) throws AuthleteApiException + CredentialDeferredIssueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( CredentialDeferredIssueResponse.class, request, - VCI_DEFERRED_ISSUE_API_PATH, mServiceId)); + VCI_DEFERRED_ISSUE_API_PATH, mServiceId) + .setOptions(options)); } @Override public IDTokenReissueResponse idTokenReissue( - IDTokenReissueRequest request) throws AuthleteApiException + IDTokenReissueRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( IDTokenReissueResponse.class, request, - ID_TOKEN_REISSUE_API_PATH, mServiceId)); + ID_TOKEN_REISSUE_API_PATH, mServiceId) + .setOptions(options)); } @Override public AuthorizationTicketInfoResponse authorizationTicketInfo( - AuthorizationTicketInfoRequest request) throws AuthleteApiException + AuthorizationTicketInfoRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( AuthorizationTicketInfoResponse.class, request, - AUTH_AUTHORIZATION_TICKET_INFO_API_PATH, mServiceId)); + AUTH_AUTHORIZATION_TICKET_INFO_API_PATH, mServiceId) + .setOptions(options)); } @Override public AuthorizationTicketUpdateResponse authorizationTicketUpdate( - AuthorizationTicketUpdateRequest request) throws AuthleteApiException + AuthorizationTicketUpdateRequest request, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( AuthorizationTicketUpdateResponse.class, request, - AUTH_AUTHORIZATION_TICKET_UPDATE_API_PATH, mServiceId)); + AUTH_AUTHORIZATION_TICKET_UPDATE_API_PATH, mServiceId) + .setOptions(options)); } @Override public TokenCreateBatchResponse tokenCreateBatch( - TokenCreateRequest[] request, boolean dryRun) throws AuthleteApiException + TokenCreateRequest[] request, boolean dryRun, Options options) throws AuthleteApiException { return executeApiCall( new PostApiCaller( TokenCreateBatchResponse.class, request, TOKEN_CREATE_BATCH_API_PATH, mServiceId) - .addParam("dryRun", dryRun)); + .addParam("dryRun", dryRun) + .setOptions(options)); } @Override public TokenCreateBatchStatusResponse getTokenCreateBatchStatus( - String requestId) throws AuthleteApiException + String requestId, Options options) throws AuthleteApiException { return executeApiCall( new GetApiCaller( TokenCreateBatchStatusResponse.class, - TOKEN_CREATE_BATCH_STATUS_API_PATH, mServiceId, requestId)); + TOKEN_CREATE_BATCH_STATUS_API_PATH, mServiceId, requestId) + .setOptions(options)); } } diff --git a/src/main/java/com/authlete/jakarta/api/AuthleteApiJaxrsImpl.java b/src/main/java/com/authlete/jakarta/api/AuthleteApiJaxrsImpl.java index cfb28ae..ba20b7b 100644 --- a/src/main/java/com/authlete/jakarta/api/AuthleteApiJaxrsImpl.java +++ b/src/main/java/com/authlete/jakarta/api/AuthleteApiJaxrsImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014-2022 Authlete, Inc. + * Copyright (C) 2014-2024 Authlete, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,17 +17,21 @@ package com.authlete.jakarta.api; +import static jakarta.ws.rs.core.HttpHeaders.ACCEPT; import static jakarta.ws.rs.core.HttpHeaders.AUTHORIZATION; +import static jakarta.ws.rs.core.HttpHeaders.CONTENT_TYPE; import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE; import java.text.ParseException; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.client.ClientBuilder; import jakarta.ws.rs.client.Entity; import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.client.Invocation.Builder; import jakarta.ws.rs.client.ResponseProcessingException; import jakarta.ws.rs.client.WebTarget; import jakarta.ws.rs.core.MediaType; @@ -35,6 +39,7 @@ import jakarta.ws.rs.core.Response.StatusType; import com.authlete.common.api.AuthleteApi; import com.authlete.common.api.AuthleteApiException; +import com.authlete.common.api.Options; import com.authlete.common.api.Settings; import com.authlete.common.conf.AuthleteConfiguration; import com.nimbusds.jose.JOSEException; @@ -406,7 +411,7 @@ private String extractResponseBody(Response response) protected TResponse callGetApi( - String auth, String path, Class responseClass, Map params) + String auth, String path, Class responseClass, Map params, Options options) { WebTarget webTarget = getTarget().path(path); @@ -418,32 +423,41 @@ protected TResponse callGetApi( } } - return wrapWithDpop(webTarget.request(APPLICATION_JSON_TYPE), path, "GET") - .header(AUTHORIZATION, auth) - .get(responseClass); + Builder builder = wrapWithDpop(webTarget.request(APPLICATION_JSON_TYPE), path, "GET") + .header(AUTHORIZATION, auth); + + setCustomRequestHeaders(builder, options); + + return builder.get(responseClass); } - protected Void callDeleteApi(String auth, String path) + protected Void callDeleteApi(String auth, String path, Options options) { - wrapWithDpop(getTarget() + Builder builder = wrapWithDpop(getTarget() .path(path) .request(), path, "DELETE") - .header(AUTHORIZATION, auth) - .delete(); + .header(AUTHORIZATION, auth); + + setCustomRequestHeaders(builder, options); + + builder.delete(); return null; } protected TResponse callPostApi( - String auth, String path, Object request, Class responseClass) + String auth, String path, Object request, Class responseClass, Options options) { - return wrapWithDpop(getTarget() + Builder builder = wrapWithDpop(getTarget() .path(path) .request(APPLICATION_JSON_TYPE), path, "POST") - .header(AUTHORIZATION, auth) - .post(Entity.entity(request, JSON_UTF8_TYPE), responseClass); + .header(AUTHORIZATION, auth); + + setCustomRequestHeaders(builder, options); + + return builder.post(Entity.entity(request, JSON_UTF8_TYPE), responseClass); } @@ -470,4 +484,45 @@ protected boolean isDpopEnabled() { return mDpopJwk != null; } + + + protected void setCustomRequestHeaders(Builder builder, Options options) + { + if (options == null) + { + return; + } + + // Custom request headers. + Map headers = options.getHeaders(); + + if (headers == null) + { + // No custom request header is specified. + return; + } + + // Add each custom request header to the builder. + for (Entry e : headers.entrySet()) + { + // The key of the header. + String key = e.getKey(); + + // Some header keys are reserved. + if (isReservedRequestHeader(key)) + { + continue; + } + + builder.header(key, e.getValue()); + } + } + + + private static boolean isReservedRequestHeader(String key) + { + return key.equalsIgnoreCase(ACCEPT) || + key.equalsIgnoreCase(AUTHORIZATION) || + key.equalsIgnoreCase(CONTENT_TYPE); + } }