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 java.io.ByteArrayInputStream;
020: import java.io.IOException;
021: import java.util.Map;
022: import java.util.Properties;
023:
024: import javax.portlet.ActionRequest;
025: import javax.portlet.ActionResponse;
026: import javax.portlet.PortletException;
027: import javax.portlet.RenderRequest;
028: import javax.portlet.RenderResponse;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032: import org.apache.geronimo.console.MultiPageModel;
033: import org.apache.geronimo.management.geronimo.CertificateRequestStore;
034: import org.apache.geronimo.crypto.CaUtils;
035: import org.apache.geronimo.crypto.asn1.x509.X509Name;
036:
037: /**
038: * Handler for "Requests to be verified" screen.
039: *
040: * @version $Rev: 617588 $ $Date: 2008-02-01 10:20:07 -0800 (Fri, 01 Feb 2008) $
041: */
042: public class ListRequestsVerifyHandler extends BaseCAHandler {
043: private final static Log log = LogFactory
044: .getLog(ListRequestsVerifyHandler.class);
045:
046: public ListRequestsVerifyHandler() {
047: super (LIST_REQUESTS_VERIFY_MODE,
048: "/WEB-INF/view/ca/listRequestsVerify.jsp");
049: }
050:
051: public String actionBeforeView(ActionRequest request,
052: ActionResponse response, MultiPageModel model)
053: throws PortletException, IOException {
054: String[] params = { ERROR_MSG, INFO_MSG };
055: for (int i = 0; i < params.length; ++i) {
056: String value = request.getParameter(params[i]);
057: if (value != null)
058: response.setRenderParameter(params[i], value);
059: }
060: return getMode();
061: }
062:
063: public void renderView(RenderRequest request,
064: RenderResponse response, MultiPageModel model)
065: throws PortletException, IOException {
066: String[] params = { ERROR_MSG, INFO_MSG };
067: for (int i = 0; i < params.length; ++i) {
068: String value = request.getParameter(params[i]);
069: if (value != null)
070: request.setAttribute(params[i], value);
071: }
072: CertificateRequestStore csrStore = getCertificateRequestStore(request);
073: String[] csrIds = csrStore.getVerificatonDueRequestIds();
074: request.setAttribute("csrIds", csrIds);
075: }
076:
077: public String actionAfterView(ActionRequest request,
078: ActionResponse response, MultiPageModel model)
079: throws PortletException, IOException {
080: String errorMsg = null;
081: String requestId = request.getParameter("requestId");
082: try {
083: response.setRenderParameter("requestId", requestId);
084: // Retrieve the request info based on the requestId
085: String certreq = getCertificateRequestStore(request)
086: .getRequest(requestId);
087: if (certreq.startsWith(CaUtils.CERT_REQ_HEADER)) {
088: // This is a PKCS10 Request
089: Map certReqMap = CaUtils.processPKCS10Request(certreq);
090: // Set the subject and publickey values to be shown in subsequent screens
091: response.setRenderParameter("subject", certReqMap.get(
092: CaUtils.CERT_REQ_SUBJECT).toString());
093: response
094: .setRenderParameter("publickey", certReqMap
095: .get(CaUtils.CERT_REQ_PUBLICKEY_OBJ)
096: .toString());
097: } else {
098: // This is a custom request containing SPKAC and X509Name attributes received through web browser
099: Properties csrProps = new Properties();
100: csrProps.load(new ByteArrayInputStream(certreq
101: .getBytes()));
102: String spkac = csrProps.getProperty("SPKAC");
103: String cn = csrProps.getProperty("CN");
104: String ou = csrProps.getProperty("OU");
105: String o = csrProps.getProperty("O");
106: String l = csrProps.getProperty("L");
107: String st = csrProps.getProperty("ST");
108: String c = csrProps.getProperty("C");
109: X509Name subject = CaUtils.getX509Name(cn, ou, o, l,
110: st, c);
111: Map certReqMap = CaUtils.processSPKAC(spkac);
112: // Set the subject and publickey values to be shown in subsequent screens
113: response.setRenderParameter("subject", subject
114: .toString());
115: response
116: .setRenderParameter("publickey", certReqMap
117: .get(CaUtils.CERT_REQ_PUBLICKEY_OBJ)
118: .toString());
119: }
120: return CONFIRM_CERT_REQ_MODE + BEFORE_ACTION;
121: } catch (Exception e) {
122: errorMsg = e.toString();
123: log.error("Errors while verifying Certificate Request. id="
124: + requestId, e);
125: }
126: response.setRenderParameter(ERROR_MSG, errorMsg);
127: return getMode() + BEFORE_ACTION;
128: }
129: }
|