001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.console.keystores;
018
019 import org.apache.commons.logging.Log;
020 import org.apache.commons.logging.LogFactory;
021 import org.apache.geronimo.console.MultiPageModel;
022 import org.apache.geronimo.management.geronimo.KeystoreException;
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 import java.io.IOException;
030 import java.text.SimpleDateFormat;
031 import java.util.Calendar;
032 import java.util.Date;
033 import java.util.GregorianCalendar;
034
035 /**
036 * Handler for entering a password to unlock a keystore
037 *
038 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
039 */
040 public class ConfirmKeyHandler extends BaseKeystoreHandler {
041 private final static Log log = LogFactory.getLog(ConfirmKeyHandler.class);
042
043 public ConfirmKeyHandler() {
044 super(CONFIRM_KEY, "/WEB-INF/view/keystore/confirmKey.jsp");
045 }
046
047 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
048 return getMode();
049 }
050
051 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException {
052 SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
053 String keystore = request.getParameter("keystore");
054 String alias = request.getParameter("alias");
055 String password = request.getParameter("password");
056 String keySize = request.getParameter("keySize");
057 String algorithm = request.getParameter("algorithm");
058 String valid = request.getParameter("valid");
059 String certCN = request.getParameter("certCN");
060 String certOU = request.getParameter("certOU");
061 String certO = request.getParameter("certO");
062 String certL = request.getParameter("certL");
063 String certST = request.getParameter("certST");
064 String certC = request.getParameter("certC");
065 request.setAttribute("keystore", keystore);
066 request.setAttribute("alias", alias);
067 request.setAttribute("password", password);
068 request.setAttribute("keySize", keySize);
069 request.setAttribute("algorithm", algorithm);
070 request.setAttribute("valid", valid);
071 request.setAttribute("validFrom", sdf.format(new Date()));
072 Calendar cal = new GregorianCalendar();
073 cal.add(Calendar.DAY_OF_YEAR, Integer.parseInt(valid));
074 request.setAttribute("validTo", sdf.format(cal.getTime()));
075 request.setAttribute("certCN", certCN);
076 request.setAttribute("certOU", certOU);
077 request.setAttribute("certO", certO);
078 request.setAttribute("certL", certL);
079 request.setAttribute("certST", certST);
080 request.setAttribute("certC", certC);
081 }
082
083 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
084 String keystore = request.getParameter("keystore");
085 String alias = request.getParameter("alias");
086 String password = request.getParameter("password");
087 String keySize = request.getParameter("keySize");
088 String algorithm = request.getParameter("algorithm");
089 String valid = request.getParameter("valid");
090 String certCN = request.getParameter("certCN");
091 String certOU = request.getParameter("certOU");
092 String certO = request.getParameter("certO");
093 String certL = request.getParameter("certL");
094 String certST = request.getParameter("certST");
095 String certC = request.getParameter("certC");
096
097 KeystoreData data = ((KeystoreData) request.getPortletSession(true).getAttribute(KEYSTORE_DATA_PREFIX + keystore));
098 try {
099 data.createKeyPair(alias, password, "RSA", Integer.parseInt(keySize), algorithm, Integer.parseInt(valid),
100 certCN, certOU, certO, certL, certST, certC);
101 } catch (NumberFormatException e) {
102 throw new PortletException(e);
103 } catch (KeystoreException e) {
104 throw new PortletException(e);
105 }
106 response.setRenderParameter("id", keystore);
107 return VIEW_KEYSTORE+BEFORE_ACTION;
108 }
109 }