-
Notifications
You must be signed in to change notification settings - Fork 37
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 <yossi.balan@sap.com>
- Loading branch information
Showing
3 changed files
with
74 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
46 changes: 46 additions & 0 deletions
46
...-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,46 @@ | ||
package org.eclipse.che.api.git; | ||
|
||
import org.eclipse.che.api.git.server.dto.DtoServerImpls; | ||
import org.eclipse.che.api.git.shared.GitUser; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Created by I053322 on 9/4/2016. | ||
*/ | ||
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