KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > servlets > responders > ResponderAdmin


1 /******************************************************************************
2  * ResponderAdmin.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.servlets.responders;
11
12 import java.io.*;
13 import java.util.Properties JavaDoc;
14 import javax.servlet.ServletConfig JavaDoc;
15 import javax.servlet.ServletException JavaDoc;
16 import javax.servlet.http.HttpServletRequest JavaDoc;
17 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc mIsInitializedLock = new Object JavaDoc();
24     private static String JavaDoc mAdminPassword = null;
25
26     private static Logger mLogger = Logger.getLogger(ResponderAdmin.class);
27
28     /** Set default property for allowRequest to false for admin requests. */
29     protected ResponderAdmin()
30     {
31         super();
32         mAllowRequestDefaultProperty = "false";
33     }
34
35     abstract protected void respondAdmin(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
36         throws IOException;
37
38
39     synchronized public void init(String JavaDoc reqName, ServletConfig JavaDoc config, Properties JavaDoc prop)
40         throws ServletException JavaDoc, 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 JavaDoc req, HttpServletResponse JavaDoc res)
51         throws IOException
52     {
53         String JavaDoc pwd = req.getParameter("pwd");
54         if ( mAdminPassword != null ) {
55             if ( pwd == null || ! pwd.equals(mAdminPassword) ) {
56                 String JavaDoc 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