1 4 5 9 10 package org.openlaszlo.servlets.responders; 11 12 import java.io.*; 13 import java.util.Properties ; 14 import javax.servlet.ServletConfig ; 15 import javax.servlet.ServletException ; 16 import javax.servlet.http.HttpServletRequest ; 17 import javax.servlet.http.HttpServletResponse ; 18 import org.apache.log4j.Logger; 19 20 public abstract class ResponderAdmin extends Responder 21 { 22 private static boolean mIsInitialized = false; 23 private static Object mIsInitializedLock = new Object (); 24 private static String mAdminPassword = null; 25 26 private static Logger mLogger = Logger.getLogger(ResponderAdmin.class); 27 28 29 protected ResponderAdmin() 30 { 31 super(); 32 mAllowRequestDefaultProperty = "false"; 33 } 34 35 abstract protected void respondAdmin(HttpServletRequest req, HttpServletResponse res) 36 throws IOException; 37 38 39 synchronized public void init(String reqName, ServletConfig config, Properties prop) 40 throws ServletException , IOException 41 { 42 super.init(reqName, config, prop); 43 44 if (! mIsInitialized) { 45 mAdminPassword = prop.getProperty("adminPassword", null); 46 mIsInitialized = true; 47 } 48 } 49 50 protected final void respondImpl(HttpServletRequest req, HttpServletResponse res) 51 throws IOException 52 { 53 String pwd = req.getParameter("pwd"); 54 if ( mAdminPassword != null ) { 55 if ( pwd == null || ! pwd.equals(mAdminPassword) ) { 56 String lzt = req.getParameter("lzt"); 57 respondWithError(res, "Forbidden: " + lzt, 58 HttpServletResponse.SC_FORBIDDEN); 59 mLogger.info("Forbidden: " + lzt); 60 return; 61 } 62 } 63 respondAdmin(req, res); 64 } 65 } 66 | Popular Tags |