Project

General

Profile

« Previous | Next » 

Revision 5057

Added by daigle over 15 years ago

Add session validation to metacat tpc and workflow scheduler. Fix sanparks skin session management so it always uses the logged in session id.

View differences:

lib/workflowscheduler/workflowscheduler.properties
151 151
######## Workflow engine section              #########################################
152 152
executionEngine.endPointAddress=http://localhost:8080/axis2/services/KeplerWebService
153 153

  
154
workflowScheduler.authServiceUrl=http://indus.msi.ucsb.edu/knb/services/AuthenticationService
155

  
154 156
######## junit test section  ################
155 157

  
156 158
test.printdebug=true
lib/style/skins/sanparks/SaeonLogin.jspx
76 76
			clientViewHelper = ClientViewHelper.clientViewHelperInstance(request);
77 77
			clientViewHelper.clientRequest(request, response);
78 78
        </jsp:scriptlet>
79
		<script type="text/javascript" >		
80
				setCookie('JSESSIONID','<jsp:getProperty name="clientViewBean" property="sessionid" />','<jsp:expression>request.getContextPath()</jsp:expression>');
81
		</script>
79 82

  
80 83
	<table>
81 84
	<tr>
lib/style/skins/sanparks/sanparks.js
226 226
function trim(stringToTrim) {
227 227
  return stringToTrim.replace(/^\s*/, '').replace(/\s*$/,'');
228 228
}
229

  
230
function setCookie(cookieName, sessionId, context) {
231
	if (sessionId != "null") {
232
		document.cookie = cookieName + "=" + sessionId + ";path=" + context;
233
	}	
234
}
workflowscheduler.build.xml
60 60
			</fileset>
61 61
			<fileset dir="lib/lsid_lib">
62 62
				<include name="commons-logging-1.0.4.jar" />
63
				<include name="commons-discovery.jar" />
64
				<include name="commons-discovery-0.2.jar" />
65
				<include name="wsdl4j-1.5.1.jar" />
66
				<include name="saaj.jar" />
63 67
				<include name="axis.jar" />
64 68
				<include name="jaxrpc.jar" />
65 69
			</fileset>
66 70
			<fileset dir="lib/spatial/geoserver/WEB-INF/lib">
67 71
				<include name="commons-httpclient-2.0.jar" />
68 72
			</fileset>
73
			<fileset dir="../seek/projects/ecogrid/build/lib">
74
				<include name="org.ecoinformatics.ecogrid.AuthenticationService-stub.jar" />
75
			</fileset>
69 76
		</path>
70 77

  
71 78
		<!-- It is less likely you'll need to make any changes from here down,
......
106 113
		<property name="ver.dir.hle"
107 114
			value="${dist.dir.hle}/harvest-list-editor-${release}" />
108 115
		<property name="pkg.dir" value="./package" />
116
		<property name="ecogrid.stublib.dir" value="../seek/projects/ecogrid/build/lib" />
109 117

  
110 118
		<property name="package.home" value="edu/ucsb/nceas/metacat" />
111 119

  
......
303 311
			</fileset>
304 312
			<fileset dir="lib/lsid_lib">
305 313
				<include name="commons-logging-1.0.4.jar" />
314
				<include name="commons-discovery.jar" />
315
				<include name="commons-discovery-0.2.jar" />
316
				<include name="wsdl4j-1.5.1.jar" />
317
				<include name="saaj.jar" />
306 318
				<include name="axis.jar" />
307 319
				<include name="jaxrpc.jar" />
308 320
			</fileset>
309 321
			<fileset dir="lib/spatial/geoserver/WEB-INF/lib">
310 322
				<include name="commons-httpclient-2.0.jar" />
311 323
			</fileset>
324
			<fileset dir="${ecogrid.stublib.dir}">
325
				<include name="org.ecoinformatics.ecogrid.AuthenticationService-stub.jar" />
326
			</fileset>
312 327
		</copy>
313 328

  
314 329
		<!-- MCD added next - Remove the tomcat5 reference-->
src/edu/ucsb/nceas/workflowscheduler/WorkflowScheduler.java
28 28

  
29 29
import java.io.IOException;
30 30
import java.io.PrintWriter;
31
import java.io.StringReader;
31 32
import java.util.Calendar;
32 33
import java.util.Hashtable;
33 34
import java.util.HashMap;
34 35

  
35 36
import javax.servlet.http.HttpServletRequest;
36 37
import javax.servlet.http.HttpServletResponse;
38
import javax.xml.xpath.XPath;
39
import javax.xml.xpath.XPathFactory;
37 40

  
38 41
import org.apache.log4j.Logger;
39 42

  
43
import org.xml.sax.InputSource;
44

  
45
import org.ecoinformatics.ecogrid.client.AuthenticationServiceClient;
46

  
40 47
import edu.ucsb.nceas.metacat.scheduler.BaseScheduler;
41 48
import edu.ucsb.nceas.metacat.scheduler.ScheduledJobAccess;
42 49
import edu.ucsb.nceas.metacat.scheduler.ScheduledJobDAO;
43 50
import edu.ucsb.nceas.metacat.scheduler.SchedulerService;
44 51
import edu.ucsb.nceas.metacat.scheduler.MetacatSchedulerException;
52
import edu.ucsb.nceas.metacat.properties.PropertyService;
45 53
import edu.ucsb.nceas.metacat.shared.AccessException;
46 54
import edu.ucsb.nceas.metacat.shared.ServiceException;
47 55
import edu.ucsb.nceas.metacat.util.ErrorSendingErrorException;
48 56
import edu.ucsb.nceas.metacat.util.ResponseUtil;
49 57
import edu.ucsb.nceas.utilities.DateUtil;
58
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
50 59
import edu.ucsb.nceas.utilities.UtilException;
51 60

  
52 61
/**
......
94 103
	 *            the user's group
95 104
	 */
96 105
	public void scheduleJob(HttpServletRequest request, HttpServletResponse response, 
97
			Hashtable<String, String[]> params, String username,
98
			String[] groups) throws MetacatSchedulerException {
99
		 		
106
			Hashtable<String, String[]> params) throws MetacatSchedulerException {
107
		 
108
		String sessionIds[] = params.get("sessionid");
100 109
		String delays[] = params.get("delay");
101 110
		String startTimes[] = params.get("starttime");
102 111
		String endTimes[] = params.get("endtime");
103 112
		HashMap<String, String> jobParams = new HashMap<String, String>();
104 113
		Calendar startCal = null;
105 114
		Calendar endCal = null;
106

  
115
		
116
		if (sessionIds == null) {
117
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - sessionid field must be populated "
118
							+ "in scheduler parameters when scheduling job.");
119
		}
120
		
121
		String sessionStatus = validateRemoteSession(sessionIds[0]);
122
		logMetacat.debug("WorkflowScheduler.scheduleJob - session status: " + sessionStatus);
123
		
124
		if (!sessionStatus.equals("valid")) {
125
			throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - session " 
126
					+ sessionIds[0] + " is not valid.");
127
		}
128
		
107 129
		try {
108 130
			SchedulerService schedulerService = SchedulerService.getInstance();
109 131

  
......
169 191

  
170 192
			// Schedule the job
171 193
			String xmlResult = schedulerService.scheduleJob(jobName, startCal, endCal, intervalValue, intervalUnit,
172
					WORKFLOW_JOB_CLASS, WORKFLOW_JOB_GROUP, jobParams, username, groups);
194
					WORKFLOW_JOB_CLASS, WORKFLOW_JOB_GROUP, jobParams);
173 195
			
174 196
			ResponseUtil.sendSuccessXML(response, xmlResult);
175 197
			
......
203 225
			Hashtable<String, String[]> params, String username, String[] groups)
204 226
			throws MetacatSchedulerException {
205 227
		try {
228
			String sessionIds[] = params.get("sessionid");
229
			
230
			// interval value must exist
231
			if (sessionIds == null || sessionIds.length == 0) {
232
				throw new MetacatSchedulerException("WorkflowScheduler.unscheduleJob - sessionid field must be populated "
233
								+ "in scheduler parameters when unscheduling job.");
234
			}
235
			
236
			String sessionStatus = validateRemoteSession(sessionIds[0]);
237
			logMetacat.debug("WorkflowScheduler.unscheduleJob - session status: " + sessionStatus);
238
			
239
			if (!sessionStatus.equals("valid")) {
240
				throw new MetacatSchedulerException("WorkflowScheduler.unscheduleJob - session " 
241
						+ sessionIds[0] + " is not valid.");
242
			}
243
			
206 244
			// workflow job id must exist
207 245
			String jobNames[] = params.get("workflowjobname");
208 246
			if (jobNames == null || jobNames.length == 0) {
......
245 283
			String[] groups) throws MetacatSchedulerException {
246 284
		 		
247 285
		try {
286
			String sessionIds[] = params.get("sessionid");
287
			
288
			// interval value must exist
289
			if (sessionIds == null || sessionIds.length == 0) {
290
				throw new MetacatSchedulerException("WorkflowScheduler.rescheduleJob - sessionid field must be populated "
291
								+ "in scheduler parameters when rescheduling job.");
292
			}
293
			
294
			String sessionStatus = validateRemoteSession(sessionIds[0]);
295
			
296
			logMetacat.debug("WorkflowScheduler.rescheduleJob - session status: " + sessionStatus);
297
			
298
			if (!sessionStatus.equals("valid")) {
299
				throw new MetacatSchedulerException("WorkflowScheduler.scheduleJob - session " 
300
						+ sessionIds[0] + " is not valid.");
301
			}
302
			
248 303
			// workflow job id must exist
249 304
			String jobNames[] = params.get("workflowjobname");	
250 305
			if (jobNames == null || jobNames.length == 0) {
251
				throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - workflowjobname field must be populated "
306
				throw new MetacatSchedulerException("WorkflowScheduler.rescheduleJob - workflowjobname field must be populated "
252 307
						+ "in scheduler parameters when rescheduling job.");
253 308
			}			
254 309
			String jobName = jobNames[0];
......
263 318
			ResponseUtil.sendSuccessXML(response, result);
264 319
			
265 320
		} catch (AccessException ae) {
266
			throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - " 
267
					+ "DB access issue when scheduling job  : ", ae);
321
			throw new MetacatSchedulerException("WorkflowScheduler.rescheduleJob - " 
322
					+ "DB access issue when rescheduling job  : ", ae);
268 323
		} catch (ServiceException se) {
269
			throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - " 
270
					+ "Service issue scheduling job", se);
324
			throw new MetacatSchedulerException("WorkflowScheduler.rescheduleJob - " 
325
					+ "Service issue rescheduling job", se);
271 326
		} catch (ErrorSendingErrorException esee) {
272
			throw new MetacatSchedulerException("WorkflowScheduler.reScheduleJob - " 
273
					+ "Issue sending erro when scheduling job: " + esee.getMessage());			
327
			throw new MetacatSchedulerException("WorkflowScheduler.rescheduleJob - " 
328
					+ "Issue sending erro when rescheduling job: " + esee.getMessage());			
274 329
		}
275 330
	}
276 331
	
......
280 335
	public void deleteJob(HttpServletRequest request, HttpServletResponse response, 
281 336
			Hashtable<String, String[]> params, String username, String[] groups) throws MetacatSchedulerException {
282 337
		 try {
338
			String sessionIds[] = params.get("sessionid");
339
				
340
			// interval value must exist
341
			if (sessionIds == null || sessionIds.length == 0) {
342
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - sessionid field must be populated "
343
								+ "in scheduler parameters when deleting job.");
344
			}
345
				
346
			String sessionStatus = validateRemoteSession(sessionIds[0]);
347
			logMetacat.debug("WorkflowScheduler.rescheduleJob - session status: " + sessionStatus);
348
				
349
			if (!sessionStatus.equals("valid")) {
350
				throw new MetacatSchedulerException("WorkflowScheduler.deleteJob - session " 
351
						+ sessionIds[0] + " is not valid.");
352
			}
353
				
283 354
			// workflow job id must exist
284 355
			String jobNames[] = params.get("workflowjobname");
285 356
			if (jobNames == null || jobNames.length == 0) {
......
294 365

  
295 366
			// delete the job
296 367
			SchedulerService schedulerService = SchedulerService.getInstance();
297
			String result = schedulerService.deleteJob(jobDAO, username, groups);
368
			String result = schedulerService.deleteJob(jobDAO);
298 369

  
299 370
			ResponseUtil.sendSuccessXML(response, result);
300 371

  
......
356 427
			}
357 428
		}
358 429
	}
430
	
431
	private String validateRemoteSession(String sessionId) throws MetacatSchedulerException {
432
		String sessionStatus = "unknown";
433
	    XPath xpath = XPathFactory.newInstance().newXPath();
434
		
435
		try {
436
			String ecogridUrl = PropertyService.getProperty("workflowScheduler.authServiceUrl");
437
		
438
			AuthenticationServiceClient authServiceClient = 
439
					new AuthenticationServiceClient(ecogridUrl);
440
			
441
			String sessionStatusXML = authServiceClient.validate_session_action(sessionId);
442
			
443
			sessionStatus = 
444
				xpath.evaluate("/validateSession/status",  new InputSource(new StringReader(sessionStatusXML)));
445
			
446
			
447
		} catch (PropertyNotFoundException pnfe) {
448
			throw new MetacatSchedulerException("WorkflowScheduler.validateSession - Could not " 
449
					+ "find property: " + pnfe.getMessage());
450
		} catch (Exception e) {
451
			throw new MetacatSchedulerException("WorkflowScheduler.validateSession - " 
452
					+ "general error when validating Session: " + e.getMessage());
453
		}
454
		
455
		
456
		return sessionStatus;
457
	}
359 458
}
src/edu/ucsb/nceas/workflowscheduler/WorkflowSchedulerServlet.java
321 321
			if (action.equals("scheduleWorkflow")) {
322 322
				try {
323 323
					WorkflowScheduler.getInstance().scheduleJob(request, response,
324
							params, userName, groupNames);
324
							params);
325 325
					return;
326 326
				} catch (BaseException be) {
327 327
					logMetacat.error("WorkflowSchedulerServlet.handleGetOrPost - error when scheduling" 
src/edu/ucsb/nceas/metacat/service/SessionService.java
186 186
		response.setContentType("text/xml");
187 187
		out.println("<?xml version=\"1.0\"?>");
188 188
		out.write("<validateSession><status>");
189
		if (sessionId != null && isSessionRegistered(sessionId)) {
189
		if (sessionId != null && !sessionId.equals(PUBLIC_SESSION_ID) && isSessionRegistered(sessionId)) {
190 190
			out.write("valid");
191 191
		} else {
192 192
			out.write("invalid");
src/edu/ucsb/nceas/metacat/workflow/WorkflowSchedulerClient.java
94 94

  
95 95
		try {
96 96
			params.put("action", new String[] { "scheduleWorkflow" });
97
			params.put("sessionid", new String[] { RequestUtil.getSessionData(request).getId() });
97 98
			
98 99
			String schedulerUrl = PropertyService.getProperty("workflowScheduler.url");
99 100
			String result = RequestUtil.get(schedulerUrl, params);
......
155 156
			String[] groups) throws MetacatSchedulerException {
156 157
		try {
157 158
			params.put("action", new String[] { "unscheduleWorkflow" });
159
			params.put("sessionid", new String[] { RequestUtil.getSessionData(request).getId() });
158 160
			
159 161
			String schedulerUrl = PropertyService.getProperty("workflowScheduler.url");
160 162
			String result = RequestUtil.get(schedulerUrl, params);
......
217 219
		 		
218 220
		try {
219 221
			params.put("action", new String[] { "rescheduleWorkflow" });
222
			params.put("sessionid", new String[] { RequestUtil.getSessionData(request).getId() });
220 223
			
221 224
			String schedulerUrl = PropertyService.getProperty("workflowScheduler.url");
222 225
			String result = RequestUtil.get(schedulerUrl, params);
......
267 270
			String[] groups) throws MetacatSchedulerException {
268 271
		try {
269 272
			params.put("action", new String[] { "deleteScheduledWorkflow" });
273
			params.put("sessionid", new String[] { RequestUtil.getSessionData(request).getId() });
270 274
			
271 275
			String schedulerUrl = PropertyService.getProperty("workflowScheduler.url");
272 276
			String result = RequestUtil.get(schedulerUrl, params);
......
327 331
			Hashtable<String, String[]> params, String username,
328 332
			String[] groups) throws MetacatSchedulerException {
329 333
		
330
//		StringWriter stringWriter = null;
331 334
		try {	
332 335
			params.put("action", new String[] { "getScheduledWorkflow" });
333 336
			
334 337
			String schedulerUrl = PropertyService.getProperty("workflowScheduler.url");
335 338
			String result = RequestUtil.get(schedulerUrl, params);
336 339
			
337
//			stringWriter = new StringWriter();
338
			
339 340
			String qformats[] = params.get("qformat");			
340 341
			String qformat = null;
341 342
			if (qformats == null || qformats.length == 0) {
src/edu/ucsb/nceas/metacat/client/MetacatClient.java
32 32
import java.io.StringWriter;
33 33
import java.io.Reader;
34 34
import java.net.URL;
35
import java.util.HashMap;
36 35
import java.util.Properties;
37 36
import java.util.Vector;
38 37
import javax.servlet.http.HttpServletRequest;
39
import javax.xml.xpath.XPath;
40
import javax.xml.xpath.XPathFactory;
41
import org.w3c.dom.Document;
42 38

  
43 39
import org.w3c.dom.Node;
44 40
import org.w3c.dom.NodeList;
......
164 160
    }
165 161
    
166 162
    /**
163
     *  Method used to log in to a metacat server. Implementations will need
164
     *  to cache a cookie value to make the session persistent.  Each time a
165
     *  call is made to one of the other methods (e.g., read), the cookie will
166
     *  need to be passed back to the metacat server along with the request.
167
     *
168
     *  @param username   the username of the user, like an LDAP DN
169
     *  @param password   the password for that user for authentication
170
     *  @return the response string from metacat in XML format
171
     *  @throws MetacatAuthException when the username/password could
172
     *                    not be authenticated
173
     */
174
    public String validateSession(String sessionId)
175
    		throws MetacatAuthException, MetacatInaccessibleException {
176
    	
177
        Properties prop = new Properties();
178
        prop.put("action", "validatesession");
179
        prop.put("sessionid", sessionId);
180
        
181
        String response = null;
182
        try {
183
            response = sendDataForString(prop, null, null, 0);
184
        } catch (Exception e) {
185
            throw new MetacatInaccessibleException(e.getMessage());
186
        }
187
        
188
        if (response.indexOf("<validateSession><status>") == -1) {
189
            setSessionId("");
190
            throw new MetacatAuthException(response);
191
        } 
192
        
193
        return response;
194
    }
195
    
196
    /**
167 197
     * Read an XML document from the metacat server session, accessed by docid,
168 198
     * and returned as a Reader.
169 199
     *
src/edu/ucsb/nceas/metacat/scheduler/SchedulerService.java
166 166
        // schedule the job
167 167
		return scheduleJob(jobDAO.getName(), startTimeCal, endTimeCal, jobDAO.getIntervalValue(), 
168 168
				jobDAO.getIntervalUnit(), jobDAO.getClassName(), jobDAO.getGroupName(), 
169
				jobParams, username, groups);
169
				jobParams);
170 170
	}
171 171
	
172 172
	/**
......
195 195
	 * @return a message saying that the job was scheduled
196 196
	 */
197 197
	public String scheduleJob(String jobName, Calendar startCal, Calendar endCal, int intervalValue, 
198
			String intervalUnit, String jobClassName, String jobGroup, HashMap<String, String> jobParams, 
199
			String username, String[] groups) throws ServiceException {
198
			String intervalUnit, String jobClassName, String jobGroup, HashMap<String, String> jobParams) 
199
	throws ServiceException {
200 200
        
201 201
        Class<Job> jobClass = null;
202 202
        try {
......
219 219
					intervalValue, intervalUnit, jobParams);
220 220
		} catch (AccessException ae) {
221 221
			try {
222
				deleteJob(jobName, username, groups);
222
				deleteJob(jobName);
223 223
			} catch (Exception e) {
224 224
				// Not much we can do here but log this
225 225
				logMetacat.error("SchedulerService.scheduleJob - An access exception was thrown when writing job: "
......
425 425
	 *            the user's group name
426 426
	 * @return a message saying that the job was deleted
427 427
	 */
428
	public String deleteJob(String jobName, String username,
429
			String[] groups) throws ServiceException {
428
	public String deleteJob(String jobName) throws ServiceException {
430 429
		
431 430
		ScheduledJobDAO jobDAO = null;
432 431
		try {	
......
437 436
					+ "scheduled job : " + jobDAO.getName() + " because of db access issue: ", ae);
438 437
		}
439 438
		
440
		return deleteJob(jobDAO, username, groups);
439
		return deleteJob(jobDAO);
441 440
	}
442 441
	
443 442
	/**
......
450 449
	 *            the user's group name
451 450
	 * @return a message saying that the job was deleted
452 451
	 */
453
	public String deleteJob(ScheduledJobDAO jobDAO, String username,
454
			String[] groups) throws ServiceException {
452
	public String deleteJob(ScheduledJobDAO jobDAO) throws ServiceException {
455 453

  
456 454
		String groupName = "";
457 455
		try {
src/edu/ucsb/nceas/metacat/scheduler/BaseScheduler.java
36 36
	// Schedule a job by extracting job specific information and registering it with the scheduler 
37 37
	// service.  
38 38
	public abstract void scheduleJob(HttpServletRequest request, HttpServletResponse response, 
39
            Hashtable<String, String[]> params, String username, String[] groups) throws MetacatSchedulerException;
39
            Hashtable<String, String[]> params) throws MetacatSchedulerException;
40 40
	
41 41
	// Unschedule a job in the scheduler service. 
42 42
	public abstract void unscheduleJob(HttpServletRequest request, HttpServletResponse response, 

Also available in: Unified diff