@Nullable private Pair<GitHttpAuthDataProvider, AuthData> findBestAuthData(@NotNull String url) { Pair<GitHttpAuthDataProvider, AuthData> candidate = null; for (GitHttpAuthDataProvider provider : getProviders()) { AuthData data = provider.getAuthData(url); if (data != null) { Pair<GitHttpAuthDataProvider, AuthData> pair = Pair.create(provider, data); if (data.getPassword() != null) { return pair; } if (candidate == null) { candidate = pair; } } } return candidate; }
@Nullable private static AuthData getSavedAuthData(@NotNull Project project, @NotNull String url) { String userName = GitRememberedInputs.getInstance().getUserNameForUrl(url); if (userName == null) { return trySavedAuthDataFromProviders(url); } String key = makeKey(url, userName); final PasswordSafe passwordSafe = PasswordSafe.getInstance(); try { String password = passwordSafe.getPassword(project, PASS_REQUESTER, key); if (password != null) { return new AuthData(userName, password); } return trySavedAuthDataFromProviders(url); } catch (PasswordSafeException e) { LOG.info("Couldn't get the password for key [" + key + "]", e); return null; } }
@Nullable private static AuthData getUsernameAndPassword(Project project, String url) { url = adjustHttpUrl(url); String userName = GitRememberedInputs.getInstance().getUserNameForUrl(url); if (userName == null) { return trySavedAuthDataFromProviders(url); } String key = keyForUrlAndLogin(url, userName); final PasswordSafe passwordSafe = PasswordSafe.getInstance(); try { String password = passwordSafe.getPassword(project, GitHttpCredentialsProvider.class, key); if (password != null) { return new AuthData(userName, password); } return null; } catch (PasswordSafeException e) { LOG.info("Couldn't get the password for key [" + key + "]", e); return null; } }
@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; } }
@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; }
@Nullable @Override public AuthData getAuthData(@NotNull String url) { String userName = getUsername(url); String key = makeKey(url, userName); final PasswordSafe passwordSafe = PasswordSafe.getInstance(); try { String password = passwordSafe.getPassword(myProject, PASS_REQUESTER, key); return new AuthData(StringUtil.notNullize(userName), password); } catch (PasswordSafeException e) { LOG.info("Couldn't get the password for key [" + key + "]", e); return null; } }
@Override public AuthData getAuthData(final String url) { assert url != null; //try to find authentication info from saved server contexts final AuthenticationInfo authenticationInfo = ServerContextManager.getInstance().getBestAuthenticationInfo(url, false); if (authenticationInfo != null) { return new AuthData(authenticationInfo.getUserName(), authenticationInfo.getPassword()); } //couldn't find authentication info from saved contexts logger.debug("getAuthData: Couldn't find authentication info from saved contexts."); if (UrlHelper.isTeamServicesUrl(url)) { // We can't determine if the url is for a TFS on premise server but prompt for credentials if we know it is VSO // IntelliJ calls us with a http server url e.g. http://myaccount.visualstudio.com // convert to https:// for team services to avoid rest call failures final String authUrl = UrlHelper.getHttpsUrlFromHttpUrl(url); if (authUrl != null) { final AuthenticationInfo vsoAuthenticationInfo = AuthHelper.getAuthenticationInfoSynchronously(VsoAuthenticationProvider.getInstance(), authUrl); if (vsoAuthenticationInfo == null) { //user cancelled authentication, send empty credentials to cause a auth failure return new AuthData("", ""); } else { return new AuthData(vsoAuthenticationInfo.getUserName(), vsoAuthenticationInfo.getPassword()); } } else { logger.warn("getAuthData: Unable to get https team services url for input url = " + url); } } //Return null if we couldn't find matching git credentials //This will tell the Git plugin to prompt the user for credentials instead of failing silently with "Not authorized" error return null; }
@Nullable @Override public AuthData getAuthData(@NotNull String url) { if (!GithubUrlUtil.isGithubUrl(url)) { return null; } GithubAuthData auth = GithubSettings.getInstance().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; } }
@Override @NotNull public String askUsername(@NotNull String url) { url = adjustUrl(url); AuthData authData = getSavedAuthData(myProject, url); String login = null; String password = null; if (authData != null) { login = authData.getLogin(); password = authData.getPassword(); } if (login != null && password != null) { myPassword = password; return login; } final AuthDialog dialog = new AuthDialog(myProject, myTitle, "Enter credentials for " + url, login, null, true); ApplicationManager.getApplication().invokeAndWait(new Runnable() { @Override public void run() { dialog.show(); } }, myModalityState == null ? ModalityState.defaultModalityState() : myModalityState); if (!dialog.isOK()) { return ""; } // remember values to store in the database afterwards, if authentication succeeds myPassword = dialog.getPassword(); myLogin = dialog.getUsername(); myUrl = url; myRememberOnDisk = dialog.isRememberPassword(); myPasswordKey = makeKey(myUrl, myLogin); return myLogin; }
@Nullable private static AuthData trySavedAuthDataFromProviders(@NotNull String url) { GitHttpAuthDataProvider[] extensions = GitHttpAuthDataProvider.EP_NAME.getExtensions(); for (GitHttpAuthDataProvider provider : extensions) { AuthData authData = provider.getAuthData(url); if (authData != null) { return authData; } } return null; }
private AuthData getAuthData(String url) { String userName = AlmRememberedInputs.getInstance().getUserNameForUrl(url); String key = makeKey(userName, url); final PasswordSafe passwordSafe = PasswordSafe.getInstance(); try { String password = passwordSafe.getPassword(project, AttachmentAgmLinkDownloadTask.class, key); return new AuthData(StringUtil.notNullize(userName), password); } catch (PasswordSafeException e) { logger.error("Couldn't get the password for key [" + key + "]", e); return null; } }
@Nullable AuthData getAuthData(@NotNull String url);