diff --git a/client/src/main/com/sinch/sdk/SinchClient.java b/client/src/main/com/sinch/sdk/SinchClient.java index c4d92875..223718f2 100644 --- a/client/src/main/com/sinch/sdk/SinchClient.java +++ b/client/src/main/com/sinch/sdk/SinchClient.java @@ -1,9 +1,5 @@ package com.sinch.sdk; -import com.sinch.sdk.auth.AuthManager; -import com.sinch.sdk.auth.adapters.BasicAuthManager; -import com.sinch.sdk.auth.adapters.BearerAuthManager; -import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.domains.numbers.NumbersService; import com.sinch.sdk.domains.sms.SMSService; import com.sinch.sdk.http.HttpClientApache; @@ -11,13 +7,9 @@ import com.sinch.sdk.models.SMSRegion; import java.io.IOException; import java.io.InputStream; -import java.util.AbstractMap; -import java.util.Map; import java.util.Objects; import java.util.Properties; import java.util.logging.Logger; -import java.util.stream.Collectors; -import java.util.stream.Stream; /** Sinch Sdk Client implementation */ public class SinchClient { @@ -143,22 +135,10 @@ private Properties handleDefaultConfigurationFile() { private HttpClientApache getHttpClient() { if (null == httpClient || httpClient.isClosed()) { - AuthManager basicAuthManager = new BasicAuthManager(configuration); - BearerAuthManager bearerAuthManager = new BearerAuthManager(configuration, new HttpMapper()); - - Map authManagers = - Stream.of(basicAuthManager, bearerAuthManager) - .map(e -> new AbstractMap.SimpleEntry<>(e.getSchema(), e)) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - // TODO: by adding a setter, we could imagine having another HTTP client provided // programmatically or use // configuration file referencing another class by name - this.httpClient = new HttpClientApache(authManagers); - - // Avoid multiple and costly http client creation and reuse it for authManager - bearerAuthManager.setHttpClient(this.httpClient); - + this.httpClient = new HttpClientApache(); LOGGER.fine("HTTP client loaded"); } return this.httpClient; diff --git a/client/src/main/com/sinch/sdk/auth/AuthManager.java b/client/src/main/com/sinch/sdk/auth/AuthManager.java deleted file mode 100644 index 23121e63..00000000 --- a/client/src/main/com/sinch/sdk/auth/AuthManager.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.sinch.sdk.auth; - -import com.sinch.sdk.core.http.HttpClient; - -public interface AuthManager { - - String getSchema(); - - void resetToken(); - - void setHttpClient(HttpClient httpClient); - - String getAuthorizationHeaderValue(); -} diff --git a/client/src/main/com/sinch/sdk/auth/adapters/BasicAuthManager.java b/client/src/main/com/sinch/sdk/auth/adapters/BasicAuthManager.java index 519a1b9a..1de2ad4e 100644 --- a/client/src/main/com/sinch/sdk/auth/adapters/BasicAuthManager.java +++ b/client/src/main/com/sinch/sdk/auth/adapters/BasicAuthManager.java @@ -1,14 +1,12 @@ package com.sinch.sdk.auth.adapters; -import com.sinch.sdk.auth.AuthManager; -import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.models.Configuration; import java.nio.charset.StandardCharsets; import java.util.Base64; public class BasicAuthManager implements AuthManager { - public static final String BASIC_SCHEMA_KEYWORD = "BasicAuth"; - private static final String BASIC_AUTH_KEYWORD = "Basic"; + private static final String AUTH_KEYWORD = "Basic"; private final Configuration configuration; public BasicAuthManager(Configuration configuration) { @@ -16,12 +14,7 @@ public BasicAuthManager(Configuration configuration) { } public String getSchema() { - return BASIC_SCHEMA_KEYWORD; - } - - @Override - public void setHttpClient(HttpClient httpClient) { - // no op + return SCHEMA_KEYWORD_BASIC; } @Override @@ -36,7 +29,7 @@ public String getAuthorizationHeaderValue() { String raw = key + ":" + secret; - return BASIC_AUTH_KEYWORD + return AUTH_KEYWORD + " " + Base64.getEncoder().encodeToString(raw.getBytes(StandardCharsets.UTF_8)); } diff --git a/client/src/main/com/sinch/sdk/auth/adapters/BearerAuthManager.java b/client/src/main/com/sinch/sdk/auth/adapters/BearerAuthManager.java index c2f43bc5..19b9b30e 100644 --- a/client/src/main/com/sinch/sdk/auth/adapters/BearerAuthManager.java +++ b/client/src/main/com/sinch/sdk/auth/adapters/BearerAuthManager.java @@ -1,43 +1,49 @@ package com.sinch.sdk.auth.adapters; import com.fasterxml.jackson.core.type.TypeReference; -import com.sinch.sdk.auth.AuthManager; import com.sinch.sdk.auth.models.BearerAuthResponse; import com.sinch.sdk.core.exceptions.ApiAuthException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; import com.sinch.sdk.core.http.HttpRequest; import com.sinch.sdk.core.http.HttpResponse; import com.sinch.sdk.models.Configuration; +import java.util.AbstractMap; import java.util.Collections; +import java.util.Map; import java.util.Optional; import java.util.logging.Logger; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class BearerAuthManager implements AuthManager { - public static final String BEARER_SCHEMA_KEYWORD = "BearerAuth"; public static final String BEARER_EXPIRED_KEYWORD = "expired"; public static final String BEARER_AUTHENTICATE_RESPONSE_HEADER_KEYWORD = "www-authenticate"; private static final Logger LOGGER = Logger.getLogger(BearerAuthManager.class.getName()); - private static final String BEARER_AUTH_KEYWORD = "Bearer"; + private static final String AUTH_KEYWORD = "Bearer"; private static final int maxRefreshAttempt = 5; private final Configuration configuration; private final HttpMapper mapper; - private HttpClient httpClient; + private final HttpClient httpClient; + private final Map authManagers; + private String token; - public BearerAuthManager(Configuration configuration, HttpMapper mapper) { + public BearerAuthManager(Configuration configuration, HttpMapper mapper, HttpClient httpClient) { this.configuration = configuration; this.mapper = mapper; - } + this.httpClient = httpClient; - public String getSchema() { - return BEARER_SCHEMA_KEYWORD; + AuthManager basicAuthManager = new BasicAuthManager(configuration); + authManagers = + Stream.of(new AbstractMap.SimpleEntry<>(SCHEMA_KEYWORD_BASIC, basicAuthManager)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - @Override - public void setHttpClient(HttpClient httpClient) { - this.httpClient = httpClient; + public String getSchema() { + return SCHEMA_KEYWORD_BEARER; } @Override @@ -51,7 +57,7 @@ public String getAuthorizationHeaderValue() { if (token == null) { refreshToken(); } - return BEARER_AUTH_KEYWORD + " " + token; + return AUTH_KEYWORD + " " + token; } private void refreshToken() { @@ -80,9 +86,10 @@ private Optional getNewToken() { null, null, Collections.singletonList("application/x-www-form-urlencoded"), - Collections.singletonList(BasicAuthManager.BASIC_SCHEMA_KEYWORD)); + Collections.singletonList(SCHEMA_KEYWORD_BASIC)); try { - HttpResponse httpResponse = httpClient.invokeAPI(configuration.getOAuthServer(), request); + HttpResponse httpResponse = + httpClient.invokeAPI(configuration.getOAuthServer(), authManagers, request); BearerAuthResponse authResponse = mapper.deserialize(httpResponse, new TypeReference() {}); return Optional.ofNullable(authResponse.getAccessToken()); diff --git a/client/src/main/com/sinch/sdk/domains/numbers/NumbersService.java b/client/src/main/com/sinch/sdk/domains/numbers/NumbersService.java index 75a79884..b66dc84f 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/NumbersService.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/NumbersService.java @@ -34,7 +34,7 @@ public interface NumbersService { ActiveNumberService active(); /** - * Callbacks Configuraiton Service instance + * Callbacks Configuration Service instance * * @return service instance for project * @since 1.0 diff --git a/client/src/main/com/sinch/sdk/domains/numbers/adapters/ActiveNumberService.java b/client/src/main/com/sinch/sdk/domains/numbers/adapters/ActiveNumberService.java index db14a2c5..f15dfe9f 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/adapters/ActiveNumberService.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/adapters/ActiveNumberService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.numbers.adapters; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.models.pagination.Page; @@ -22,6 +23,7 @@ import com.sinch.sdk.models.Configuration; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -32,9 +34,12 @@ public class ActiveNumberService implements com.sinch.sdk.domains.numbers.Active public ActiveNumberService() {} - public ActiveNumberService(Configuration configuration, HttpClient httpClient) { + public ActiveNumberService( + Configuration configuration, HttpClient httpClient, Map authManagers) { this.configuration = configuration; - this.api = new ActiveNumberApi(httpClient, configuration.getNumbersServer(), new HttpMapper()); + this.api = + new ActiveNumberApi( + httpClient, configuration.getNumbersServer(), authManagers, new HttpMapper()); } private ActiveNumberApi getApi() { diff --git a/client/src/main/com/sinch/sdk/domains/numbers/adapters/AvailableNumberService.java b/client/src/main/com/sinch/sdk/domains/numbers/adapters/AvailableNumberService.java index f158c800..7e17658d 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/adapters/AvailableNumberService.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/adapters/AvailableNumberService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.numbers.adapters; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.utils.EnumDynamic; @@ -20,6 +21,7 @@ import com.sinch.sdk.models.Configuration; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -31,10 +33,12 @@ public class AvailableNumberService public AvailableNumberService() {} - public AvailableNumberService(Configuration configuration, HttpClient httpClient) { + public AvailableNumberService( + Configuration configuration, HttpClient httpClient, Map authManagers) { this.configuration = configuration; this.api = - new AvailableNumberApi(httpClient, configuration.getNumbersServer(), new HttpMapper()); + new AvailableNumberApi( + httpClient, configuration.getNumbersServer(), authManagers, new HttpMapper()); } private AvailableNumberApi getApi() { diff --git a/client/src/main/com/sinch/sdk/domains/numbers/adapters/AvailableRegionService.java b/client/src/main/com/sinch/sdk/domains/numbers/adapters/AvailableRegionService.java index 77a6a988..12ec8f8d 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/adapters/AvailableRegionService.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/adapters/AvailableRegionService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.numbers.adapters; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.utils.EnumDynamic; @@ -13,6 +14,7 @@ import com.sinch.sdk.models.Configuration; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; public class AvailableRegionService @@ -23,10 +25,12 @@ public class AvailableRegionService public AvailableRegionService() {} - public AvailableRegionService(Configuration configuration, HttpClient httpClient) { + public AvailableRegionService( + Configuration configuration, HttpClient httpClient, Map authManagers) { this.configuration = configuration; this.api = - new AvailableRegionsApi(httpClient, configuration.getNumbersServer(), new HttpMapper()); + new AvailableRegionsApi( + httpClient, configuration.getNumbersServer(), authManagers, new HttpMapper()); } public AvailableRegionListResponse list(AvailableRegionListAllRequestParameters parameters) diff --git a/client/src/main/com/sinch/sdk/domains/numbers/adapters/CallbackConfigurationService.java b/client/src/main/com/sinch/sdk/domains/numbers/adapters/CallbackConfigurationService.java index 8d7542cf..667e088a 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/adapters/CallbackConfigurationService.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/adapters/CallbackConfigurationService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.numbers.adapters; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.domains.numbers.adapters.api.v1.CallbackConfigurationApi; @@ -10,6 +11,7 @@ import com.sinch.sdk.domains.numbers.models.dto.v1.CallbackConfigurationDto; import com.sinch.sdk.domains.numbers.models.requests.CallbackConfigurationUpdateRequestParameters; import com.sinch.sdk.models.Configuration; +import java.util.Map; public class CallbackConfigurationService implements com.sinch.sdk.domains.numbers.CallbackConfigurationService { @@ -19,11 +21,12 @@ public class CallbackConfigurationService public CallbackConfigurationService() {} - public CallbackConfigurationService(Configuration configuration, HttpClient httpClient) { + public CallbackConfigurationService( + Configuration configuration, HttpClient httpClient, Map authManagers) { this.configuration = configuration; this.api = new CallbackConfigurationApi( - httpClient, configuration.getNumbersServer(), new HttpMapper()); + httpClient, configuration.getNumbersServer(), authManagers, new HttpMapper()); } private CallbackConfigurationApi getApi() { diff --git a/client/src/main/com/sinch/sdk/domains/numbers/adapters/NumbersService.java b/client/src/main/com/sinch/sdk/domains/numbers/adapters/NumbersService.java index cee4cd15..a5b83af2 100644 --- a/client/src/main/com/sinch/sdk/domains/numbers/adapters/NumbersService.java +++ b/client/src/main/com/sinch/sdk/domains/numbers/adapters/NumbersService.java @@ -1,9 +1,16 @@ package com.sinch.sdk.domains.numbers.adapters; +import com.sinch.sdk.auth.adapters.BasicAuthManager; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.models.Configuration; +import java.util.AbstractMap; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class NumbersService implements com.sinch.sdk.domains.numbers.NumbersService { + private static final String SECURITY_SCHEME_KEYWORD_NUMBERS = "BasicAuth"; private final Configuration configuration; private final HttpClient httpClient; @@ -11,36 +18,42 @@ public class NumbersService implements com.sinch.sdk.domains.numbers.NumbersServ private ActiveNumberService active; private AvailableRegionService regions; private CallbackConfigurationService callback; + private final Map authManagers; public NumbersService(Configuration configuration, HttpClient httpClient) { this.configuration = configuration; this.httpClient = httpClient; + AuthManager basicAuthManager = new BasicAuthManager(configuration); + + authManagers = + Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_NUMBERS, basicAuthManager)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } public AvailableNumberService available() { if (null == this.available) { - this.available = new AvailableNumberService(configuration, httpClient); + this.available = new AvailableNumberService(configuration, httpClient, authManagers); } return this.available; } public AvailableRegionService regions() { if (null == this.regions) { - this.regions = new AvailableRegionService(configuration, httpClient); + this.regions = new AvailableRegionService(configuration, httpClient, authManagers); } return this.regions; } public ActiveNumberService active() { if (null == this.active) { - this.active = new ActiveNumberService(configuration, httpClient); + this.active = new ActiveNumberService(configuration, httpClient, authManagers); } return this.active; } public CallbackConfigurationService callback() { if (null == this.callback) { - this.callback = new CallbackConfigurationService(configuration, httpClient); + this.callback = new CallbackConfigurationService(configuration, httpClient, authManagers); } return this.callback; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/GroupsService.java b/client/src/main/com/sinch/sdk/domains/sms/GroupsService.java index 22c8d857..8111bb1e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/GroupsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/GroupsService.java @@ -114,6 +114,7 @@ public interface GroupsService { * Get phone numbers for a group * * @param groupId ID of a group that you are interested in getting. + * @return A list of phone numbers in E.164 format. * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup * @since 1.0 diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java index 9e85d85b..0e4a1606 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.sms.adapters; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.models.pagination.CursorPageNavigator; @@ -19,6 +20,7 @@ import com.sinch.sdk.models.Configuration; import java.time.Instant; import java.util.Collection; +import java.util.Map; public class BatchesService implements com.sinch.sdk.domains.sms.BatchesService { @@ -27,9 +29,11 @@ public class BatchesService implements com.sinch.sdk.domains.sms.BatchesService public BatchesService() {} - public BatchesService(Configuration configuration, HttpClient httpClient) { + public BatchesService( + Configuration configuration, HttpClient httpClient, Map authManagers) { this.configuration = configuration; - this.api = new BatchesApi(httpClient, configuration.getSmsServer(), new HttpMapper()); + this.api = + new BatchesApi(httpClient, configuration.getSmsServer(), authManagers, new HttpMapper()); } private BatchesApi getApi() { diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java index 6b6fde31..b8f4c7d3 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.sms.adapters; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.models.pagination.CursorPageNavigator; @@ -19,6 +20,7 @@ import com.sinch.sdk.models.Configuration; import java.time.Instant; import java.util.Collection; +import java.util.Map; import java.util.stream.Collectors; /** @@ -44,9 +46,12 @@ private DeliveryReportsApi getApi() { return this.api; } - public DeliveryReportsService(Configuration configuration, HttpClient httpClient) { + public DeliveryReportsService( + Configuration configuration, HttpClient httpClient, Map authManagers) { this.configuration = configuration; - this.api = new DeliveryReportsApi(httpClient, configuration.getSmsServer(), new HttpMapper()); + this.api = + new DeliveryReportsApi( + httpClient, configuration.getSmsServer(), authManagers, new HttpMapper()); } public DeliveryReportBatch get(String batchId, DeliveryReportBatchGetRequestParameters parameters) diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java index 70575b03..488f5775 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.sms.adapters; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.models.pagination.CursorPageNavigator; @@ -18,6 +19,7 @@ import com.sinch.sdk.domains.sms.models.responses.GroupsListResponse; import com.sinch.sdk.models.Configuration; import java.util.Collection; +import java.util.Map; public class GroupsService implements com.sinch.sdk.domains.sms.GroupsService { @@ -30,9 +32,11 @@ private GroupsApi getApi() { return this.api; } - public GroupsService(Configuration configuration, HttpClient httpClient) { + public GroupsService( + Configuration configuration, HttpClient httpClient, Map authManagers) { this.configuration = configuration; - this.api = new GroupsApi(httpClient, configuration.getSmsServer(), new HttpMapper()); + this.api = + new GroupsApi(httpClient, configuration.getSmsServer(), authManagers, new HttpMapper()); } public Group get(String groupId) throws ApiException { diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java index cb12b013..0a70014f 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.sms.adapters; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.models.pagination.CursorPageNavigator; @@ -16,6 +17,7 @@ import com.sinch.sdk.models.Configuration; import java.time.Instant; import java.util.Collection; +import java.util.Map; public class InboundsService implements com.sinch.sdk.domains.sms.InboundsService { @@ -28,9 +30,11 @@ private InboundsApi getApi() { return this.api; } - public InboundsService(Configuration configuration, HttpClient httpClient) { + public InboundsService( + Configuration configuration, HttpClient httpClient, Map authManagers) { this.configuration = configuration; - this.api = new InboundsApi(httpClient, configuration.getSmsServer(), new HttpMapper()); + this.api = + new InboundsApi(httpClient, configuration.getSmsServer(), authManagers, new HttpMapper()); } public InboundsListResponse list() throws ApiException { diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java index bbdd773f..3b0b6cbb 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java @@ -1,13 +1,21 @@ package com.sinch.sdk.domains.sms.adapters; +import com.sinch.sdk.auth.adapters.BearerAuthManager; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.domains.sms.BatchesService; import com.sinch.sdk.domains.sms.DeliveryReportsService; import com.sinch.sdk.domains.sms.InboundsService; import com.sinch.sdk.domains.sms.WebHooksService; import com.sinch.sdk.models.Configuration; +import java.util.AbstractMap; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class SMSService implements com.sinch.sdk.domains.sms.SMSService { + private static final String SECURITY_SCHEME_KEYWORD_SMS = "BearerAuth"; private final Configuration configuration; private final HttpClient httpClient; @@ -16,17 +24,26 @@ public class SMSService implements com.sinch.sdk.domains.sms.SMSService { private DeliveryReportsService deliveryReports; private InboundsService inbounds; private GroupsService groups; + private final Map authManagers; public SMSService(Configuration configuration, HttpClient httpClient) { this.configuration = configuration; this.httpClient = httpClient; + + BearerAuthManager bearerAuthManager = + new BearerAuthManager(configuration, new HttpMapper(), httpClient); + + authManagers = + Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_SMS, bearerAuthManager)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } @Override public BatchesService batches() { if (null == this.batches) { this.batches = - new com.sinch.sdk.domains.sms.adapters.BatchesService(configuration, httpClient); + new com.sinch.sdk.domains.sms.adapters.BatchesService( + configuration, httpClient, authManagers); } return this.batches; } @@ -43,7 +60,8 @@ public WebHooksService webHooks() { public DeliveryReportsService deliveryReports() { if (null == this.deliveryReports) { this.deliveryReports = - new com.sinch.sdk.domains.sms.adapters.DeliveryReportsService(configuration, httpClient); + new com.sinch.sdk.domains.sms.adapters.DeliveryReportsService( + configuration, httpClient, authManagers); } return this.deliveryReports; } @@ -52,7 +70,8 @@ public DeliveryReportsService deliveryReports() { public InboundsService inbounds() { if (null == this.inbounds) { this.inbounds = - new com.sinch.sdk.domains.sms.adapters.InboundsService(configuration, httpClient); + new com.sinch.sdk.domains.sms.adapters.InboundsService( + configuration, httpClient, authManagers); } return this.inbounds; } @@ -60,7 +79,9 @@ public InboundsService inbounds() { @Override public GroupsService groups() { if (null == this.groups) { - this.groups = new com.sinch.sdk.domains.sms.adapters.GroupsService(configuration, httpClient); + this.groups = + new com.sinch.sdk.domains.sms.adapters.GroupsService( + configuration, httpClient, authManagers); } return this.groups; } diff --git a/client/src/main/com/sinch/sdk/http/HttpClientApache.java b/client/src/main/com/sinch/sdk/http/HttpClientApache.java index 588ff3f4..3e69205d 100644 --- a/client/src/main/com/sinch/sdk/http/HttpClientApache.java +++ b/client/src/main/com/sinch/sdk/http/HttpClientApache.java @@ -4,15 +4,27 @@ import static com.sinch.sdk.auth.adapters.BearerAuthManager.BEARER_EXPIRED_KEYWORD; import static com.sinch.sdk.core.http.URLParameterUtils.encodeParametersAsString; -import com.sinch.sdk.auth.AuthManager; import com.sinch.sdk.auth.adapters.BearerAuthManager; import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.core.http.*; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.HttpStatus; +import com.sinch.sdk.core.http.URLParameter; import com.sinch.sdk.core.models.ServerConfiguration; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Scanner; import java.util.logging.Logger; +import java.util.stream.Collectors; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.HttpClients; import org.apache.hc.core5.http.ClassicHttpRequest; @@ -23,14 +35,13 @@ import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; public class HttpClientApache implements com.sinch.sdk.core.http.HttpClient { + private static final Logger LOGGER = Logger.getLogger(HttpClientApache.class.getName()); private static final String AUTHORIZATION_HEADER_KEYWORD = "Authorization"; - private final Map authManagers; private CloseableHttpClient client; - public HttpClientApache(Map authManagers) { + public HttpClientApache() { this.client = HttpClients.createDefault(); - this.authManagers = authManagers; } private static HttpResponse processResponse(ClassicHttpResponse response) throws IOException { @@ -67,7 +78,10 @@ private static Map> transformResponseHeaders(Header[] heade } @Override - public HttpResponse invokeAPI(ServerConfiguration serverConfiguration, HttpRequest httpRequest) + public HttpResponse invokeAPI( + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpRequest httpRequest) throws ApiException { try { @@ -98,7 +112,7 @@ public HttpResponse invokeAPI(ServerConfiguration serverConfiguration, HttpReque addCollectionHeader(requestBuilder, "Content-Type", contentType); addCollectionHeader(requestBuilder, "Accept", accept); - addAuth(requestBuilder, authNames); + addAuth(requestBuilder, authManagersByOasSecuritySchemes, authNames); ClassicHttpRequest request = requestBuilder.build(); @@ -107,10 +121,11 @@ public HttpResponse invokeAPI(ServerConfiguration serverConfiguration, HttpReque // UNAUTHORIZED (HTTP 401) error code could imply refreshing the OAuth token if (response.getCode() == HttpStatus.UNAUTHORIZED) { - boolean couldRetryRequest = processUnauthorizedResponse(httpRequest, response); + boolean couldRetryRequest = + processUnauthorizedResponse(httpRequest, response, authManagersByOasSecuritySchemes); if (couldRetryRequest) { // refresh authorization - addAuth(requestBuilder, authNames); + addAuth(requestBuilder, authManagersByOasSecuritySchemes, authNames); request = requestBuilder.build(); response = processRequest(client, request); LOGGER.finest("connection response on retry: " + response); @@ -123,14 +138,35 @@ public HttpResponse invokeAPI(ServerConfiguration serverConfiguration, HttpReque } } - private boolean processUnauthorizedResponse(HttpRequest request, HttpResponse response) { + private boolean processUnauthorizedResponse( + HttpRequest request, + HttpResponse response, + Map authManagersByOasSecuritySchemes) { + + Map authManagersByAuthSchemes = + authManagersByOasSecuritySchemes.values().stream() + .map(authManager -> new AbstractMap.SimpleEntry<>(authManager.getSchema(), authManager)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a1, a2) -> a1)); + AuthManager bearerAuthManager = + authManagersByAuthSchemes.get(BearerAuthManager.SCHEMA_KEYWORD_BEARER); + if (null == bearerAuthManager) { + // no bearer manager registered + return false; + } - AuthManager bearerAuthManager = authManagers.get(BearerAuthManager.BEARER_SCHEMA_KEYWORD); - // is request was with Bearer authentication ? Collection auths = request.getAuthNames(); - - if (null == bearerAuthManager || !auths.contains(BearerAuthManager.BEARER_SCHEMA_KEYWORD)) { - // not required to ask for a new token: original request is not using it + Optional requestSupportBearerAuthentication = + auths.stream() + .filter( + f -> + null != authManagersByOasSecuritySchemes.get(f) + && authManagersByOasSecuritySchemes + .get(f) + .getSchema() + .equals(BearerAuthManager.SCHEMA_KEYWORD_BEARER)) + .findFirst(); + + if (!requestSupportBearerAuthentication.isPresent()) { return false; } // looking for "expired" keyword present in "www-authenticate" header @@ -169,14 +205,17 @@ private void addCollectionHeader( } } - private void addAuth(ClassicRequestBuilder requestBuilder, Collection values) { - if (null == values || values.isEmpty()) { + private void addAuth( + ClassicRequestBuilder requestBuilder, + Map authManagersByOasSecuritySchemes, + Collection values) { + if (null == values || values.isEmpty() || null == authManagersByOasSecuritySchemes) { return; } for (String entry : values) { - if (authManagers.containsKey(entry)) { - AuthManager authManager = authManagers.get(entry); + if (authManagersByOasSecuritySchemes.containsKey(entry)) { + AuthManager authManager = authManagersByOasSecuritySchemes.get(entry); requestBuilder.setHeader( AUTHORIZATION_HEADER_KEYWORD, authManager.getAuthorizationHeaderValue()); return; diff --git a/client/src/test/java/com/sinch/sdk/auth/adapters/BasicAuthManagerTest.java b/client/src/test/java/com/sinch/sdk/auth/adapters/BasicAuthManagerTest.java index b0269728..c768946e 100644 --- a/client/src/test/java/com/sinch/sdk/auth/adapters/BasicAuthManagerTest.java +++ b/client/src/test/java/com/sinch/sdk/auth/adapters/BasicAuthManagerTest.java @@ -2,7 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import com.sinch.sdk.auth.AuthManager; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.models.Configuration; import java.nio.charset.StandardCharsets; import java.util.Base64; @@ -21,7 +21,7 @@ class BasicAuthManagerTest { @Test void getSchema() { - assertEquals("BasicAuth", authManager.getSchema()); + assertEquals("Basic", authManager.getSchema()); } @Test diff --git a/client/src/test/java/com/sinch/sdk/auth/adapters/BearerAuthManagerTest.java b/client/src/test/java/com/sinch/sdk/auth/adapters/BearerAuthManagerTest.java index 3584ffc8..4045e23a 100644 --- a/client/src/test/java/com/sinch/sdk/auth/adapters/BearerAuthManagerTest.java +++ b/client/src/test/java/com/sinch/sdk/auth/adapters/BearerAuthManagerTest.java @@ -7,8 +7,8 @@ import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; -import com.sinch.sdk.auth.AuthManager; import com.sinch.sdk.core.exceptions.ApiAuthException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; @@ -17,6 +17,7 @@ import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.models.Configuration; import java.nio.charset.StandardCharsets; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -42,22 +43,26 @@ public class BearerAuthManagerTest extends BaseTest { .setOAuthUrl("OAuth url") .build(); - AuthManager authManager = new BearerAuthManager(configuration, new HttpMapper()); + AuthManager authManager; + + @BeforeEach + public void initEach() { + authManager = new BearerAuthManager(configuration, new HttpMapper(), httpClient); + } @Test void getSchema() { - assertEquals("BearerAuth", authManager.getSchema()); + assertEquals("Bearer", authManager.getSchema()); } @Test void getAuthorizationHeaderValue() { String expectedToken = "Bearer token value"; - when(httpClient.invokeAPI(any(), any())) + when(httpClient.invokeAPI(any(), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, jsonResponse.getBytes(StandardCharsets.UTF_8))); - authManager.setHttpClient(httpClient); String token = authManager.getAuthorizationHeaderValue(); @@ -66,11 +71,11 @@ void getAuthorizationHeaderValue() { @Test void callToOAuthServer() { - when(httpClient.invokeAPI(serverConfigurationCaptor.capture(), httpRequestCaptor.capture())) + when(httpClient.invokeAPI( + serverConfigurationCaptor.capture(), any(), httpRequestCaptor.capture())) .thenReturn( new HttpResponse( 200, "foo message", null, jsonResponse.getBytes(StandardCharsets.UTF_8))); - authManager.setHttpClient(httpClient); authManager.getAuthorizationHeaderValue(); @@ -79,7 +84,7 @@ void callToOAuthServer() { HttpRequest httpRequestCaptorValue = httpRequestCaptor.getValue(); assertEquals(HttpMethod.POST, httpRequestCaptorValue.getMethod()); - assertTrue(httpRequestCaptorValue.getAuthNames().stream().anyMatch(e -> e.equals("BasicAuth"))); + assertTrue(httpRequestCaptorValue.getAuthNames().stream().anyMatch(e -> e.equals("Basic"))); assertTrue( httpRequestCaptorValue.getContentType().stream() .anyMatch(e -> e.equals("application/x-www-form-urlencoded"))); @@ -88,22 +93,19 @@ void callToOAuthServer() { @Test void resetToken() { - when(httpClient.invokeAPI(any(), any())) + when(httpClient.invokeAPI(any(), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, jsonResponse.getBytes(StandardCharsets.UTF_8))); - authManager.setHttpClient(httpClient); authManager.resetToken(); authManager.getAuthorizationHeaderValue(); - verify(httpClient, times(1)).invokeAPI(any(), any()); + verify(httpClient, times(1)).invokeAPI(any(), any(), any()); } @Test void noInfiniteLoopAndException() { - authManager.setHttpClient(httpClient); - ApiAuthException exception = assertThrows(ApiAuthException.class, authManager::getAuthorizationHeaderValue); assertEquals(exception.getCode(), 401); diff --git a/client/src/test/java/com/sinch/sdk/core/adapters/apache/HttpClientTestIT.java b/client/src/test/java/com/sinch/sdk/core/adapters/apache/HttpClientTestIT.java index 20e94b60..650139b4 100644 --- a/client/src/test/java/com/sinch/sdk/core/adapters/apache/HttpClientTestIT.java +++ b/client/src/test/java/com/sinch/sdk/core/adapters/apache/HttpClientTestIT.java @@ -6,10 +6,10 @@ import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; -import com.sinch.sdk.auth.AuthManager; import com.sinch.sdk.auth.adapters.BasicAuthManager; import com.sinch.sdk.auth.adapters.BearerAuthManager; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; import com.sinch.sdk.core.http.HttpRequest; @@ -28,7 +28,6 @@ import okhttp3.mockwebserver.RecordedRequest; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @TestWithResources @@ -42,16 +41,17 @@ class HttpClientTestIT extends BaseTest { Configuration configuration = Configuration.builder().setOAuthUrl(String.format("%s/auth", serverUrl)).build(); + HttpClientApache httpClient = new HttpClientApache(); + AuthManager basicAuthManager = new BasicAuthManager(configuration); - BearerAuthManager bearerAuthManager = new BearerAuthManager(configuration, new HttpMapper()); + BearerAuthManager bearerAuthManager = + new BearerAuthManager(configuration, new HttpMapper(), httpClient); Map authManagers = Stream.of(basicAuthManager, bearerAuthManager) .map(e -> new AbstractMap.SimpleEntry<>(e.getSchema(), e)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - HttpClientApache httpClient = new HttpClientApache(authManagers); - @BeforeAll static void classSetUp() throws IOException { mockBackEnd = new MockWebServer(); @@ -63,11 +63,6 @@ static void tearDown() throws IOException { mockBackEnd.shutdown(); } - @BeforeEach - void testSetUp() { - bearerAuthManager.setHttpClient(httpClient); - } - @Test void basicAuthorization() throws InterruptedException { @@ -75,6 +70,7 @@ void basicAuthorization() throws InterruptedException { new MockResponse().setBody("foo").addHeader("Content-Type", "application/json")); httpClient.invokeAPI( new ServerConfiguration(String.format("%s/foo", serverUrl)), + authManagers, new HttpRequest( "foo-path", HttpMethod.GET, @@ -83,7 +79,7 @@ void basicAuthorization() throws InterruptedException { null, null, null, - Collections.singletonList(BasicAuthManager.BASIC_SCHEMA_KEYWORD))); + Collections.singletonList(basicAuthManager.getSchema()))); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); String header = recordedRequest.getHeader("Authorization"); @@ -99,6 +95,7 @@ void initialBearerAuthorization() throws InterruptedException { new MockResponse().setBody("foo3").addHeader("Content-Type", "application/json")); httpClient.invokeAPI( new ServerConfiguration(String.format("%s/foo", serverUrl)), + authManagers, new HttpRequest( "foo-path", HttpMethod.GET, @@ -107,7 +104,7 @@ void initialBearerAuthorization() throws InterruptedException { null, null, null, - Collections.singletonList(BearerAuthManager.BEARER_SCHEMA_KEYWORD))); + Collections.singletonList(bearerAuthManager.getSchema()))); RecordedRequest recordedRequest = mockBackEnd.takeRequest(); @@ -141,6 +138,7 @@ void bearerAutoRefresh() throws InterruptedException { try { httpClient.invokeAPI( new ServerConfiguration(String.format("%s/foo/", serverUrl)), + authManagers, new HttpRequest( "foo-path", HttpMethod.GET, @@ -149,7 +147,7 @@ void bearerAutoRefresh() throws InterruptedException { null, null, null, - Collections.singletonList(BearerAuthManager.BEARER_SCHEMA_KEYWORD))); + Collections.singletonList(bearerAuthManager.getSchema()))); } catch (ApiException ae) { // noop } diff --git a/core/src/main/com/sinch/sdk/core/http/AuthManager.java b/core/src/main/com/sinch/sdk/core/http/AuthManager.java new file mode 100644 index 00000000..20a73243 --- /dev/null +++ b/core/src/main/com/sinch/sdk/core/http/AuthManager.java @@ -0,0 +1,13 @@ +package com.sinch.sdk.core.http; + +public interface AuthManager { + + final String SCHEMA_KEYWORD_BEARER = "Bearer"; + final String SCHEMA_KEYWORD_BASIC = "Basic"; + + String getSchema(); + + void resetToken(); + + String getAuthorizationHeaderValue(); +} diff --git a/core/src/main/com/sinch/sdk/core/http/HttpClient.java b/core/src/main/com/sinch/sdk/core/http/HttpClient.java index def19014..11ccebb1 100644 --- a/core/src/main/com/sinch/sdk/core/http/HttpClient.java +++ b/core/src/main/com/sinch/sdk/core/http/HttpClient.java @@ -2,6 +2,7 @@ import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.models.ServerConfiguration; +import java.util.Map; public interface HttpClient extends AutoCloseable { @@ -9,6 +10,9 @@ public interface HttpClient extends AutoCloseable { void close() throws Exception; - HttpResponse invokeAPI(ServerConfiguration serverConfiguration, HttpRequest request) + HttpResponse invokeAPI( + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpRequest request) throws ApiException; } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApi.java index a381369e..b4495ea2 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApi.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; @@ -41,12 +42,17 @@ public class ActiveNumberApi { private static final Logger LOGGER = Logger.getLogger(ActiveNumberApi.class.getName()); private HttpClient httpClient; private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; private HttpMapper mapper; public ActiveNumberApi( - HttpClient httpClient, ServerConfiguration serverConfiguration, HttpMapper mapper) { + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { this.httpClient = httpClient; this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; this.mapper = mapper; } @@ -75,7 +81,9 @@ public ActiveNumberDto numberServiceGetActiveNumber(String projectId, String pho + phoneNumber); HttpRequest httpRequest = numberServiceGetActiveNumberRequestBuilder(projectId, phoneNumber); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = new TypeReference() {}; @@ -212,7 +220,9 @@ public ActiveNumbersResponseDto numberServiceListActiveNumbers( pageSize, pageToken, orderBy); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -356,7 +366,9 @@ public ActiveNumberDto numberServiceReleaseNumber(String projectId, String phone + phoneNumber); HttpRequest httpRequest = numberServiceReleaseNumberRequestBuilder(projectId, phoneNumber); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = new TypeReference() {}; @@ -451,7 +463,9 @@ public ActiveNumberDto numberServiceUpdateActiveNumber( HttpRequest httpRequest = numberServiceUpdateActiveNumberRequestBuilder( projectId, phoneNumber, activeNumberRequestDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = new TypeReference() {}; diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApi.java index 5e726f75..40674927 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApi.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; @@ -43,12 +44,17 @@ public class AvailableNumberApi { private static final Logger LOGGER = Logger.getLogger(AvailableNumberApi.class.getName()); private HttpClient httpClient; private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; private HttpMapper mapper; public AvailableNumberApi( - HttpClient httpClient, ServerConfiguration serverConfiguration, HttpMapper mapper) { + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { this.httpClient = httpClient; this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; this.mapper = mapper; } @@ -79,7 +85,9 @@ public AvailableNumberDto numberServiceGetAvailableNumber(String projectId, Stri + phoneNumber); HttpRequest httpRequest = numberServiceGetAvailableNumberRequestBuilder(projectId, phoneNumber); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -208,7 +216,9 @@ public AvailableNumbersResponseDto numberServiceListAvailableNumbers( numberPatternSearchPattern, capabilities, size); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -343,7 +353,9 @@ public ActiveNumberDto numberServiceRentAnyNumber( HttpRequest httpRequest = numberServiceRentAnyNumberRequestBuilder(projectId, rentAnyNumberRequestDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = new TypeReference() {}; @@ -434,7 +446,9 @@ public ActiveNumberDto numberServiceRentNumber( HttpRequest httpRequest = numberServiceRentNumberRequestBuilder(projectId, phoneNumber, rentNumberRequestDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = new TypeReference() {}; diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApi.java index 8fe90f51..6ce73532 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApi.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; @@ -39,12 +40,17 @@ public class AvailableRegionsApi { private static final Logger LOGGER = Logger.getLogger(AvailableRegionsApi.class.getName()); private HttpClient httpClient; private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; private HttpMapper mapper; public AvailableRegionsApi( - HttpClient httpClient, ServerConfiguration serverConfiguration, HttpMapper mapper) { + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { this.httpClient = httpClient; this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; this.mapper = mapper; } @@ -75,7 +81,9 @@ public ListAvailableRegionsResponseDto numberServiceListAvailableRegions( + types); HttpRequest httpRequest = numberServiceListAvailableRegionsRequestBuilder(projectId, types); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApi.java index c5e6af56..120d64dc 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApi.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; @@ -40,12 +41,17 @@ public class CallbackConfigurationApi { private static final Logger LOGGER = Logger.getLogger(CallbackConfigurationApi.class.getName()); private HttpClient httpClient; private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; private HttpMapper mapper; public CallbackConfigurationApi( - HttpClient httpClient, ServerConfiguration serverConfiguration, HttpMapper mapper) { + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { this.httpClient = httpClient; this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; this.mapper = mapper; } @@ -63,7 +69,9 @@ public CallbackConfigurationDto getCallbackConfiguration(String projectId) throw LOGGER.finest("[getCallbackConfiguration] " + "projectId: " + projectId); HttpRequest httpRequest = getCallbackConfigurationRequestBuilder(projectId); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -138,7 +146,9 @@ public CallbackConfigurationDto updateCallbackConfiguration( HttpRequest httpRequest = updateCallbackConfigurationRequestBuilder(projectId, callbackConfigurationUpdateDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java index d8fed58f..266bdc50 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; @@ -44,12 +45,17 @@ public class BatchesApi { private static final Logger LOGGER = Logger.getLogger(BatchesApi.class.getName()); private HttpClient httpClient; private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; private HttpMapper mapper; public BatchesApi( - HttpClient httpClient, ServerConfiguration serverConfiguration, HttpMapper mapper) { + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { this.httpClient = httpClient; this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; this.mapper = mapper; } @@ -74,7 +80,9 @@ public SendSMS201ResponseDto cancelBatchMessage(String servicePlanId, String bat "[cancelBatchMessage] " + "servicePlanId: " + servicePlanId + ", " + "batchId: " + batchId); HttpRequest httpRequest = cancelBatchMessageRequestBuilder(servicePlanId, batchId); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -167,7 +175,9 @@ public void deliveryFeedback( HttpRequest httpRequest = deliveryFeedbackRequestBuilder(servicePlanId, batchId, apiDeliveryFeedbackDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { return; @@ -267,7 +277,9 @@ public DryRun200ResponseDto dryRun( HttpRequest httpRequest = dryRunRequestBuilder(servicePlanId, perRecipient, numberOfRecipients, sendSMSRequestDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -354,7 +366,9 @@ public SendSMS201ResponseDto getBatchMessage(String servicePlanId, String batchI "[getBatchMessage] " + "servicePlanId: " + servicePlanId + ", " + "batchId: " + batchId); HttpRequest httpRequest = getBatchMessageRequestBuilder(servicePlanId, batchId); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -469,7 +483,9 @@ public ApiBatchListDto listBatches( HttpRequest httpRequest = listBatchesRequestBuilder( servicePlanId, page, pageSize, from, startDate, endDate, clientReference); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = new TypeReference() {}; @@ -584,7 +600,9 @@ public SendSMS201ResponseDto replaceBatch( + sendSMSRequestDto); HttpRequest httpRequest = replaceBatchRequestBuilder(servicePlanId, batchId, sendSMSRequestDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -670,7 +688,9 @@ public SendSMS201ResponseDto sendSMS(String servicePlanId, SendSMSRequestDto sen + sendSMSRequestDto); HttpRequest httpRequest = sendSMSRequestBuilder(servicePlanId, sendSMSRequestDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -751,7 +771,9 @@ public SendSMS201ResponseDto updateBatchMessage( HttpRequest httpRequest = updateBatchMessageRequestBuilder(servicePlanId, batchId, updateBatchMessageRequestDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/DeliveryReportsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/DeliveryReportsApi.java index 050f5334..df92a507 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/DeliveryReportsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/DeliveryReportsApi.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; @@ -41,12 +42,17 @@ public class DeliveryReportsApi { private static final Logger LOGGER = Logger.getLogger(DeliveryReportsApi.class.getName()); private HttpClient httpClient; private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; private HttpMapper mapper; public DeliveryReportsApi( - HttpClient httpClient, ServerConfiguration serverConfiguration, HttpMapper mapper) { + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { this.httpClient = httpClient; this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; this.mapper = mapper; } @@ -91,7 +97,9 @@ public DeliveryReportDto getDeliveryReportByBatchId( HttpRequest httpRequest = getDeliveryReportByBatchIdRequestBuilder(servicePlanId, batchId, type, status, code); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -192,7 +200,9 @@ public RecipientDeliveryReportDto getDeliveryReportByPhoneNumber( HttpRequest httpRequest = getDeliveryReportByPhoneNumberRequestBuilder(servicePlanId, batchId, recipientMsisdn); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -321,7 +331,9 @@ public DeliveryReportListDto getDeliveryReports( HttpRequest httpRequest = getDeliveryReportsRequestBuilder( servicePlanId, page, pageSize, startDate, endDate, status, code, clientReference); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/GroupsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/GroupsApi.java index bd3546e6..d258a8ae 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/GroupsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/GroupsApi.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; @@ -43,12 +44,17 @@ public class GroupsApi { private static final Logger LOGGER = Logger.getLogger(GroupsApi.class.getName()); private HttpClient httpClient; private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; private HttpMapper mapper; public GroupsApi( - HttpClient httpClient, ServerConfiguration serverConfiguration, HttpMapper mapper) { + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { this.httpClient = httpClient; this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; this.mapper = mapper; } @@ -75,7 +81,9 @@ public CreateGroupResponseDto createGroup(String servicePlanId, GroupObjectDto g + groupObjectDto); HttpRequest httpRequest = createGroupRequestBuilder(servicePlanId, groupObjectDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -140,7 +148,9 @@ public void deleteGroup(String servicePlanId, String groupId) throws ApiExceptio "[deleteGroup] " + "servicePlanId: " + servicePlanId + ", " + "groupId: " + groupId); HttpRequest httpRequest = deleteGroupRequestBuilder(servicePlanId, groupId); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { return; @@ -213,7 +223,9 @@ public List getMembers(String servicePlanId, String groupId) throws ApiE "[getMembers] " + "servicePlanId: " + servicePlanId + ", " + "groupId: " + groupId); HttpRequest httpRequest = getMembersRequestBuilder(servicePlanId, groupId); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference> localVarReturnType = new TypeReference>() {}; @@ -297,7 +309,9 @@ public ApiGroupListDto listGroups(String servicePlanId, Integer page, Integer pa + pageSize); HttpRequest httpRequest = listGroupsRequestBuilder(servicePlanId, page, pageSize); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = new TypeReference() {}; @@ -385,7 +399,9 @@ public CreateGroupResponseDto replaceGroup( HttpRequest httpRequest = replaceGroupRequestBuilder(servicePlanId, groupId, replaceGroupRequestDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -461,7 +477,9 @@ public CreateGroupResponseDto retrieveGroup(String servicePlanId, String groupId "[retrieveGroup] " + "servicePlanId: " + servicePlanId + ", " + "groupId: " + groupId); HttpRequest httpRequest = retrieveGroupRequestBuilder(servicePlanId, groupId); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -557,7 +575,9 @@ public CreateGroupResponseDto updateGroup( HttpRequest httpRequest = updateGroupRequestBuilder(servicePlanId, groupId, updateGroupRequestDto); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/InboundsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/InboundsApi.java index a79ded82..9b150ba7 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/InboundsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/InboundsApi.java @@ -15,6 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.http.HttpMethod; @@ -40,12 +41,17 @@ public class InboundsApi { private static final Logger LOGGER = Logger.getLogger(InboundsApi.class.getName()); private HttpClient httpClient; private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; private HttpMapper mapper; public InboundsApi( - HttpClient httpClient, ServerConfiguration serverConfiguration, HttpMapper mapper) { + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { this.httpClient = httpClient; this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; this.mapper = mapper; } @@ -114,7 +120,9 @@ public ApiInboundListDto listInboundMessages( HttpRequest httpRequest = listInboundMessagesRequestBuilder( servicePlanId, page, pageSize, to, startDate, endDate, clientReference); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = @@ -225,7 +233,9 @@ public InboundDto retrieveInboundMessage(String servicePlanId, String inboundId) + inboundId); HttpRequest httpRequest = retrieveInboundMessageRequestBuilder(servicePlanId, inboundId); - HttpResponse response = httpClient.invokeAPI(this.serverConfiguration, httpRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { TypeReference localVarReturnType = new TypeReference() {}; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApiTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApiTest.java index a0a3e4b9..1ff91287 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApiTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/ActiveNumberApiTest.java @@ -32,10 +32,11 @@ class ActiveNumberApiTest extends BaseTest { @Mock HttpClient httpClient; @Mock ServerConfiguration serverConfiguration; + HttpMapper mapper = new HttpMapper(); @InjectMocks - ActiveNumberApi service = new ActiveNumberApi(httpClient, serverConfiguration, mapper); + ActiveNumberApi service = new ActiveNumberApi(httpClient, serverConfiguration, null, mapper); ActiveNumberDto expectedActiveNumberDto = new ActiveNumberDto( @@ -72,7 +73,7 @@ class ActiveNumberApiTest extends BaseTest { @Test void list() { - when(httpClient.invokeAPI(eq(serverConfiguration), any())) + when(httpClient.invokeAPI(eq(serverConfiguration), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, activeListResponse.getBytes(StandardCharsets.UTF_8))); @@ -101,7 +102,7 @@ void list() { @Test void get() { - when(httpClient.invokeAPI(eq(serverConfiguration), any())) + when(httpClient.invokeAPI(eq(serverConfiguration), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, activeGetResponse.getBytes(StandardCharsets.UTF_8))); @@ -114,7 +115,7 @@ void get() { @Test void release() { - when(httpClient.invokeAPI(eq(serverConfiguration), any())) + when(httpClient.invokeAPI(eq(serverConfiguration), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, activeGetResponse.getBytes(StandardCharsets.UTF_8))); @@ -127,7 +128,7 @@ void release() { @Test void update() { - when(httpClient.invokeAPI(eq(serverConfiguration), any())) + when(httpClient.invokeAPI(eq(serverConfiguration), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, activeGetResponse.getBytes(StandardCharsets.UTF_8))); diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApiTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApiTest.java index b6a6a029..32eef4cd 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApiTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableNumberApiTest.java @@ -43,7 +43,8 @@ class AvailableNumberApiTest extends BaseTest { HttpMapper mapper = new HttpMapper(); @InjectMocks - AvailableNumberApi service = new AvailableNumberApi(httpClient, serverConfiguration, mapper); + AvailableNumberApi service = + new AvailableNumberApi(httpClient, serverConfiguration, null, mapper); AvailableNumberDto expectedAvailableNumberDto = new AvailableNumberDto("+46650553763", "SE", 1, true) @@ -92,7 +93,7 @@ class AvailableNumberApiTest extends BaseTest { @Test void listAll() { - when(httpClient.invokeAPI(any(), any())) + when(httpClient.invokeAPI(any(), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, availableListResponse.getBytes(StandardCharsets.UTF_8))); @@ -117,7 +118,7 @@ void listAll() { @Test void get() { - when(httpClient.invokeAPI(any(), any())) + when(httpClient.invokeAPI(any(), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, availableGetResponse.getBytes(StandardCharsets.UTF_8))); @@ -132,7 +133,7 @@ void get() { @Test void rentAny() { - when(httpClient.invokeAPI(any(), any())) + when(httpClient.invokeAPI(any(), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, rentResponse.getBytes(StandardCharsets.UTF_8))); @@ -159,7 +160,7 @@ void rentAny() { @Test void rent() { - when(httpClient.invokeAPI(any(), any())) + when(httpClient.invokeAPI(any(), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, rentResponse.getBytes(StandardCharsets.UTF_8))); @@ -173,7 +174,7 @@ void rent() { @Test void rentWithError() { - when(httpClient.invokeAPI(any(), any())) + when(httpClient.invokeAPI(any(), any(), any())) .thenReturn( new HttpResponse( 500, "foo message", null, errorTrialAccount.getBytes(StandardCharsets.UTF_8))); diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApiTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApiTest.java index 823cc1f3..5a972ad2 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApiTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/AvailableRegionsApiTest.java @@ -30,7 +30,8 @@ class AvailableRegionsApiTest extends BaseTest { HttpMapper mapper = new HttpMapper(); @InjectMocks - AvailableRegionsApi service = new AvailableRegionsApi(httpClient, serverConfiguration, mapper); + AvailableRegionsApi service = + new AvailableRegionsApi(httpClient, serverConfiguration, null, mapper); AvailableRegionDto expectedAvailableRegionDto = new AvailableRegionDto("AU", "Australia", Collections.singletonList("MOBILE")); @@ -38,7 +39,7 @@ class AvailableRegionsApiTest extends BaseTest { @Test void listAll() { - when(httpClient.invokeAPI(any(), any())) + when(httpClient.invokeAPI(any(), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, availableListResponse.getBytes(StandardCharsets.UTF_8))); diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApiTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApiTest.java index 7769e109..010b7d64 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApiTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/numbers/adapters/api/v1/CallbackConfigurationApiTest.java @@ -31,7 +31,7 @@ class CallbackConfigurationApiTest extends BaseTest { @InjectMocks CallbackConfigurationApi service = - new CallbackConfigurationApi(httpClient, serverConfiguration, mapper); + new CallbackConfigurationApi(httpClient, serverConfiguration, null, mapper); CallbackConfigurationDto expectedDto = new CallbackConfigurationDto().projectId("The project ID").hmacSecret("The secret HMAC"); @@ -39,7 +39,7 @@ class CallbackConfigurationApiTest extends BaseTest { @Test void get() { - when(httpClient.invokeAPI(eq(serverConfiguration), any())) + when(httpClient.invokeAPI(eq(serverConfiguration), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, callbackConfiguration.getBytes(StandardCharsets.UTF_8))); @@ -52,7 +52,7 @@ void get() { @Test void update() { - when(httpClient.invokeAPI(eq(serverConfiguration), any())) + when(httpClient.invokeAPI(eq(serverConfiguration), any(), any())) .thenReturn( new HttpResponse( 200, "foo message", null, callbackConfiguration.getBytes(StandardCharsets.UTF_8))); diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java index afa44d61..03286734 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java @@ -23,14 +23,14 @@ public static void main(String[] args) { public void run() { - LOGGER.info("Send Text"); + LOGGER.info("Send Text to " + phoneNumber); BatchText value = client .sms() .batches() .send( SendSmsBatchTextRequest.builder() - .setTo(Collections.singletonList("+foo ")) + .setTo(Collections.singletonList(phoneNumber)) .setBody("the body") .setClientReference("a client reference") .setFrom("+33123456789") diff --git a/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/GetForNumber.java b/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/GetForNumber.java index 8a25f1c0..14cbbcbb 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/GetForNumber.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/deliveryReports/GetForNumber.java @@ -12,7 +12,7 @@ public GetForNumber() throws IOException {} public static void main(String[] args) { try { - new Get().run(); + new GetForNumber().run(); } catch (Exception e) { LOGGER.severe(e.getMessage()); e.printStackTrace(); @@ -21,7 +21,7 @@ public static void main(String[] args) { public void run() { - LOGGER.info("Get for :" + phoneNumber); + LOGGER.info("Get for: " + phoneNumber); DeliveryReportRecipient response = client.sms().deliveryReports().getForNumber(batchId, phoneNumber);