Source Code Cross Referenced for ControllerSecurityMatrix.java in  » J2EE » Expresso » com » jcorporate » expresso » services » controller » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Expresso » com.jcorporate.expresso.services.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
003:         *
004:         * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution,
019:         *    if any, must include the following acknowledgment:
020:         *       "This product includes software developed by Jcorporate Ltd.
021:         *        (http://www.jcorporate.com/)."
022:         *    Alternately, this acknowledgment may appear in the software itself,
023:         *    if and wherever such third-party acknowledgments normally appear.
024:         *
025:         * 4. "Jcorporate" and product names such as "Expresso" must
026:         *    not be used to endorse or promote products derived from this
027:         *    software without prior written permission. For written permission,
028:         *    please contact info@jcorporate.com.
029:         *
030:         * 5. Products derived from this software may not be called "Expresso",
031:         *    or other Jcorporate product names; nor may "Expresso" or other
032:         *    Jcorporate product names appear in their name, without prior
033:         *    written permission of Jcorporate Ltd.
034:         *
035:         * 6. No product derived from this software may compete in the same
036:         *    market space, i.e. framework, without prior written permission
037:         *    of Jcorporate Ltd. For written permission, please contact
038:         *    partners@jcorporate.com.
039:         *
040:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
041:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
042:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
043:         * DISCLAIMED.  IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
044:         * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
045:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
046:         * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
047:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
048:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
049:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
050:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
051:         * SUCH DAMAGE.
052:         * ====================================================================
053:         *
054:         * This software consists of voluntary contributions made by many
055:         * individuals on behalf of the Jcorporate Ltd. Contributions back
056:         * to the project(s) are encouraged when you make modifications.
057:         * Please send them to support@jcorporate.com. For more information
058:         * on Jcorporate Ltd. and its products, please see
059:         * <http://www.jcorporate.com/>.
060:         *
061:         * Portions of this software are based upon other open source
062:         * products and are subject to their respective licenses.
063:         */
064:
065:        /**
066:         * ControllerSecurityMatrix.java
067:         *
068:         * Copyright 2000, 2001 Jcorporate Ltd.
069:         */package com.jcorporate.expresso.services.controller;
070:
071:        import com.jcorporate.expresso.core.controller.Block;
072:        import com.jcorporate.expresso.core.controller.Controller;
073:        import com.jcorporate.expresso.core.controller.ControllerException;
074:        import com.jcorporate.expresso.core.controller.ControllerRequest;
075:        import com.jcorporate.expresso.core.controller.ControllerResponse;
076:        import com.jcorporate.expresso.core.controller.DBController;
077:        import com.jcorporate.expresso.core.controller.Input;
078:        import com.jcorporate.expresso.core.controller.NonHandleableException;
079:        import com.jcorporate.expresso.core.controller.Output;
080:        import com.jcorporate.expresso.core.controller.State;
081:        import com.jcorporate.expresso.core.controller.Transition;
082:        import com.jcorporate.expresso.core.db.DBException;
083:        import com.jcorporate.expresso.core.dbobj.Schema;
084:        import com.jcorporate.expresso.core.dbobj.SchemaFactory;
085:        import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
086:        import com.jcorporate.expresso.core.dbobj.ValidValue;
087:        import com.jcorporate.expresso.core.misc.ConfigManager;
088:        import com.jcorporate.expresso.core.misc.StringUtil;
089:        import com.jcorporate.expresso.core.servlet.StdServlet;
090:        import com.jcorporate.expresso.services.dbobj.ControllerSecurity;
091:        import com.jcorporate.expresso.services.dbobj.SchemaList;
092:        import com.jcorporate.expresso.services.dbobj.UserGroup;
093:
094:        import java.util.Enumeration;
095:        import java.util.Hashtable;
096:        import java.util.Iterator;
097:        import java.util.Vector;
098:
099:        /**
100:         * The ControllerSecurityMatrix controller allows easy administration of
101:         * access to controller and states within the controllers.
102:         *
103:         * @author Michael Nash
104:         * @version $Revision: 1.19 $      $Date: 2004/11/17 20:48:17 $
105:         */
106:        public class ControllerSecurityMatrix extends DBController {
107:            private static final String this Class = ControllerSecurityMatrix.class
108:                    .getName()
109:                    + ".";
110:
111:            /**
112:             * Constructor which specifies the allowed states in this
113:             * controller
114:             */
115:            public ControllerSecurityMatrix() {
116:                State prompt = new State("prompt",
117:                        "Choose Schema and User Group");
118:                addState(prompt);
119:
120:                State selcon = new State("selcon", "Select Controller");
121:                selcon.addRequiredParameter("GroupName");
122:                selcon.addRequiredParameter("SchemaClass");
123:                addState(selcon);
124:
125:                State setcon = new State("setcon", "Set Allowed Controllers");
126:                setcon.addRequiredParameter("SchemaClass");
127:                setcon.addRequiredParameter("GroupName");
128:                addState(setcon);
129:
130:                State updcon = new State("updcon", "Update Allowed Controllers");
131:                updcon.addRequiredParameter("SchemaClass");
132:                updcon.addRequiredParameter("GroupName");
133:                addState(updcon);
134:
135:                State selstates = new State("selstates",
136:                        "Select Allowed States");
137:                selstates.addRequiredParameter("GroupName");
138:                selstates.addRequiredParameter("ControllerClass");
139:                addState(selstates);
140:
141:                State updstates = new State("updstates",
142:                        "Update Allowed States");
143:                updstates.addRequiredParameter("GroupName");
144:                updstates.addRequiredParameter("ControllerClass");
145:                addState(updstates);
146:
147:                this .setInitialState("prompt");
148:                this 
149:                        .setSchema(com.jcorporate.expresso.core.ExpressoSchema.class);
150:
151:            } /* ControllerSecurityMatrix() */
152:
153:            /**
154:             * Add a 'start again' button to the response that points to the prompt
155:             * state.
156:             *
157:             * @param request  The <code>ControllerRequest</code> object
158:             * @param response The <code>ControllerResponse</code> object
159:             * @throws ControllerException upon error
160:             */
161:            private void addStartAgainButton(ControllerRequest request,
162:                    ControllerResponse response) throws ControllerException {
163:
164:                Transition again = new Transition("Start Again", getClass()
165:                        .getName());
166:                again.setName("again");
167:                again.addParam(STATE_PARAM_KEY, "prompt");
168:                response.addTransition(again);
169:            }
170:
171:            /**
172:             * Instantiate & return the schema class given in the current parameter
173:             *
174:             * @param className the name of the class to load
175:             * @return an instantiated Schema object
176:             * @throws ControllerException upon error
177:             */
178:            private Schema getSchema(String className)
179:                    throws ControllerException {
180:                return SchemaFactory.getInstance().getSchema(className);
181:            } /* getSchema(String) */
182:
183:            /**
184:             * Build the matrix for user to select the allowed controllers
185:             * for this user and this schema
186:             *
187:             * @param myResponse the ControllerResponse object
188:             * @param params     the ControllerRequest object
189:             * @throws ControllerException upon error
190:             */
191:            private void getSelControllerMatrix(ControllerRequest params,
192:                    ControllerResponse myResponse) throws ControllerException {
193:                String myName = (this Class + "getDBObjMatrix()");
194:                Schema mySchema = getSchema(params.getParameter("SchemaClass"));
195:
196:                if (mySchema == null) {
197:                    throw new ControllerException(myName
198:                            + ":Unable to instantiate the '"
199:                            + params.getParameter("SchemaClass") + "' schema.");
200:                }
201:                try {
202:
203:                    /* get each of the database objects for this schema */
204:                    Block matrix = new Block("matrix");
205:                    matrix.setAttribute("table", "Y");
206:
207:                    String head = ("Controller|Allowed?");
208:                    matrix.setAttribute("header-row", head);
209:
210:                    Block oneRow = new Block("row");
211:                    oneRow.setAttribute("row", "Y");
212:                    myResponse.add(matrix);
213:
214:                    Controller oneController = null;
215:                    ControllerSecurity secur = new ControllerSecurity(
216:                            SecuredDBObject.SYSTEM_ACCOUNT);
217:                    secur.setDataContext(params.getDataContext());
218:
219:                    Input cb = null;
220:
221:                    for (Iterator e = mySchema.getControllerList().iterator(); e
222:                            .hasNext();) {
223:                        oneRow = new Block("row");
224:                        oneRow.setAttribute("row", "Y");
225:                        oneController = (Controller) e.next();
226:                        oneRow.add(new Output(oneController.getTitle()));
227:
228:                        /* now determine existing security for this group */
229:
230:                        /* and this object */
231:                        boolean conAllowed = false;
232:                        secur.clear();
233:                        secur.setField("ControllerClass", oneController
234:                                .getClass().getName());
235:                        secur.setField("GroupName", params
236:                                .getParameter("GroupName"));
237:
238:                        if (secur.find()) {
239:                            conAllowed = true;
240:                        }
241:
242:                        cb = new Input(oneController.getClass().getName());
243:                        cb.setType("boolean");
244:                        cb.setAttribute("checkbox", "");
245:
246:                        if (conAllowed) {
247:                            cb.setDefaultValue("Y");
248:                        } else {
249:                            cb.setDefaultValue("N");
250:                        }
251:
252:                        oneRow.add(cb);
253:                        matrix.add(oneRow);
254:                    } /* for each controller object */
255:
256:                    StdServlet oneServlet;
257:
258:                    /* Now for each non-controller servlet */
259:                    for (Enumeration se = mySchema.getServlets(); se
260:                            .hasMoreElements();) {
261:                        oneRow = new Block("row");
262:                        oneRow.setAttribute("row", "Y");
263:                        oneServlet = (StdServlet) se.nextElement();
264:                        oneRow.add(new Output(oneServlet.getTitle()));
265:
266:                        /* now determine existing security for this group */
267:
268:                        /* and this object */
269:                        boolean conAllowed = false;
270:                        secur.clear();
271:                        secur.setField("ControllerClass", oneServlet.getClass()
272:                                .getName());
273:                        secur.setField("GroupName", params
274:                                .getParameter("GroupName"));
275:
276:                        if (secur.find()) {
277:                            conAllowed = true;
278:                        }
279:
280:                        cb = new Input(oneServlet.getClass().getName());
281:                        cb.setType("boolean");
282:                        cb.setAttribute("checkbox", "");
283:
284:                        if (conAllowed) {
285:                            cb.setDefaultValue("Y");
286:                        } else {
287:                            cb.setDefaultValue("N");
288:                        }
289:
290:                        oneRow.add(cb);
291:                        matrix.add(oneRow);
292:                    } /* for each servlet object */
293:
294:                } catch (DBException de) {
295:                    throw new ControllerException(myName
296:                            + ":Database exception reading " + "security info",
297:                            de);
298:                }
299:            } /* getSelControllerMatrix() */
300:
301:            /**
302:             * Build the matrix for user to select the allowed states
303:             * for this user and this controller
304:             *
305:             * @param myResponse the ControllerResponse object
306:             * @param params     the ControllerRequest object
307:             * @throws NonHandleableException upon fatal error
308:             */
309:            private void getSelStatesMatrix(ControllerResponse myResponse,
310:                    ControllerRequest params) throws ControllerException,
311:                    NonHandleableException {
312:                Controller con = ConfigManager.getControllerFactory()
313:                        .getController(params.getParameter("ControllerClass"));
314:
315:                /* must have GroupName and ControllerClass fields */
316:                try {
317:
318:                    /* get each of the database objects for this schema */
319:                    Block matrix = new Block("matrix");
320:                    matrix.setAttribute("table", "Y");
321:
322:                    String head = ("State|Allowed?");
323:                    matrix.setAttribute("header-row", head);
324:
325:                    Block oneRow = new Block("row");
326:                    oneRow.setAttribute("row", "Y");
327:                    myResponse.add(matrix);
328:
329:                    ControllerSecurity secur = new ControllerSecurity(
330:                            SecuredDBObject.SYSTEM_ACCOUNT);
331:                    secur.setDataContext(params.getDataContext());
332:                    secur.setField("ControllerClass", con.getClass().getName());
333:                    secur.setField("GroupName", params
334:                            .getParameter("GroupName"));
335:
336:                    String currentSecurity = ("");
337:
338:                    if (secur.find()) {
339:                        currentSecurity = secur.getField("States");
340:                    }
341:
342:                    Input cb = null;
343:                    Hashtable allStates = con.getStates();
344:                    String oneStateName;
345:                    State oneState;
346:
347:                    for (Enumeration e = allStates.keys(); e.hasMoreElements();) {
348:                        oneRow = new Block("row");
349:                        oneRow.setAttribute("row", "Y");
350:                        oneStateName = (String) e.nextElement();
351:                        oneState = (State) allStates.get(oneStateName);
352:                        oneRow.add(new Output((String) oneState
353:                                .getDescription()));
354:
355:                        /* now determine existing security for this group */
356:
357:                        /* and this object */
358:                        boolean stateAllowed = false;
359:
360:                        if (currentSecurity.indexOf(oneStateName) != -1) {
361:                            stateAllowed = true;
362:                        }
363:                        if (currentSecurity.indexOf("*") != -1) {
364:                            stateAllowed = true;
365:                        }
366:
367:                        cb = new Input(oneStateName);
368:                        cb.setType("boolean");
369:                        cb.setAttribute("checkbox", "");
370:
371:                        if (stateAllowed) {
372:                            cb.setDefaultValue("Y");
373:                        } else {
374:                            cb.setDefaultValue("N");
375:                        }
376:
377:                        oneRow.add(cb);
378:                        matrix.add(oneRow);
379:                    } /* for each controller object */
380:
381:                } catch (DBException de) {
382:                    throw new ControllerException("Database exception reading "
383:                            + "security info", de);
384:                }
385:            } /* getSelStatesMatrix() */
386:
387:            /**
388:             * Return the title of this Controller
389:             *
390:             * @return The title of this controller
391:             */
392:            public String getTitle() {
393:                return ("Administer Controller Security");
394:            } /* getTitle() */
395:
396:            /**
397:             * Prompt for a schema and usergroup
398:             *
399:             * @param myResponse the ControllerResponse object
400:             * @param params     the ControllerRequest object
401:             */
402:            private void runPromptState(ControllerRequest params,
403:                    ControllerResponse myResponse) throws ControllerException {
404:                {
405:                    Input chooseGroup = new Input();
406:                    chooseGroup.setLabel("Choose Group");
407:                    chooseGroup.setName("GroupName");
408:
409:                    Vector v = new Vector(2);
410:
411:                    try {
412:                        UserGroup gl = new UserGroup(
413:                                SecuredDBObject.SYSTEM_ACCOUNT);
414:                        gl.setDataContext(params.getDataContext());
415:
416:                        UserGroup oneGroup = null;
417:
418:                        for (Iterator e = gl.searchAndRetrieveList().iterator(); e
419:                                .hasNext();) {
420:                            oneGroup = (UserGroup) e.next();
421:                            v.addElement(new ValidValue(oneGroup
422:                                    .getField("GroupName"), oneGroup
423:                                    .getField("Descrip")));
424:                        }
425:                    } catch (DBException de) {
426:                        throw new ControllerException("Unable to retrieve "
427:                                + "group information", de);
428:                    }
429:                    if (v.size() == 0) {
430:                        throw new ControllerException("There are no groups "
431:                                + "defined.");
432:                    }
433:
434:                    chooseGroup.setValidValues(v);
435:                    myResponse.addInput(chooseGroup);
436:                } /* end block for choosegroup */
437:
438:                {
439:                    Input chooseSchema = new Input();
440:                    chooseSchema.setLabel("Choose Schema");
441:                    chooseSchema.setName("SchemaClass");
442:
443:                    Vector v = new Vector(2);
444:                    v.addElement(new ValidValue("com.jcorporate.expresso.core."
445:                            + "ExpressoSchema", "General"));
446:
447:                    try {
448:                        Schema oneSchemaObj;
449:                        SchemaList sl = new SchemaList(
450:                                SecuredDBObject.SYSTEM_ACCOUNT);
451:                        sl.setDataContext(params.getDataContext());
452:
453:                        SchemaList oneSchema = null;
454:
455:                        for (Iterator e = sl.searchAndRetrieveList().iterator(); e
456:                                .hasNext();) {
457:                            oneSchema = (SchemaList) e.next();
458:                            oneSchemaObj = getSchema(oneSchema
459:                                    .getField("SchemaClass"));
460:
461:                            if (oneSchemaObj != null) {
462:                                if (oneSchemaObj.getControllerList().iterator()
463:                                        .hasNext()) {
464:                                    v.addElement(new ValidValue(oneSchema
465:                                            .getField("SchemaClass"), oneSchema
466:                                            .getField("Descrip")));
467:                                }
468:                            }
469:                        } /* for each listed schema */
470:
471:                    } catch (DBException de) {
472:                        throw new ControllerException("Unable to retrieve "
473:                                + "schema information", de);
474:                    }
475:
476:                    chooseSchema.setValidValues(v);
477:                    myResponse.addInput(chooseSchema);
478:                } /* end chooseschema block */
479:
480:                Transition setcon = new Transition(
481:                        "Select Allowed Controllers", getClass().getName());
482:                setcon.setName("setcon");
483:                setcon.addParam(STATE_PARAM_KEY, "setcon");
484:                myResponse.addTransition(setcon);
485:
486:                Transition selcon = new Transition("Select Allowed States",
487:                        getClass().getName());
488:                selcon.setName("selcon");
489:                selcon.addParam(STATE_PARAM_KEY, "selcon");
490:                myResponse.addTransition(selcon);
491:            } /* promptState() */
492:
493:            /**
494:             * Select a Controller to administer states for.
495:             *
496:             * @param myResponse the ControllerResponse object
497:             * @param params     the ControllerRequest object
498:             */
499:            private void runSelconState(ControllerRequest params,
500:                    ControllerResponse myResponse) throws ControllerException {
501:                String myName = (this Class + "selControllerState()");
502:                Schema mySchema = getSchema(params.getParameter("SchemaClass"));
503:
504:                if (mySchema == null) {
505:                    throw new ControllerException(myName
506:                            + ":Can't find the schema class '"
507:                            + params.getParameter("SchemaClass") + "'");
508:                }
509:
510:                Controller oneController;
511:                Input chooseController = new Input();
512:                chooseController.setLabel("Choose Controller");
513:                chooseController.setName("ControllerClass");
514:
515:                Vector v = new Vector(2);
516:
517:                for (Iterator e = mySchema.getControllerList().iterator(); e
518:                        .hasNext();) {
519:                    oneController = (Controller) e.next();
520:                    v.addElement(new ValidValue(oneController.getClass()
521:                            .getName(), oneController.getTitle()));
522:                } /* for each controller in the selected schema */
523:
524:                if (v.size() == 0) {
525:                    throw new ControllerException(myName
526:                            + ":There are no controllers "
527:                            + "defined in the selected schema.");
528:                }
529:
530:                chooseController.setValidValues(v);
531:                myResponse.addInput(chooseController);
532:
533:                try {
534:                    UserGroup myGroup = new UserGroup(
535:                            SecuredDBObject.SYSTEM_ACCOUNT);
536:                    myGroup.setDataContext(params.getDataContext());
537:                    myGroup.setField("GroupName", params
538:                            .getParameter("GroupName"));
539:                    myGroup.retrieve();
540:                    myResponse.addOutput(new Output(
541:                            "Choose a Controller to administer states "
542:                                    + "for group '"
543:                                    + myGroup.getField("Descrip") + "'"));
544:                } catch (DBException de) {
545:                    throw new ControllerException("Unable to retrieve group",
546:                            de);
547:                }
548:
549:                Transition selstates = new Transition("Select Allowed States",
550:                        getClass().getName());
551:                selstates.setName("selstates");
552:                selstates.addParam(STATE_PARAM_KEY, "selstates");
553:                selstates.addParam("GroupName", params
554:                        .getParameter("GroupName"));
555:                selstates.addParam("SchemaClass", params
556:                        .getParameter("SchemaClass"));
557:                myResponse.addTransition(selstates);
558:            } /* selControllerState() */
559:
560:            /**
561:             * Set allowed states of a particular controller for
562:             * one group and controller combination
563:             *
564:             * @param myResponse the ControllerResponse object
565:             * @param params     the ControllerRequest object
566:             * @throws NonHandleableException upon fatal error
567:             */
568:            private void runSelstatesState(ControllerRequest params,
569:                    ControllerResponse myResponse) throws ControllerException,
570:                    NonHandleableException {
571:                String myName = (this Class + "selStatesState()");
572:                Controller oneController = ConfigManager.getControllerFactory()
573:                        .getController(params.getParameter("ControllerClass"));
574:
575:                try {
576:                    UserGroup oneGroup = new UserGroup(
577:                            SecuredDBObject.SYSTEM_ACCOUNT);
578:                    oneGroup.setDataContext(params.getDataContext());
579:                    oneGroup.setField("GroupName", params
580:                            .getParameter("GroupName"));
581:                    oneGroup.retrieve();
582:                    myResponse.addOutput(new Output(
583:                            "Select allowed States for Controller'"
584:                                    + oneController.getTitle()
585:                                    + "' and group '"
586:                                    + oneGroup.getField("Descrip") + "'"));
587:                    getSelStatesMatrix(myResponse, params);
588:                } catch (DBException de) {
589:                    throw new ControllerException(myName
590:                            + ":Unable to locate group '"
591:                            + params.getParameter("GroupName"));
592:                }
593:
594:                Transition updstates = new Transition("Update", getClass()
595:                        .getName());
596:                updstates.setName("updstates");
597:                updstates.addParam(STATE_PARAM_KEY, "updstates");
598:                updstates.addParam("GroupName", params
599:                        .getParameter("GroupName"));
600:                updstates.addParam("ControllerClass", params
601:                        .getParameter("ControllerClass"));
602:                myResponse.addTransition(updstates);
603:            } /* selStatesState() */
604:
605:            /**
606:             * Set allowed Controller for a schema and group
607:             *
608:             * @param myResponse the ControllerResponse object
609:             * @param params     the ControllerRequest object
610:             */
611:            private void runSetconState(ControllerRequest params,
612:                    ControllerResponse myResponse) throws ControllerException,
613:                    NonHandleableException {
614:                String myName = (this Class + "setControllerState()");
615:
616:                /* present a list of controllers from the current */
617:                /* schema to the user to check off the ones this group */
618:                try {
619:                    UserGroup myGroup = new UserGroup(
620:                            SecuredDBObject.SYSTEM_ACCOUNT);
621:                    myGroup.setDataContext(params.getDataContext());
622:                    myGroup.setField("GroupName", params
623:                            .getParameter("GroupName"));
624:                    myGroup.retrieve();
625:
626:                    String schemaName;
627:
628:                    if (params.getParameter("SchemaClass").equals(
629:                            "com.jcorporate." + "expresso.core.ExpressoSchema")) {
630:                        schemaName = ("General");
631:                    } else {
632:                        SchemaList mySL = new SchemaList(
633:                                SecuredDBObject.SYSTEM_ACCOUNT);
634:                        mySL.setDataContext(params.getDataContext());
635:                        mySL.setField("SchemaClass", params
636:                                .getParameter("SchemaClass"));
637:                        mySL.retrieve();
638:                        schemaName = mySL.getField("Descrip");
639:                    }
640:
641:                    myResponse.addOutput(new Output(
642:                            "Select allowed Controllers for group '"
643:                                    + myGroup.getField("Descrip")
644:                                    + "' in Schema '" + schemaName + "'"));
645:                    getSelControllerMatrix(params, myResponse);
646:                } catch (DBException de) {
647:                    throw new ControllerException(myName
648:                            + ":Unable to read state, group or schema "
649:                            + "information", de);
650:                }
651:
652:                Transition updcon = new Transition("Update", getClass()
653:                        .getName());
654:                updcon.setName("updcon");
655:                updcon.addParam(STATE_PARAM_KEY, "updcon");
656:                updcon.addParam("GroupName", params.getParameter("GroupName"));
657:                updcon.addParam("SchemaClass", params
658:                        .getParameter("SchemaClass"));
659:                myResponse.addTransition(updcon);
660:            } /* setControllerState() */
661:
662:            /**
663:             * Update allowed states for a particular controller
664:             * and group
665:             *
666:             * @param response the ControllerResponse object
667:             * @param request  the ControllerRequest object
668:             */
669:            private void runUpdconState(ControllerRequest request,
670:                    ControllerResponse response) throws ControllerException {
671:                String myName = (this Class + "updControllerState()");
672:                Schema mySchema = getSchema(request.getParameter("SchemaClass"));
673:
674:                if (mySchema == null) {
675:                    throw new ControllerException(myName
676:                            + ":Can't find the schema class '"
677:                            + request.getParameter("SchemaClass") + "'");
678:                }
679:
680:                try {
681:                    ControllerSecurity secur = new ControllerSecurity(
682:                            SecuredDBObject.SYSTEM_ACCOUNT);
683:                    secur.setDataContext(request.getDataContext());
684:
685:                    Controller checkController;
686:                    int changes = 0;
687:
688:                    for (Iterator pe = mySchema.getControllerList().iterator(); pe
689:                            .hasNext();) {
690:                        checkController = (Controller) pe.next();
691:                        secur.clear();
692:                        secur.setField("ControllerClass", checkController
693:                                .getClass().getName());
694:                        secur.setField("GroupName", request
695:                                .getParameter("GroupName"));
696:
697:                        if (StringUtil.notNull(
698:                                request.getParameter(checkController.getClass()
699:                                        .getName())).equals("Y")) {
700:
701:                            /* check that permission is allowed */
702:                            if (!secur.find()) {
703:                                secur.setField("States", "*");
704:                                secur.add();
705:                                response.addOutput(new Output(
706:                                        "Permission granted for "
707:                                                + "Controller"
708:                                                + checkController.getTitle()));
709:                                changes++;
710:                            }
711:                        } else {
712:
713:                            /* make sure permission is NOT allowed */
714:                            if (secur.find()) {
715:                                secur.delete();
716:                                response.addOutput(new Output(
717:                                        "Permission removed for "
718:                                                + "Controller"
719:                                                + checkController.getTitle()));
720:                                changes++;
721:                            }
722:                        } /* else not allowed */
723:
724:                    } /* for each controller in the schema */
725:
726:                    /* Now for each servlet that's not a controller */
727:                    StdServlet checkServlet;
728:
729:                    for (Enumeration se = mySchema.getServlets(); se
730:                            .hasMoreElements();) {
731:                        checkServlet = (StdServlet) se.nextElement();
732:                        secur.clear();
733:                        secur.setField("ControllerClass", checkServlet
734:                                .getClass().getName());
735:                        secur.setField("GroupName", request
736:                                .getParameter("GroupName"));
737:
738:                        if (StringUtil.notNull(
739:                                request.getParameter(checkServlet.getClass()
740:                                        .getName())).equals("Y")) {
741:
742:                            /* check that permission is allowed */
743:                            if (!secur.find()) {
744:                                secur.setField("States", "*");
745:                                secur.add();
746:                                response.addOutput(new Output(
747:                                        "Permission granted for " + "Servlet "
748:                                                + checkServlet.getTitle()));
749:                                changes++;
750:                            }
751:                        } else {
752:
753:                            /* make sure permission is NOT allowed */
754:                            if (secur.find()) {
755:                                secur.delete();
756:                                response.addOutput(new Output(
757:                                        "Permission removed for " + "Servlet "
758:                                                + checkServlet.getTitle()));
759:                                changes++;
760:                            }
761:                        } /* else not allowed */
762:
763:                    } /* for each servlet in the schema */
764:
765:                    if (changes == 0) {
766:                        response.addOutput(new Output("No changes required"));
767:                    }
768:                } catch (DBException de) {
769:                    throw new ControllerException(myName
770:                            + ":Unable to update security " + "info", de);
771:                }
772:            } /* updControllerState() */
773:
774:            /**
775:             * Update the allowed states
776:             *
777:             * @param response the ControllerResponse object
778:             * @param request  the ControllerRequest object
779:             * @throws NonHandleableException upon fatal error
780:             */
781:            private void runUpdstatesState(ControllerRequest request,
782:                    ControllerResponse response) throws ControllerException,
783:                    NonHandleableException {
784:                String myName = (this Class + "updStatesState()");
785:                Controller con = ConfigManager.getControllerFactory()
786:                        .getController(request.getParameter("ControllerClass"));
787:
788:                try {
789:                    Hashtable allStates = con.getStates();
790:                    String oneStateName;
791:                    State oneState;
792:                    StringBuffer newSecurity = new StringBuffer("");
793:                    boolean allAllowed = true;
794:
795:                    for (Enumeration e = allStates.keys(); e.hasMoreElements();) {
796:                        oneStateName = (String) e.nextElement();
797:                        oneState = (State) allStates.get(oneStateName);
798:
799:                        if (StringUtil.notNull(
800:                                request.getParameter(oneStateName)).equals("Y")) {
801:                            newSecurity.append(oneStateName);
802:                            newSecurity.append(", ");
803:                            response.addOutput(new Output(
804:                                    "Access granted to state '"
805:                                            + oneState.getDescription() + "'"));
806:                        } else {
807:                            response.addOutput(new Output(
808:                                    "Access denied to state '"
809:                                            + oneState.getDescription() + "'"));
810:                            allAllowed = false;
811:                        }
812:                    } /* for each state of this controller */
813:
814:                    ControllerSecurity secur = new ControllerSecurity(
815:                            SecuredDBObject.SYSTEM_ACCOUNT);
816:                    secur.setDataContext(request.getDataContext());
817:                    secur.setField("ControllerClass", con.getClass().getName());
818:                    secur.setField("GroupName", request
819:                            .getParameter("GroupName"));
820:
821:                    if (allAllowed) {
822:                        newSecurity = new StringBuffer("*");
823:                    }
824:                    if (secur.find()) {
825:                        secur.setField("States", newSecurity.toString());
826:                        secur.update();
827:                    } else {
828:                        secur.setField("States", newSecurity.toString());
829:                        secur.add();
830:                    }
831:                } catch (DBException de) {
832:                    throw new ControllerException(myName
833:                            + ":Database exception reading " + "security info",
834:                            de);
835:                }
836:            } /* updStatesState() */
837:
838:        } /* ControllerSecurityMatrix */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.