Search in sources :

Example 1 with AuthData

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;
}
Also used : AuthData(com.intellij.util.AuthData) GitHttpAuthDataProvider(git4idea.remote.GitHttpAuthDataProvider) AuthDialog(com.intellij.vcsUtil.AuthDialog) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with AuthData

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;
    }
}
Also used : AuthData(com.intellij.util.AuthData) GithubAuthData(org.jetbrains.plugins.github.util.GithubAuthData) GithubAuthData(org.jetbrains.plugins.github.util.GithubAuthData) GithubSettings(org.jetbrains.plugins.github.util.GithubSettings) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AuthData (com.intellij.util.AuthData)2 AuthDialog (com.intellij.vcsUtil.AuthDialog)1 GitHttpAuthDataProvider (git4idea.remote.GitHttpAuthDataProvider)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 GithubAuthData (org.jetbrains.plugins.github.util.GithubAuthData)1 GithubSettings (org.jetbrains.plugins.github.util.GithubSettings)1