mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'idea90' of git.labs.intellij.net:idea/community into idea90
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.svn;
|
||||
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import org.tmatesoft.svn.core.auth.*;
|
||||
|
||||
public class SvnAuthEquals {
|
||||
private SvnAuthEquals() {
|
||||
}
|
||||
|
||||
public static boolean equals(final SVNAuthentication a1, final SVNAuthentication a2) {
|
||||
if (a1 == a2) return true;
|
||||
if (a1 == null || a2 == null) return false;
|
||||
if (! Comparing.equal(a1.getKind(), a2.getKind())) return false;
|
||||
if (! Comparing.equal(a1.getUserName(), a2.getUserName())) return false;
|
||||
|
||||
final Class<? extends SVNAuthentication> a1Class = a1.getClass();
|
||||
if (! a1Class.equals(a2.getClass())) return false;
|
||||
|
||||
if (SVNUserNameAuthentication.class.equals(a1Class)) return true;
|
||||
if (SVNPasswordAuthentication.class.equals(a1Class)) {
|
||||
return Comparing.equal(((SVNPasswordAuthentication) a1).getPassword(), ((SVNPasswordAuthentication) a2).getPassword());
|
||||
}
|
||||
if (SVNSSLAuthentication.class.equals(a1Class)) {
|
||||
if (! Comparing.equal(((SVNSSLAuthentication) a1).getCertificateFile(), ((SVNSSLAuthentication) a2).getCertificateFile())) return false;
|
||||
return Comparing.equal(((SVNSSLAuthentication) a1).getPassword(), ((SVNSSLAuthentication) a2).getPassword());
|
||||
}
|
||||
if (SVNSSHAuthentication.class.equals(a1Class)) {
|
||||
if (! Comparing.equal(((SVNSSHAuthentication) a1).getPrivateKeyFile(), ((SVNSSHAuthentication) a2).getPrivateKeyFile())) return false;
|
||||
if (! Comparing.equal(((SVNSSHAuthentication) a1).getPassphrase(), ((SVNSSHAuthentication) a2).getPassphrase())) return false;
|
||||
if (! Comparing.equal(((SVNSSHAuthentication) a1).getPortNumber(), ((SVNSSHAuthentication) a2).getPortNumber())) return false;
|
||||
return Comparing.equal(((SVNSSHAuthentication) a1).getPassword(), ((SVNSSHAuthentication) a2).getPassword());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int hashCode(final SVNAuthentication a) {
|
||||
int result = a.getKind().hashCode();
|
||||
if (a.getUserName() != null) {
|
||||
result = (31 * result) + a.getUserName().hashCode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.changes.ui.ChangesViewBalloonProblemNotifier;
|
||||
import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.util.containers.SoftHashMap;
|
||||
import com.intellij.util.net.HttpConfigurable;
|
||||
import org.tmatesoft.svn.core.SVNErrorMessage;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
@@ -60,11 +61,14 @@ public class SvnAuthenticationManager extends DefaultSVNAuthenticationManager {
|
||||
}
|
||||
|
||||
private static class PersistentAuthenticationProviderProxy implements ISVNAuthenticationProvider, IPersistentAuthenticationProvider {
|
||||
private final Map<SvnAuthWrapperEqualable, Long> myRewritePreventer;
|
||||
private static final long ourRefreshInterval = 6000 * 1000;
|
||||
private final ISVNAuthenticationProvider myDelegate;
|
||||
private Project myProject;
|
||||
|
||||
private PersistentAuthenticationProviderProxy(final ISVNAuthenticationProvider delegate) {
|
||||
myDelegate = delegate;
|
||||
myRewritePreventer = new SoftHashMap<SvnAuthWrapperEqualable, Long>();
|
||||
}
|
||||
|
||||
public void setProject(Project project) {
|
||||
@@ -83,7 +87,13 @@ public class SvnAuthenticationManager extends DefaultSVNAuthenticationManager {
|
||||
|
||||
public void saveAuthentication(final SVNAuthentication auth, final String kind, final String realm) throws SVNException {
|
||||
try {
|
||||
((IPersistentAuthenticationProvider) myDelegate).saveAuthentication(auth, kind, realm);
|
||||
final SvnAuthWrapperEqualable newKey = new SvnAuthWrapperEqualable(auth);
|
||||
final Long recent = myRewritePreventer.get(newKey);
|
||||
final long currTime = System.currentTimeMillis();
|
||||
if (recent == null || ((recent != null) && ((currTime - recent.longValue()) > ourRefreshInterval))) {
|
||||
((IPersistentAuthenticationProvider) myDelegate).saveAuthentication(auth, kind, realm);
|
||||
myRewritePreventer.put(newKey, currTime);
|
||||
}
|
||||
}
|
||||
catch (final SVNException e) {
|
||||
// show notification so that user was aware his credentials were not saved
|
||||
@@ -280,4 +290,25 @@ public class SvnAuthenticationManager extends DefaultSVNAuthenticationManager {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class SvnAuthWrapperEqualable extends Wrapper<SVNAuthentication> {
|
||||
private SvnAuthWrapperEqualable(SVNAuthentication svnAuthentication) {
|
||||
super(svnAuthentication);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) return false;
|
||||
if (this == obj) return true;
|
||||
if (obj instanceof SvnAuthWrapperEqualable) {
|
||||
return SvnAuthEquals.equals(this.getT(), ((SvnAuthWrapperEqualable) obj).getT());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return SvnAuthEquals.hashCode(getT());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.svn;
|
||||
|
||||
public class Wrapper<T> {
|
||||
private final T myT;
|
||||
|
||||
public Wrapper(T t) {
|
||||
myT = t;
|
||||
}
|
||||
|
||||
public T getT() {
|
||||
return myT;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user