1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that implements utility methods for a metadata catalog
|
4
|
* Copyright: 2008 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Michael Daigle
|
7
|
*
|
8
|
* '$Author: daigle $'
|
9
|
* '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
|
10
|
* '$Revision: 4080 $'
|
11
|
*
|
12
|
* This program is free software; you can redistribute it and/or modify
|
13
|
* it under the terms of the GNU General Public License as published by
|
14
|
* the Free Software Foundation; either version 2 of the License, or
|
15
|
* (at your option) any later version.
|
16
|
*
|
17
|
* This program is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
* GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25
|
*/
|
26
|
|
27
|
package edu.ucsb.nceas.metacat.admin;
|
28
|
|
29
|
import java.io.IOException;
|
30
|
import java.util.Vector;
|
31
|
|
32
|
import javax.servlet.ServletConfig;
|
33
|
import javax.servlet.ServletException;
|
34
|
import javax.servlet.http.HttpServlet;
|
35
|
import javax.servlet.http.HttpServletRequest;
|
36
|
import javax.servlet.http.HttpServletResponse;
|
37
|
import javax.servlet.http.HttpSession;
|
38
|
|
39
|
import org.apache.log4j.Logger;
|
40
|
|
41
|
import edu.ucsb.nceas.metacat.service.PropertyService;
|
42
|
import edu.ucsb.nceas.metacat.service.SessionService;
|
43
|
import edu.ucsb.nceas.metacat.util.LDAPUtil;
|
44
|
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
|
45
|
import edu.ucsb.nceas.metacat.util.RequestUtil;
|
46
|
import edu.ucsb.nceas.metacat.util.SkinUtil;
|
47
|
import edu.ucsb.nceas.metacat.util.SystemUtil;
|
48
|
import edu.ucsb.nceas.metacat.util.UtilException;
|
49
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
50
|
|
51
|
/**
|
52
|
* Entry servlet for the metadata configuration utility
|
53
|
*/
|
54
|
public class MetaCatAdminServlet extends HttpServlet {
|
55
|
|
56
|
private static final long serialVersionUID = 1L;
|
57
|
|
58
|
private Logger logMetacat = Logger.getLogger(MetaCatAdminServlet.class);
|
59
|
|
60
|
/**
|
61
|
* Initialize the servlet
|
62
|
*/
|
63
|
public void init(ServletConfig config) throws ServletException {
|
64
|
super.init(config);
|
65
|
}
|
66
|
|
67
|
/** Handle "GET" method requests from HTTP clients */
|
68
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
69
|
throws ServletException, IOException {
|
70
|
|
71
|
// Process the data and send back the response
|
72
|
handleGetOrPost(request, response);
|
73
|
}
|
74
|
|
75
|
/** Handle "POST" method requests from HTTP clients */
|
76
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
77
|
throws ServletException, IOException {
|
78
|
|
79
|
// Process the data and send back the response
|
80
|
handleGetOrPost(request, response);
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* Control servlet response depending on the action parameter specified
|
85
|
*
|
86
|
* @param request
|
87
|
* the http request information
|
88
|
* @param response
|
89
|
* the http response to be sent back to the client
|
90
|
*/
|
91
|
private void handleGetOrPost(HttpServletRequest request,
|
92
|
HttpServletResponse response) throws ServletException, IOException {
|
93
|
String action = request.getParameter("configureType");
|
94
|
logMetacat.debug("Processing admin action: " + action);
|
95
|
Vector<String> processingMessage = new Vector<String>();
|
96
|
Vector<String> processingErrors = new Vector<String>();
|
97
|
|
98
|
try {
|
99
|
// Update the last update time for this user if they are not new
|
100
|
HttpSession httpSession = request.getSession(false);
|
101
|
if (httpSession != null) {
|
102
|
SessionService.touchSession(httpSession.getId());
|
103
|
}
|
104
|
|
105
|
// if ldap isn't configured, change the action to ldap. ldap
|
106
|
// needs to be set up before we do anything else
|
107
|
if (!LDAPUtil.isLDAPConfigured()) {
|
108
|
processingMessage.add("You must configure LDAP before "
|
109
|
+ "you can continue with MetaCat configuration.");
|
110
|
RequestUtil.setRequestMessage(request, processingMessage);
|
111
|
action = "ldap";
|
112
|
logMetacat.debug("Admin action changed to 'ldap'");
|
113
|
}
|
114
|
|
115
|
// Once ldap is configured, see if the user is logged in
|
116
|
// as an administrator. If not, they need to log in before
|
117
|
// they can continue with configuration.
|
118
|
if (LDAPUtil.isLDAPConfigured()
|
119
|
&& !LDAPUtil.isUserLoggedInAsAdmin(request)) {
|
120
|
processingMessage.add("You must log in as an administrative " + "" +
|
121
|
"user before you can continue with MetaCat configuration.");
|
122
|
RequestUtil.setRequestMessage(request, processingMessage);
|
123
|
action = "login";
|
124
|
logMetacat.debug("Admin action changed to 'login'");
|
125
|
}
|
126
|
|
127
|
if (action == null || action.equals("configure")) {
|
128
|
// Forward the request main configuration page
|
129
|
request.setAttribute("metaCatVersion", SystemUtil.getMetacatVersion());
|
130
|
request.setAttribute("propsConfigured", new Boolean(PropertyService.arePropertiesConfigured()));
|
131
|
if (PropertyService.arePropertiesConfigured()) {
|
132
|
request.setAttribute("databaseVersion",
|
133
|
DBAdmin.getInstance().getDBVersion());
|
134
|
}
|
135
|
request.setAttribute("ldapConfigured", new Boolean(LDAPUtil.isLDAPConfigured()));
|
136
|
request.setAttribute("skinsConfigured", new Boolean(SkinUtil.areSkinsConfigured()));
|
137
|
request.setAttribute("metacatConfigured", new Boolean(MetaCatUtil.isMetacatConfigured()));
|
138
|
RequestUtil.forwardRequest(request, response,
|
139
|
"/admin/metacat-configuration.jsp?configureType=configure");
|
140
|
return;
|
141
|
} else if (action.equals("properties")) {
|
142
|
// process properties
|
143
|
PropertiesAdmin.getInstance().configureProperties(request,
|
144
|
response);
|
145
|
return;
|
146
|
} else if (action.equals("skins")) {
|
147
|
// process skins
|
148
|
SkinsAdmin.getInstance().configureSkins(request, response);
|
149
|
return;
|
150
|
} else if (action.equals("database")) {
|
151
|
// process properties
|
152
|
DBAdmin.getInstance().configureDatabase(request, response);
|
153
|
return;
|
154
|
} else if (action.equals("ldap")) {
|
155
|
// process properties
|
156
|
LDAPAdmin.getInstance().configureLDAP(request, response);
|
157
|
return;
|
158
|
} else if (action.equals("login")) {
|
159
|
// process properties
|
160
|
AuthAdmin.getInstance().authenticateUser(request, response);
|
161
|
return;
|
162
|
} else {
|
163
|
String errorMessage = "Invalid action in configuration request: " + action;
|
164
|
logMetacat.error(errorMessage);
|
165
|
processingErrors.add(errorMessage);
|
166
|
}
|
167
|
} catch (PropertyNotFoundException pnfe) {
|
168
|
String errorMessage =
|
169
|
"Property problem while handling request: " + pnfe.getMessage();
|
170
|
logMetacat.error(errorMessage);
|
171
|
processingErrors.add(errorMessage);
|
172
|
} catch (AdminException ae) {
|
173
|
String errorMessage =
|
174
|
"Admin problem while handling request: " + ae.getMessage();
|
175
|
logMetacat.error(errorMessage);
|
176
|
processingErrors.add(errorMessage);
|
177
|
} catch (UtilException ue) {
|
178
|
String errorMessage =
|
179
|
"Utility problem while handling request: " + ue.getMessage();
|
180
|
logMetacat.error(errorMessage);
|
181
|
processingErrors.add(errorMessage);
|
182
|
}
|
183
|
|
184
|
if (processingErrors.size() > 0) {
|
185
|
RequestUtil.clearRequestMessages(request);
|
186
|
RequestUtil.setRequestErrors(request,processingErrors);
|
187
|
RequestUtil.forwardRequest(request, response, "/admin/metacat-configuration.jsp");
|
188
|
}
|
189
|
}
|
190
|
}
|