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