KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > controller > JobSecurityMatrix


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.services.controller;
66
67 /**
68  * JobSecurityMatrix.java
69  *
70  * Copyright 2000, 2001 Jcorporate Ltd.
71  */

72
73 import com.jcorporate.expresso.core.controller.Block;
74 import com.jcorporate.expresso.core.controller.ControllerException;
75 import com.jcorporate.expresso.core.controller.ControllerRequest;
76 import com.jcorporate.expresso.core.controller.ControllerResponse;
77 import com.jcorporate.expresso.core.controller.DBController;
78 import com.jcorporate.expresso.core.controller.ErrorCollection;
79 import com.jcorporate.expresso.core.controller.Input;
80 import com.jcorporate.expresso.core.controller.NonHandleableException;
81 import com.jcorporate.expresso.core.controller.Output;
82 import com.jcorporate.expresso.core.controller.State;
83 import com.jcorporate.expresso.core.controller.Transition;
84 import com.jcorporate.expresso.core.db.DBException;
85 import com.jcorporate.expresso.core.dbobj.Schema;
86 import com.jcorporate.expresso.core.dbobj.SchemaFactory;
87 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
88 import com.jcorporate.expresso.core.dbobj.ValidValue;
89 import com.jcorporate.expresso.core.job.Job;
90 import com.jcorporate.expresso.core.misc.StringUtil;
91 import com.jcorporate.expresso.services.dbobj.JobSecurity;
92 import com.jcorporate.expresso.services.dbobj.SchemaList;
93 import com.jcorporate.expresso.services.dbobj.UserGroup;
94 import org.apache.log4j.Logger;
95
96 import java.util.Enumeration JavaDoc;
97 import java.util.Hashtable JavaDoc;
98 import java.util.Iterator JavaDoc;
99 import java.util.Vector JavaDoc;
100
101
102 /**
103  * The JobSecurityMatrix controller allows easy administration of the
104  * security rights of user groups to get to certain Jobs and to certain
105  * methods in those Jobs (assuming the job has more than one method).
106  *
107  * @author Michael Nash
108  * @version $Revision: 1.18 $ $Date: 2004/11/17 20:48:17 $
109  */

110 public class JobSecurityMatrix
111         extends DBController {
112     private static final String JavaDoc thisClass = JobSecurityMatrix.class.getName() + ".";
113     private static Logger log = Logger.getLogger(JobSecurityMatrix.class);
114
115     /**
116      * Constructor that specifies the states available in
117      * this Controller
118      */

119     public JobSecurityMatrix() {
120         State prompt = new State("prompt", "Prompt for Schema");
121         addState(prompt);
122         setInitialState("prompt");
123
124         State seljob = new State("seljob", "Select Job");
125         seljob.addRequiredParameter("GroupName");
126         seljob.addRequiredParameter("SchemaClass");
127         addState(seljob);
128
129         State setjob = new State("setjob", "Set Allowed Jobs");
130         setjob.addRequiredParameter("SchemaClass");
131         setjob.addRequiredParameter("GroupName");
132         addState(setjob);
133
134         State updjob = new State("updjob", "Update Allowed Jobs");
135         updjob.addRequiredParameter("SchemaClass");
136         updjob.addRequiredParameter("GroupName");
137         addState(updjob);
138
139         State selfunctions = new State("selfunctions",
140                 "Select Allowed Functions");
141         selfunctions.addRequiredParameter("GroupName");
142         selfunctions.addRequiredParameter("JobClass");
143         addState(selfunctions);
144
145         State updfunctions = new State("updfunctions",
146                 "Update Allowed Functions");
147         updfunctions.addRequiredParameter("GroupName");
148         updfunctions.addRequiredParameter("JobClass");
149         addState(updfunctions);
150         this.setSchema(com.jcorporate.expresso.core.ExpressoSchema.class);
151     } /* JobSecurityMatrix() */
152
153     /**
154      * Instantiate & return the Job class
155      *
156      * @param className The name of the Job object to instantiate
157      * @return An instance of the named Job object
158      * @throws ControllerException upon error
159      */

160     private Job getJob(String JavaDoc className)
161             throws ControllerException {
162         String JavaDoc myName = (thisClass + "getController(String)");
163         Job myController;
164
165         try {
166             myController = (Job) Class.forName(className).newInstance();
167         } catch (IllegalAccessException JavaDoc ie) {
168             throw new ControllerException(myName + ":Illegal Access " +
169                     "Exception loading Job class " +
170                     className + ":" + ie.getMessage());
171         } catch (InstantiationException JavaDoc ie) {
172             throw new ControllerException(myName + ":Can't instantiate " +
173                     "Job class " + className + ":" +
174                     ie.getMessage());
175         } catch (ClassNotFoundException JavaDoc se) {
176             throw new ControllerException(myName + ":Can't find a Job " +
177                     "class called " + className + ":" +
178                     se.getMessage());
179         } catch (Exception JavaDoc eo) {
180             log.error(eo);
181             throw new ControllerException(myName + ":Exception loading " +
182                     "Job" + className +
183                     "- see detailed message in server log:" +
184                     eo.getMessage());
185         }
186
187         return myController;
188     } /* getJob(String) */
189
190
191     /**
192      * Instantiate & return the schema class given in the current parameter
193      *
194      * @param className Name of the Schema object to instantiate
195      * @param failIfNotLoaded if the schema cannot be loaded should we throw an exception
196      * @return A Schema object, ready for use
197      * @throws ControllerException upon error
198      */

199     private Schema getSchema(String JavaDoc className, boolean failIfNotLoaded)
200             throws ControllerException {
201         Schema mySchema = SchemaFactory.getInstance().getSchema(className);
202
203         if (mySchema == null && failIfNotLoaded) {
204             if (failIfNotLoaded) {
205                 throw new ControllerException("Cannot access schema '" +
206                         className + "'");
207             }
208         }
209
210         return mySchema;
211     } /* getSchema(String) */
212
213
214     /**
215      * Build the matrix for user to select the allowed jobs
216      * for this user and this schema
217      *
218      * @param params the ControllerRequest object
219      * @param myResponse the ControllerResponse object
220      * @throws ControllerException upon error
221      */

222     private void getSelJobMatrix(ControllerResponse myResponse,
223                                  ControllerRequest params)
224             throws ControllerException {
225         String JavaDoc myName = (thisClass + "getDBObjMatrix()");
226         Schema mySchema = getSchema(params.getParameter("SchemaClass"), true);
227
228         try { /* get each of the database objects for this schema */
229             Block matrix = new Block("matrix");
230             matrix.setAttribute("table", "Y");
231             matrix.setAttribute("header-row", ("Job|Allowed?"));
232             myResponse.add(matrix);
233
234             Job oneController = null;
235             JobSecurity secur = new JobSecurity(SecuredDBObject.SYSTEM_ACCOUNT);
236             secur.setDataContext(params.getDataContext());
237
238             Input cb = null;
239             Block oneRow = null;
240
241             for (Enumeration JavaDoc e = mySchema.getJobs(); e.hasMoreElements();) {
242                 oneRow = new Block("oneRow");
243                 oneRow.setAttribute("row", "Y");
244                 oneController = (Job) e.nextElement();
245                 oneRow.add(new Output(oneController.getTitle()));
246
247                 /* now determine existing security for this group */
248
249                 /* and this object */
250                 boolean conAllowed = false;
251                 secur.clear();
252                 secur.setField("JobClass", oneController.getClass().getName());
253                 secur.setField("GroupName", params.getParameter("GroupName"));
254
255                 if (secur.find()) {
256                     conAllowed = true;
257                 }
258
259                 cb = new Input(oneController.getClass().getName());
260                 cb.setType("boolean");
261                 cb.setAttribute("checkbox", "");
262
263                 if (conAllowed) {
264                     cb.setDefaultValue("Y");
265                 } else {
266                     cb.setDefaultValue("N");
267                 }
268
269                 oneRow.add(cb);
270                 matrix.add(oneRow);
271             } /* for each job object */
272
273         } catch (DBException de) {
274             throw new ControllerException(myName +
275                     ":Database exception reading " +
276                     "security info:" + de.getMessage());
277         }
278     } /* getSelJobMatrix() */
279
280
281     /**
282      * Build the matrix for user to select the allowed functions
283      * for this user and this job
284      *
285      * @param params the ControllerRequest object
286      * @param myResponse the ControllerResponse object
287      * @throws ControllerException upon error
288      */

289     private void getSelFunctionsMatrix(ControllerResponse myResponse,
290                                        ControllerRequest params)
291             throws ControllerException {
292         String JavaDoc myName = (thisClass + "getSelFunctionsMatrix()");
293         Job con = getJob(params.getParameter("JobClass"));
294
295         /* must have GroupName and JobClass fields */
296         try {
297
298             /* get each of the database objects for this schema */
299             Block matrix = new Block("matrix");
300             matrix.setAttribute("table", "Y");
301
302             String JavaDoc head = ("Function|Allowed?");
303             matrix.setAttribute("header-row", head);
304             myResponse.add(matrix);
305
306             JobSecurity secur = new JobSecurity(SecuredDBObject.SYSTEM_ACCOUNT);
307             secur.setDataContext(params.getDataContext());
308             secur.setField("JobClass", con.getClass().getName());
309             secur.setField("GroupName", params.getParameter("GroupName"));
310
311             String JavaDoc currentSecurity = ("");
312
313             if (secur.find()) {
314                 currentSecurity = secur.getField("Functions");
315             }
316
317             Input cb = null;
318             Block oneRow = null;
319             Hashtable JavaDoc allStates = con.getFunctions();
320             String JavaDoc oneStateName;
321             State oneState;
322
323             for (Enumeration JavaDoc e = allStates.keys(); e.hasMoreElements();) {
324                 oneRow = new Block("oneRow");
325                 oneRow.setAttribute("row", "Y");
326                 oneStateName = (String JavaDoc) e.nextElement();
327                 oneState = (State) allStates.get(oneStateName);
328                 oneRow.add(new Output((String JavaDoc) oneState.getDescription()));
329
330                 /* now determine existing security for this group */
331
332                 /* and this object */
333                 boolean stateAllowed = false;
334
335                 if (currentSecurity.indexOf(oneStateName) != -1) {
336                     stateAllowed = true;
337                 }
338                 if (currentSecurity.indexOf("*") != -1) {
339                     stateAllowed = true;
340                 }
341
342                 cb = new Input(oneStateName);
343                 cb.setType("boolean");
344                 cb.setAttribute("checkbox", "");
345
346                 if (stateAllowed) {
347                     cb.setDefaultValue("Y");
348                 } else {
349                     cb.setDefaultValue("N");
350                 }
351
352                 oneRow.add(cb);
353                 matrix.add(oneRow);
354             } /* for each job object */
355
356         } catch (DBException de) {
357             throw new ControllerException(myName +
358                     ":Database exception reading " +
359                     "security info:" + de.getMessage());
360         }
361     } /* getSelFunctionsMatrix(ControllerRequest, ControllerResponse) */
362
363
364     /**
365      * Return the title of this Job
366      *
367      * @return The title of this Controller
368      */

369     public String JavaDoc getTitle() {
370         return ("Job Security Matrix");
371     } /* getTitle() */
372
373     /**
374      * Specify a new state for this Controller to transition into
375      *
376      * @param newState The new state to transition into. Must be
377      * one of the valid states for this Controller
378      * @param params the ControllerRequest object
379      * @return a ControllerResponse object
380      * @throws NonHandleableException upon fatal error
381      */

382     public ControllerResponse newState(String JavaDoc newState,
383                                        ControllerRequest params)
384             throws ControllerException,
385             NonHandleableException {
386         ControllerResponse myResponse = super.newState(newState, params);
387
388         if (newState.equals("prompt")) {
389             promptState(myResponse, params);
390         } else if (newState.equals("seljob")) {
391             selJobState(myResponse, params);
392         } else if (newState.equals("setjob")) {
393             setJobState(myResponse, params);
394         } else if (newState.equals("updjob")) {
395             updJobState(myResponse, params);
396         } else if (newState.equals("selfunctions")) {
397             selFunctionsState(myResponse, params);
398         } else if (newState.equals("updstates")) {
399             updFunctionsState(myResponse, params);
400         }
401         if (!newState.equals("prompt")) {
402             Transition again = new Transition("Start Again",
403                     getClass().getName());
404             again.setName("again");
405             again.addParam(STATE_PARAM_KEY, "prompt");
406             myResponse.addTransition(again);
407         }
408
409         return myResponse;
410     } /* newState(String) */
411
412
413     /**
414      * Prompt for a schema and usergroup
415      *
416      * @param params the ControllerRequest object
417      * @param myResponse the ControllerResponse object
418      */

419     private void promptState(ControllerResponse myResponse,
420                              ControllerRequest params)
421             throws ControllerException {
422         String JavaDoc myName = (thisClass + "promptState()");
423
424         try {
425             Input chooseGroup = new Input();
426             chooseGroup.setLabel("Choose Group");
427             chooseGroup.setName("GroupName");
428
429             Vector JavaDoc vg = new Vector JavaDoc(2);
430             UserGroup gl = new UserGroup(SecuredDBObject.SYSTEM_ACCOUNT);
431             gl.setDataContext(params.getDataContext());
432
433             UserGroup oneGroup = null;
434
435             for (Iterator JavaDoc eg = gl.searchAndRetrieveList().iterator();
436                  eg.hasNext();) {
437                 oneGroup = (UserGroup) eg.next();
438                 vg.addElement(new ValidValue(oneGroup.getField("GroupName"),
439                         oneGroup.getField("Descrip")));
440             } /* for each group */
441
442             if (vg.size() == 0) {
443                 throw new ControllerException(myName +
444                         ":There are no groups " +
445                         "defined.");
446             }
447
448             chooseGroup.setValidValues(vg);
449             myResponse.addInput(chooseGroup);
450
451             /* ..and a schema */
452             Input chooseSchema = new Input();
453             chooseSchema.setLabel("Choose Schema");
454             chooseSchema.setName("SchemaClass");
455
456             Vector JavaDoc vs = new Vector JavaDoc(2);
457             vs.addElement(new ValidValue("com.jcorporate.expresso." + "core.ExpressoSchema",
458                     "General"));
459
460             Schema oneSchemaObj;
461             SchemaList sl = new SchemaList(SecuredDBObject.SYSTEM_ACCOUNT);
462             sl.setDataContext(params.getDataContext());
463
464             SchemaList oneSchema = null;
465
466             for (Iterator JavaDoc es = sl.searchAndRetrieveList().iterator();
467                  es.hasNext();) {
468                 oneSchema = (SchemaList) es.next();
469                 oneSchemaObj = getSchema(oneSchema.getField("SchemaClass"),
470                         false);
471
472                 if (oneSchemaObj != null) {
473                     if (oneSchemaObj.getJobs().hasMoreElements()) {
474                         vs.addElement(new ValidValue(oneSchema.getField("SchemaClass"),
475                                 oneSchema.getField("Descrip")));
476                     }
477                 }
478             } /* for each listed schema */
479
480
481             chooseSchema.setValidValues(vs);
482             myResponse.addInput(chooseSchema);
483         } catch (DBException de) {
484             throw new ControllerException(myName + ":Unable to retrieve " +
485                     "schema information:" +
486                     de.getMessage());
487         }
488
489         Transition setjob = new Transition("Select Allowed Jobs",
490                 getClass().getName());
491         setjob.setName("setjob");
492         setjob.setState("setjob");
493         myResponse.addTransition(setjob);
494
495         Transition seljob = new Transition("Select Allowed Functions",
496                 getClass().getName());
497         seljob.setName("seljob");
498         seljob.setState("seljob");
499 // seljob.setState("selfunctions");
500
myResponse.addTransition(seljob);
501     } /* promptState() */
502
503
504     /**
505      * Select a Job to administer functions for.
506      *
507      * @param params the ControllerRequest object
508      * @param myResponse the ControllerResponse object
509      */

510     private void selJobState(ControllerResponse myResponse,
511                              ControllerRequest params)
512             throws ControllerException, NonHandleableException {
513         String JavaDoc myName = (thisClass + "selJobState()");
514         Schema mySchema = getSchema(params.getParameter("SchemaClass"), true);
515         Job oneController;
516         Input chooseController = new Input();
517         chooseController.setLabel("Choose Job");
518         chooseController.setName("JobClass");
519
520         Vector JavaDoc v = new Vector JavaDoc(2);
521
522         for (Enumeration JavaDoc e = mySchema.getJobs(); e.hasMoreElements();) {
523             oneController = (Job) e.nextElement();
524
525             /* if the job has no functions (e.g. it's all or nothing) then */
526             /* don't show it */
527             if (oneController.getFunctions().size() != 0) {
528                 v.addElement(new ValidValue(oneController.getClass().getName(),
529                         oneController.getTitle()));
530             }
531         } /* for each job in the selected schema */
532
533         if (v.size() == 0) {
534             ErrorCollection ec = new ErrorCollection();
535             ec.addError(myName + ":There are no jobs " +
536                     "defined in the selected schema with functions defined." +
537                     " Use 'Select Allowed Jobs' to enable access to jobs.");
538             myResponse.saveErrors(ec);
539             transition("prompt", params, myResponse);
540             return;
541         }
542
543         chooseController.setValidValues(v);
544         myResponse.addInput(chooseController);
545
546         try {
547             UserGroup myGroup = new UserGroup(SecuredDBObject.SYSTEM_ACCOUNT);
548             myGroup.setDataContext(params.getDataContext());
549             myGroup.setField("GroupName", params.getParameter("GroupName"));
550             myGroup.retrieve();
551             myResponse.addOutput(new Output("Choose a Job to administer functions " + "for group '" +
552                     myGroup.getField("Descrip") +
553                     "'"));
554         } catch (DBException de) {
555             throw new ControllerException(myName +
556                     ":Unable to retrieve group:" +
557                     de.getMessage());
558         }
559
560         Transition selfunctions = new Transition("Select Allowed Functions",
561                 getClass().getName());
562         selfunctions.setName("selfunctions");
563         selfunctions.addParam(STATE_PARAM_KEY, "selfunctions");
564         selfunctions.addParam("GroupName", params.getParameter("GroupName"));
565         selfunctions.addParam("SchemaClass",
566                 params.getParameter("SchemaClass"));
567         myResponse.addTransition(selfunctions);
568     } /* selControllerState() */
569
570
571     /**
572      * Set allowed functions of a particular job for
573      * one group and job combination
574      *
575      * @param params the ControllerRequest object
576      * @param myResponse the ControllerResponse object
577      */

578     private void selFunctionsState(ControllerResponse myResponse,
579                                    ControllerRequest params)
580             throws ControllerException {
581         String JavaDoc myName = (thisClass + "selFunctionsState()");
582         Job oneController = getJob(params.getParameter("JobClass"));
583
584         try {
585             UserGroup oneGroup = new UserGroup(SecuredDBObject.SYSTEM_ACCOUNT);
586             oneGroup.setDataContext(params.getDataContext());
587             oneGroup.setField("GroupName", params.getParameter("GroupName"));
588             oneGroup.retrieve();
589             myResponse.addOutput(new Output("Select allowed Functions for Job '" + oneController.getTitle() +
590                     "' and group '" +
591                     oneGroup.getField("Descrip") +
592                     "'"));
593         } catch (DBException de) {
594             throw new ControllerException(myName +
595                     ":Unable to locate group '" +
596                     params.getParameter("GroupName"));
597         }
598
599         getSelFunctionsMatrix(myResponse, params);
600
601         Transition updstates = new Transition("Update", getClass().getName());
602         updstates.setName("updstates");
603         updstates.addParam(STATE_PARAM_KEY, "updstates");
604         updstates.addParam("GroupName", params.getParameter("GroupName"));
605         updstates.addParam("JobClass", params.getParameter("JobClass"));
606         myResponse.addTransition(updstates);
607     } /* selStatesState() */
608
609
610     /**
611      * Set allowed Job for a schema and group
612      *
613      * @param params the ControllerRequest object
614      * @param myResponse the ControllerResponse object
615      */

616     private void setJobState(ControllerResponse myResponse,
617                              ControllerRequest params)
618             throws ControllerException {
619         String JavaDoc myName = (thisClass + "setControllerState()");
620
621         /* present a list of controllers from the current */
622         /* schema to the user to check off the ones this group */
623         try {
624             UserGroup myGroup = new UserGroup(SecuredDBObject.SYSTEM_ACCOUNT);
625             myGroup.setDataContext(params.getDataContext());
626             myGroup.setField("GroupName", params.getParameter("GroupName"));
627             myGroup.retrieve();
628
629             String JavaDoc schemaName;
630
631             if (params.getParameter("SchemaClass").equals("com.jcorporate." + "expresso.core.ExpressoSchema")) {
632                 schemaName = ("General");
633             } else {
634                 SchemaList mySL = new SchemaList(SecuredDBObject.SYSTEM_ACCOUNT);
635                 mySL.setDataContext(params.getDataContext());
636                 mySL.setField("SchemaClass",
637                         params.getParameter("SchemaClass"));
638                 mySL.retrieve();
639                 schemaName = mySL.getField("Descrip");
640             }
641
642             myResponse.addOutput(new Output("Select allowed Jobs for group '" + myGroup.getField("Descrip") +
643                     "' in Schema '" + schemaName +
644                     "'"));
645             getSelJobMatrix(myResponse, params);
646         } catch (DBException de) {
647             throw new ControllerException(myName +
648                     ":Unable to read state or group " +
649                     "information:" + de.getMessage());
650         }
651
652         Transition updjob = new Transition("Update", getClass().getName());
653         updjob.setName("updjob");
654         updjob.addParam(STATE_PARAM_KEY, "updjob");
655         updjob.addParam("GroupName", params.getParameter("GroupName"));
656         updjob.addParam("SchemaClass", params.getParameter("SchemaClass"));
657         myResponse.addTransition(updjob);
658     } /* setControllerState() */
659
660
661     /**
662      * Update allowed states for a particular job
663      * and group
664      *
665      * @param params the ControllerRequest object
666      * @param myResponse the ControllerResponse object
667      */

668     private void updJobState(ControllerResponse myResponse,
669                              ControllerRequest params)
670             throws ControllerException {
671         String JavaDoc myName = (thisClass + "updJobState()");
672         Schema mySchema = getSchema(params.getParameter("SchemaClass"), true);
673
674         try {
675             JobSecurity secur = new JobSecurity(SecuredDBObject.SYSTEM_ACCOUNT);
676             secur.setDataContext(params.getDataContext());
677
678             Job checkController;
679             int changes = 0;
680
681             for (Enumeration JavaDoc pe = mySchema.getJobs(); pe.hasMoreElements();) {
682                 checkController = (Job) pe.nextElement();
683                 secur.clear();
684                 secur.setField("JobClass",
685                         checkController.getClass().getName());
686                 secur.setField("GroupName", params.getParameter("GroupName"));
687
688                 if (StringUtil.notNull(params.getParameter(checkController.getClass().getName())).equals("Y")) {
689
690                     /* check that permission is allowed */
691                     if (!secur.find()) {
692                         secur.setField("Functions", "*");
693                         secur.add();
694                         myResponse.addOutput(new Output("Permission granted for " + "Job " +
695                                 checkController.getTitle()));
696                         changes++;
697                     }
698                 } else {
699
700                     /* make sure permission is NOT allowed */
701                     if (secur.find()) {
702                         secur.delete();
703                         myResponse.addOutput(new Output("Permission removed for " + "Job " +
704                                 checkController.getTitle()));
705                         changes++;
706                     }
707                 } /* else not allowed */
708
709             } /* for each controller in the schema */
710
711             if (changes == 0) {
712                 myResponse.addOutput(new Output("No changes required"));
713             }
714         } catch (DBException de) {
715             throw new ControllerException(myName +
716                     ":Unable to update security " +
717                     "info", de);
718         }
719     } /* updControllerState() */
720
721
722     /**
723      * Update the allowed states for this Job
724      *
725      * @param params the ControllerRequest object
726      * @param myResponse the ControllerResponse object
727      */

728     private void updFunctionsState(ControllerResponse myResponse,
729                                    ControllerRequest params)
730             throws ControllerException {
731         String JavaDoc myName = (thisClass + "updStatesState()");
732         Job con = getJob(params.getParameter("JobClass"));
733
734         try {
735             Hashtable JavaDoc allStates = con.getFunctions();
736             String JavaDoc oneStateName;
737             State oneState;
738             StringBuffer JavaDoc newSecurity = new StringBuffer JavaDoc("");
739             boolean allAllowed = true;
740
741             for (Enumeration JavaDoc e = allStates.keys(); e.hasMoreElements();) {
742                 oneStateName = (String JavaDoc) e.nextElement();
743                 oneState = (State) allStates.get(oneStateName);
744
745                 if (StringUtil.notNull(params.getParameter(oneStateName)).equals("Y")) {
746                     newSecurity.append(oneStateName);
747                     newSecurity.append(", ");
748                     myResponse.addOutput(new Output("Access granted to function '" + oneState.getDescription() +
749                             "'"));
750                 } else {
751                     myResponse.addOutput(new Output("Access denied to function '" + oneState.getDescription() +
752                             "'"));
753                     allAllowed = false;
754                 }
755             } /* for each state of this controller */
756
757
758             JobSecurity secur = new JobSecurity(SecuredDBObject.SYSTEM_ACCOUNT);
759             secur.setDataContext(params.getDataContext());
760             secur.setField("JobClass", con.getClass().getName());
761             secur.setField("GroupName", params.getParameter("GroupName"));
762
763             if (allAllowed) {
764                 newSecurity = new StringBuffer JavaDoc("*");
765             }
766             if (secur.find()) {
767                 secur.setField("Functions", newSecurity.toString());
768                 secur.update();
769             } else {
770                 secur.setField("Functions", newSecurity.toString());
771                 secur.add();
772             }
773         } catch (DBException de) {
774             throw new ControllerException(myName +
775                     ":Database exception reading " +
776                     "security info:" + de.getMessage());
777         }
778     } /* updStatesState() */
779
780
781 } /* JobSecurityMatrix */
782
Popular Tags