-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow to configure 2 github providers simultaneously (#598)
* feat: Support enabling Github enterprise and SaaS simultaneously on Dev Spaces Signed-off-by: Anatolii Bazko <[email protected]>
- Loading branch information
Showing
44 changed files
with
1,529 additions
and
879 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
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,70 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2012-2023 Red Hat, Inc. | ||
This program and the accompanying materials are made | ||
available under the terms of the Eclipse Public License 2.0 | ||
which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>che-master-parent</artifactId> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<version>7.77.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>che-core-api-auth-github-common</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Che Core :: API :: Authentication Github Common</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.http-client</groupId> | ||
<artifactId>google-http-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.inject</groupId> | ||
<artifactId>jakarta.inject-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-auth</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-auth-shared</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-commons-lang</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.tomakehurst</groupId> | ||
<artifactId>wiremock-jre8-standalone</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wiremock</groupId> | ||
<artifactId>wiremock-standalone</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
114 changes: 114 additions & 0 deletions
114
...rc/main/java/org/eclipse/che/security/oauth/AbstractGitHubOAuthAuthenticatorProvider.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,114 @@ | ||
/* | ||
* Copyright (c) 2012-2023 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.security.oauth; | ||
|
||
import static com.google.common.base.Strings.isNullOrEmpty; | ||
import static org.eclipse.che.commons.lang.StringUtils.trimEnd; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
import javax.inject.Provider; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Provides implementation of GitHub {@link OAuthAuthenticator} based on available configuration. | ||
* | ||
* @author Pavol Baran | ||
*/ | ||
public abstract class AbstractGitHubOAuthAuthenticatorProvider | ||
implements Provider<OAuthAuthenticator> { | ||
private static final Logger LOG = | ||
LoggerFactory.getLogger(AbstractGitHubOAuthAuthenticatorProvider.class); | ||
private final String providerName; | ||
private final OAuthAuthenticator authenticator; | ||
|
||
public AbstractGitHubOAuthAuthenticatorProvider( | ||
String gitHubClientIdPath, | ||
String gitHubClientSecretPath, | ||
String[] redirectUris, | ||
String oauthEndpoint, | ||
String authUri, | ||
String tokenUri, | ||
String providerName) | ||
throws IOException { | ||
this.providerName = providerName; | ||
authenticator = | ||
getOAuthAuthenticator( | ||
gitHubClientIdPath, | ||
gitHubClientSecretPath, | ||
redirectUris, | ||
oauthEndpoint, | ||
authUri, | ||
tokenUri); | ||
LOG.debug("{} GitHub OAuth Authenticator is used.", authenticator); | ||
} | ||
|
||
@Override | ||
public OAuthAuthenticator get() { | ||
return authenticator; | ||
} | ||
|
||
private OAuthAuthenticator getOAuthAuthenticator( | ||
String clientIdPath, | ||
String clientSecretPath, | ||
String[] redirectUris, | ||
String oauthEndpoint, | ||
String authUri, | ||
String tokenUri) | ||
throws IOException { | ||
|
||
String trimmedOauthEndpoint = isNullOrEmpty(oauthEndpoint) ? null : trimEnd(oauthEndpoint, '/'); | ||
authUri = | ||
isNullOrEmpty(trimmedOauthEndpoint) | ||
? authUri | ||
: trimmedOauthEndpoint + "/login/oauth/authorize"; | ||
tokenUri = | ||
isNullOrEmpty(trimmedOauthEndpoint) | ||
? tokenUri | ||
: trimmedOauthEndpoint + "/login/oauth/access_token"; | ||
if (!isNullOrEmpty(clientIdPath) | ||
&& !isNullOrEmpty(clientSecretPath) | ||
&& !isNullOrEmpty(authUri) | ||
&& !isNullOrEmpty(tokenUri) | ||
&& Objects.nonNull(redirectUris) | ||
&& redirectUris.length != 0) { | ||
final String clientId = Files.readString(Path.of(clientIdPath)).trim(); | ||
final String clientSecret = Files.readString(Path.of(clientSecretPath)).trim(); | ||
if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret)) { | ||
return new GitHubOAuthAuthenticator( | ||
clientId, | ||
clientSecret, | ||
redirectUris, | ||
trimmedOauthEndpoint, | ||
authUri, | ||
tokenUri, | ||
providerName); | ||
} | ||
} | ||
return new NoopOAuthAuthenticator(); | ||
} | ||
|
||
static class NoopOAuthAuthenticator extends OAuthAuthenticator { | ||
@Override | ||
public String getOAuthProvider() { | ||
return "Noop"; | ||
} | ||
|
||
@Override | ||
public String getEndpointUrl() { | ||
return "Noop"; | ||
} | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...clipse/che/security/oauth/GitHubUser.java → ...clipse/che/security/oauth/GitHubUser.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
Oops, something went wrong.