summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/cms/servlet/csadmin/ConfigBaseServlet.java
blob: dbda788f62dc362e2e55cc78d5deae0630d18d2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cms.servlet.csadmin;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.Template;
import org.apache.velocity.context.Context;

import com.netscape.certsrv.apps.CMS;

public abstract class ConfigBaseServlet extends BaseServlet {
    /**
     *
     */
    private static final long serialVersionUID = 7692352201878710530L;

    public boolean isDisplayMode(HttpServletRequest request,
            HttpServletResponse response,
            Context context) {
        String display = request.getParameter("display");

        if (display == null) {
            return true;
        } else {
            return false;
        }
    }

    public abstract void display(HttpServletRequest request,
            HttpServletResponse response, Context context);

    public abstract void update(HttpServletRequest request,
            HttpServletResponse response, Context context);

    public abstract Template getTemplate(HttpServletRequest request,
            HttpServletResponse response,
            Context context);

    public void outputHttpParameters(HttpServletRequest httpReq) {
        CMS.debug("ConfigBaseServlet:service() uri = " + httpReq.getRequestURI());
        @SuppressWarnings("unchecked")
        Enumeration<String> paramNames = httpReq.getParameterNames();

        while (paramNames.hasMoreElements()) {
            String pn = paramNames.nextElement();
            // added this facility so that password can be hidden,
            // all sensitive parameters should be prefixed with 
            // __ (double underscores); however, in the event that
            // a security parameter slips through, we perform multiple
            // additional checks to insure that it is NOT displayed
            if (pn.startsWith("__") ||
                    pn.endsWith("password") ||
                    pn.endsWith("passwd") ||
                    pn.endsWith("pwd") ||
                    pn.equalsIgnoreCase("admin_password_again") ||
                    pn.equalsIgnoreCase("directoryManagerPwd") ||
                    pn.equalsIgnoreCase("bindpassword") ||
                    pn.equalsIgnoreCase("bindpwd") ||
                    pn.equalsIgnoreCase("passwd") ||
                    pn.equalsIgnoreCase("password") ||
                    pn.equalsIgnoreCase("pin") ||
                    pn.equalsIgnoreCase("pwd") ||
                    pn.equalsIgnoreCase("pwdagain") ||
                    pn.equalsIgnoreCase("uPasswd")) {
                CMS.debug("ConfigBaseServlet::service() param name='" + pn +
                         "' value='(sensitive)'");
            } else {
                CMS.debug("ConfigBaseServlet::service() param name='" + pn +
                         "' value='" + httpReq.getParameter(pn) + "'");
            }
        }
    }

    /**
     * Processes request.
     */
    public Template process(HttpServletRequest request,
            HttpServletResponse response,
            Context context) {

        if (CMS.debugOn()) {
            outputHttpParameters(request);
        }

        if (isDisplayMode(request, response, context)) {
            display(request, response, context);
        } else {
            update(request, response, context);
        }

        Template template = null;

        try {
            context.put("name", "Velocity Test");
            template = getTemplate(request, response, context);
        } catch (Exception e) {
            System.err.println("Exception caught: " + e.getMessage());
        }

        return template;
    }
}