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: leinfelder $'
|
9
|
* '$Date: 2012-01-25 07:41:29 -0800 (Wed, 25 Jan 2012) $'
|
10
|
* '$Revision: 6951 $'
|
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.MetaCatServlet;
|
42
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
43
|
import edu.ucsb.nceas.metacat.service.SessionService;
|
44
|
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
|
45
|
import edu.ucsb.nceas.metacat.shared.ServiceException;
|
46
|
import edu.ucsb.nceas.metacat.util.AuthUtil;
|
47
|
import edu.ucsb.nceas.metacat.util.ConfigurationUtil;
|
48
|
import edu.ucsb.nceas.metacat.util.RequestUtil;
|
49
|
import edu.ucsb.nceas.metacat.util.SkinUtil;
|
50
|
import edu.ucsb.nceas.metacat.util.SystemUtil;
|
51
|
import edu.ucsb.nceas.utilities.GeneralPropertyException;
|
52
|
|
53
|
/**
|
54
|
* Entry servlet for the metadata configuration utility
|
55
|
*/
|
56
|
public class MetacatAdminServlet extends HttpServlet {
|
57
|
|
58
|
private static final long serialVersionUID = 1L;
|
59
|
|
60
|
private Logger logMetacat = Logger.getLogger(MetacatAdminServlet.class);
|
61
|
|
62
|
/**
|
63
|
* Initialize the servlet
|
64
|
*/
|
65
|
public void init(ServletConfig config) throws ServletException {
|
66
|
super.init(config);
|
67
|
}
|
68
|
|
69
|
/** Handle "GET" method requests from HTTP clients */
|
70
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
71
|
throws ServletException, IOException {
|
72
|
|
73
|
// Process the data and send back the response
|
74
|
handleGetOrPost(request, response);
|
75
|
}
|
76
|
|
77
|
/** Handle "POST" method requests from HTTP clients */
|
78
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
79
|
throws ServletException, IOException {
|
80
|
|
81
|
// Process the data and send back the response
|
82
|
handleGetOrPost(request, response);
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* Control servlet response depending on the action parameter specified
|
87
|
*
|
88
|
* @param request
|
89
|
* the http request information
|
90
|
* @param response
|
91
|
* the http response to be sent back to the client
|
92
|
*/
|
93
|
private void handleGetOrPost(HttpServletRequest request,
|
94
|
HttpServletResponse response) throws ServletException, IOException {
|
95
|
String action = request.getParameter("configureType");
|
96
|
logMetacat.debug("MetacatAdminServlet.handleGetOrPost - Processing admin action: " + action);
|
97
|
Vector<String> processingMessage = new Vector<String>();
|
98
|
Vector<String> processingErrors = new Vector<String>();
|
99
|
|
100
|
try {
|
101
|
// Update the last update time for this user if they are not new
|
102
|
HttpSession httpSession = request.getSession(false);
|
103
|
if (httpSession != null) {
|
104
|
SessionService.getInstance().touchSession(httpSession.getId());
|
105
|
}
|
106
|
|
107
|
if (!ConfigurationUtil.isBackupDirConfigured()) {
|
108
|
// if the backup dir has not been configured, then show the
|
109
|
// backup directory configuration screen.
|
110
|
processingMessage.add("You must configure the backup directory"
|
111
|
+ " before you can continue with Metacat configuration.");
|
112
|
RequestUtil.setRequestMessage(request, processingMessage);
|
113
|
action = "backup";
|
114
|
logMetacat.debug("MetacatAdminServlet.handleGetOrPost - Admin action changed to 'backup'");
|
115
|
} else if (!AuthUtil.isAuthConfigured()) {
|
116
|
// if authentication isn't configured, change the action to auth.
|
117
|
// Authentication needs to be set up before we do anything else
|
118
|
processingMessage.add("You must configure authentication before "
|
119
|
+ "you can continue with MetaCat configuration.");
|
120
|
RequestUtil.setRequestMessage(request, processingMessage);
|
121
|
action = "auth";
|
122
|
logMetacat.debug("MetacatAdminServlet.handleGetOrPost - Admin action changed to 'auth'");
|
123
|
} else if (!AuthUtil.isUserLoggedInAsAdmin(request)) {
|
124
|
// If auth is configured, see if the user is logged in
|
125
|
// as an administrator. If not, they need to log in before
|
126
|
// they can continue with configuration.
|
127
|
processingMessage.add("You must log in as an administrative " + "" +
|
128
|
"user before you can continue with MetaCat configuration.");
|
129
|
RequestUtil.setRequestMessage(request, processingMessage);
|
130
|
action = "login";
|
131
|
logMetacat.debug("MetacatAdminServlet.handleGetOrPost - Admin action changed to 'login'");
|
132
|
}
|
133
|
|
134
|
if (action == null || action.equals("configure")) {
|
135
|
// Forward the request main configuration page
|
136
|
request.setAttribute("metaCatVersion", SystemUtil.getMetacatVersion());
|
137
|
request.setAttribute("propsConfigured", new Boolean(PropertyService.arePropertiesConfigured()));
|
138
|
request.setAttribute("authConfigured", new Boolean(AuthUtil.isAuthConfigured()));
|
139
|
// TODO MCD figure out if we still need an org section
|
140
|
//request.setAttribute("orgsConfigured", new Boolean(OrganizationUtil.areOrganizationsConfigured()));
|
141
|
request.setAttribute("skinsConfigured", new Boolean(SkinUtil.areSkinsConfigured()));
|
142
|
request.setAttribute("metacatConfigured", new Boolean(ConfigurationUtil.isMetacatConfigured()));
|
143
|
request.setAttribute("geoserverConfigured",
|
144
|
PropertyService.getProperty("configutil.geoserverConfigured"));
|
145
|
request.setAttribute("dataoneConfigured",
|
146
|
PropertyService.getProperty("configutil.dataoneConfigured"));
|
147
|
request.setAttribute("metcatServletInitialized", MetaCatServlet.isFullyInitialized());
|
148
|
if (PropertyService.arePropertiesConfigured()) {
|
149
|
request.setAttribute("databaseVersion",
|
150
|
DBAdmin.getInstance().getDBVersion());
|
151
|
request.setAttribute("contextURL", SystemUtil.getContextURL());
|
152
|
}
|
153
|
RequestUtil.forwardRequest(request, response,
|
154
|
"/admin/metacat-configuration.jsp?configureType=configure", null);
|
155
|
return;
|
156
|
} else if (action.equals("properties")) {
|
157
|
// process properties
|
158
|
PropertiesAdmin.getInstance().configureProperties(request,
|
159
|
response);
|
160
|
return;
|
161
|
} else if (action.equals("skins")) {
|
162
|
// process skins
|
163
|
SkinsAdmin.getInstance().configureSkins(request, response);
|
164
|
return;
|
165
|
} else if (action.equals("database")) {
|
166
|
// process database
|
167
|
DBAdmin.getInstance().configureDatabase(request, response);
|
168
|
return;
|
169
|
} else if (action.equals("auth")) {
|
170
|
// process authentication
|
171
|
AuthAdmin.getInstance().configureAuth(request, response);
|
172
|
return;
|
173
|
} else if (action.equals("login")) {
|
174
|
// process login
|
175
|
LoginAdmin.getInstance().authenticateUser(request, response);
|
176
|
return;
|
177
|
} else if (action.equals("backup")) {
|
178
|
// process login
|
179
|
BackupAdmin.getInstance().configureBackup(request, response);
|
180
|
return;
|
181
|
} else if (action.equals("geoserver")) {
|
182
|
// process geoserver password change
|
183
|
GeoserverAdmin.getInstance().configureGeoserver(request, response);
|
184
|
return;
|
185
|
} else if (action.equals("dataone")) {
|
186
|
// process dataone config
|
187
|
D1Admin.getInstance().configureDataONE(request, response);
|
188
|
return;
|
189
|
} else if (action.equals("replication")) {
|
190
|
// process replication config
|
191
|
ReplicationAdmin.getInstance().handleRequest(request, response);
|
192
|
return;
|
193
|
} else {
|
194
|
String errorMessage = "MetacatAdminServlet.handleGetOrPost - Invalid action in configuration request: " + action;
|
195
|
logMetacat.error(errorMessage);
|
196
|
processingErrors.add(errorMessage);
|
197
|
}
|
198
|
|
199
|
if (processingErrors.size() > 0) {
|
200
|
RequestUtil.clearRequestMessages(request);
|
201
|
RequestUtil.setRequestErrors(request,processingErrors);
|
202
|
// if the action that threw an exception was "configure" just go straight to the metacat
|
203
|
// configuration. This will avoid a loop. Otherwise, call the admin servlet with
|
204
|
// configuration action.
|
205
|
if (action != null && action.equals("configure")) {
|
206
|
RequestUtil.forwardRequest(request, response, "/admin/metacat-configuration.jsp", null);
|
207
|
} else {
|
208
|
RequestUtil.forwardRequest(request, response, "/admin?configureType=configure", null);
|
209
|
}
|
210
|
}
|
211
|
} catch (GeneralPropertyException ge) {
|
212
|
String errorMessage =
|
213
|
"MetacatAdminServlet.handleGetOrPost - Property problem while handling request: " + ge.getMessage();
|
214
|
logMetacat.error(errorMessage);
|
215
|
processingErrors.add(errorMessage);
|
216
|
} catch (AdminException ae) {
|
217
|
String errorMessage =
|
218
|
"MetacatAdminServlet.handleGetOrPost - Admin problem while handling request: " + ae.getMessage();
|
219
|
logMetacat.error(errorMessage);
|
220
|
processingErrors.add(errorMessage);
|
221
|
} catch (MetacatUtilException ue) {
|
222
|
String errorMessage =
|
223
|
"MetacatAdminServlet.handleGetOrPost - Utility problem while handling request: " + ue.getMessage();
|
224
|
logMetacat.error(errorMessage);
|
225
|
processingErrors.add(errorMessage);
|
226
|
} catch (ServiceException e) {
|
227
|
String errorMessage =
|
228
|
"MetacatAdminServlet.handleGetOrPost - Service problem while handling request: " + e.getMessage();
|
229
|
logMetacat.error(errorMessage);
|
230
|
processingErrors.add(errorMessage);
|
231
|
}
|
232
|
}
|
233
|
}
|