View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.security.credentials;
17  
18  import org.junit.Before;
19  import org.junit.Test;
20  
21  import java.math.BigInteger;
22  import java.security.InvalidKeyException;
23  import java.security.NoSuchAlgorithmException;
24  import java.security.NoSuchProviderException;
25  import java.security.Principal;
26  import java.security.PublicKey;
27  import java.security.SignatureException;
28  import java.security.cert.CertificateEncodingException;
29  import java.security.cert.CertificateException;
30  import java.security.cert.CertificateExpiredException;
31  import java.security.cert.CertificateNotYetValidException;
32  import java.security.cert.X509Certificate;
33  import java.util.Date;
34  import java.util.Set;
35  
36  import static org.junit.Assert.assertEquals;
37  import static org.junit.Assert.assertNotNull;
38  /**
39   * 
40   * @author Kuali Rice Team (rice.collab@kuali.org)
41   * @since 0.9
42   *
43   */
44  public class X509CredentialsSourceTest {
45  
46  	private X509CredentialsSource credentialsSource;
47  	
48  	private X509Certificate cert = new KualiX509Certificate();
49  
50      @Before
51  	public void setUp() throws Exception {
52  		this.credentialsSource = new X509CredentialsSource(cert);
53  	}
54  
55      @Test
56  	public void testX509Certificate() {
57  		final X509Credentials context = (X509Credentials) this.credentialsSource.getCredentials("test");
58  		assertNotNull(context);
59  		final X509Certificate cert = context.getX509Certificate();
60  		
61  		assertEquals(this.cert, cert);
62  	}
63  	
64  	public static class KualiX509Certificate extends X509Certificate {
65  		
66  		protected KualiX509Certificate() {
67  			// nothing to do
68  		}
69  
70  		public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException {
71  			// nothing to do
72  		}
73  
74  		public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException {
75  			// nothing to do
76  		}
77  
78  		public int getBasicConstraints() {
79  			return 0;
80  		}
81  
82  		public Principal getIssuerDN() {
83  			return null;
84  		}
85  
86  		public boolean[] getIssuerUniqueID() {
87  			return null;
88  		}
89  
90  		public boolean[] getKeyUsage() {
91  			return null;
92  		}
93  
94  		public Date getNotAfter() {
95  			return null;
96  		}
97  
98  		public Date getNotBefore() {
99  			return null;
100 		}
101 
102 		public BigInteger getSerialNumber() {
103 			return null;
104 		}
105 
106 		public String getSigAlgName() {
107 			return null;
108 		}
109 
110 		public String getSigAlgOID() {
111 			return null;
112 		}
113 
114 		public byte[] getSigAlgParams() {
115 			return null;
116 		}
117 
118 		public byte[] getSignature() {
119 			return null;
120 		}
121 
122 		public Principal getSubjectDN() {
123 			return null;
124 		}
125 
126 		public boolean[] getSubjectUniqueID() {
127 			return null;
128 		}
129 
130 		public byte[] getTBSCertificate() throws CertificateEncodingException {
131 			return null;
132 		}
133 
134 		public int getVersion() {
135 			return 0;
136 		}
137 
138 		public Set<String> getCriticalExtensionOIDs() {
139 			return null;
140 		}
141 
142 		public byte[] getExtensionValue(String arg0) {
143 			return null;
144 		}
145 
146 		public Set<String> getNonCriticalExtensionOIDs() {
147 			return null;
148 		}
149 
150 		public boolean hasUnsupportedCriticalExtension() {
151 			return false;
152 		}
153 
154 		public byte[] getEncoded() throws CertificateEncodingException {
155 			return null;
156 		}
157 
158 		public PublicKey getPublicKey() {
159 			return null;
160 		}
161 
162 		public String toString() {
163 			return null;
164 		}
165 
166 		public void verify(PublicKey arg0, String arg1) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
167 			// nothing to do
168 		}
169 
170 		public void verify(PublicKey arg0) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
171 			// nothing to do
172 		}
173 	}
174 }