KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > loginterface > SubjectDNProxy


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.ui.web.admin.loginterface;
15
16 import java.math.BigInteger JavaDoc;
17 import java.rmi.RemoteException JavaDoc;
18 import java.security.cert.Certificate JavaDoc;
19 import java.security.cert.X509Certificate JavaDoc;
20 import java.util.HashMap JavaDoc;
21
22 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocal;
23 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionRemote;
24 import org.ejbca.core.model.log.Admin;
25 import org.ejbca.util.CertTools;
26
27 /**
28  * A class used to improve performance by proxying certificatesnr to subjectdn mappings by minimizing the number of needed lockups over rmi.
29  *
30  * @version $Id: SubjectDNProxy.java,v 1.1 2006/01/17 20:32:20 anatom Exp $
31  */

32 public class SubjectDNProxy implements java.io.Serializable JavaDoc {
33
34     /** Creates a new instance of SubjectDNProxy with remote access to CA part */
35     public SubjectDNProxy(Admin admin, ICertificateStoreSessionRemote certificatesession){
36               // Get the RaAdminSession instance.
37
this.local = false;
38       this.certificatesessionremote = certificatesession;
39       this.subjectdnstore = new HashMap JavaDoc();
40       this.admin = admin;
41
42     }
43
44     /** Creates a new instance of SubjectDNProxy with local access to CA part */
45     public SubjectDNProxy(Admin admin, ICertificateStoreSessionLocal certificatesession){
46               // Get the RaAdminSession instance.
47
this.local = true;
48       this.certificatesessionlocal = certificatesession;
49       this.subjectdnstore = new HashMap JavaDoc();
50       this.admin = admin;
51     }
52
53     /**
54      * Method that first tries to find subjectDN in local hashmap and if it doesn't exists looks it up over RMI.
55      *
56      * @param certificatesnr the certificate serial number number to look up.
57      * @return the subjectDN or null if no subjectDN is relatied to the given id
58      */

59     public String JavaDoc getSubjectDN(String JavaDoc admindata) throws RemoteException JavaDoc {
60       String JavaDoc returnval = null;
61       Certificate JavaDoc result = null;
62
63       // Check if name is in hashmap
64
returnval = (String JavaDoc) subjectdnstore.get(admindata);
65
66       if(returnval==null && admindata.indexOf(',') != -1){
67         // Retreive subjectDN over RMI
68
String JavaDoc certificatesnr = admindata.substring(0,admindata.indexOf(','));
69         String JavaDoc issuerdn = admindata.substring(admindata.indexOf(',')+1);
70           
71         if(local)
72           result = certificatesessionlocal.findCertificateByIssuerAndSerno(admin, issuerdn, new BigInteger JavaDoc(certificatesnr,16));
73         else
74           result = certificatesessionremote.findCertificateByIssuerAndSerno(admin, issuerdn, new BigInteger JavaDoc(certificatesnr, 16));
75         if(result != null){
76           returnval = CertTools.getSubjectDN((X509Certificate JavaDoc) result);
77           subjectdnstore.put(admindata,returnval);
78         }
79       }
80
81       return returnval;
82     }
83
84     // Private fields
85
private boolean local;
86     private HashMap JavaDoc subjectdnstore;
87     private ICertificateStoreSessionLocal certificatesessionlocal;
88     private ICertificateStoreSessionRemote certificatesessionremote;
89     private Admin admin;
90
91 }
92
Popular Tags