-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Obtain and persist Bitbucket personal access token as k8s secret
Signed-off-by: Sergii Kabashniuk <skabashniuk@redhat.com>
- Loading branch information
1 parent
2c7b403
commit d20ef75
Showing
43 changed files
with
2,628 additions
and
13 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,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2012-2018 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.25.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>che-core-api-auth-bitbucket</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Che Core :: API :: Authentication Bitbucket</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.inject</groupId> | ||
<artifactId>javax.inject</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-commons-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-commons-inject</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
...ore-api-auth-bitbucket/src/main/java/org/eclipse/che/security/oauth1/BitbucketModule.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,31 @@ | ||
/* | ||
* Copyright (c) 2012-2018 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.oauth1; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.multibindings.Multibinder; | ||
import org.eclipse.che.inject.DynaModule; | ||
|
||
/** | ||
* Setup BitbucketServerOAuthAuthenticator in guice container. | ||
* | ||
* @author Sergii Kabashniuk | ||
*/ | ||
@DynaModule | ||
public class BitbucketModule extends AbstractModule { | ||
@Override | ||
protected void configure() { | ||
Multibinder<OAuthAuthenticator> oAuthAuthenticators = | ||
Multibinder.newSetBinder(binder(), OAuthAuthenticator.class); | ||
oAuthAuthenticators.addBinding().toProvider(BitbucketServerOAuthAuthenticatorProvider.class); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...cket/src/main/java/org/eclipse/che/security/oauth1/BitbucketServerOAuthAuthenticator.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,41 @@ | ||
/* | ||
* Copyright (c) 2012-2018 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.oauth1; | ||
|
||
import com.google.inject.Singleton; | ||
|
||
/** | ||
* OAuth1 authentication for Bitbucket Server account. | ||
* | ||
* @author Igor Vinokur | ||
*/ | ||
@Singleton | ||
public class BitbucketServerOAuthAuthenticator extends OAuthAuthenticator { | ||
public static final String AUTHENTICATOR_NAME = "bitbucket-server"; | ||
|
||
public BitbucketServerOAuthAuthenticator( | ||
String consumerKey, String privateKey, String bitbucketEndpoint, String apiEndpoint) { | ||
super( | ||
consumerKey, | ||
bitbucketEndpoint + "/plugins/servlet/oauth/request-token", | ||
bitbucketEndpoint + "/plugins/servlet/oauth/access-token", | ||
bitbucketEndpoint + "/plugins/servlet/oauth/authorize", | ||
apiEndpoint + "/oauth/1.0/callback", | ||
null, | ||
privateKey); | ||
} | ||
|
||
@Override | ||
public final String getOAuthProvider() { | ||
return AUTHENTICATOR_NAME; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
.../main/java/org/eclipse/che/security/oauth1/BitbucketServerOAuthAuthenticatorProvider.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,67 @@ | ||
/* | ||
* Copyright (c) 2012-2018 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.oauth1; | ||
|
||
import static com.google.common.base.Strings.isNullOrEmpty; | ||
|
||
import com.google.inject.name.Named; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
import javax.inject.Singleton; | ||
import org.eclipse.che.commons.annotation.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@Singleton | ||
public class BitbucketServerOAuthAuthenticatorProvider implements Provider<OAuthAuthenticator> { | ||
private final OAuthAuthenticator authenticator; | ||
private static final Logger LOG = | ||
LoggerFactory.getLogger(BitbucketServerOAuthAuthenticatorProvider.class); | ||
|
||
@Inject | ||
public BitbucketServerOAuthAuthenticatorProvider( | ||
@Nullable @Named("che.oauth1.bitbucket.consumerkeypath") String consumerKeyPath, | ||
@Nullable @Named("che.oauth1.bitbucket.privatekeypath") String privateKeyPath, | ||
@Nullable @Named("che.oauth1.bitbucket.endpoint") String bitbucketEndpoint, | ||
@Named("che.api") String apiEndpoint) | ||
throws IOException { | ||
|
||
authenticator = | ||
getOAuthAuthenticator(consumerKeyPath, privateKeyPath, bitbucketEndpoint, apiEndpoint); | ||
LOG.debug("{} Bitbucket OAuthAuthenticator is used.", authenticator); | ||
} | ||
|
||
@Override | ||
public OAuthAuthenticator get() { | ||
return authenticator; | ||
} | ||
|
||
private static OAuthAuthenticator getOAuthAuthenticator( | ||
String consumerKeyPath, String privateKeyPath, String bitbucketEndpoint, String apiEndpoint) | ||
throws IOException { | ||
if (!isNullOrEmpty(bitbucketEndpoint) | ||
&& !isNullOrEmpty(consumerKeyPath) | ||
&& !isNullOrEmpty(privateKeyPath)) { | ||
String consumerKey = Files.readString(Path.of(consumerKeyPath)); | ||
String privateKey = Files.readString(Path.of(privateKeyPath)); | ||
if (!isNullOrEmpty(consumerKey) && !isNullOrEmpty(privateKey)) { | ||
return new BitbucketServerOAuthAuthenticator( | ||
consumerKey, privateKey, bitbucketEndpoint, apiEndpoint); | ||
} | ||
} | ||
|
||
return new NoopOAuthAuthenticator(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...-auth-bitbucket/src/main/java/org/eclipse/che/security/oauth1/NoopOAuthAuthenticator.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,46 @@ | ||
/* | ||
* Copyright (c) 2012-2018 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.oauth1; | ||
|
||
import java.net.URL; | ||
|
||
/** | ||
* Dummy implementation of @{@link OAuthAuthenticator} used in the case if no Bitbucket Server | ||
* integration is configured. | ||
*/ | ||
public class NoopOAuthAuthenticator extends OAuthAuthenticator { | ||
protected NoopOAuthAuthenticator() { | ||
super(null, null, null, null, null, null, null); | ||
} | ||
|
||
@Override | ||
String getOAuthProvider() { | ||
return "Noop"; | ||
} | ||
|
||
@Override | ||
String getAuthenticateUrl(URL requestUrl, String requestMethod, String signatureMethod) | ||
throws OAuthAuthenticationException { | ||
throw new RuntimeException("Invalid usage of NoopOAuthAuthenticator"); | ||
} | ||
|
||
@Override | ||
String callback(URL requestUrl) throws OAuthAuthenticationException { | ||
throw new RuntimeException("Invalid usage of NoopOAuthAuthenticator"); | ||
} | ||
|
||
@Override | ||
String computeAuthorizationHeader(String userId, String requestMethod, String requestUrl) | ||
throws OAuthAuthenticationException { | ||
throw new RuntimeException("Invalid usage of NoopOAuthAuthenticator"); | ||
} | ||
} |
Oops, something went wrong.