View Javadoc
1 /* 2 * Copyright �, Aegeus Technology Limited. All rights reserved. 3 */ 4 package jsdsi.certstore; 5 6 import java.util.Collection; 7 8 import jsdsi.AuthCert; 9 import jsdsi.AuthCertSelector; 10 import jsdsi.CertSelector; 11 import jsdsi.Certificate; 12 import jsdsi.CompatibleCertSelector; 13 import jsdsi.Name; 14 import jsdsi.NameCert; 15 import jsdsi.NameCertSelector; 16 import jsdsi.SubjectCertSelector; 17 import jsdsi.util.MultiMap; 18 19 /*** 20 * Pure memory based implementation of {@link CertificateDAO}, storing certificates indexed by 21 * various {@link MultiMap}s. 22 * 23 * @author Sean Radford 24 * @version $Revision: 1.1.2.1 $ $Date: 2004/12/12 17:01:39 $ 25 */ 26 public class InMemoryCertificateDAO implements CertificateDAO { 27 28 /*** 29 * issuer -> set of AuthCert(issuer -> RHS) 30 */ 31 MultiMap auth = new MultiMap(); 32 33 /*** 34 * name -> set of NameCert(name -> RHS) 35 */ 36 MultiMap name = new MultiMap(); 37 38 /*** 39 * name -> set of Cert(LHS -> name+X) 40 */ 41 MultiMap compatible = new MultiMap(); 42 43 /*** 44 * subject -> set of Cert(LHS -> subject) 45 */ 46 MultiMap subject = new MultiMap(); 47 48 /*** 49 * 50 */ 51 public InMemoryCertificateDAO() { 52 super(); 53 } 54 55 /*** 56 * @see jsdsi.certstore.CertificateDAO#store(jsdsi.Certificate) 57 */ 58 public void store(Certificate certificate) { 59 if (certificate.getCert().getSubject() instanceof Name) { 60 Name n = (Name) certificate.getCert().getSubject(); 61 compatible.put(n.prefix(), certificate); 62 } else { 63 // subject is not a name 64 subject.put(certificate.getCert().getSubject(), certificate); 65 } 66 if (certificate.getCert() instanceof NameCert) { 67 NameCert nc = (NameCert) certificate.getCert(); 68 name.put(nc.getFullName(), certificate); 69 } 70 if (certificate.getCert() instanceof AuthCert) { 71 auth.put(certificate.getCert().getIssuer(), certificate); 72 } 73 } 74 75 /*** 76 * @see jsdsi.certstore.CertificateDAO#retrieve(jsdsi.CertSelector) 77 */ 78 public Collection retrieve(CertSelector selector) { 79 if (selector instanceof SubjectCertSelector) { 80 return subject.get(((SubjectCertSelector) selector).getSubject()); 81 } 82 if (selector instanceof CompatibleCertSelector) { 83 return compatible.get(((CompatibleCertSelector) selector).getFullName()); 84 } 85 if (selector instanceof NameCertSelector) { 86 return name.get(((NameCertSelector) selector).getFullName()); 87 } 88 if (selector instanceof AuthCertSelector) { 89 // FIXME: this may return certs that don't satisfy the selector! 90 return auth.get(((AuthCertSelector) selector).getIssuer()); 91 } 92 throw new IllegalArgumentException("unrecognized selector: " 93 + selector.getClass().getName()); 94 } 95 96 }

This page was automatically generated by Maven