-
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
7efc8c6
commit 8a06b53
Showing
41 changed files
with
2,303 additions
and
10 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
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,55 @@ | ||
<?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> | ||
</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); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...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,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 com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import com.google.inject.name.Named; | ||
|
||
/** | ||
* OAuth1 authentication for Bitbucket Server account. | ||
* | ||
* @author Igor Vinokur | ||
*/ | ||
@Singleton | ||
public class BitbucketServerOAuthAuthenticator extends OAuthAuthenticator { | ||
|
||
@Inject | ||
public BitbucketServerOAuthAuthenticator( | ||
@Named("che.oauth1.bitbucket.consumerkey") String consumerKey, | ||
@Named("che.oauth1.bitbucket.privatekey") String privateKey, | ||
@Named("che.oauth1.bitbucket.endpoint") String bitbucketEndpoint, | ||
@Named("che.api") 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 "bitbucket-server"; | ||
} | ||
} |
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.info("authenticator={}", authenticator); | ||
} | ||
|
||
@Override | ||
public OAuthAuthenticator get() { | ||
return authenticator; | ||
} | ||
|
||
private static OAuthAuthenticator getOAuthAuthenticator( | ||
String consumerKeyPath, String privateKeyPath, String bitbucketEndpoint, String apiEndpoint) | ||
throws IOException { | ||
LOG.info("1"); | ||
if (!isNullOrEmpty(bitbucketEndpoint) && consumerKeyPath != null && privateKeyPath != null) { | ||
String consumerKey = Files.readString(Path.of(consumerKeyPath)); | ||
String privateKey = Files.readString(Path.of(privateKeyPath)); | ||
LOG.info("consumerKey={} privateKey={}", consumerKey, privateKey); | ||
if (!isNullOrEmpty(consumerKey) && !isNullOrEmpty(privateKey)) { | ||
return new BitbucketServerOAuthAuthenticator( | ||
consumerKey, privateKey, bitbucketEndpoint, apiEndpoint); | ||
} | ||
} | ||
|
||
return new NoopOAuthAuthenticator(); | ||
} | ||
} |
Oops, something went wrong.