-
Notifications
You must be signed in to change notification settings - Fork 49
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 #371 from diadoc/DDCORE-8912-OIDC
OIDC
- Loading branch information
Showing
16 changed files
with
449 additions
and
18 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
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
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,6 @@ | ||
package Diadoc.Api.auth; | ||
|
||
public enum AuthenticationType { | ||
OIDC, | ||
DIADOC | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/Diadoc/Api/auth/CredentialsSchemeFactory.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package Diadoc.Api.auth; | ||
|
||
import Diadoc.Api.auth.oidc.DiadocOidcCredentials; | ||
import Diadoc.Api.auth.oidc.OidcAuthScheme; | ||
import org.apache.http.auth.AuthScheme; | ||
import org.apache.http.auth.Credentials; | ||
|
||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public class CredentialsSchemeFactory { | ||
|
||
private static final Map<Class<? extends Credentials>, Supplier<AuthScheme>> SCHEME_SUPPLIERS = Map.of( | ||
DiadocOidcCredentials.class, OidcAuthScheme::new, | ||
DiadocCredentials.class, DiadocAuthScheme::new | ||
); | ||
|
||
public AuthScheme createScheme(Credentials credentials) { | ||
Supplier<AuthScheme> schemeSupplier = SCHEME_SUPPLIERS.get(credentials.getClass()); | ||
if (schemeSupplier == null) { | ||
throw new IllegalArgumentException("Unsupported credentials type: " + credentials.getClass().getName()); | ||
} | ||
return schemeSupplier.get(); | ||
} | ||
} |
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
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,50 @@ | ||
package Diadoc.Api.auth; | ||
|
||
import Diadoc.Api.httpClient.DiadocHttpClient; | ||
import org.apache.http.client.CredentialsProvider; | ||
|
||
/** | ||
* A temporary fallback authentication manager to maintain backward compatibility. | ||
* | ||
* <p>This class serves as a stub implementation of {@link AuthManager} when migrating | ||
* authentication mechanisms (e.g., from API key-based authentication to OIDC authentication). | ||
* It does not support authentication operations and will throw {@link UnsupportedOperationException} | ||
* when any method is invoked.</p> | ||
* | ||
* <p>Usage of this class should be temporary and replaced with a proper authentication mechanism.</p> | ||
*/ | ||
public class FallbackAuthManager extends AuthManager { | ||
public FallbackAuthManager() { | ||
super("EMPTY"); | ||
} | ||
|
||
@Override | ||
public AuthenticateClient createAuthenticateClient(DiadocHttpClient httpClient) { | ||
throw new UnsupportedOperationException("Cannot determine Diadoc authentication manager operations for OIDC authentication."); | ||
} | ||
|
||
@Override | ||
public CredentialsProvider getCredentialsProvider() { | ||
throw new UnsupportedOperationException("Cannot determine Diadoc authentication manager operations for OIDC authentication."); | ||
} | ||
|
||
@Override | ||
public AuthenticationType getAuthenticationType() { | ||
throw new UnsupportedOperationException("Cannot determine Diadoc authentication manager operations for OIDC authentication."); | ||
} | ||
|
||
@Override | ||
public boolean isAuthenticated() { | ||
throw new UnsupportedOperationException("Cannot determine Diadoc authentication manager operations for OIDC authentication."); | ||
} | ||
|
||
@Override | ||
public void setCredentials(String authToken) { | ||
throw new UnsupportedOperationException("Cannot determine Diadoc authentication manager operations for OIDC authentication."); | ||
} | ||
|
||
@Override | ||
public void clearCredentials() { | ||
throw new UnsupportedOperationException("Cannot determine Diadoc authentication manager operations for OIDC authentication."); | ||
} | ||
} |
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,13 @@ | ||
package Diadoc.Api.auth; | ||
|
||
import Diadoc.Api.httpClient.DiadocHttpClient; | ||
import org.apache.http.client.CredentialsProvider; | ||
|
||
public interface IAuthManager { | ||
|
||
AuthenticateClient createAuthenticateClient(DiadocHttpClient httpClient); | ||
|
||
CredentialsProvider getCredentialsProvider(); | ||
|
||
AuthenticationType getAuthenticationType(); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/Diadoc/Api/auth/oidc/ContainerTokenProvider.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package Diadoc.Api.auth.oidc; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Default implementation | ||
*/ | ||
public class ContainerTokenProvider implements TokenProvider { | ||
|
||
private volatile String token; | ||
|
||
@Override | ||
public String getToken() { | ||
return token; | ||
} | ||
|
||
public void setToken(String token) { | ||
this.token = token; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ContainerTokenProvider that = (ContainerTokenProvider) o; | ||
return Objects.equals(token, that.token); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(token); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/Diadoc/Api/auth/oidc/DiadocOidcCredentials.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package Diadoc.Api.auth.oidc; | ||
|
||
import org.apache.http.annotation.Contract; | ||
import org.apache.http.annotation.ThreadingBehavior; | ||
import org.apache.http.auth.BasicUserPrincipal; | ||
import org.apache.http.auth.Credentials; | ||
|
||
import java.security.Principal; | ||
|
||
@Contract(threading = ThreadingBehavior.IMMUTABLE) | ||
public class DiadocOidcCredentials implements Credentials { | ||
|
||
private final TokenProvider tokenProvider; | ||
private final Principal userPrincipal; | ||
|
||
public DiadocOidcCredentials(TokenProvider tokenProvider) { | ||
this.tokenProvider = tokenProvider; | ||
this.userPrincipal = new BasicUserPrincipal("DefaultUser"); | ||
} | ||
|
||
|
||
public TokenProvider getTokenProvider() { | ||
return tokenProvider; | ||
} | ||
|
||
@Override | ||
public Principal getUserPrincipal() { | ||
return userPrincipal; | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return ""; | ||
} | ||
} |
Oops, something went wrong.