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-08-04 17:08:44 -0700 (Mon, 04 Aug 2008) $'
|
10
|
* '$Revision: 4200 $'
|
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.service.PropertyService;
|
43
|
import edu.ucsb.nceas.metacat.service.SessionService;
|
44
|
import edu.ucsb.nceas.metacat.util.LDAPUtil;
|
45
|
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
|
46
|
//import edu.ucsb.nceas.metacat.util.OrganizationUtil;
|
47
|
import edu.ucsb.nceas.metacat.util.RequestUtil;
|
48
|
import edu.ucsb.nceas.metacat.util.SkinUtil;
|
49
|
import edu.ucsb.nceas.metacat.util.SystemUtil;
|
50
|
import edu.ucsb.nceas.metacat.util.UtilException;
|
51
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
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("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.touchSession(httpSession.getId());
|
105
|
}
|
106
|
|
107
|
// if ldap isn't configured, change the action to ldap. ldap
|
108
|
// needs to be set up before we do anything else
|
109
|
if (!LDAPUtil.isLDAPConfigured()) {
|
110
|
processingMessage.add("You must configure LDAP before "
|
111
|
+ "you can continue with MetaCat configuration.");
|
112
|
RequestUtil.setRequestMessage(request, processingMessage);
|
113
|
action = "ldap";
|
114
|
logMetacat.debug("Admin action changed to 'ldap'");
|
115
|
}
|
116
|
|
117
|
// Once ldap is configured, see if the user is logged in
|
118
|
// as an administrator. If not, they need to log in before
|
119
|
// they can continue with configuration.
|
120
|
if (LDAPUtil.isLDAPConfigured()
|
121
|
&& !LDAPUtil.isUserLoggedInAsAdmin(request)) {
|
122
|
processingMessage.add("You must log in as an administrative " + "" +
|
123
|
"user before you can continue with MetaCat configuration.");
|
124
|
RequestUtil.setRequestMessage(request, processingMessage);
|
125
|
action = "login";
|
126
|
logMetacat.debug("Admin action changed to 'login'");
|
127
|
}
|
128
|
|
129
|
if (action == null || action.equals("configure")) {
|
130
|
// Forward the request main configuration page
|
131
|
request.setAttribute("metaCatVersion", SystemUtil.getMetacatVersion());
|
132
|
request.setAttribute("propsConfigured", new Boolean(PropertyService.arePropertiesConfigured()));
|
133
|
if (PropertyService.arePropertiesConfigured()) {
|
134
|
request.setAttribute("databaseVersion",
|
135
|
DBAdmin.getInstance().getDBVersion());
|
136
|
}
|
137
|
request.setAttribute("ldapConfigured", new Boolean(LDAPUtil.isLDAPConfigured()));
|
138
|
// TODO MCD figure out if we still need an org section
|
139
|
//request.setAttribute("orgsConfigured", new Boolean(OrganizationUtil.areOrganizationsConfigured()));
|
140
|
request.setAttribute("skinsConfigured", new Boolean(SkinUtil.areSkinsConfigured()));
|
141
|
request.setAttribute("metacatConfigured", new Boolean(MetaCatUtil.isMetacatConfigured()));
|
142
|
request.setAttribute("geoserverConfigured",
|
143
|
PropertyService.getProperty("configutil.geoserverConfigured"));
|
144
|
request.setAttribute("metcatServletInitialized", MetaCatServlet.isFullyInitialized());
|
145
|
RequestUtil.forwardRequest(request, response,
|
146
|
"/admin/metacat-configuration.jsp?configureType=configure");
|
147
|
return;
|
148
|
} else if (action.equals("properties")) {
|
149
|
// process properties
|
150
|
PropertiesAdmin.getInstance().configureProperties(request,
|
151
|
response);
|
152
|
return;
|
153
|
} else if (action.equals("skins")) {
|
154
|
// process skins
|
155
|
SkinsAdmin.getInstance().configureSkins(request, response);
|
156
|
return;
|
157
|
} else if (action.equals("database")) {
|
158
|
// process database
|
159
|
DBAdmin.getInstance().configureDatabase(request, response);
|
160
|
return;
|
161
|
} else if (action.equals("ldap")) {
|
162
|
// process ldap
|
163
|
LDAPAdmin.getInstance().configureLDAP(request, response);
|
164
|
return;
|
165
|
// TODO MCD figure out if org configuration is still needed
|
166
|
// } else if (action.equals("organization")) {
|
167
|
// // process organization
|
168
|
// OrganizationAdmin.getInstance().configureOrganization(request, response);
|
169
|
// return;
|
170
|
} else if (action.equals("login")) {
|
171
|
// process login
|
172
|
AuthAdmin.getInstance().authenticateUser(request, response);
|
173
|
return;
|
174
|
} else if (action.equals("geoserver")) {
|
175
|
// process geoserver password change
|
176
|
GeoserverAdmin.getInstance().configureGeoserver(request, response);
|
177
|
return;
|
178
|
} else {
|
179
|
String errorMessage = "Invalid action in configuration request: " + action;
|
180
|
logMetacat.error(errorMessage);
|
181
|
processingErrors.add(errorMessage);
|
182
|
}
|
183
|
} catch (PropertyNotFoundException pnfe) {
|
184
|
String errorMessage =
|
185
|
"Property problem while handling request: " + pnfe.getMessage();
|
186
|
logMetacat.error(errorMessage);
|
187
|
processingErrors.add(errorMessage);
|
188
|
} catch (AdminException ae) {
|
189
|
String errorMessage =
|
190
|
"Admin problem while handling request: " + ae.getMessage();
|
191
|
logMetacat.error(errorMessage);
|
192
|
processingErrors.add(errorMessage);
|
193
|
} catch (UtilException ue) {
|
194
|
String errorMessage =
|
195
|
"Utility problem while handling request: " + ue.getMessage();
|
196
|
logMetacat.error(errorMessage);
|
197
|
processingErrors.add(errorMessage);
|
198
|
}
|
199
|
|
200
|
if (processingErrors.size() > 0) {
|
201
|
RequestUtil.clearRequestMessages(request);
|
202
|
RequestUtil.setRequestErrors(request,processingErrors);
|
203
|
RequestUtil.forwardRequest(request, response, "/admin/metacat-configuration.jsp");
|
204
|
}
|
205
|
}
|
206
|
}
|