1 | package org.greenstone.gsdl3.core;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.io.IOException;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Arrays;
|
---|
7 | import java.util.HashMap;
|
---|
8 | import java.util.Hashtable;
|
---|
9 | import java.util.Map;
|
---|
10 |
|
---|
11 | import javax.servlet.Filter;
|
---|
12 | import javax.servlet.FilterChain;
|
---|
13 | import javax.servlet.FilterConfig;
|
---|
14 | import javax.servlet.ServletContext;
|
---|
15 | import javax.servlet.ServletException;
|
---|
16 | import javax.servlet.ServletOutputStream;
|
---|
17 | import javax.servlet.ServletRequest;
|
---|
18 | import javax.servlet.ServletResponse;
|
---|
19 | import javax.servlet.http.HttpSession;
|
---|
20 | import javax.servlet.http.HttpServletRequest;
|
---|
21 | import javax.servlet.http.HttpServletRequestWrapper;
|
---|
22 | import javax.servlet.http.HttpServletResponse;
|
---|
23 |
|
---|
24 | import java.awt.event.ActionEvent;
|
---|
25 | import java.awt.event.ActionListener;
|
---|
26 | import javax.swing.Timer;
|
---|
27 |
|
---|
28 | import org.apache.commons.io.FileUtils;
|
---|
29 | import org.apache.commons.lang3.StringUtils;
|
---|
30 |
|
---|
31 | import org.apache.log4j.Logger;
|
---|
32 | import org.greenstone.gsdl3.util.GSParams;
|
---|
33 | import org.greenstone.gsdl3.util.GSPath;
|
---|
34 | import org.greenstone.gsdl3.util.GSXML;
|
---|
35 | import org.greenstone.gsdl3.util.UserContext;
|
---|
36 | import org.greenstone.gsdl3.util.XMLConverter;
|
---|
37 | import org.greenstone.gsdl3.service.Authentication;
|
---|
38 | import org.w3c.dom.Document;
|
---|
39 | import org.w3c.dom.Element;
|
---|
40 | import org.w3c.dom.NodeList;
|
---|
41 |
|
---|
42 | public class URLFilter implements Filter
|
---|
43 | {
|
---|
44 | private FilterConfig _filterConfig = null;
|
---|
45 | private static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.URLFilter.class.getName());
|
---|
46 |
|
---|
47 | //Restricted URLs
|
---|
48 | protected static final String SITECONFIG_URL = "sites/[^/]+/siteConfig.xml";
|
---|
49 | protected static final String USERS_DB_URL = "etc/usersDB/.*";
|
---|
50 | protected static final ArrayList<String> _restrictedURLs;
|
---|
51 | static
|
---|
52 | {
|
---|
53 | ArrayList<String> restrictedURLs = new ArrayList<String>();
|
---|
54 | restrictedURLs.add(SITECONFIG_URL);
|
---|
55 | restrictedURLs.add(USERS_DB_URL);
|
---|
56 | _restrictedURLs = restrictedURLs;
|
---|
57 | }
|
---|
58 |
|
---|
59 | //Constants
|
---|
60 | protected static final String DOCUMENT_PATH = "document";
|
---|
61 | protected static final String COLLECTION_PATH = "collection";
|
---|
62 | protected static final String GROUP_PATH = "group";
|
---|
63 | protected static final String PAGE_PATH = "page";
|
---|
64 | protected static final String SYSTEM_PATH = "system";
|
---|
65 | protected static final String BROWSE_PATH = "browse";
|
---|
66 | protected static final String SEARCH_PATH = "search";
|
---|
67 |
|
---|
68 | protected static final String METADATA_RETRIEVAL_SERVICE = "DocumentMetadataRetrieve";
|
---|
69 | protected static final String ASSOCIATED_FILE_PATH = "/index/assoc/";
|
---|
70 | protected static final String COLLECTION_FILE_PATH = "/collect/";
|
---|
71 | protected static final String INTERFACE_PATH = "/interfaces/";
|
---|
72 | protected static final String SITES_PATH = "/sites/";
|
---|
73 |
|
---|
74 | protected static final String SYSTEM_SUBACTION_CONFIGURE = "configure";
|
---|
75 | protected static final String SYSTEM_SUBACTION_RECONFIGURE = "reconfigure";
|
---|
76 | protected static final String SYSTEM_SUBACTION_ACTIVATE = "activate";
|
---|
77 | protected static final String SYSTEM_SUBACTION_DEACTIVATE = "deactivate";
|
---|
78 |
|
---|
79 | // if we are showing terms and conditions to user, this remembers who has accepted already
|
---|
80 | protected Hashtable<String, UserTimer> verifiedUserMap = null;
|
---|
81 | protected static final int verifiedUserTimeout = 24 * 60 * 60 * 1000;
|
---|
82 |
|
---|
83 | public void init(FilterConfig filterConfig) throws ServletException
|
---|
84 | {
|
---|
85 | this._filterConfig = filterConfig;
|
---|
86 | }
|
---|
87 |
|
---|
88 | public void destroy()
|
---|
89 | {
|
---|
90 | this._filterConfig = null;
|
---|
91 | }
|
---|
92 |
|
---|
93 | @SuppressWarnings("deprecation")
|
---|
94 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
|
---|
95 | {
|
---|
96 | if (!(request instanceof HttpServletRequest)) {
|
---|
97 | // Can this ever happen?
|
---|
98 | logger.error("The request was not an HttpServletRequest");
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | HttpServletRequest hRequest = ((HttpServletRequest) request);
|
---|
104 | HttpSession hSession = hRequest.getSession();
|
---|
105 | String session_id = hSession.getId();
|
---|
106 | ServletContext context = hSession.getServletContext();
|
---|
107 |
|
---|
108 | GSHttpServletRequestWrapper gRequest = new GSHttpServletRequestWrapper(hRequest);
|
---|
109 |
|
---|
110 | // this is the part before the ?
|
---|
111 | String url = hRequest.getRequestURI().toString();
|
---|
112 | if (isURLRestricted(url)) {
|
---|
113 |
|
---|
114 | // TODO - should we make this a proper HTML page?
|
---|
115 | response.getWriter().println("ERROR: Access to this page is forbidden.");
|
---|
116 | return;
|
---|
117 | }
|
---|
118 | logger.error("in do Filter: "+url);
|
---|
119 |
|
---|
120 | // Run security checks on files requested from a collection's index/assoc folder
|
---|
121 | if (url.contains(ASSOCIATED_FILE_PATH)) {
|
---|
122 |
|
---|
123 | // now we need to get library name from the path, which is like
|
---|
124 | // /greenstone3/library/sites/localsite/collect/collname/index/assoc/...
|
---|
125 | String library_name = url.replaceFirst(context.getContextPath(), "");
|
---|
126 | library_name = library_name.substring(0, library_name.indexOf(SITES_PATH));
|
---|
127 | if (library_name.equals("")) {
|
---|
128 | response.getWriter().println("ERROR: Assoc file paths must now contain the library name");
|
---|
129 | return;
|
---|
130 | }
|
---|
131 | // remove initial '/'
|
---|
132 | library_name = library_name.substring(1);
|
---|
133 |
|
---|
134 | MessageRouter gsRouter = (MessageRouter) context.getAttribute(library_name+"Router");
|
---|
135 |
|
---|
136 | if (gsRouter == null) {
|
---|
137 | logger.error("Receptionist is null, stopping filter");
|
---|
138 | return;
|
---|
139 | }
|
---|
140 | // Sometimes we have a // before the filename - that mucks up the following code, so lets remove them
|
---|
141 | url = url.replaceAll("//","/");
|
---|
142 |
|
---|
143 | String dir = null;
|
---|
144 | int dirStart = url.indexOf(ASSOCIATED_FILE_PATH) + ASSOCIATED_FILE_PATH.length();
|
---|
145 | int dirEnd = -1;
|
---|
146 | if (dirStart < url.length() && url.indexOf("/", dirStart) != -1)
|
---|
147 | {
|
---|
148 | dirEnd = url.lastIndexOf("/");
|
---|
149 | }
|
---|
150 | if (dirEnd != -1)
|
---|
151 | {
|
---|
152 | dir = url.substring(dirStart, dirEnd);
|
---|
153 | }
|
---|
154 | if (dir == null)
|
---|
155 | {
|
---|
156 | return;
|
---|
157 | }
|
---|
158 |
|
---|
159 | String collection = null;
|
---|
160 | int colStart = url.indexOf(COLLECTION_FILE_PATH) + COLLECTION_FILE_PATH.length();
|
---|
161 | int colEnd = -1;
|
---|
162 | if (colStart < url.length() && url.indexOf("/", colStart) != -1)
|
---|
163 | {
|
---|
164 | colEnd = url.indexOf("/", colStart);
|
---|
165 | }
|
---|
166 | if (colEnd != -1)
|
---|
167 | {
|
---|
168 | collection = url.substring(colStart, colEnd);
|
---|
169 | }
|
---|
170 | if (collection == null)
|
---|
171 | {
|
---|
172 | return;
|
---|
173 | }
|
---|
174 |
|
---|
175 | String file_name = url.substring(url.lastIndexOf("/")+1);
|
---|
176 |
|
---|
177 |
|
---|
178 |
|
---|
179 | // Query the MR with a request for the contains metadata for node "dir" - where dir is the assocfilepath
|
---|
180 | // In the jdbm db, have entries like
|
---|
181 | // [HASH1552e]
|
---|
182 | // <contains>HASH1552e3sdlkjf7sdfsdfk
|
---|
183 | // mapping assocfilepath to doc id
|
---|
184 | String document = queryMRforDOCID(gsRouter, collection, dir);
|
---|
185 | if (document == null) {
|
---|
186 | response.getWriter().println("ERROR: Couldn't find the document associated with assocfilepath: "+dir);
|
---|
187 | return;
|
---|
188 | }
|
---|
189 |
|
---|
190 | //Query the MR for the security info for this document - can we show it? Or do we need to be logged in?
|
---|
191 | // Or do we need to throw up the verify page?
|
---|
192 |
|
---|
193 | // While we are doing this, query the document for its srclinkFile metadata - then we can determine if the
|
---|
194 | // file we are being asked for is the main doc (eg pdf) or just a supporting image on the page
|
---|
195 |
|
---|
196 | //Get the security info for this collection
|
---|
197 | Document gsDoc = XMLConverter.newDOM();
|
---|
198 | Element securityMessage = gsDoc.createElement(GSXML.MESSAGE_ELEM);
|
---|
199 | Element securityRequest = GSXML.createBasicRequest(gsDoc, GSXML.REQUEST_TYPE_SECURITY, collection, new UserContext());
|
---|
200 |
|
---|
201 | securityMessage.appendChild(securityRequest);
|
---|
202 | securityRequest.setAttribute(GSXML.NODE_OID, document);
|
---|
203 |
|
---|
204 | // get the srclinkFile for the document
|
---|
205 | Element metadata_request = GSXML.createBasicRequest(gsDoc, GSXML.REQUEST_TYPE_PROCESS, GSPath.appendLink(collection, "DocumentMetadataRetrieve"), new UserContext());
|
---|
206 | Element param_list = gsDoc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
207 | GSXML.addParameterToList(param_list, "metadata", "srclinkFile");
|
---|
208 | metadata_request.appendChild(param_list);
|
---|
209 | Element doc_list = gsDoc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
210 | metadata_request.appendChild(doc_list);
|
---|
211 | Element d = gsDoc.createElement(GSXML.DOC_NODE_ELEM);
|
---|
212 | d.setAttribute(GSXML.NODE_ID_ATT, document);
|
---|
213 | doc_list.appendChild(d);
|
---|
214 | securityMessage.appendChild(metadata_request);
|
---|
215 |
|
---|
216 |
|
---|
217 | Element mr_response = (Element)gsRouter.process(securityMessage);
|
---|
218 | logger.debug("security response = "+XMLConverter.getPrettyString(mr_response));
|
---|
219 |
|
---|
220 | boolean verifiable_file = true;
|
---|
221 | // TODO check for errors
|
---|
222 |
|
---|
223 | Element meta_response = (Element) GSXML.getNamedElement(mr_response, GSXML.RESPONSE_ELEM, GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
|
---|
224 | Element metadata_list = (Element)meta_response.getElementsByTagName(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER).item(0);
|
---|
225 | String srcdoc = GSXML.getMetadataValue(metadata_list, "srclinkFile");
|
---|
226 | if (!srcdoc.equals(file_name)) {
|
---|
227 | // the specified file is just a supporting file, not the main file.
|
---|
228 | // eg an image in an html doc.
|
---|
229 | verifiable_file = false;
|
---|
230 | }
|
---|
231 |
|
---|
232 | Element securityResponse = (Element) GSXML.getNamedElement(mr_response, GSXML.RESPONSE_ELEM, GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_SECURITY);
|
---|
233 | ArrayList<String> groups = GSXML.getGroupsFromSecurityResponse(securityResponse);
|
---|
234 |
|
---|
235 | if (!groups.contains(""))
|
---|
236 | {
|
---|
237 | boolean found = false;
|
---|
238 | for (String group : groups)
|
---|
239 | {
|
---|
240 | if (((HttpServletRequest) request).isUserInRole(group))
|
---|
241 | {
|
---|
242 | found = true;
|
---|
243 | break;
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | if (!found)
|
---|
248 | {
|
---|
249 | // return an error page to the browser
|
---|
250 | String new_url = context.getContextPath()+"/"+ library_name+"?a=p&sa=error&c="+collection+"&ec=wrong_group";
|
---|
251 | ((HttpServletResponse)response).sendRedirect(new_url);
|
---|
252 | return;
|
---|
253 | }
|
---|
254 | }
|
---|
255 | // if got here have no groups that we need to belong to
|
---|
256 | // do we have human verify thing?
|
---|
257 | if (verifiable_file) {
|
---|
258 | // we are asking for the main document - lets check human verify
|
---|
259 | logger.error("KATH verifiable file is true");
|
---|
260 | if (!securityResponse.getAttribute(GSXML.VERIFY_ATT).equals("")) {
|
---|
261 | // have we done the test previously?
|
---|
262 | boolean already_verified = false;
|
---|
263 | if (verifiedUserMap == null) {
|
---|
264 | // we haven't done this at all, set up the map
|
---|
265 | verifiedUserMap = new Hashtable<String, UserTimer>();
|
---|
266 | logger.error("KATH setting up new user map");
|
---|
267 | } else {
|
---|
268 | // check this map
|
---|
269 | if (verifiedUserMap.containsKey(session_id)) {
|
---|
270 | already_verified = true;
|
---|
271 | }
|
---|
272 | }
|
---|
273 | logger.error("KATH already verified = "+already_verified);
|
---|
274 |
|
---|
275 | if (!already_verified) {
|
---|
276 | // have we just done the test?
|
---|
277 | String hmvf_response = gRequest.getParameter(GSParams.VERIFIED);
|
---|
278 | // hmvf param will be set by form if the verify page was submitted
|
---|
279 | if (hmvf_response != null && hmvf_response.equals("1")) {
|
---|
280 | logger.error("user has submitted the form, check recaptcha response");
|
---|
281 | if (!securityResponse.getAttribute(GSXML.SITE_KEY_ATT).equals("")) {
|
---|
282 | String recaptcha_response = gRequest.getParameter(Authentication.RECAPTCHA_RESPONSE_PARAM);
|
---|
283 | String secret_key = securityResponse.getAttribute(GSXML.SECRET_KEY_ATT);
|
---|
284 | int result = Authentication.verifyRecaptcha(secret_key, recaptcha_response);
|
---|
285 | logger.error("recaptcha result code = "+result);
|
---|
286 | if (result == Authentication.NO_ERROR) {
|
---|
287 | logger.error("RECAPTCHA SUCCESS, hopefully going to the document");
|
---|
288 |
|
---|
289 |
|
---|
290 | } else {
|
---|
291 | logger.error("something went wrong with recaptcha, error="+result);
|
---|
292 | logger.error(Authentication.getErrorKey(result));
|
---|
293 | // display error page
|
---|
294 | String new_url = context.getContextPath()+"/"+ library_name+"?a=p&sa=error&c="+collection+"&ec=recap_fail";
|
---|
295 | ((HttpServletResponse)response).sendRedirect(new_url);
|
---|
296 |
|
---|
297 | return;
|
---|
298 | }
|
---|
299 |
|
---|
300 | // store the fact that user has verified
|
---|
301 | UserTimer timer = new UserTimer(verifiedUserTimeout, session_id);
|
---|
302 | verifiedUserMap.put(session_id, timer);
|
---|
303 | timer.start();
|
---|
304 |
|
---|
305 | }
|
---|
306 |
|
---|
307 | } else {
|
---|
308 | // hmvf param is not set - we haven't shown them the form yet
|
---|
309 | // we need to display the verify page
|
---|
310 | logger.error("KATH display verify page");
|
---|
311 | //String new_url = context.getContextPath()+"/"+ context.getAttribute("LibraryName")+"?a=p&sa=verify&c="+collection+"&url="+url;
|
---|
312 | String new_url = context.getContextPath()+"/"+ library_name+"?a=p&sa=verify&c="+collection+"&url="+url;
|
---|
313 | ((HttpServletResponse)response).sendRedirect(new_url);
|
---|
314 | return;
|
---|
315 | }
|
---|
316 | }
|
---|
317 | } // end if we are asked to verify it
|
---|
318 | } // end if verifiable file
|
---|
319 |
|
---|
320 |
|
---|
321 | // if we got here, we have passed all security checks and just want to view the file.
|
---|
322 | // However, we need to remove the library_name from the URL. As can't change the
|
---|
323 | // existing URL, we need to forward to the new one.
|
---|
324 | // (Can't do redirect as it will come back into this code and fail as there won't be library in the url)
|
---|
325 | // Remove the context and library name parts.
|
---|
326 | // don't know what happens with the rest of the filter chain? Does this bypass that??
|
---|
327 | url = url.replaceFirst(context.getContextPath(), "");
|
---|
328 | url = url.replaceFirst("/"+library_name, "");
|
---|
329 | request.getRequestDispatcher(url).forward(request, response);
|
---|
330 |
|
---|
331 | return;
|
---|
332 | }
|
---|
333 | else if (url.contains(INTERFACE_PATH))
|
---|
334 | {
|
---|
335 | String fileURL = url.replaceFirst(context.getContextPath(), "");
|
---|
336 | File requestedFile = new File(context.getRealPath(fileURL));
|
---|
337 |
|
---|
338 | if (!requestedFile.exists())
|
---|
339 | {
|
---|
340 | int interfaceNameStart = fileURL.indexOf(INTERFACE_PATH) + INTERFACE_PATH.length();
|
---|
341 | int interfaceNameEnd = fileURL.indexOf("/", interfaceNameStart);
|
---|
342 | String interfaceName = fileURL.substring(interfaceNameStart, interfaceNameEnd);
|
---|
343 | String interfacesDir = fileURL.substring(0, interfaceNameStart);
|
---|
344 | File interfaceConfigFile = new File(context.getRealPath(interfacesDir + interfaceName + "/interfaceConfig.xml"));
|
---|
345 |
|
---|
346 | if (interfaceConfigFile.exists())
|
---|
347 | {
|
---|
348 | Document interfaceConfigDoc = XMLConverter.getDOM(interfaceConfigFile);
|
---|
349 |
|
---|
350 | String baseInterface = interfaceConfigDoc.getDocumentElement().getAttribute("baseInterface");
|
---|
351 | if (baseInterface.length() > 0)
|
---|
352 | {
|
---|
353 | File baseInterfaceFile = new File(context.getRealPath(fileURL.replace("/" + interfaceName + "/", "/" + baseInterface + "/")));
|
---|
354 | if (baseInterfaceFile.exists())
|
---|
355 | {
|
---|
356 | ServletOutputStream out = response.getOutputStream();
|
---|
357 | out.write(FileUtils.readFileToByteArray(baseInterfaceFile));
|
---|
358 | out.flush();
|
---|
359 | out.close();
|
---|
360 | return;
|
---|
361 | }
|
---|
362 | }
|
---|
363 | }
|
---|
364 | }
|
---|
365 | }
|
---|
366 | else
|
---|
367 | {
|
---|
368 | ArrayList<String> keywords = new ArrayList<String>();
|
---|
369 | keywords.add(PAGE_PATH);
|
---|
370 | keywords.add(BROWSE_PATH);
|
---|
371 | keywords.add(SEARCH_PATH);
|
---|
372 | keywords.add(DOCUMENT_PATH);
|
---|
373 | //If we have a jsessionid on the end of our URL we want to ignore it
|
---|
374 | int index;
|
---|
375 | if ((index = url.indexOf(";jsessionid")) != -1)
|
---|
376 | {
|
---|
377 | url = url.substring(0, index);
|
---|
378 | }
|
---|
379 | String[] segments = url.split("/");
|
---|
380 | for (int i = 0; i < segments.length; i++)
|
---|
381 | {
|
---|
382 | String[] additionalParameters = null;
|
---|
383 | String[] defaultParamValues = null;
|
---|
384 | //COLLECTION
|
---|
385 | if (segments[i].equals(COLLECTION_PATH) && (i + 1) < segments.length) {
|
---|
386 | int j=i+1;
|
---|
387 | while(j+1 < segments.length && !keywords.contains(segments[j+1])) {
|
---|
388 | j++;
|
---|
389 | }
|
---|
390 |
|
---|
391 | if (j>i+1) {
|
---|
392 | // we had a group part
|
---|
393 | String [] groups = Arrays.copyOfRange(segments, i+1, j);
|
---|
394 | String group = StringUtils.join(groups, "/");
|
---|
395 | gRequest.setParameter(GSParams.GROUP, group);
|
---|
396 | }
|
---|
397 | gRequest.setParameter(GSParams.COLLECTION, segments[j]);
|
---|
398 | }
|
---|
399 | // GROUP
|
---|
400 | else if(segments[i].equals(GROUP_PATH) && (i + 1) < segments.length)
|
---|
401 | {
|
---|
402 | // assume for now, no other path parts for group links
|
---|
403 | int j= segments.length - 1;
|
---|
404 | String group;
|
---|
405 | if (j==i+1) {
|
---|
406 | group = segments[j];
|
---|
407 | } else {
|
---|
408 | String [] groups = Arrays.copyOfRange(segments, i+1, j+1);
|
---|
409 | group = StringUtils.join(groups, "/");
|
---|
410 | }
|
---|
411 | gRequest.setParameter(GSParams.GROUP, group);
|
---|
412 | gRequest.setParameter(GSParams.ACTION, "p");
|
---|
413 | gRequest.setParameter(GSParams.SUBACTION, "home");
|
---|
414 |
|
---|
415 | }
|
---|
416 | //DOCUMENT
|
---|
417 | else if (segments[i].equals(DOCUMENT_PATH) && (i + 1) < segments.length)
|
---|
418 | {
|
---|
419 | gRequest.setParameter(GSParams.DOCUMENT, segments[i + 1]);
|
---|
420 |
|
---|
421 | additionalParameters = new String[] { GSParams.ACTION };
|
---|
422 | defaultParamValues = new String[] { "d" };
|
---|
423 | if ((i+2) < segments.length && segments[i+2].equals("print")) {
|
---|
424 | gRequest.setParameter(GSParams.SUBACTION, "print");
|
---|
425 | gRequest.setParameter("ed", "1");
|
---|
426 |
|
---|
427 | }
|
---|
428 |
|
---|
429 | }
|
---|
430 | //PAGE
|
---|
431 | else if (segments[i].equals(PAGE_PATH) && (i + 1) < segments.length)
|
---|
432 | {
|
---|
433 | gRequest.setParameter(GSParams.SUBACTION, segments[i + 1]);
|
---|
434 |
|
---|
435 | additionalParameters = new String[] { GSParams.ACTION };
|
---|
436 | defaultParamValues = new String[] { "p" };
|
---|
437 | }
|
---|
438 | //SYSTEM
|
---|
439 | else if (segments[i].equals(SYSTEM_PATH) && (i + 1) < segments.length)
|
---|
440 | {
|
---|
441 | String sa = segments[i + 1];
|
---|
442 | if (sa.equals(SYSTEM_SUBACTION_CONFIGURE) || sa.equals(SYSTEM_SUBACTION_RECONFIGURE))
|
---|
443 | {
|
---|
444 | sa = "c";
|
---|
445 | }
|
---|
446 | else if (sa.equals(SYSTEM_SUBACTION_ACTIVATE))
|
---|
447 | {
|
---|
448 | sa = "a";
|
---|
449 | }
|
---|
450 | else if (sa.equals(SYSTEM_SUBACTION_DEACTIVATE))
|
---|
451 | {
|
---|
452 | sa = "d";
|
---|
453 | }
|
---|
454 |
|
---|
455 | if (sa.equals("c") && (i + 2) < segments.length)
|
---|
456 | {
|
---|
457 | gRequest.setParameter(GSParams.SYSTEM_CLUSTER, segments[i + 2]);
|
---|
458 | }
|
---|
459 |
|
---|
460 | if (sa.equals("a") && (i + 2) < segments.length)
|
---|
461 | {
|
---|
462 | gRequest.setParameter(GSParams.SYSTEM_MODULE_TYPE, "collection");
|
---|
463 | gRequest.setParameter(GSParams.SYSTEM_MODULE_NAME, segments[i + 2]);
|
---|
464 | }
|
---|
465 |
|
---|
466 | if (sa.equals("d") && (i + 2) < segments.length)
|
---|
467 | {
|
---|
468 | gRequest.setParameter(GSParams.SYSTEM_CLUSTER, segments[i + 2]);
|
---|
469 | }
|
---|
470 |
|
---|
471 | gRequest.setParameter(GSParams.SUBACTION, sa);
|
---|
472 |
|
---|
473 | additionalParameters = new String[] { GSParams.ACTION };
|
---|
474 | defaultParamValues = new String[] { "s" };
|
---|
475 | }
|
---|
476 | //ADMIN
|
---|
477 | else if (segments[i].equals("admin") && (i + 1) < segments.length)
|
---|
478 | {
|
---|
479 | String pageName = segments[i + 1];
|
---|
480 |
|
---|
481 | gRequest.setParameter("s1.authpage", pageName);
|
---|
482 |
|
---|
483 | additionalParameters = new String[] { GSParams.ACTION, GSParams.REQUEST_TYPE, GSParams.SUBACTION, GSParams.SERVICE };
|
---|
484 | defaultParamValues = new String[] { "g", "r", "authen", "Authentication" };
|
---|
485 | }
|
---|
486 | //BROWSE
|
---|
487 | else if (segments[i].equals(BROWSE_PATH) && (i + 1) < segments.length)
|
---|
488 | {
|
---|
489 | String cl = "";
|
---|
490 | for (int j = 1; (i + j) < segments.length; j++)
|
---|
491 | {
|
---|
492 | String currentSegment = segments[i + j].replace("CL", "").replace("cl", "");
|
---|
493 | if (currentSegment.contains("."))
|
---|
494 | {
|
---|
495 | String[] subsegments = currentSegment.split("\\.");
|
---|
496 | for (String subsegment : subsegments)
|
---|
497 | {
|
---|
498 | subsegment = subsegment.replace("CL", "").replace("cl", "");
|
---|
499 |
|
---|
500 | if (cl.length() > 0)
|
---|
501 | {
|
---|
502 | cl += ".";
|
---|
503 | }
|
---|
504 |
|
---|
505 | if (subsegment.length() > 0)
|
---|
506 | {
|
---|
507 | cl += subsegment;
|
---|
508 | }
|
---|
509 | }
|
---|
510 | continue;
|
---|
511 | }
|
---|
512 | if (!currentSegment.matches("^(CL|cl)?\\d+$"))
|
---|
513 | {
|
---|
514 | continue;
|
---|
515 | }
|
---|
516 |
|
---|
517 | if (cl.length() > 0)
|
---|
518 | {
|
---|
519 | cl += ".";
|
---|
520 | }
|
---|
521 |
|
---|
522 | cl += currentSegment;
|
---|
523 | }
|
---|
524 |
|
---|
525 | gRequest.setParameter("cl", "CL" + cl);
|
---|
526 |
|
---|
527 | additionalParameters = new String[] { GSParams.ACTION, GSParams.REQUEST_TYPE, GSParams.SERVICE };
|
---|
528 | defaultParamValues = new String[] { "b", "s", "ClassifierBrowse" };
|
---|
529 | }
|
---|
530 | //QUERY
|
---|
531 | else if (segments[i].equals(SEARCH_PATH))
|
---|
532 | {
|
---|
533 | String serviceName = "";
|
---|
534 | if ((i + 1) < segments.length)
|
---|
535 | {
|
---|
536 | serviceName = segments[i + 1];
|
---|
537 | gRequest.setParameter("s", serviceName);
|
---|
538 |
|
---|
539 | additionalParameters = new String[] { GSParams.ACTION, GSParams.SUBACTION, GSParams.REQUEST_TYPE };
|
---|
540 | defaultParamValues = new String[] { "q", "", "d" };
|
---|
541 | }
|
---|
542 | if ((i + 2) < segments.length)
|
---|
543 | {
|
---|
544 | if (serviceName.equals("TextQuery") || serviceName.equals("RawQuery"))
|
---|
545 | {
|
---|
546 |
|
---|
547 | gRequest.setParameter("s1.query", segments[i + 2]);
|
---|
548 | }
|
---|
549 | else if (serviceName.equals("FieldQuery"))
|
---|
550 | {
|
---|
551 | gRequest.setParameter("s1.fqv", segments[i + 2]);
|
---|
552 | }
|
---|
553 | else if (serviceName.equals("AdvancedFieldQuery"))
|
---|
554 | {
|
---|
555 | gRequest.setParameter("s1.fqv", segments[i + 2]);
|
---|
556 | }
|
---|
557 | }
|
---|
558 | }
|
---|
559 | if (additionalParameters != null)
|
---|
560 | {
|
---|
561 | for (int j = 0; j < additionalParameters.length; j++)
|
---|
562 | {
|
---|
563 | if (gRequest.getParameter(additionalParameters[j]) == null)
|
---|
564 | {
|
---|
565 | gRequest.setParameter(additionalParameters[j], defaultParamValues[j]);
|
---|
566 | }
|
---|
567 | }
|
---|
568 | }
|
---|
569 | }
|
---|
570 | }
|
---|
571 |
|
---|
572 | chain.doFilter(gRequest, response);
|
---|
573 | }
|
---|
574 |
|
---|
575 | private boolean isURLRestricted(String url)
|
---|
576 | {
|
---|
577 | for (String restrictedURL : _restrictedURLs)
|
---|
578 | {
|
---|
579 | if (url.matches(".*" + restrictedURL + ".*"))
|
---|
580 | {
|
---|
581 | return true;
|
---|
582 | }
|
---|
583 | }
|
---|
584 |
|
---|
585 | return false;
|
---|
586 | }
|
---|
587 |
|
---|
588 | private String queryMRforDOCID(MessageRouter gsRouter, String collection, String assocfiledir) {
|
---|
589 | Document gsDoc = XMLConverter.newDOM();
|
---|
590 |
|
---|
591 | Element metaMessage = gsDoc.createElement(GSXML.MESSAGE_ELEM);
|
---|
592 | Element metaRequest = GSXML.createBasicRequest(gsDoc, GSXML.REQUEST_TYPE_PROCESS, collection + "/" + METADATA_RETRIEVAL_SERVICE, new UserContext());
|
---|
593 | metaMessage.appendChild(metaRequest);
|
---|
594 |
|
---|
595 | Element paramList = gsDoc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
596 | metaRequest.appendChild(paramList);
|
---|
597 |
|
---|
598 | Element param = gsDoc.createElement(GSXML.PARAM_ELEM);
|
---|
599 | param.setAttribute(GSXML.NAME_ATT, "metadata");
|
---|
600 | param.setAttribute(GSXML.VALUE_ATT, "contains");
|
---|
601 | paramList.appendChild(param);
|
---|
602 |
|
---|
603 | Element docList = gsDoc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
604 | metaRequest.appendChild(docList);
|
---|
605 |
|
---|
606 | Element doc = gsDoc.createElement(GSXML.DOC_NODE_ELEM);
|
---|
607 | doc.setAttribute(GSXML.NODE_ID_ATT, assocfiledir);
|
---|
608 | docList.appendChild(doc);
|
---|
609 |
|
---|
610 | Element metaResponse = (Element) gsRouter.process(metaMessage);
|
---|
611 |
|
---|
612 | NodeList metadataList = metaResponse.getElementsByTagName(GSXML.METADATA_ELEM);
|
---|
613 | if (metadataList.getLength() == 0) {
|
---|
614 |
|
---|
615 | logger.error("Could not find the document related to this url");
|
---|
616 | return null;
|
---|
617 | }
|
---|
618 |
|
---|
619 | Element metadata = (Element) metadataList.item(0);
|
---|
620 | String document = metadata.getTextContent();
|
---|
621 | if (document != null && document.equals("")) {
|
---|
622 | document = null;
|
---|
623 | }
|
---|
624 | return document;
|
---|
625 |
|
---|
626 |
|
---|
627 | }
|
---|
628 |
|
---|
629 | private class UserTimer extends Timer implements ActionListener
|
---|
630 | {
|
---|
631 | String id = "";
|
---|
632 |
|
---|
633 | public UserTimer(int delay, String id)
|
---|
634 | {
|
---|
635 | super(delay, (ActionListener) null);
|
---|
636 | addActionListener(this);
|
---|
637 | this.id = id;
|
---|
638 | }
|
---|
639 |
|
---|
640 | public void actionPerformed(ActionEvent e)
|
---|
641 | {
|
---|
642 | verifiedUserMap.remove(id);
|
---|
643 | stop();
|
---|
644 | }
|
---|
645 |
|
---|
646 | }
|
---|
647 |
|
---|
648 |
|
---|
649 | }
|
---|