KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > cainterface > CAInfoView


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.cainterface;
15
16 import java.security.cert.X509Certificate JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 import org.ejbca.core.model.SecConst;
22 import org.ejbca.core.model.ca.caadmin.CAInfo;
23 import org.ejbca.core.model.ca.caadmin.X509CAInfo;
24 import org.ejbca.core.model.ca.caadmin.extendedcaservices.ExtendedCAServiceInfo;
25 import org.ejbca.core.model.ca.caadmin.extendedcaservices.OCSPCAServiceInfo;
26 import org.ejbca.core.model.ca.catoken.HardCATokenInfo;
27 import org.ejbca.core.model.ca.catoken.IHardCAToken;
28 import org.ejbca.ui.web.admin.configuration.EjbcaWebBean;
29 import org.ejbca.ui.web.admin.rainterface.RevokedInfoView;
30
31
32 /**
33  * A class representing a view of a CA Information view..
34  *
35  * @version $Id: CAInfoView.java,v 1.4 2006/05/26 17:23:28 anatom Exp $
36  */

37 public class CAInfoView implements java.io.Serializable JavaDoc, Cloneable JavaDoc {
38     // Public constants.
39

40    public static final int NAME = 0;
41    public static final int SUBJECTDN = 1;
42    public static final int SUBJECTALTNAME = 2;
43    public static final int CATYPE = 3;
44    
45    private static final int CASPACER = 4;
46    
47    public static final int EXPIRETIME = 5;
48    public static final int STATUS = 6;
49    public static final int CATOKEN_STATUS = 7;
50    public static final int DESCRIPTION = 8;
51    
52    private static final int CRLSPACER = 9;
53    
54    public static final int CRLPERIOD = 10;
55    public static final int CRLISSUEINTERVAL = 11;
56    public static final int CRLOVERLAPTIME = 12;
57    public static final int CRLPUBLISHERS = 13;
58    
59    private static final int OCSPSPACER = 14;
60    
61    public static final int OCSP = 15;
62   
63     
64    public static String JavaDoc[] X509CA_CAINFODATATEXTS = {"NAME","SUBJECTDN","SUBJECTALTNAME","CATYPE","",
65                                                     "EXPIRES","STATUS","CATOKENSTATUS","DESCRIPTION","", "CRLPERIOD",
66                                                     "CRLISSUEINTERVAL", "CRLOVERLAPTIME", "CRLPUBLISHERS", "", "OCSPSERVICE"};
67    
68    private String JavaDoc[] cainfodata = null;
69    private String JavaDoc[] cainfodatatexts = null;
70    
71    private CAInfo cainfo = null;
72    private X509Certificate JavaDoc ocspcert = null;
73    
74     public CAInfoView(CAInfo cainfo, EjbcaWebBean ejbcawebbean, HashMap JavaDoc publishersidtonamemap){
75       this.cainfo = cainfo;
76         
77       if(cainfo instanceof X509CAInfo){
78         cainfodatatexts = new String JavaDoc[X509CA_CAINFODATATEXTS.length];
79         cainfodata = new String JavaDoc[X509CA_CAINFODATATEXTS.length];
80         
81         for(int i=0; i < X509CA_CAINFODATATEXTS.length; i++){
82           if(X509CA_CAINFODATATEXTS[i].equals(""))
83               cainfodatatexts[i]="&nbsp;";
84           else
85               cainfodatatexts[i] = ejbcawebbean.getText(X509CA_CAINFODATATEXTS[i]);
86         }
87         
88         cainfodata[SUBJECTDN] = cainfo.getSubjectDN();
89         cainfodata[SUBJECTALTNAME] = ((X509CAInfo) cainfo).getSubjectAltName();
90         cainfodata[NAME] = cainfo.getName();
91         cainfodata[CATYPE] = ejbcawebbean.getText("X509");
92         cainfodata[CASPACER] = "&nbsp;"; // blank line
93
if(cainfo.getExpireTime() == null)
94           cainfodata[EXPIRETIME] = "";
95         else
96           cainfodata[EXPIRETIME] = ejbcawebbean.printDateTime(cainfo.getExpireTime());
97         
98         switch(cainfo.getStatus()){
99             case SecConst.CA_ACTIVE :
100               cainfodata[STATUS] = ejbcawebbean.getText("ACTIVE");
101               break;
102             case SecConst.CA_EXPIRED :
103               cainfodata[STATUS] = ejbcawebbean.getText("EXPIRED");
104               break;
105             case SecConst.CA_OFFLINE :
106               cainfodata[STATUS] = ejbcawebbean.getText("OFFLINE");
107               break;
108             case SecConst.CA_REVOKED :
109               cainfodata[STATUS] = ejbcawebbean.getText("CAREVOKED") + "<br>&nbsp;&nbsp;" +
110                                                     ejbcawebbean.getText("REASON") + " : <br>&nbsp;&nbsp;&nbsp;&nbsp;" +
111                                                     ejbcawebbean.getText(RevokedInfoView.reasontexts[cainfo.getRevokationReason()]) + "<br>&nbsp;&nbsp;" +
112                                                     ejbcawebbean.getText("REVOKATIONDATE") + "<br>&nbsp;&nbsp;&nbsp;&nbsp;" +
113                                                     ejbcawebbean.printDateTime(cainfo.getRevokationDate());
114               break;
115             case SecConst.CA_WAITING_CERTIFICATE_RESPONSE :
116               cainfodata[STATUS] = ejbcawebbean.getText("WAITINGFORCERTRESPONSE");
117               break;
118         }
119         
120         if(cainfo.getCATokenInfo() instanceof HardCATokenInfo){
121             switch(((HardCATokenInfo) cainfo.getCATokenInfo()).getCATokenStatus()){
122               case IHardCAToken.STATUS_ACTIVE :
123                 cainfodata[CATOKEN_STATUS] = ejbcawebbean.getText("HARDTOKEN") + ", " + ejbcawebbean.getText("ACTIVE");
124                 break;
125               case IHardCAToken.STATUS_OFFLINE :
126                 cainfodata[CATOKEN_STATUS] = ejbcawebbean.getText("HARDTOKEN") +", " + ejbcawebbean.getText("OFFLINE");
127                 break;
128             }
129         }else{
130             cainfodata[CATOKEN_STATUS] = ejbcawebbean.getText("SOFT") + ", " + ejbcawebbean.getText("ACTIVE");
131         }
132
133         
134         cainfodata[DESCRIPTION] = cainfo.getDescription();
135         
136         cainfodata[CRLSPACER] = "&nbsp;"; // blank line
137

138         cainfodata[CRLPERIOD] = Integer.toString(((X509CAInfo) cainfo).getCRLPeriod());
139         cainfodata[CRLISSUEINTERVAL] = Integer.toString(((X509CAInfo) cainfo).getCRLIssueInterval());
140         cainfodata[CRLOVERLAPTIME] = Integer.toString(((X509CAInfo) cainfo).getCRLOverlapTime());
141         
142         cainfodata[CRLPUBLISHERS] = "";
143         Iterator JavaDoc iter = ((X509CAInfo) cainfo).getCRLPublishers().iterator();
144         if(iter.hasNext())
145           cainfodata[CRLPUBLISHERS] = (String JavaDoc) publishersidtonamemap.get(iter.next());
146         else
147         cainfodata[CRLPUBLISHERS] = ejbcawebbean.getText("NONE");
148         
149         while(iter.hasNext())
150             cainfodata[CRLPUBLISHERS] = cainfodata[CRLPUBLISHERS] + ", " +
151                                                            (String JavaDoc) publishersidtonamemap.get(iter.next());
152         
153         cainfodata[OCSPSPACER] = "&nbsp;"; // blank line
154

155         boolean active = false;
156         iter = ((X509CAInfo) cainfo).getExtendedCAServiceInfos().iterator();
157         while(iter.hasNext()){
158           ExtendedCAServiceInfo next = (ExtendedCAServiceInfo) iter.next();
159           if(next instanceof OCSPCAServiceInfo){
160             active = next.getStatus() == ExtendedCAServiceInfo.STATUS_ACTIVE;
161             if(((OCSPCAServiceInfo) next).getOCSPSignerCertificatePath() != null)
162               ocspcert = (X509Certificate JavaDoc) ((OCSPCAServiceInfo) next).getOCSPSignerCertificatePath().get(0);
163           }
164         }
165         
166         if(active){
167           cainfodata[OCSP] = ejbcawebbean.getText("ACTIVE") +
168                              "<br>" + "&nbsp;<a style='cursor:hand;' onClick='viewocspcert()'><u>" +
169                              ejbcawebbean.getText("VIEWOCSPCERTIFICATE") +
170                              "</u></a>";
171         }else{
172           cainfodata[OCSP] = ejbcawebbean.getText("INACTIVE");
173         }
174        
175         
176       }
177    }
178
179    public String JavaDoc[] getCAInfoData(){ return cainfodata;}
180    public String JavaDoc[] getCAInfoDataText(){ return cainfodatatexts;}
181
182    public CAInfo getCAInfo() { return cainfo;}
183    public Collection JavaDoc getCertificateChain() { return cainfo.getCertificateChain(); }
184    
185    public X509Certificate JavaDoc getOCSPSignerCertificate() { return ocspcert;}
186    
187    
188 }
189
Popular Tags