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.IOException;
021 import java.util.Map;
022
023 import javax.portlet.ActionRequest;
024 import javax.portlet.ActionResponse;
025 import javax.portlet.PortletException;
026 import javax.portlet.RenderRequest;
027 import javax.portlet.RenderResponse;
028
029 import org.apache.commons.logging.Log;
030 import org.apache.commons.logging.LogFactory;
031 import org.apache.geronimo.console.MultiPageModel;
032 import org.apache.geronimo.util.CaUtils;
033
034 /**
035 * Handler for process CSR screen.
036 *
037 * @version $Rev: 514091 $ $Date: 2007-03-03 01:26:39 -0500 (Sat, 03 Mar 2007) $
038 */
039 public class ProcessCSRHandler extends BaseCAHandler {
040 private final static Log log = LogFactory.getLog(ProcessCSRHandler.class);
041 public ProcessCSRHandler() {
042 super(PROCESS_CSR_MODE, "/WEB-INF/view/ca/processCSR.jsp");
043 }
044
045 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
046 String[] params = {ERROR_MSG, INFO_MSG};
047 for(int i = 0; i < params.length; ++i) {
048 String value = request.getParameter(params[i]);
049 if(value != null) response.setRenderParameter(params[i], value);
050 }
051 return getMode();
052 }
053
054 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException {
055 String[] params = {ERROR_MSG, INFO_MSG};
056 for(int i = 0; i < params.length; ++i) {
057 Object value = request.getParameter(params[i]);
058 if(value != null) request.setAttribute(params[i], value);
059 }
060 }
061
062 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
063 String errorMsg = null;
064 try {
065 // Process the PKCS10 Certificate Request
066 String pkcs10certreq = request.getParameter("pkcs10certreq");
067 Map certReqMap = CaUtils.processPKCS10Request(pkcs10certreq);
068 response.setRenderParameter("pkcs10certreq", pkcs10certreq);
069 // Set the subject and publickey values to be shown in subsequent screens
070 response.setRenderParameter("subject", certReqMap.get(CaUtils.CERT_REQ_SUBJECT).toString());
071 response.setRenderParameter("publickey", certReqMap.get(CaUtils.CERT_REQ_PUBLICKEY_OBJ).toString());
072 return CERT_REQ_DETAILS_MODE+BEFORE_ACTION;
073 } catch(Exception e) {
074 errorMsg = e.toString();
075 log.error("Errors while processing a CSR.", e);
076 }
077 response.setRenderParameter(ERROR_MSG, errorMsg);
078 return getMode()+BEFORE_ACTION;
079 }
080 }