Skip to content

Commit 02613cf

Browse files
Merge pull request #9 from emnify/remove-username-password-auth
CI-3316-Java SDK using username and password is deprecated
2 parents aec2f47 + dc9f7cf commit 02613cf

15 files changed

Lines changed: 1 addition & 603 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ You can use environment variables for storing configuration settings like an app
7272
|--------------------|--------------------------------------------------------------------------|
7373
| `EMNIFY_BASE_PATH` | Base URL to form a request. Default value: `https://cdn.emnify.net` |
7474
| `EMNIFY_APPLICATION_TOKEN` | Variable for authenticating via an [application token](https://cdn.emnify.net/api/doc/application-token.html). |
75-
| `EMNIFY_USERNAME` and `EMNIFY_PASSWORD` | Variables for authenticating via [username and password](https://cdn.emnify.net/api/doc/basic-auth.html). |
7675

7776
## Documentation
7877

api/docs/Authentication.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
Name | Type | Description | Notes
99
------------ | ------------- | ------------- | -------------
1010
**applicationToken** | **String** | | [optional]
11-
**username** | **String** | | [optional]
12-
**password** | **String** | | [optional]
1311
**refreshToken** | **String** | | [optional]
1412

1513

api/src/main/java/com/emnify/sdk/ApiClient.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.io.InputStream;
3636
import java.io.UnsupportedEncodingException;
3737
import java.lang.reflect.Type;
38-
import java.net.URI;
3938
import java.net.URLConnection;
4039
import java.net.URLEncoder;
4140
import java.nio.file.Files;
@@ -46,7 +45,6 @@
4645
import java.security.cert.Certificate;
4746
import java.security.cert.CertificateException;
4847
import java.security.cert.CertificateFactory;
49-
import java.security.cert.X509Certificate;
5048
import java.text.DateFormat;
5149
import java.time.LocalDate;
5250
import java.time.OffsetDateTime;
@@ -58,7 +56,6 @@
5856
import java.util.regex.Pattern;
5957

6058
import com.emnify.sdk.auth.Authentication;
61-
import com.emnify.sdk.auth.HttpBasicAuth;
6259
import com.emnify.sdk.auth.HttpBearerAuth;
6360
import com.emnify.sdk.auth.ApiKeyAuth;
6461

@@ -323,35 +320,7 @@ public void setBearerToken(String bearerToken) {
323320
throw new RuntimeException("No Bearer authentication configured!");
324321
}
325322

326-
/**
327-
* Helper method to set username for the first HTTP basic authentication.
328-
*
329-
* @param username Username
330-
*/
331-
public void setUsername(String username) {
332-
for (Authentication auth : authentications.values()) {
333-
if (auth instanceof HttpBasicAuth) {
334-
((HttpBasicAuth) auth).setUsername(username);
335-
return;
336-
}
337-
}
338-
throw new RuntimeException("No HTTP basic authentication configured!");
339-
}
340323

341-
/**
342-
* Helper method to set password for the first HTTP basic authentication.
343-
*
344-
* @param password Password
345-
*/
346-
public void setPassword(String password) {
347-
for (Authentication auth : authentications.values()) {
348-
if (auth instanceof HttpBasicAuth) {
349-
((HttpBasicAuth) auth).setPassword(password);
350-
return;
351-
}
352-
}
353-
throw new RuntimeException("No HTTP basic authentication configured!");
354-
}
355324

356325
/**
357326
* Helper method to set API key value for the first API key authentication.

api/src/main/java/com/emnify/sdk/auth/HttpBasicAuth.java

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

api/src/main/java/com/emnify/sdk/model/Authentication.java

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ public class Authentication {
4141
@SerializedName(SERIALIZED_NAME_APPLICATION_TOKEN)
4242
private String applicationToken;
4343

44-
public static final String SERIALIZED_NAME_USERNAME = "username";
45-
@SerializedName(SERIALIZED_NAME_USERNAME)
46-
private String username;
47-
48-
public static final String SERIALIZED_NAME_PASSWORD = "password";
49-
@SerializedName(SERIALIZED_NAME_PASSWORD)
50-
private String password;
5144

5245
public static final String SERIALIZED_NAME_REFRESH_TOKEN = "refresh_token";
5346
@SerializedName(SERIALIZED_NAME_REFRESH_TOKEN)
@@ -77,50 +70,8 @@ public void setApplicationToken(String applicationToken) {
7770
}
7871

7972

80-
public Authentication username(String username) {
81-
82-
this.username = username;
83-
return this;
84-
}
85-
86-
/**
87-
* Get username
88-
* @return username
89-
**/
90-
@javax.annotation.Nullable
91-
@ApiModelProperty(value = "")
92-
93-
public String getUsername() {
94-
return username;
95-
}
96-
97-
98-
public void setUsername(String username) {
99-
this.username = username;
100-
}
10173

10274

103-
public Authentication password(String password) {
104-
105-
this.password = password;
106-
return this;
107-
}
108-
109-
/**
110-
* Get password
111-
* @return password
112-
**/
113-
@javax.annotation.Nullable
114-
@ApiModelProperty(value = "")
115-
116-
public String getPassword() {
117-
return password;
118-
}
119-
120-
121-
public void setPassword(String password) {
122-
this.password = password;
123-
}
12475

12576

12677
public Authentication refreshToken(String refreshToken) {
@@ -156,23 +107,19 @@ public boolean equals(Object o) {
156107
}
157108
Authentication authentication = (Authentication) o;
158109
return Objects.equals(this.applicationToken, authentication.applicationToken) &&
159-
Objects.equals(this.username, authentication.username) &&
160-
Objects.equals(this.password, authentication.password) &&
161110
Objects.equals(this.refreshToken, authentication.refreshToken);
162111
}
163112

164113
@Override
165114
public int hashCode() {
166-
return Objects.hash(applicationToken, username, password, refreshToken);
115+
return Objects.hash(applicationToken, refreshToken);
167116
}
168117

169118
@Override
170119
public String toString() {
171120
StringBuilder sb = new StringBuilder();
172121
sb.append("class Authentication {\n");
173122
sb.append(" applicationToken: ").append(toIndentedString(applicationToken)).append("\n");
174-
sb.append(" username: ").append(toIndentedString(username)).append("\n");
175-
sb.append(" password: ").append(toIndentedString(password)).append("\n");
176123
sb.append(" refreshToken: ").append(toIndentedString(refreshToken)).append("\n");
177124
sb.append("}");
178125
return sb.toString();

api/src/test/java/com/emnify/sdk/model/AuthenticationTest.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,6 @@ public void applicationTokenTest() {
5656
// TODO: test applicationToken
5757
}
5858

59-
/**
60-
* Test the property 'username'
61-
*/
62-
@Test
63-
public void usernameTest() {
64-
// TODO: test username
65-
}
66-
67-
/**
68-
* Test the property 'password'
69-
*/
70-
@Test
71-
public void passwordTest() {
72-
// TODO: test password
73-
}
7459

7560
/**
7661
* Test the property 'refreshToken'

emnify/src/main/java/com/emnify/sdk/client/EMnify.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
public class EMnify {
3636

3737
private static final String APPLICATION_TOKEN_ENV = "EMNIFY_APPLICATION_TOKEN";
38-
private static final String USERNAME_ENV = "EMNIFY_USERNAME";
39-
private static final String PASSWORD_ENV = "EMNIFY_PASSWORD";
4038

4139
private final Authentication authentication;
4240
private final AuthenticationRetrier authenticationRetrier;
@@ -52,7 +50,6 @@ private EMnify(Authentication authentication, ApiClient apiClient) {
5250
* Performs api client authorization according to configured system environment variables:
5351
* <ul>
5452
* <li>EMNIFY_APPLICATION_TOKEN - is used for <a href="https://cdn.emnify.net/api/doc/application-token.html" target="_blank">Application Token Authentication</a></li>
55-
* <li>EMNIFY_USERNAME and EMNIFY_USERNAME - are used for <a href="https://cdn.emnify.net/api/doc/basic-auth.html" target="_blank">User Authentication</a></li>
5653
* </ul>
5754
* @return instance of authorized EMnify Client
5855
* @throws SdkException if authentication failed
@@ -61,27 +58,10 @@ public static EMnify authenticate() throws SdkException {
6158
Authentication authentication;
6259
authentication = createAuthentication(SystemUtils.getEnvironmentVariable(APPLICATION_TOKEN_ENV, ""));
6360

64-
if (authentication == null) {
65-
String username = SystemUtils.getEnvironmentVariable(USERNAME_ENV, "");
66-
String password = SystemUtils.getEnvironmentVariable(PASSWORD_ENV, "");
67-
authentication = Configuration.createAuthentication(username, password);
68-
}
6961

7062
return authenticate(authentication);
7163
}
7264

73-
/**
74-
* Performs api client authorization with user/password combination
75-
*
76-
* @param username username
77-
* @param password password
78-
*
79-
* @return instance of authorized EMnify Client
80-
* @throws SdkException if authentication failed
81-
*/
82-
public static EMnify authenticate(String username, String password) throws SdkException {
83-
return authenticate(Configuration.createAuthentication(username, password));
84-
}
8565

8666
/**
8767
* Performs api client authorization with application token

0 commit comments

Comments
 (0)