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
022 import javax.portlet.ActionRequest;
023 import javax.portlet.ActionResponse;
024 import javax.portlet.PortletException;
025 import javax.portlet.RenderRequest;
026 import javax.portlet.RenderResponse;
027
028 import org.apache.commons.logging.Log;
029 import org.apache.commons.logging.LogFactory;
030 import org.apache.geronimo.console.MultiPageModel;
031 import org.apache.geronimo.management.geronimo.CertificationAuthority;
032
033 /**
034 * Handler for the CA home screen.
035 *
036 * @version $Rev: 514091 $ $Date: 2007-03-03 01:26:39 -0500 (Sat, 03 Mar 2007) $
037 */
038 public class IntroHandler extends BaseCAHandler {
039 private final static Log log = LogFactory.getLog(IntroHandler.class);
040 public IntroHandler() {
041 super(INDEX_MODE, "/WEB-INF/view/ca/index.jsp");
042 }
043
044 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
045 String[] params = new String[] {ERROR_MSG, INFO_MSG};
046 for(int i = 0; i < params.length; ++i) {
047 String value = request.getParameter(params[i]);
048 if(value != null) response.setRenderParameter(params[i], value);
049 }
050 return getMode();
051 }
052
053 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) 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) request.setAttribute(params[i], value);
058 }
059
060 CertificationAuthority ca = getCertificationAuthority(request);
061 if(ca == null) {
062 // CA GBean is not running or the CA has not been initialized.
063 request.setAttribute("caNotSetup", Boolean.TRUE);
064 } else {
065 request.setAttribute("caNotSetup", Boolean.FALSE);
066 request.setAttribute("caLocked", ca.isLocked() ? Boolean.TRUE : Boolean.FALSE);
067 }
068 }
069
070 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException {
071 if(request.getParameter("lock") != null) {
072 CertificationAuthority ca = getCertificationAuthority(request);
073 if(ca == null) {
074 log.warn("CA is not running or CA may not have been initialized. Unable to lock CA.");
075 response.setRenderParameter(ERROR_MSG, "CA is not running or CA may not have been initialized. Unable to lock CA.");
076 } else {
077 ca.lock();
078 log.info("CA is now locked.");
079 response.setRenderParameter(INFO_MSG, "CA has been locked!");
080 }
081 } else if(request.getParameter("publish") != null) {
082 CertificationAuthority ca = getCertificationAuthority(request);
083 try {
084 getCertificateStore(request).storeCACertificate(ca.getCertificate());
085 response.setRenderParameter(INFO_MSG, "CA's certificate published to Certificate Store");
086 } catch (Exception e) {
087 log.error("Error while publishing CA's certificate to Certificate Store", e);
088 response.setRenderParameter(ERROR_MSG, "Error while publishing CA's certificate to Certificate Store. "+e);
089 }
090 }
091 return getMode()+BEFORE_ACTION;
092 }
093 }