001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.geronimo.console.ca;
018:
019: import javax.portlet.ActionResponse;
020: import javax.portlet.PortletRequest;
021: import javax.portlet.PortletSession;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.apache.geronimo.console.MultiPageAbstractHandler;
026: import org.apache.geronimo.console.MultiPageModel;
027: import org.apache.geronimo.console.util.PortletManager;
028: import org.apache.geronimo.management.geronimo.CertificateRequestStore;
029: import org.apache.geronimo.management.geronimo.CertificateStore;
030: import org.apache.geronimo.management.geronimo.CertificationAuthority;
031: import org.apache.geronimo.management.geronimo.KeystoreException;
032: import org.apache.geronimo.management.geronimo.KeystoreInstance;
033:
034: /**
035: * The base class for all handlers for CA portlet
036: *
037: * @version $Rev: 615625 $ $Date: 2008-01-27 10:12:55 -0800 (Sun, 27 Jan 2008) $
038: */
039: public abstract class BaseCAHandler extends MultiPageAbstractHandler {
040: private final static Log log = LogFactory
041: .getLog(BaseCAHandler.class);
042:
043: protected static final String INDEX_MODE = "index";
044: protected static final String SETUPCA_MODE = "setupCA";
045: protected static final String CONFIRM_CA_MODE = "confirmCA";
046: protected static final String CADETAILS_MODE = "caDetails";
047: protected static final String UNLOCKCA_MODE = "unlockCA";
048: protected static final String PROCESS_CSR_MODE = "processCSR";
049: protected static final String CERT_REQ_DETAILS_MODE = "certReqDetails";
050: protected static final String CONFIRM_CLIENT_CERT_MODE = "confirmClientCert";
051: protected static final String VIEW_CERT_MODE = "viewCert";
052: protected static final String LIST_REQUESTS_ISSUE_MODE = "listRequestsIssue";
053: protected static final String LIST_REQUESTS_VERIFY_MODE = "listRequestsVerify";
054: protected static final String CONFIRM_CERT_REQ_MODE = "confirmCertReq";
055:
056: // Key algorithm for CA's keypair
057: protected static final String defaultKeyAlgorithm = "RSA";
058: // CA's private key and self-signed certificate is stored under this keystore created using KeystoreManager
059: // Using FileKeystoreManager, the file willbe <server-base-dir>/var/security/keystores/<defaultCAKeystore>
060: protected static final String defaultCAKeystore = "ca-keystore";
061: // CA's certificate store directory
062: protected static final String defaultCAStoreDir = "var/security/ca/certs";
063: // Certificate request store directory
064: protected static final String defaultCSRStoreDir = "var/security/ca/requests";
065:
066: // Name of the attribute for error message to be displayed in a page
067: protected static final String ERROR_MSG = "errorMsg";
068: // Name of the attribute for information message to be displayed in a page
069: protected static final String INFO_MSG = "infoMsg";
070:
071: /**
072: * Constructor
073: */
074: protected BaseCAHandler(String mode, String viewName) {
075: super (mode, viewName);
076: }
077:
078: public final static class CAModel implements MultiPageModel {
079: public CAModel(PortletRequest request) {
080: }
081:
082: public void save(ActionResponse response, PortletSession session) {
083: }
084: }
085:
086: /**
087: * This method returns CertificationAuthority GBbean.
088: * @param request PortletRequest to execute retrieve GBean
089: * @return null if a CA GBean is not running.
090: */
091: protected CertificationAuthority getCertificationAuthority(
092: PortletRequest request) {
093: Object[] cas = PortletManager.getManagementHelper(request)
094: .getGBeansImplementing(CertificationAuthority.class);
095: return (CertificationAuthority) (cas != null && cas.length > 0 ? cas[0]
096: : null);
097: }
098:
099: /**
100: * This methods creates CA's keystore using KeystoreManager.
101: * @param request PortletRequest to get KeystoreManager
102: * @param password Password for newly created Keystore
103: * @throws KeystoreException
104: */
105: protected KeystoreInstance createCAKeystoreInstance(
106: PortletRequest request, String password, String type)
107: throws KeystoreException {
108: return PortletManager.getCurrentServer(request)
109: .getKeystoreManager().createKeystore(defaultCAKeystore,
110: password.toCharArray(), type);
111: }
112:
113: /**
114: * This method returns CertificateRequestStore GBean.
115: * @param request PortletRequest to execute retrieve GBean
116: * @return null if a CertificateRequestStore GBean is not running.
117: */
118: protected CertificateRequestStore getCertificateRequestStore(
119: PortletRequest request) {
120: Object[] crs = PortletManager.getManagementHelper(request)
121: .getGBeansImplementing(CertificateRequestStore.class);
122: return (CertificateRequestStore) (crs != null && crs.length > 0 ? crs[0]
123: : null);
124: }
125:
126: /**
127: * This method returns CertificateStore GBean.
128: * @param request PortletRequest to execute retrieve GBean
129: * @return null if a CertificateStore GBean is not running.
130: */
131: protected CertificateStore getCertificateStore(
132: PortletRequest request) {
133: Object[] cs = PortletManager.getManagementHelper(request)
134: .getGBeansImplementing(CertificateStore.class);
135: return (CertificateStore) (cs != null && cs.length > 0 ? cs[0]
136: : null);
137: }
138: }
|