-
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 gitlab providers simultaneously (#731)
- Loading branch information
Showing
40 changed files
with
1,294 additions
and
741 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2012-2024 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.94.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>che-core-api-auth-gitlab-common</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Che Core :: API :: Authentication GitLab 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-json</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>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> |
80 changes: 80 additions & 0 deletions
80
...rc/main/java/org/eclipse/che/security/oauth/AbstractGitLabOAuthAuthenticatorProvider.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,80 @@ | ||
/* | ||
* Copyright (c) 2012-2024 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 java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import javax.inject.Provider; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Provides implementation of GitLab {@link OAuthAuthenticator} based on available configuration. | ||
* | ||
* @author Pavol Baran | ||
*/ | ||
public class AbstractGitLabOAuthAuthenticatorProvider implements Provider<OAuthAuthenticator> { | ||
private static final Logger LOG = | ||
LoggerFactory.getLogger(AbstractGitLabOAuthAuthenticatorProvider.class); | ||
private final OAuthAuthenticator authenticator; | ||
private final String providerName; | ||
|
||
public AbstractGitLabOAuthAuthenticatorProvider( | ||
String clientIdPath, | ||
String clientSecretPath, | ||
String gitlabEndpoint, | ||
String cheApiEndpoint, | ||
String providerName) | ||
throws IOException { | ||
this.providerName = providerName; | ||
authenticator = | ||
getOAuthAuthenticator(clientIdPath, clientSecretPath, gitlabEndpoint, cheApiEndpoint); | ||
LOG.debug("{} GitLab OAuth Authenticator is used.", authenticator); | ||
} | ||
|
||
@Override | ||
public OAuthAuthenticator get() { | ||
return authenticator; | ||
} | ||
|
||
private OAuthAuthenticator getOAuthAuthenticator( | ||
String clientIdPath, String clientSecretPath, String gitlabEndpoint, String cheApiEndpoint) | ||
throws IOException { | ||
if (!isNullOrEmpty(clientIdPath) | ||
&& !isNullOrEmpty(clientSecretPath) | ||
&& !isNullOrEmpty(gitlabEndpoint)) { | ||
String clientId = Files.readString(Path.of(clientIdPath)); | ||
String clientSecret = Files.readString(Path.of(clientSecretPath)); | ||
if (!isNullOrEmpty(clientId) && !isNullOrEmpty(clientSecret)) { | ||
return new GitLabOAuthAuthenticator( | ||
clientId, clientSecret, gitlabEndpoint, cheApiEndpoint, 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/GitLabUser.java → ...clipse/che/security/oauth/GitLabUser.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
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
Oops, something went wrong.