1 13 14 package org.ejbca.ui.web.admin.configuration; 15 16 import java.io.IOException ; 17 import java.security.SecureRandom ; 18 import java.util.Collection ; 19 import java.util.Iterator ; 20 21 import javax.servlet.ServletConfig ; 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServlet ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 27 import org.apache.commons.lang.StringUtils; 28 import org.apache.log4j.BasicConfigurator; 29 import org.apache.log4j.Logger; 30 import org.ejbca.core.ejb.ServiceLocator; 31 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal; 32 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome; 33 import org.ejbca.core.ejb.services.IServiceTimerSessionLocalHome; 34 import org.ejbca.core.model.InternalResources; 35 import org.ejbca.core.model.ca.caadmin.CAInfo; 36 import org.ejbca.core.model.log.Admin; 37 import org.ejbca.util.CertTools; 38 39 60 public class StartServicesServlet extends HttpServlet { 61 62 private static final Logger log = Logger.getLogger(StartServicesServlet.class); 63 64 private static final InternalResources intres = InternalResources.getInstance(); 65 66 70 public void destroy() { 71 String iMsg = intres.getLocalizedMessage("startservice.shutdown"); 72 log.info(iMsg); 73 74 log.debug(">destroy calling ServiceSession.unload"); 75 try { 76 getServiceHome().create().unload(); 77 } catch (Exception e) { 78 log.error(e); 79 } 80 super.destroy(); 81 } 82 83 84 private IServiceTimerSessionLocalHome servicehome = null; 85 86 private synchronized IServiceTimerSessionLocalHome getServiceHome() throws IOException { 87 try{ 88 if(servicehome == null){ 89 servicehome = (IServiceTimerSessionLocalHome)ServiceLocator.getInstance().getLocalHome(IServiceTimerSessionLocalHome.COMP_NAME); 90 } 91 } catch(Exception e){ 92 throw new java.io.IOException ("Authorization Denied"); 93 } 94 return servicehome; 95 } 96 97 98 public void init(ServletConfig config) throws ServletException { 99 super.init(config); 100 String iMsg = intres.getLocalizedMessage("startservice.startup"); 101 log.info(iMsg); 102 103 log.debug(">init calling ServiceSession.load"); 104 try { 105 getServiceHome().create().load(); 106 } catch (Exception e) { 107 log.error("Error init ServiceSession: ", e); 108 } 109 110 log.debug(">init initializing log4j"); 111 String configfile = ServiceLocator.getInstance().getString("java:comp/env/LOG4JCONFIG"); 112 if (!StringUtils.equals(configfile, "false")) { 113 if (StringUtils.equals(configfile, "basic")) { 115 BasicConfigurator.configure(); 117 } else { 118 } 120 } 121 122 log.debug("Re-installing BC-provider"); 124 CertTools.removeBCProvider(); 125 CertTools.installBCProvider(); 126 127 log.debug(">init initializing random seed"); 129 SecureRandom rand = new SecureRandom (); 130 rand.nextInt(); 131 132 log.debug("init loading CAs into cache"); 134 try { 135 ICAAdminSessionLocalHome casessionhome = (ICAAdminSessionLocalHome)ServiceLocator.getInstance().getLocalHome(ICAAdminSessionLocalHome.COMP_NAME); 136 ICAAdminSessionLocal casession; 137 casession = casessionhome.create(); 138 Admin admin = new Admin(Admin.TYPE_CACOMMANDLINE_USER, "StartServicesServlet"); 139 Collection caids = casession.getAvailableCAs(admin); 140 Iterator iter = caids.iterator(); 141 while (iter.hasNext()) { 142 int caid = ((Integer )iter.next()).intValue(); 143 CAInfo ca = casession.getCAInfo(admin, caid); 144 log.debug("Found CA: "+ca.getName()+", with expire time: "+ca.getExpireTime()); 145 } 146 } catch (Exception e) { 147 log.error("Error creating CAAdminSession: ", e); 148 } 149 150 } 152 public void doPost(HttpServletRequest req, HttpServletResponse res) 153 throws IOException , ServletException { 154 log.debug(">doPost()"); 155 doGet(req, res); 156 log.debug("<doPost()"); 157 } 159 public void doGet(HttpServletRequest req, HttpServletResponse res) throws java.io.IOException , ServletException { 160 log.debug(">doGet()"); 161 res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Servlet doesn't support requests is only loaded on startup."); 162 log.debug("<doGet()"); 163 } 165 } 166 | Popular Tags |