use of com.intellij.util.AuthData in project intellij-community by JetBrains.
the class GitHttpGuiAuthenticator method askUsername.
@Override
@NotNull
public String askUsername(@NotNull String url) {
myUnifiedUrl = getUnifiedUrl(url);
Pair<GitHttpAuthDataProvider, AuthData> authData = findBestAuthData(getUnifiedUrl(url));
String login = null;
String password = null;
if (authData != null) {
login = authData.second.getLogin();
password = authData.second.getPassword();
myDataProvider = authData.first;
}
LOG.debug("askUsername. dataProvider=" + getCurrentDataProviderName() + ", unifiedUrl= " + getUnifiedUrl(url) + ", login=" + login + ", passwordKnown=" + (password != null));
if (login != null && password != null) {
myPassword = password;
return login;
}
AuthDialog dialog = showAuthDialog(getDisplayableUrl(url), login);
LOG.debug("askUsername. Showed dialog:" + (dialog == null ? "NULL" : dialog.isOK() ? "OK" : "Cancel"));
if (dialog == null || !dialog.isOK()) {
myWasCancelled = true;
return "";
}
// remember values to store in the database afterwards, if authentication succeeds
myPassword = dialog.getPassword();
myLogin = dialog.getUsername();
mySaveOnDisk = dialog.isRememberPassword();
myPasswordKey = makeKey(myUnifiedUrl, myLogin);
return myLogin;
}
use of com.intellij.util.AuthData in project intellij-community by JetBrains.
the class GithubHttpAuthDataProvider method getAuthData.
@Nullable
@Override
public AuthData getAuthData(@NotNull String url) {
if (!GithubUrlUtil.isGithubUrl(url)) {
return null;
}
GithubSettings settings = GithubSettings.getInstance();
if (!settings.isValidGitAuth()) {
return null;
}
String host1 = GithubUrlUtil.getHostFromUrl(settings.getHost());
String host2 = GithubUrlUtil.getHostFromUrl(url);
if (!host1.equalsIgnoreCase(host2)) {
return null;
}
GithubAuthData auth = settings.getAuthData();
switch(auth.getAuthType()) {
case BASIC:
GithubAuthData.BasicAuth basicAuth = auth.getBasicAuth();
assert basicAuth != null;
if (StringUtil.isEmptyOrSpaces(basicAuth.getLogin()) || StringUtil.isEmptyOrSpaces(basicAuth.getPassword())) {
return null;
}
return new AuthData(basicAuth.getLogin(), basicAuth.getPassword());
case TOKEN:
GithubAuthData.TokenAuth tokenAuth = auth.getTokenAuth();
assert tokenAuth != null;
if (StringUtil.isEmptyOrSpaces(tokenAuth.getToken())) {
return null;
}
return new AuthData(tokenAuth.getToken(), "x-oauth-basic");
default:
return null;
}
}
Aggregations