-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of BasicAuthentication Authentication to Git
Change-Id: I16aed5c77cf321173c5259c26b014b80366a55c3 Signed-off-by: i053322 <[email protected]>
- Loading branch information
Showing
3 changed files
with
85 additions
and
9 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
57 changes: 57 additions & 0 deletions
57
...-git/src/main/java/org/eclipse/che/api/git/GitBasicAuthenticationCredentialsProvider.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,57 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.api.git; | ||
|
||
import org.eclipse.che.api.git.server.dto.DtoServerImpls; | ||
import org.eclipse.che.api.git.shared.GitUser; | ||
|
||
/** | ||
* Credentials provider for Git basic authentication | ||
* | ||
* @author Yossi Balan | ||
*/ | ||
public class GitBasicAuthenticationCredentialsProvider implements CredentialsProvider { | ||
|
||
private static ThreadLocal<UserCredential> currRequestCredentials = new ThreadLocal<>(); | ||
private static final String BASIC_PROVIDER_NAME = "basic"; | ||
|
||
@Override | ||
public UserCredential getUserCredential() { | ||
return currRequestCredentials.get(); | ||
} | ||
|
||
@Override | ||
public GitUser getUser() throws GitException { | ||
DtoServerImpls.GitUserImpl gitUser = new DtoServerImpls.GitUserImpl(); | ||
gitUser.setName(currRequestCredentials.get().getUserName()); | ||
return gitUser; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return BASIC_PROVIDER_NAME; | ||
} | ||
|
||
@Override | ||
public boolean canProvideCredentials(String url) { | ||
return getUserCredential() != null; | ||
} | ||
|
||
public static void setCurrentCredentials(String user, String password) { | ||
UserCredential creds = new UserCredential(user, password, BASIC_PROVIDER_NAME); | ||
currRequestCredentials.set(creds); | ||
} | ||
|
||
public static void clearCredentials() { | ||
currRequestCredentials.set(null); | ||
} | ||
|
||
} |
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