KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > keystore > CertificateItem


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.keystore;
21
22 import java.security.cert.Certificate JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import com.sslexplorer.boot.KeyStoreManager;
27 import com.sslexplorer.core.CoreUtil;
28 import com.sslexplorer.install.actions.InstallAction;
29 import com.sslexplorer.security.LogonController;
30 import com.sslexplorer.table.TableItem;
31
32 /**
33  * A {@link com.sslexplorer.table.TableItem} implementation used by displaying
34  * certificates or keys in a {@link com.sslexplorer.boot.KeyStoreManager}.
35  *
36  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
37  */

38 public class CertificateItem implements TableItem {
39     
40     // Private instance variables
41

42     /**
43      * Constant for the if the selected item is a key.
44      */

45     public static final String JavaDoc KEY = "key";
46     /**
47      * Constant for the if the selected item is a certificate.
48      */

49     public static final String JavaDoc CERTIFICATE = "cert";
50     /**
51      * Constant for the if the selected item is unknown.
52      */

53     public static final String JavaDoc UNKNOWN = "unknown";
54     
55     
56     private String JavaDoc alias;
57     private KeyStoreManager keyStoreManager;
58
59     /**
60      * Constructor
61      *
62      * @param alias alias for certificate
63      * @param certificate the certificate object itself
64      * @param keyStoreManager the key store manager that stores this key
65      *
66      */

67     public CertificateItem(String JavaDoc alias, Certificate JavaDoc certificate, KeyStoreManager keyStoreManager) {
68         super();
69         this.alias = alias;
70         this.keyStoreManager = keyStoreManager;
71     }
72     
73     /**
74      * Get if this item is removable
75      *
76      * @return removeable
77      */

78     public boolean isRemoveable() {
79         return keyStoreManager.getRemoveable() && !(keyStoreManager.getName().equals(KeyStoreManager.DEFAULT_KEY_STORE) && alias.equals(InstallAction.SSLEXPLORER_SERVER));
80     }
81     
82     /**
83      * Get the type of certificate as a string. Current possible values are
84      * <b>Trusted Cert.</b>, <b>Certificate</b>, <b>Trusted Key</b>,
85      * <b>Key</b> or <b>Unknown</b>.
86      *
87      * @return type of certificate as a string.
88      */

89     public String JavaDoc getType() {
90         try {
91             if(keyStoreManager.getKeyStore().isCertificateEntry(alias)) {
92                 return CERTIFICATE ;
93             }
94             else if (keyStoreManager.getKeyStore().isKeyEntry(alias)){
95                 return KEY ;
96             }
97         }
98         catch(Exception JavaDoc e) {
99         }
100         return UNKNOWN;
101     }
102     
103     /**
104      * Get the alias of the certificate / key
105      *
106      * @return alias
107      */

108     public String JavaDoc getAlias() {
109         return alias;
110     }
111
112     /* (non-Javadoc)
113      * @see com.sslexplorer.table.TableItem#getColumnValue(int)
114      */

115     public Object JavaDoc getColumnValue(int col) {
116         switch(col) {
117             case 0:
118                 return alias;
119             default:
120                 return getType();
121         }
122     }
123
124     public String JavaDoc getSmallIconPath(HttpServletRequest JavaDoc request) {
125         if (getType().equals(CERTIFICATE)){
126             return CoreUtil.getThemePath(request.getSession()) + "/images/actions/exportCertificate.gif";
127         }
128         else{
129             return CoreUtil.getThemePath(request.getSession()) + "/images/actions/exportPrivate.gif";
130         }
131     }
132
133 }
134
Popular Tags