KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > ca > BaseCAHandler


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.console.ca;
19
20 import javax.portlet.ActionResponse;
21 import javax.portlet.PortletRequest;
22 import javax.portlet.PortletSession;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.geronimo.console.MultiPageAbstractHandler;
27 import org.apache.geronimo.console.MultiPageModel;
28 import org.apache.geronimo.console.util.PortletManager;
29 import org.apache.geronimo.management.geronimo.CertificateRequestStore;
30 import org.apache.geronimo.management.geronimo.CertificateStore;
31 import org.apache.geronimo.management.geronimo.CertificationAuthority;
32 import org.apache.geronimo.management.geronimo.KeystoreException;
33 import org.apache.geronimo.management.geronimo.KeystoreInstance;
34
35 /**
36  * The base class for all handlers for CA portlet
37  *
38  * @version $Rev: 487523 $ $Date: 2006-12-15 06:55:39 -0500 (Fri, 15 Dec 2006) $
39  */

40 public abstract class BaseCAHandler extends MultiPageAbstractHandler {
41     private final static Log log = LogFactory.getLog(BaseCAHandler.class);
42
43     protected static final String JavaDoc INDEX_MODE = "index";
44     protected static final String JavaDoc SETUPCA_MODE = "setupCA";
45     protected static final String JavaDoc CONFIRM_CA_MODE = "confirmCA";
46     protected static final String JavaDoc CADETAILS_MODE = "caDetails";
47     protected static final String JavaDoc UNLOCKCA_MODE = "unlockCA";
48     protected static final String JavaDoc PROCESS_CSR_MODE = "processCSR";
49     protected static final String JavaDoc CERT_REQ_DETAILS_MODE = "certReqDetails";
50     protected static final String JavaDoc CONFIRM_CLIENT_CERT_MODE = "confirmClientCert";
51     protected static final String JavaDoc VIEW_CERT_MODE = "viewCert";
52     protected static final String JavaDoc LIST_REQUESTS_ISSUE_MODE = "listRequestsIssue";
53     protected static final String JavaDoc LIST_REQUESTS_VERIFY_MODE = "listRequestsVerify";
54     protected static final String JavaDoc CONFIRM_CERT_REQ_MODE = "confirmCertReq";
55     
56     // Key algorithm for CA's keypair
57
protected static final String JavaDoc defaultKeyAlgorithm = "RSA";
58     // CA's private key and self-signed certificate is stored under this keystore created using KeystoreManager
59
// Using FileKeystoreManager, the file willbe <server-base-dir>/var/security/keystores/<defaultCAKeystore>
60
protected static final String JavaDoc defaultCAKeystore = "ca-keystore";
61     // CA's certificate store directory
62
protected static final String JavaDoc defaultCAStoreDir = "var/security/ca/certs";
63     // Certificate request store directory
64
protected static final String JavaDoc defaultCSRStoreDir = "var/security/ca/requests";
65
66     // Name of the attribute for error message to be displayed in a page
67
protected static final String JavaDoc ERROR_MSG = "errorMsg";
68     // Name of the attribute for information message to be displayed in a page
69
protected static final String JavaDoc INFO_MSG = "infoMsg";
70
71     /**
72      * Constructor
73      */

74     protected BaseCAHandler(String JavaDoc mode, String JavaDoc viewName) {
75         super(mode, viewName);
76     }
77
78     public final static class CAModel implements MultiPageModel {
79         public CAModel(PortletRequest request) {
80         }
81
82         public void save(ActionResponse response, PortletSession session) {
83         }
84     }
85     
86     /**
87      * This method returns CertificationAuthority GBbean.
88      * @param request PortletRequest to execute retrieve GBean
89      * @return null if a CA GBean is not running.
90      */

91     protected CertificationAuthority getCertificationAuthority(PortletRequest request) {
92         Object JavaDoc[] cas = PortletManager.getManagementHelper(request).getGBeansImplementing(CertificationAuthority.class);
93         return (CertificationAuthority)(cas != null && cas.length > 0 ? cas[0] : null);
94     }
95
96     /**
97      * This methods creates CA's keystore using KeystoreManager.
98      * @param request PortletRequest to get KeystoreManager
99      * @param password Password for newly created Keystore
100      * @throws KeystoreException
101      */

102     protected KeystoreInstance createCAKeystoreInstance(PortletRequest request, String JavaDoc password) throws KeystoreException {
103         return PortletManager.getCurrentServer(request).getKeystoreManager().createKeystore(defaultCAKeystore, password.toCharArray());
104     }
105     
106     /**
107      * This method returns CertificateRequestStore GBean.
108      * @param request PortletRequest to execute retrieve GBean
109      * @return null if a CertificateRequestStore GBean is not running.
110      */

111     protected CertificateRequestStore getCertificateRequestStore(PortletRequest request) {
112         Object JavaDoc[] crs = PortletManager.getManagementHelper(request).getGBeansImplementing(CertificateRequestStore.class);
113         return (CertificateRequestStore)(crs != null && crs.length > 0 ? crs[0] : null);
114     }
115
116     /**
117      * This method returns CertificateStore GBean.
118      * @param request PortletRequest to execute retrieve GBean
119      * @return null if a CertificateStore GBean is not running.
120      */

121     protected CertificateStore getCertificateStore(PortletRequest request) {
122         Object JavaDoc[] cs = PortletManager.getManagementHelper(request).getGBeansImplementing(CertificateStore.class);
123         return (CertificateStore)(cs != null && cs.length > 0 ? cs[0] : null);
124     }
125 }
126
Popular Tags