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