001 /** 002 * Copyright 2005-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.ksb.security.credentials; 017 018 import org.junit.Before; 019 import org.junit.Test; 020 021 import java.math.BigInteger; 022 import java.security.InvalidKeyException; 023 import java.security.NoSuchAlgorithmException; 024 import java.security.NoSuchProviderException; 025 import java.security.Principal; 026 import java.security.PublicKey; 027 import java.security.SignatureException; 028 import java.security.cert.CertificateEncodingException; 029 import java.security.cert.CertificateException; 030 import java.security.cert.CertificateExpiredException; 031 import java.security.cert.CertificateNotYetValidException; 032 import java.security.cert.X509Certificate; 033 import java.util.Date; 034 import java.util.Set; 035 036 import static org.junit.Assert.assertEquals; 037 import static org.junit.Assert.assertNotNull; 038 /** 039 * 040 * @author Kuali Rice Team (rice.collab@kuali.org) 041 * @since 0.9 042 * 043 */ 044 public class X509CredentialsSourceTest { 045 046 private X509CredentialsSource credentialsSource; 047 048 private X509Certificate cert = new KualiX509Certificate(); 049 050 @Before 051 public void setUp() throws Exception { 052 this.credentialsSource = new X509CredentialsSource(cert); 053 } 054 055 @Test 056 public void testX509Certificate() { 057 final X509Credentials context = (X509Credentials) this.credentialsSource.getCredentials("test"); 058 assertNotNull(context); 059 final X509Certificate cert = context.getX509Certificate(); 060 061 assertEquals(this.cert, cert); 062 } 063 064 public static class KualiX509Certificate extends X509Certificate { 065 066 protected KualiX509Certificate() { 067 // nothing to do 068 } 069 070 public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException { 071 // nothing to do 072 } 073 074 public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException { 075 // nothing to do 076 } 077 078 public int getBasicConstraints() { 079 return 0; 080 } 081 082 public Principal getIssuerDN() { 083 return null; 084 } 085 086 public boolean[] getIssuerUniqueID() { 087 return null; 088 } 089 090 public boolean[] getKeyUsage() { 091 return null; 092 } 093 094 public Date getNotAfter() { 095 return null; 096 } 097 098 public Date getNotBefore() { 099 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 }