直接上代码

解决jdk版本问题:Security.setProperty("jdk.tls.disabledAlgorithms", "");

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.security.Security;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import org.apache.log4j.Logger;
import org.tmatesoft.svn.core.ISVNDirEntryHandler;
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNCommitClient;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil; import cn.internetware.yanphone.genplatform.constants.ServerConstants;
import cn.internetware.yanphone.genplatform.model.ApiInfo;
import cn.internetware.yanphone.genplatform.model.Commit;
import cn.internetware.yanphone.genplatform.model.Group;
import cn.internetware.yanphone.genplatform.model.SVNProjectLog; public class SVNUtils { private static final Logger LOGGER = Logger.getLogger(SVNUtils.class); static {
Security.setProperty("jdk.tls.disabledAlgorithms", "");
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
} public static boolean deleteFile(String url, String username, String password, String message) {
try { SVNURL svnUrl = SVNURL.parseURIEncoded(url); ISVNAuthenticationManager authManager = new BasicWithCertificateTrustedAuthenticationManager(username,
password);
SVNClientManager clientManager = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),
authManager);
SVNCommitClient commitClient = clientManager.getCommitClient();
commitClient.doDelete(new SVNURL[] { svnUrl }, "delete project " + message);
} catch (SVNException e) {
LOGGER.error("Delete svn error", e);
return false;
}
return true;
} public static long checkout(String url, File destPath) {
ISVNAuthenticationManager authManager = new BasicWithCertificateTrustedAuthenticationManager(
ServerConstants.SVN_ADMIN_USERNAME, ServerConstants.SVN_ADMIN_PASSWORD);
SVNClientManager clientManager = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),
authManager);
SVNUpdateClient updateClient = clientManager.getUpdateClient();
try {
SVNURL svnUrl = SVNURL.parseURIEncoded(url);
return updateClient.doCheckout(svnUrl, destPath, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, false);
} catch (SVNException e) {
LOGGER.error("svn checkout error ...... ", e);
}
return 0;
} }

  

import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager; /**
* TrustManager utilities for generating TrustManagers.
*
* @since 3.0
*/
public final class TrustManagerUtils
{
private static final X509Certificate[] EMPTY_X509CERTIFICATE_ARRAY = new X509Certificate[]{}; private static class TrustManager implements X509TrustManager { private final boolean checkServerValidity; TrustManager(boolean checkServerValidity) {
this.checkServerValidity = checkServerValidity;
} /**
* Never generates a CertificateException.
*/
public void checkClientTrusted(X509Certificate[] certificates, String authType)
{
return;
} public void checkServerTrusted(X509Certificate[] certificates, String authType)
throws CertificateException
{
if (checkServerValidity) {
for (int i = 0; i < certificates.length; ++i)
{
certificates[i].checkValidity();
}
}
} /**
* @return an empty array of certificates
*/
public X509Certificate[] getAcceptedIssuers()
{
return EMPTY_X509CERTIFICATE_ARRAY;
}
} private static final X509TrustManager ACCEPT_ALL=new TrustManager(false); private static final X509TrustManager CHECK_SERVER_VALIDITY=new TrustManager(true); /**
* Generate a TrustManager that performs no checks.
*
* @return the TrustManager
*/
public static X509TrustManager getAcceptAllTrustManager(){
return ACCEPT_ALL;
} /**
* Generate a TrustManager that checks server certificates for validity,
* but otherwise performs no checks.
*
* @return the validating TrustManager
*/
public static X509TrustManager getValidateServerCertificateTrustManager(){
return CHECK_SERVER_VALIDITY;
} /**
* Return the default TrustManager provided by the JVM.
* <p>
* This should be the same as the default used by {@link javax.net.ssl.SSLContext#init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], java.security.SecureRandom)
* SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}
* when the TrustManager parameter is set to {@code null}
* @param keyStore the KeyStore to use, may be {@code null}
* @return the default TrustManager
* @throws GeneralSecurityException
*/
public static X509TrustManager getDefaultTrustManager(KeyStore keyStore) throws GeneralSecurityException {
String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory instance = TrustManagerFactory.getInstance(defaultAlgorithm);
instance.init(keyStore);
return (X509TrustManager) instance.getTrustManagers()[0];
} }

  

import java.security.cert.X509Certificate;

import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager; import org.tmatesoft.svn.core.SVNErrorCode;
import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager; public class BasicWithCertificateTrustedAuthenticationManager extends BasicAuthenticationManager { public BasicWithCertificateTrustedAuthenticationManager(String userName, String password) { super(userName, password); } @Override public TrustManager getTrustManager(SVNURL url) throws SVNException { try { // HTTPS URL requires certificate trust process // if (url != null && url.getProtocol() != null &&
// url.getProtocol().startsWith("https")) { // TrustManagerUtils comes from commons-net:commons-net:3.3 TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
} public void checkClientTrusted(X509Certificate[] chain, String authType) { } public void checkServerTrusted(X509Certificate[] chain, String authType) { }
} };
return trustAllCerts[0]; // } } catch (Exception e) { throw new SVNException(SVNErrorMessage.create(SVNErrorCode.IO_ERROR, e.getMessage()), e); } } }

  

最新文章

  1. 【Win 10 应用开发】导入.pfx证书
  2. VC 单文档视图分割
  3. android html 与webview属性从冲突
  4. 如何将SQL Server 2008库导入2000中
  5. angularJS使用$watch监控数据模型的变化
  6. javascript每日一练(八)——事件三:默认行为
  7. Maven2的配置文件settings.xml
  8. 注意Vietnamese_CI_AS排序规则下的特殊字符大小敏感问题
  9. python的u&#39;字符串&quot;(字符编码):字符串前有u,表示字符串以unicode格式存储
  10. 自定义用户认证(继承django的)
  11. Linux-Centon7安装以及配置
  12. scrapy简单使用
  13. Entity Framwork学习笔记
  14. THUWC2019 摸鱼记
  15. python基础之数据类型操作补充,集合及其操作,深浅拷贝
  16. odoo 打印格式中 打印第一个数据默认
  17. 20155334 网络对抗PC平台逆向破解(二)
  18. python之模块datetime详解
  19. oracle 11g空表导不出问题
  20. 【驱动】——错误: 初始值设定项里有未知的字段‘ioctl’

热门文章

  1. 红黑树与AVL树
  2. 多个SpingBoot项目的搭建与部署
  3. Tomcat启动startup.bat闪退和JRE_HOME错误
  4. CSS的vertical-align
  5. LeetCode(48):旋转图像
  6. Java 清理和垃圾回收
  7. bzoj营业额统计
  8. 线上Slave报1062的案例
  9. 从输入url到显示网页,后台发生了什么?
  10. Web应用程序项目XXXX已配置为使用IIS。无法访问IIS 元数据库。您没有足够的特权访问计算机上的IIS