/[aagtl_public1]/src/com/byarger/exchangeit/EasyX509TrustManager.java
aagtl

Contents of /src/com/byarger/exchangeit/EasyX509TrustManager.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Sun Aug 5 13:48:36 2012 UTC (11 years, 7 months ago) by zoffadmin
File size: 2917 byte(s)
initial import of aagtl source code
1 package com.byarger.exchangeit;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.security.KeyStore;
23 import java.security.KeyStoreException;
24 import java.security.NoSuchAlgorithmException;
25 import java.security.cert.CertificateException;
26 import java.security.cert.X509Certificate;
27
28 import javax.net.ssl.TrustManager;
29 import javax.net.ssl.TrustManagerFactory;
30 import javax.net.ssl.X509TrustManager;
31
32 /**
33 * @author olamy
34 * @version $Id: EasyX509TrustManager.java 765355 2009-04-15 20:59:07Z evenisse $
35 * @since 1.2.3
36 */
37 public class EasyX509TrustManager implements X509TrustManager
38 {
39
40 private X509TrustManager standardTrustManager = null;
41
42 /**
43 * Constructor for EasyX509TrustManager.
44 */
45 public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException
46 {
47 super();
48 TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
49 factory.init(keystore);
50 TrustManager[] trustmanagers = factory.getTrustManagers();
51 if (trustmanagers.length == 0)
52 {
53 throw new NoSuchAlgorithmException("no trust manager found");
54 }
55 this.standardTrustManager = (X509TrustManager) trustmanagers[0];
56 }
57
58 /**
59 * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType)
60 */
61 public void checkClientTrusted(X509Certificate[] certificates, String authType) throws CertificateException
62 {
63 standardTrustManager.checkClientTrusted(certificates, authType);
64 }
65
66 /**
67 * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType)
68 */
69 public void checkServerTrusted(X509Certificate[] certificates, String authType) throws CertificateException
70 {
71 if ((certificates != null) && (certificates.length == 1))
72 {
73 certificates[0].checkValidity();
74 }
75 else
76 {
77 standardTrustManager.checkServerTrusted(certificates, authType);
78 }
79 }
80
81 /**
82 * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
83 */
84 public X509Certificate[] getAcceptedIssuers()
85 {
86 return this.standardTrustManager.getAcceptedIssuers();
87 }
88
89 }

   
Visit the aagtl Website