Skip to content

Commit d4af1f8

Browse files
Revert "feat(multiple-auth): add support for multiple auth (#79)" (#84)
This reverts commit 3baa14a.
1 parent a50cbf4 commit d4af1f8

File tree

13 files changed

+85
-1033
lines changed

13 files changed

+85
-1033
lines changed

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,13 @@ Core lib's Maven group ID is `io.apimatic`, and its artifact ID is `core`.
1717
|-------------------------------------------------------------------------|--------------------------------------------------------------------|
1818
| [`ApiCall`](./src/main/java/io/apimatic/core/ApiCall.java) | An API call, or API request, is a message sent to a server asking an API to provide a service or information |
1919
| [`Parameter`](./src/main/java/io/apimatic/core/Parameter.java) | HTTP parameters consist of a type, a name, and a value. These parameters appear in the header and body of an HTTP request. |
20-
| [`ErrorCase`](./src/main/java/io/apimatic/core/ErrorCase.java) | A class which is responsible to generate the SDK Exception |
20+
| [`ErrorCase`](./src/main/java/io/apimatic/core/ErrorCase.java) | A class is responsible to generate the SDK Exception |
2121
| [`GlobalConfiguration`](./src/main/java/io/apimatic/core/GlobalConfiguration.java) | A class which hold the global configuration properties to make a successful Api Call |
2222
| [`HttpRequest`](./src/main/java/io/apimatic/core/HttpRequest.java) | An HTTP request is made by a client, to a named host, which is located on a server |
2323
| [`ResponseHandler`](./src/main/java/io/apimatic/core/ResponseHandler.java) | Handler that encapsulates the process of generating a response object from a Response |
2424
| [`HttpLogger`](./src/main/java/io/apimatic/core/logger/HttpLogger.java) | A class to log the Http events. |
25-
| [`AuthBuilder`](./src/main/java/io/apimatic/core/authentication/AuthBuilder.java) | A class to build and validate provided combination of auth schemes. |
26-
| [`AuthCredential`](./src/main/java/io/apimatic/core/authentication/AuthCredential.java) | A parent class of [`HeaderAuth`](./src/main/java/io/apimatic/core/authentication/HeaderAuth.java) and [`QueryAuth`](./src/main/java/io/apimatic/core/authentication/QueryAuth.java) to hold the common implementation for header and query parameters |
2725
| [`HeaderAuth`](./src/main/java/io/apimatic/core/authentication/HeaderAuth.java) | A class supports HTTP authentication through HTTP Headers |
2826
| [`QueryAuth`](./src/main/java/io/apimatic/core/authentication/QueryAuth.java) | A class supports HTTP authentication through query parameters |
29-
| [`AuthGroup`](./src/main/java/io/apimatic/core/authentication/multiple/AuthGroup.java) | A parent class of [`And`](./src/main/java/io/apimatic/core/authentication/multiple/And.java) and [`Or`](./src/main/java/io/apimatic/core/authentication/multiple/Or.java) to hold the common functionality of multiple auth |
30-
| [`And`](./src/main/java/io/apimatic/core/authentication/multiple/And.java) | A class to hold the algorithm for `And` combination of auth schemes|
31-
| [`Or`](./src/main/java/io/apimatic/core/authentication/multiple/Or.java) | A class to hold the algorithm for `Or` combination of auth schemes |
32-
| [`Single`](./src/main/java/io/apimatic/core/authentication/multiple/Single.java) | A class to hold the logic for single auth scheme, it is used as leaf node for auth combination or it could be used directly to apply one auth only to the http request |
3327
| [`CoreHttpClientConfiguration`](./src/main/java/io/apimatic/core/configurations/http/client/CoreHttpClientConfiguration.java) | To hold HTTP Client Configuration |
3428
| [`ApiLoggingConfiguration`](./src/main/java/io/apimatic/core/configurations/http/client/ApiLoggingConfiguration.java) | To hold logging configuration |
3529
| [`EndpointConfiguration`](./src/main/java/io/apimatic/core/configurations/http/request/EndpointConfiguration.java) | The configuration for an endpoint |

src/main/java/io/apimatic/core/HttpRequest.java

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import java.util.Map;
1010
import java.util.Set;
1111
import java.util.function.Consumer;
12-
import io.apimatic.core.authentication.AuthBuilder;
13-
import io.apimatic.core.exceptions.AuthValidationException;
1412
import io.apimatic.core.types.http.request.MultipartFileWrapper;
1513
import io.apimatic.core.types.http.request.MultipartWrapper;
1614
import io.apimatic.core.utilities.CoreHelper;
@@ -57,7 +55,7 @@ public final class HttpRequest {
5755
* @param server
5856
* @param path
5957
* @param httpMethod
60-
* @param authentication
58+
* @param authenticationKey
6159
* @param queryParams
6260
* @param templateParams
6361
* @param headerParams
@@ -67,18 +65,16 @@ public final class HttpRequest {
6765
* @param bodySerializer
6866
* @param bodyParameters
6967
* @param arraySerializationFormat
70-
* @param isSingleAuth
7168
* @throws IOException
7269
*/
7370
private HttpRequest(final GlobalConfiguration coreConfig, final String server,
74-
final String path, final Method httpMethod, final Authentication authentication,
71+
final String path, final Method httpMethod, final String authenticationKey,
7572
final Map<String, Object> queryParams,
7673
final Map<String, SimpleEntry<Object, Boolean>> templateParams,
7774
final Map<String, List<String>> headerParams, final Set<Parameter> formParams,
7875
final Map<String, Object> formParameters, final Object body,
7976
final Serializer bodySerializer, final Map<String, Object> bodyParameters,
80-
final ArraySerializationFormat arraySerializationFormat,
81-
final boolean isSingleAuth) throws IOException {
77+
final ArraySerializationFormat arraySerializationFormat) throws IOException {
8278
this.coreConfig = coreConfig;
8379
this.compatibilityFactory = coreConfig.getCompatibilityFactory();
8480
urlBuilder = getStringBuilder(server, path);
@@ -90,7 +86,7 @@ private HttpRequest(final GlobalConfiguration coreConfig, final String server,
9086
coreHttpRequest =
9187
buildRequest(httpMethod, bodyValue, addHeaders(headerParams), queryParams,
9288
formFields, arraySerializationFormat);
93-
applyAuthentication(authentication, isSingleAuth);
89+
applyAuthentication(authenticationKey);
9490
}
9591

9692
/**
@@ -100,6 +96,21 @@ public Request getCoreHttpRequest() {
10096
return coreHttpRequest;
10197
}
10298

99+
private void applyAuthentication(String authenticationKey) {
100+
if (authenticationKey == null) {
101+
return;
102+
}
103+
104+
Map<String, Authentication> authentications = coreConfig.getAuthentications();
105+
if (authentications != null) {
106+
Authentication authManager = authentications.get(authenticationKey);
107+
if (authManager != null) {
108+
authManager.validate();
109+
authManager.apply(coreHttpRequest);
110+
}
111+
}
112+
}
113+
103114
private Request buildRequest(
104115
Method httpMethod, Object body, HttpHeaders headerParams,
105116
Map<String, Object> queryParams, List<SimpleEntry<String, Object>> formFields,
@@ -113,22 +124,6 @@ private Request buildRequest(
113124
queryParams, formFields);
114125
}
115126

116-
private void applyAuthentication(Authentication authentication, boolean isSingleAuth) {
117-
if (authentication != null) {
118-
authentication.validate();
119-
if (!authentication.isValid() && !isSingleAuth) {
120-
throw new AuthValidationException(authentication.getErrorMessage());
121-
}
122-
123-
// The following block should be removed with the next major version release.
124-
if (isSingleAuth && authentication.getErrorMessage() != null) {
125-
throw new AuthValidationException(authentication.getErrorMessage());
126-
}
127-
128-
authentication.apply(coreHttpRequest);
129-
}
130-
}
131-
132127
/**
133128
* @param formParams
134129
* @param optionalFormParamaters
@@ -244,15 +239,9 @@ public static class Builder {
244239
private Method httpMethod;
245240

246241
/**
247-
* An auth builder for the request.
248-
*/
249-
private AuthBuilder authBuilder = new AuthBuilder();
250-
251-
/**
252-
* Flag to use for backward compatibility.
253-
* It should be removed with the next major version release.
242+
* A authentication key string.
254243
*/
255-
private boolean isSingleAuth = false;
244+
private String authenticationKey;
256245

257246
/**
258247
* A map of query parameters.
@@ -336,23 +325,12 @@ public Builder httpMethod(Method httpMethod) {
336325
}
337326

338327
/**
339-
* Setter for authentication key.
328+
* Setter for requiresAuth.
340329
* @param authenticationKey string value for authenticationKey.
341330
* @return Builder.
342331
*/
343332
public Builder authenticationKey(String authenticationKey) {
344-
authBuilder = authBuilder.add(authenticationKey);
345-
isSingleAuth = true;
346-
return this;
347-
}
348-
349-
/**
350-
* Setter for Authentication Builder, used for authenticating the request.
351-
* @param consumer the builder consumer for authentication.
352-
* @return Builder.
353-
*/
354-
public Builder withAuth(Consumer<AuthBuilder> consumer) {
355-
consumer.accept(authBuilder);
333+
this.authenticationKey = authenticationKey;
356334
return this;
357335
}
358336

@@ -494,12 +472,10 @@ public Builder arraySerializationFormat(ArraySerializationFormat arraySerializat
494472
* @throws IOException Signals that an I/O exception of some sort has occurred.
495473
*/
496474
public Request build(GlobalConfiguration coreConfig) throws IOException {
497-
Authentication authentication = authBuilder.build(coreConfig.getAuthentications());
498475
HttpRequest coreRequest =
499-
new HttpRequest(coreConfig, server, path, httpMethod, authentication,
476+
new HttpRequest(coreConfig, server, path, httpMethod, authenticationKey,
500477
queryParams, templateParams, headerParams, formParams, formParamaters,
501-
body, bodySerializer, bodyParameters, arraySerializationFormat,
502-
isSingleAuth);
478+
body, bodySerializer, bodyParameters, arraySerializationFormat);
503479
Request coreHttpRequest = coreRequest.getCoreHttpRequest();
504480

505481
if (coreConfig.getHttpCallback() != null) {

src/main/java/io/apimatic/core/authentication/AuthBuilder.java

Lines changed: 0 additions & 139 deletions
This file was deleted.

src/main/java/io/apimatic/core/authentication/AuthCredential.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)