1 18 package org.apache.geronimo.console.ca; 19 20 import java.io.IOException ; 21 22 import javax.portlet.ActionRequest; 23 import javax.portlet.ActionResponse; 24 import javax.portlet.PortletException; 25 import javax.portlet.RenderRequest; 26 import javax.portlet.RenderResponse; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.geronimo.console.MultiPageModel; 31 import org.apache.geronimo.management.geronimo.CertificationAuthority; 32 33 38 public class UnlockCAHandler extends BaseCAHandler { 39 private final static Log log = LogFactory.getLog(UnlockCAHandler.class); 40 public UnlockCAHandler() { 41 super(UNLOCKCA_MODE, "/WEB-INF/view/ca/unlockCA.jsp"); 42 } 43 44 public String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 45 String [] params = {ERROR_MSG, INFO_MSG}; 46 for(int i = 0; i < params.length; ++i) { 47 String value = request.getParameter(params[i]); 48 if(value != null) response.setRenderParameter(params[i], value); 49 } 50 return getMode(); 51 } 52 53 public void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException { 54 String [] params = {ERROR_MSG, INFO_MSG}; 55 for(int i = 0; i < params.length; ++i) { 56 Object value = request.getParameter(params[i]); 57 if(value != null) request.setAttribute(params[i], value); 58 } 59 } 60 61 public String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException { 62 String errorMsg = null; 63 try { 64 String password = request.getParameter("password"); 65 if(password == null) { 66 throw new Exception ("Password is null."); 67 } 68 CertificationAuthority ca = getCertificationAuthority(request); 69 if(ca == null) { 70 throw new Exception ("CA is not running. CA may not have been initialized."); 71 } 72 ca.unlock(password.toCharArray()); 73 74 response.setRenderParameter(INFO_MSG, "CA has been unlocked successfully!"); 76 log.info("CA has been unlocked successfully!"); 77 return INDEX_MODE+BEFORE_ACTION; 78 } catch(Exception e) { 79 errorMsg = e.toString(); 80 log.error("Errors in unlocking CA.", e); 81 } 82 response.setRenderParameter(ERROR_MSG, errorMsg); 84 return getMode()+BEFORE_ACTION; 85 } 86 } 87 | Popular Tags |