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: */package org.apache.geronimo.console.keystores;
017:
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.apache.geronimo.console.MultiPageModel;
021: import org.apache.geronimo.management.geronimo.KeystoreException;
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: import java.io.IOException;
029: import java.text.SimpleDateFormat;
030: import java.util.Calendar;
031: import java.util.Date;
032: import java.util.GregorianCalendar;
033:
034: /**
035: * Handler for entering a password to unlock a keystore
036: *
037: * @version $Rev: 476061 $ $Date: 2006-11-16 22:36:50 -0800 (Thu, 16 Nov 2006) $
038: */
039: public class ConfirmKeyHandler extends BaseKeystoreHandler {
040: private final static Log log = LogFactory
041: .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,
048: ActionResponse response, MultiPageModel model)
049: throws PortletException, IOException {
050: return getMode();
051: }
052:
053: public void renderView(RenderRequest request,
054: RenderResponse response, MultiPageModel model)
055: throws PortletException, IOException {
056: SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
057: String keystore = request.getParameter("keystore");
058: String alias = request.getParameter("alias");
059: String password = request.getParameter("password");
060: String keySize = request.getParameter("keySize");
061: String algorithm = request.getParameter("algorithm");
062: String valid = request.getParameter("valid");
063: String certCN = request.getParameter("certCN");
064: String certOU = request.getParameter("certOU");
065: String certO = request.getParameter("certO");
066: String certL = request.getParameter("certL");
067: String certST = request.getParameter("certST");
068: String certC = request.getParameter("certC");
069: request.setAttribute("keystore", keystore);
070: request.setAttribute("alias", alias);
071: request.setAttribute("password", password);
072: request.setAttribute("keySize", keySize);
073: request.setAttribute("algorithm", algorithm);
074: request.setAttribute("valid", valid);
075: request.setAttribute("validFrom", sdf.format(new Date()));
076: Calendar cal = new GregorianCalendar();
077: cal.add(Calendar.DAY_OF_YEAR, Integer.parseInt(valid));
078: request.setAttribute("validTo", sdf.format(cal.getTime()));
079: request.setAttribute("certCN", certCN);
080: request.setAttribute("certOU", certOU);
081: request.setAttribute("certO", certO);
082: request.setAttribute("certL", certL);
083: request.setAttribute("certST", certST);
084: request.setAttribute("certC", certC);
085: }
086:
087: public String actionAfterView(ActionRequest request,
088: ActionResponse response, MultiPageModel model)
089: throws PortletException, IOException {
090: String keystore = request.getParameter("keystore");
091: String alias = request.getParameter("alias");
092: String password = request.getParameter("password");
093: String keySize = request.getParameter("keySize");
094: String algorithm = request.getParameter("algorithm");
095: String valid = request.getParameter("valid");
096: String certCN = request.getParameter("certCN");
097: String certOU = request.getParameter("certOU");
098: String certO = request.getParameter("certO");
099: String certL = request.getParameter("certL");
100: String certST = request.getParameter("certST");
101: String certC = request.getParameter("certC");
102:
103: KeystoreData data = ((KeystoreData) request.getPortletSession(
104: true).getAttribute(KEYSTORE_DATA_PREFIX + keystore));
105: try {
106: data.createKeyPair(alias, password, "RSA", Integer
107: .parseInt(keySize), algorithm, Integer
108: .parseInt(valid), certCN, certOU, certO, certL,
109: certST, certC);
110: } catch (NumberFormatException e) {
111: throw new PortletException(e);
112: } catch (KeystoreException e) {
113: throw new PortletException(e);
114: }
115: response.setRenderParameter("id", keystore);
116: return VIEW_KEYSTORE + BEFORE_ACTION;
117: }
118: }
|