Skip to content

Commit

Permalink
Merge pull request #9 from emnify/remove-username-password-auth
Browse files Browse the repository at this point in the history
CI-3316-Java SDK using username and password is deprecated
  • Loading branch information
martin-scholz-emnify authored Jul 24, 2024
2 parents aec2f47 + dc9f7cf commit 02613cf
Show file tree
Hide file tree
Showing 15 changed files with 1 addition and 603 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ You can use environment variables for storing configuration settings like an app
|--------------------|--------------------------------------------------------------------------|
| `EMNIFY_BASE_PATH` | Base URL to form a request. Default value: `https://cdn.emnify.net` |
| `EMNIFY_APPLICATION_TOKEN` | Variable for authenticating via an [application token](https://cdn.emnify.net/api/doc/application-token.html). |
| `EMNIFY_USERNAME` and `EMNIFY_PASSWORD` | Variables for authenticating via [username and password](https://cdn.emnify.net/api/doc/basic-auth.html). |

## Documentation

Expand Down
2 changes: 0 additions & 2 deletions api/docs/Authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**applicationToken** | **String** | | [optional]
**username** | **String** | | [optional]
**password** | **String** | | [optional]
**refreshToken** | **String** | | [optional]


Expand Down
31 changes: 0 additions & 31 deletions api/src/main/java/com/emnify/sdk/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URI;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.file.Files;
Expand All @@ -46,7 +45,6 @@
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.text.DateFormat;
import java.time.LocalDate;
import java.time.OffsetDateTime;
Expand All @@ -58,7 +56,6 @@
import java.util.regex.Pattern;

import com.emnify.sdk.auth.Authentication;
import com.emnify.sdk.auth.HttpBasicAuth;
import com.emnify.sdk.auth.HttpBearerAuth;
import com.emnify.sdk.auth.ApiKeyAuth;

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

/**
* Helper method to set username for the first HTTP basic authentication.
*
* @param username Username
*/
public void setUsername(String username) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setUsername(username);
return;
}
}
throw new RuntimeException("No HTTP basic authentication configured!");
}

/**
* Helper method to set password for the first HTTP basic authentication.
*
* @param password Password
*/
public void setPassword(String password) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBasicAuth) {
((HttpBasicAuth) auth).setPassword(password);
return;
}
}
throw new RuntimeException("No HTTP basic authentication configured!");
}

/**
* Helper method to set API key value for the first API key authentication.
Expand Down
62 changes: 0 additions & 62 deletions api/src/main/java/com/emnify/sdk/auth/HttpBasicAuth.java

This file was deleted.

55 changes: 1 addition & 54 deletions api/src/main/java/com/emnify/sdk/model/Authentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ public class Authentication {
@SerializedName(SERIALIZED_NAME_APPLICATION_TOKEN)
private String applicationToken;

public static final String SERIALIZED_NAME_USERNAME = "username";
@SerializedName(SERIALIZED_NAME_USERNAME)
private String username;

public static final String SERIALIZED_NAME_PASSWORD = "password";
@SerializedName(SERIALIZED_NAME_PASSWORD)
private String password;

public static final String SERIALIZED_NAME_REFRESH_TOKEN = "refresh_token";
@SerializedName(SERIALIZED_NAME_REFRESH_TOKEN)
Expand Down Expand Up @@ -77,50 +70,8 @@ public void setApplicationToken(String applicationToken) {
}


public Authentication username(String username) {

this.username = username;
return this;
}

/**
* Get username
* @return username
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")

public String getUsername() {
return username;
}


public void setUsername(String username) {
this.username = username;
}


public Authentication password(String password) {

this.password = password;
return this;
}

/**
* Get password
* @return password
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")

public String getPassword() {
return password;
}


public void setPassword(String password) {
this.password = password;
}


public Authentication refreshToken(String refreshToken) {
Expand Down Expand Up @@ -156,23 +107,19 @@ public boolean equals(Object o) {
}
Authentication authentication = (Authentication) o;
return Objects.equals(this.applicationToken, authentication.applicationToken) &&
Objects.equals(this.username, authentication.username) &&
Objects.equals(this.password, authentication.password) &&
Objects.equals(this.refreshToken, authentication.refreshToken);
}

@Override
public int hashCode() {
return Objects.hash(applicationToken, username, password, refreshToken);
return Objects.hash(applicationToken, refreshToken);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Authentication {\n");
sb.append(" applicationToken: ").append(toIndentedString(applicationToken)).append("\n");
sb.append(" username: ").append(toIndentedString(username)).append("\n");
sb.append(" password: ").append(toIndentedString(password)).append("\n");
sb.append(" refreshToken: ").append(toIndentedString(refreshToken)).append("\n");
sb.append("}");
return sb.toString();
Expand Down
15 changes: 0 additions & 15 deletions api/src/test/java/com/emnify/sdk/model/AuthenticationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ public void applicationTokenTest() {
// TODO: test applicationToken
}

/**
* Test the property 'username'
*/
@Test
public void usernameTest() {
// TODO: test username
}

/**
* Test the property 'password'
*/
@Test
public void passwordTest() {
// TODO: test password
}

/**
* Test the property 'refreshToken'
Expand Down
20 changes: 0 additions & 20 deletions emnify/src/main/java/com/emnify/sdk/client/EMnify.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
public class EMnify {

private static final String APPLICATION_TOKEN_ENV = "EMNIFY_APPLICATION_TOKEN";
private static final String USERNAME_ENV = "EMNIFY_USERNAME";
private static final String PASSWORD_ENV = "EMNIFY_PASSWORD";

private final Authentication authentication;
private final AuthenticationRetrier authenticationRetrier;
Expand All @@ -52,7 +50,6 @@ private EMnify(Authentication authentication, ApiClient apiClient) {
* Performs api client authorization according to configured system environment variables:
* <ul>
* <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>
* <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>
* </ul>
* @return instance of authorized EMnify Client
* @throws SdkException if authentication failed
Expand All @@ -61,27 +58,10 @@ public static EMnify authenticate() throws SdkException {
Authentication authentication;
authentication = createAuthentication(SystemUtils.getEnvironmentVariable(APPLICATION_TOKEN_ENV, ""));

if (authentication == null) {
String username = SystemUtils.getEnvironmentVariable(USERNAME_ENV, "");
String password = SystemUtils.getEnvironmentVariable(PASSWORD_ENV, "");
authentication = Configuration.createAuthentication(username, password);
}

return authenticate(authentication);
}

/**
* Performs api client authorization with user/password combination
*
* @param username username
* @param password password
*
* @return instance of authorized EMnify Client
* @throws SdkException if authentication failed
*/
public static EMnify authenticate(String username, String password) throws SdkException {
return authenticate(Configuration.createAuthentication(username, password));
}

/**
* Performs api client authorization with application token
Expand Down
Loading

0 comments on commit 02613cf

Please sign in to comment.