forked from kruize/autotune
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kruize#1311 from khansaad/auth-updates
Database updates for authentication
- Loading branch information
Showing
18 changed files
with
431 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.autotune.common.auth; | ||
|
||
public enum AuthType { | ||
BASIC, BEARER, API_KEY, OAUTH2, NONE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 92 additions & 52 deletions
144
src/main/java/com/autotune/common/auth/Credentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,148 @@ | ||
package com.autotune.common.auth; | ||
|
||
public class Credentials { | ||
private String grantType; // OAuth2 | ||
private String clientId; // OAuth2 | ||
private String clientSecret; // OAuth2 | ||
private String username; // Basic auth | ||
private String password; // Basic auth | ||
private String tokenEndpoint; // OAuth2 | ||
private String tokenFilePath; // Bearer token | ||
private String apiKey; // API key | ||
private String headerName; // API key header name | ||
|
||
public Credentials(String username, String password) { | ||
this.username = username; | ||
this.password = password; | ||
} | ||
import java.util.Objects; | ||
|
||
public Credentials() { | ||
} | ||
public abstract class Credentials { | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
class OAuth2Credentials extends Credentials { | ||
private String grantType; | ||
private String clientId; | ||
private String clientSecret; | ||
private String tokenEndpoint; | ||
|
||
public String getGrantType() { | ||
return grantType; | ||
} | ||
|
||
public String getClientSecret() { | ||
return clientSecret; | ||
public void setGrantType(String grantType) { | ||
this.grantType = grantType; | ||
} | ||
|
||
public String getClientId() { | ||
return clientId; | ||
} | ||
|
||
public String getTokenEndpoint() { | ||
return tokenEndpoint; | ||
public void setClientId(String clientId) { | ||
this.clientId = clientId; | ||
} | ||
|
||
public String getHeaderName() { | ||
return headerName; | ||
public String getClientSecret() { | ||
return clientSecret; | ||
} | ||
|
||
public String getApiKey() { | ||
return apiKey; | ||
public void setClientSecret(String clientSecret) { | ||
this.clientSecret = clientSecret; | ||
} | ||
|
||
public String getTokenFilePath() { | ||
return tokenFilePath; | ||
public String getTokenEndpoint() { | ||
return tokenEndpoint; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
public void setTokenEndpoint(String tokenEndpoint) { | ||
this.tokenEndpoint = tokenEndpoint; | ||
} | ||
|
||
public void setGrantType(String grantType) { | ||
this.grantType = grantType; | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
OAuth2Credentials that = (OAuth2Credentials) o; | ||
return Objects.equals(grantType, that.grantType) && | ||
Objects.equals(clientId, that.clientId) && | ||
Objects.equals(clientSecret, that.clientSecret) && | ||
Objects.equals(tokenEndpoint, that.tokenEndpoint); | ||
} | ||
|
||
public void setClientId(String clientId) { | ||
this.clientId = clientId; | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(grantType, clientId, clientSecret, tokenEndpoint); | ||
} | ||
} | ||
|
||
public void setClientSecret(String clientSecret) { | ||
this.clientSecret = clientSecret; | ||
class BasicAuthCredentials extends Credentials { | ||
private String username; | ||
private String password; | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
} | ||
|
||
public void setTokenEndpoint(String tokenEndpoint) { | ||
this.tokenEndpoint = tokenEndpoint; | ||
class BearerTokenCredentials extends Credentials { | ||
private String tokenFilePath; | ||
|
||
public String getTokenFilePath() { | ||
return tokenFilePath; | ||
} | ||
|
||
public void setTokenFilePath(String tokenFilePath) { | ||
this.tokenFilePath = tokenFilePath; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
BearerTokenCredentials that = (BearerTokenCredentials) o; | ||
return Objects.equals(tokenFilePath, that.tokenFilePath); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(tokenFilePath); | ||
} | ||
@Override | ||
public String toString() { | ||
return "BearerTokenCredentials{" + | ||
"tokenFilePath='" + tokenFilePath + '\'' + | ||
'}'; | ||
} | ||
} | ||
|
||
class ApiKeyCredentials extends Credentials { | ||
private String apiKey; | ||
private String headerName; | ||
|
||
public String getApiKey() { | ||
return apiKey; | ||
} | ||
|
||
public void setApiKey(String apiKey) { | ||
this.apiKey = apiKey; | ||
} | ||
|
||
public String getHeaderName() { | ||
return headerName; | ||
} | ||
|
||
public void setHeaderName(String headerName) { | ||
this.headerName = headerName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Credentials{" + | ||
"grantType='" + grantType + '\'' + | ||
", clientId='" + clientId + '\'' + | ||
", clientSecret='" + clientSecret + '\'' + | ||
", username='" + username + '\'' + | ||
", password='" + password + '\'' + | ||
", tokenEndpoint='" + tokenEndpoint + '\'' + | ||
", tokenFilePath='" + tokenFilePath + '\'' + | ||
", apiKey='" + apiKey + '\'' + | ||
", headerName='" + headerName + '\'' + | ||
'}'; | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ApiKeyCredentials that = (ApiKeyCredentials) o; | ||
return Objects.equals(apiKey, that.apiKey); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(apiKey); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.