diff options
Diffstat (limited to 'plugins/svn4idea/src/org/jetbrains/idea/svn/auth')
-rw-r--r-- | plugins/svn4idea/src/org/jetbrains/idea/svn/auth/AbstractAuthenticator.java | 14 | ||||
-rw-r--r-- | plugins/svn4idea/src/org/jetbrains/idea/svn/auth/AuthenticationService.java (renamed from plugins/svn4idea/src/org/jetbrains/idea/svn/auth/IdeaSvnkitBasedAuthenticationCallback.java) | 51 | ||||
-rw-r--r-- | plugins/svn4idea/src/org/jetbrains/idea/svn/auth/CredentialsAuthenticator.java | 14 | ||||
-rw-r--r-- | plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SSLServerCertificateAuthenticator.java | 10 | ||||
-rw-r--r-- | plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SvnAuthenticationNotifier.java | 26 |
5 files changed, 62 insertions, 53 deletions
diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/AbstractAuthenticator.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/AbstractAuthenticator.java index 203265dea263..0c11d5a488e6 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/AbstractAuthenticator.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/AbstractAuthenticator.java @@ -39,16 +39,16 @@ abstract class AbstractAuthenticator { private static final Logger LOG = Logger.getInstance(AbstractAuthenticator.class); - @NotNull protected final IdeaSvnkitBasedAuthenticationCallback myAuthService; + @NotNull protected final AuthenticationService myAuthenticationService; @NotNull protected final SvnVcs myVcs; @NotNull protected final SVNURL myUrl; protected final String myRealm; protected boolean myStoreInUsual; protected SvnAuthenticationManager myTmpDirManager; - AbstractAuthenticator(@NotNull IdeaSvnkitBasedAuthenticationCallback authService, @NotNull SVNURL url, String realm) { - myAuthService = authService; - myVcs = myAuthService.getVcs(); + AbstractAuthenticator(@NotNull AuthenticationService authenticationService, @NotNull SVNURL url, String realm) { + myAuthenticationService = authenticationService; + myVcs = myAuthenticationService.getVcs(); myUrl = url; myRealm = realm; } @@ -58,7 +58,7 @@ abstract class AbstractAuthenticator { final SvnAuthenticationManager active = myVcs.getSvnConfiguration().getAuthenticationManager(myVcs); try { - boolean authenticated = getWithPassive(passive) || getWithActive(active); + boolean authenticated = getWithPassive(passive) || (myAuthenticationService.isActive() && getWithActive(active)); if (!authenticated) return false; SvnAuthenticationManager manager = myStoreInUsual ? active : createTmpManager(); @@ -80,8 +80,8 @@ abstract class AbstractAuthenticator { @NotNull protected SvnAuthenticationManager createTmpManager() throws IOException { if (myTmpDirManager == null) { - myAuthService.initTmpDir(myVcs.getSvnConfiguration()); - myTmpDirManager = new SvnAuthenticationManager(myVcs.getProject(), myAuthService.getTempDirectory()); + myAuthenticationService.initTmpDir(myVcs.getSvnConfiguration()); + myTmpDirManager = new SvnAuthenticationManager(myVcs.getProject(), myAuthenticationService.getTempDirectory()); myTmpDirManager.setRuntimeStorage(SvnConfiguration.RUNTIME_AUTH_CACHE); myTmpDirManager.setAuthenticationProvider(new SvnInteractiveAuthenticationProvider(myVcs, myTmpDirManager)); } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/IdeaSvnkitBasedAuthenticationCallback.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/AuthenticationService.java index 5b77f78aa7e1..9fb377e1dafe 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/IdeaSvnkitBasedAuthenticationCallback.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/AuthenticationService.java @@ -20,7 +20,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.popup.util.PopupUtil; import com.intellij.openapi.util.Getter; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.WaitForProgressToShow; @@ -32,7 +31,6 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.SvnBundle; import org.jetbrains.idea.svn.SvnConfiguration; import org.jetbrains.idea.svn.SvnVcs; -import org.jetbrains.idea.svn.commandLine.AuthenticationCallback; import org.jetbrains.idea.svn.dialogs.SimpleCredentialsDialog; import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; @@ -52,16 +50,19 @@ import java.util.Set; * Date: 2/26/13 * Time: 1:27 PM */ -public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCallback { +public class AuthenticationService { + @NotNull private final SvnVcs myVcs; - private static final Logger LOG = Logger.getInstance(IdeaSvnkitBasedAuthenticationCallback.class); + private final boolean myIsActive; + private static final Logger LOG = Logger.getInstance(AuthenticationService.class); private File myTempDirectory; private boolean myProxyCredentialsWereReturned; private SvnConfiguration myConfiguration; private final Set<String> myRequestedCredentials; - public IdeaSvnkitBasedAuthenticationCallback(@NotNull SvnVcs vcs) { + public AuthenticationService(@NotNull SvnVcs vcs, boolean isActive) { myVcs = vcs; + myIsActive = isActive; myConfiguration = SvnConfiguration.getInstance(myVcs.getProject()); myRequestedCredentials = ContainerUtil.newHashSet(); } @@ -76,8 +77,11 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall return myTempDirectory; } - @Override - public boolean authenticateFor(String realm, SVNURL repositoryUrl, boolean previousFailed, boolean passwordRequest) { + public boolean isActive() { + return myIsActive; + } + + public boolean authenticateFor(@Nullable String realm, SVNURL repositoryUrl, boolean passwordRequest) { if (repositoryUrl == null) { return false; } @@ -85,20 +89,17 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall } @Nullable - @Override public SVNAuthentication requestCredentials(final SVNURL repositoryUrl, final String type) { SVNAuthentication authentication = null; if (repositoryUrl != null) { final String realm = repositoryUrl.toDecodedString(); - authentication = requestCredentials(realm, type, new Getter<Pair<SVNAuthentication, Boolean>>() { + authentication = requestCredentials(realm, type, new Getter<SVNAuthentication>() { @Override - public Pair<SVNAuthentication, Boolean> get() { - SVNAuthentication result = myVcs.getSvnConfiguration().getInteractiveManager(myVcs).getInnerProvider() + public SVNAuthentication get() { + return myVcs.getSvnConfiguration().getInteractiveManager(myVcs).getInnerProvider() .requestClientAuthentication(type, repositoryUrl, realm, null, null, true); - - return new Pair<SVNAuthentication, Boolean>(result, true); } }); } @@ -111,8 +112,8 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall } @Nullable - private <T> T requestCredentials(@NotNull String realm, @NotNull String type, @NotNull Getter<Pair<T, Boolean>> fromUserProvider) { - T result; + private <T> T requestCredentials(@NotNull String realm, @NotNull String type, @NotNull Getter<T> fromUserProvider) { + T result = null; // Search for stored credentials not only by key but also by "parent" keys. This is useful when we work just with URLs // (not working copy) and can't detect repository url beforehand because authentication is required. If found credentials of "parent" // are not correct then current key will already be stored in myRequestedCredentials - thus user will be asked for credentials and @@ -126,12 +127,10 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall result = (T)data; myRequestedCredentials.add(key); } - else { + else if (myIsActive) { // ask user for credentials - Pair<T, Boolean> userData = fromUserProvider.get(); - result = userData.first; - - if (result != null && userData.second) { + result = fromUserProvider.get(); + if (result != null) { // save user credentials to memory cache myVcs.getSvnConfiguration().acknowledge(type, realm, result); myRequestedCredentials.add(key); @@ -141,14 +140,13 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall return result; } - @Override @Nullable public String requestSshCredentials(@NotNull final String realm, @NotNull final SimpleCredentialsDialog.Mode mode, @NotNull final String key) { - return requestCredentials(realm, ISVNAuthenticationManager.SSH, new Getter<Pair<String, Boolean>>() { + return requestCredentials(realm, ISVNAuthenticationManager.SSH, new Getter<String>() { @Override - public Pair<String, Boolean> get() { + public String get() { final Ref<String> answer = new Ref<String>(); Runnable command = new Runnable() { @@ -169,12 +167,11 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall // the thread that started progress WaitForProgressToShow.runOrInvokeAndWaitAboveProgress(command, ModalityState.any()); - return new Pair<String, Boolean>(answer.get(), true); + return answer.get(); } }); } - @Override public boolean acceptSSLServerCertificate(final SVNURL repositoryUrl, final String realm) { if (repositoryUrl == null) { return false; @@ -183,7 +180,6 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall return new SSLServerCertificateAuthenticator(this, repositoryUrl, realm).tryAuthenticate(); } - @Override public void clearPassiveCredentials(String realm, SVNURL repositoryUrl, boolean password) { if (repositoryUrl == null) { return; @@ -197,7 +193,6 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall } } - @Override public boolean haveDataForTmpConfig() { final HttpConfigurable instance = HttpConfigurable.getInstance(); return SvnConfiguration.getInstance(myVcs.getProject()).isIsUseDefaultProxy() && @@ -227,7 +222,6 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall return null; } - @Override @Nullable public PasswordAuthentication getProxyAuthentication(@NotNull SVNURL repositoryUrl) { Proxy proxy = getIdeaDefinedProxy(repositoryUrl); @@ -296,7 +290,6 @@ public class IdeaSvnkitBasedAuthenticationCallback implements AuthenticationCall } @Nullable - @Override public File getSpecialConfigDir() { return myTempDirectory != null ? myTempDirectory : new File(myConfiguration.getConfigurationDirectory()); } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/CredentialsAuthenticator.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/CredentialsAuthenticator.java index 410cb0997201..9658e2adbba7 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/CredentialsAuthenticator.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/CredentialsAuthenticator.java @@ -37,14 +37,12 @@ class CredentialsAuthenticator extends AbstractAuthenticator { private String myRealm2; private SVNAuthentication myAuthentication; - CredentialsAuthenticator(@NotNull IdeaSvnkitBasedAuthenticationCallback authService, - @NotNull SVNURL url, - @Nullable String realm) { - super(authService, url, realm == null ? url.getHost() : realm); + CredentialsAuthenticator(@NotNull AuthenticationService authenticationService, @NotNull SVNURL url, @Nullable String realm) { + super(authenticationService, url, realm == null ? url.getHost() : realm); } public boolean tryAuthenticate(boolean passwordRequest) { - final List<String> kinds = IdeaSvnkitBasedAuthenticationCallback.getKinds(myUrl, passwordRequest); + final List<String> kinds = AuthenticationService.getKinds(myUrl, passwordRequest); for (String kind : kinds) { myKind = kind; if (!tryAuthenticate()) { @@ -58,8 +56,8 @@ class CredentialsAuthenticator extends AbstractAuthenticator { protected boolean getWithPassive(SvnAuthenticationManager passive) throws SVNException { myAuthentication = getWithPassiveImpl(passive); if (myAuthentication != null && !checkAuthOk(myAuthentication)) { - myAuthService.clearPassiveCredentials(myRealm, myUrl, - myAuthentication instanceof SVNPasswordAuthentication); //clear passive also take into acconut ssl filepath + //clear passive also take into account ssl file path + myAuthenticationService.clearPassiveCredentials(myRealm, myUrl, myAuthentication instanceof SVNPasswordAuthentication); myAuthentication = null; } return myAuthentication != null; @@ -88,7 +86,7 @@ class CredentialsAuthenticator extends AbstractAuthenticator { if (super.getWithActive(active)) return true; } myAuthentication = active.getProvider().requestClientAuthentication(myKind, myUrl, myRealm, null, null, true); - myStoreInUsual = myAuthService.getTempDirectory() == null && myAuthentication != null && myAuthentication.isStorageAllowed(); + myStoreInUsual = myAuthenticationService.getTempDirectory() == null && myAuthentication != null && myAuthentication.isStorageAllowed(); return myAuthentication != null; } diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SSLServerCertificateAuthenticator.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SSLServerCertificateAuthenticator.java index 3b78aa55d867..7d76a1fa0536 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SSLServerCertificateAuthenticator.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SSLServerCertificateAuthenticator.java @@ -41,10 +41,8 @@ class SSLServerCertificateAuthenticator extends AbstractAuthenticator { private int myResult; private SVNAuthentication myAuthentication; - SSLServerCertificateAuthenticator(@NotNull IdeaSvnkitBasedAuthenticationCallback authService, - @NotNull SVNURL url, - String realm) { - super(authService, url, realm); + SSLServerCertificateAuthenticator(@NotNull AuthenticationService authenticationService, @NotNull SVNURL url, String realm) { + super(authenticationService, url, realm); } @Override @@ -102,7 +100,7 @@ class SSLServerCertificateAuthenticator extends AbstractAuthenticator { myCertificate = createCertificate(stored); myCertificateRealm = myRealm; } - if (myAuthService.getTempDirectory() != null && myCertificate != null) { + if (myAuthenticationService.getTempDirectory() != null && myCertificate != null) { storeServerCertificate(); if (myAuthentication != null) { @@ -142,7 +140,7 @@ class SSLServerCertificateAuthenticator extends AbstractAuthenticator { } int failures = SVNSSLUtil.getServerCertificateFailures(x509Certificate, myUrl.getHost()); - storeServerCertificate(myAuthService.getTempDirectory(), myCertificateRealm, stored, failures); + storeServerCertificate(myAuthenticationService.getTempDirectory(), myCertificateRealm, stored, failures); } private void storeServerCertificate(final File configDir, String realm, String data, int failures) throws SVNException { diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SvnAuthenticationNotifier.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SvnAuthenticationNotifier.java index ffc21a011334..29f15423e581 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SvnAuthenticationNotifier.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/auth/SvnAuthenticationNotifier.java @@ -44,6 +44,10 @@ import com.intellij.util.proxy.CommonProxy; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.*; +import org.jetbrains.idea.svn.api.ClientFactory; +import org.jetbrains.idea.svn.commandLine.SvnBindException; +import org.jetbrains.idea.svn.info.Info; +import org.jetbrains.idea.svn.info.InfoClient; import org.tmatesoft.svn.core.SVNAuthenticationException; import org.tmatesoft.svn.core.SVNCancelException; import org.tmatesoft.svn.core.SVNException; @@ -172,6 +176,7 @@ public class SvnAuthenticationNotifier extends GenericNotifierImpl<SvnAuthentica } log("on state changed "); ApplicationManager.getApplication().invokeLater(new Runnable() { + @Override public void run() { for (SVNURL key : outdatedRequests) { removeLazyNotificationByKey(key); @@ -223,7 +228,7 @@ public class SvnAuthenticationNotifier extends GenericNotifierImpl<SvnAuthentica /** * Bases on presence of notifications! */ - public ThreeState isAuthenticatedFor(@NotNull VirtualFile vf) { + public ThreeState isAuthenticatedFor(@NotNull VirtualFile vf, @Nullable ClientFactory factory) { final WorkingCopy wcCopy = myRootsToWorkingCopies.getWcRoot(vf); if (wcCopy == null) return ThreeState.UNSURE; @@ -236,11 +241,24 @@ public class SvnAuthenticationNotifier extends GenericNotifierImpl<SvnAuthentica if (Boolean.FALSE.equals(keptResult)) return ThreeState.NO; // check have credentials - final boolean calculatedResult = passiveValidation(myVcs.getProject(), wcCopy.getUrl()); + final boolean calculatedResult = + factory == null ? passiveValidation(myVcs.getProject(), wcCopy.getUrl()) : passiveValidation(factory, wcCopy.getUrl()); myCopiesPassiveResults.put(wcCopy.getUrl(), calculatedResult); return calculatedResult ? ThreeState.YES : ThreeState.NO; } + private static boolean passiveValidation(@NotNull ClientFactory factory, @NotNull SVNURL url) { + Info info = null; + + try { + info = factory.create(InfoClient.class, false).doInfo(url, SVNRevision.UNDEFINED, SVNRevision.UNDEFINED); + } + catch (SvnBindException ignore) { + } + + return info != null; + } + @NotNull @Override protected String getNotificationContent(AuthenticationRequest obj) { @@ -470,6 +488,7 @@ public class SvnAuthenticationNotifier extends GenericNotifierImpl<SvnAuthentica final File authDir = new File(configuration.getConfigurationDirectory(), "auth"); if (authDir.exists()) { final Runnable process = new Runnable() { + @Override public void run() { final ProgressIndicator ind = ProgressManager.getInstance().getProgressIndicator(); if (ind != null) { @@ -477,7 +496,8 @@ public class SvnAuthenticationNotifier extends GenericNotifierImpl<SvnAuthentica ind.setText("Clearing stored credentials in " + authDir.getAbsolutePath()); } final File[] files = authDir.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { + @Override + public boolean accept(@NotNull File dir, @NotNull String name) { return ourAuthKinds.contains(name); } }); |