KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > services > dbobj > DBObjSecurity


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.dbobj;
66
67 import com.jcorporate.expresso.core.controller.ControllerRequest;
68 import com.jcorporate.expresso.core.db.DBException;
69 import com.jcorporate.expresso.core.dbobj.DBObject;
70 import com.jcorporate.expresso.core.dbobj.Schema;
71 import com.jcorporate.expresso.core.dbobj.SchemaFactory;
72 import com.jcorporate.expresso.core.dbobj.SecuredDBObject;
73 import com.jcorporate.expresso.core.dbobj.ValidValue;
74
75 import java.util.Enumeration JavaDoc;
76 import java.util.Iterator JavaDoc;
77 import java.util.Vector JavaDoc;
78
79
80 /**
81  * <p/>
82  * <p>Database Object Security: What is this user allowed to do with a given
83  * database object</p>
84  *
85  * @author Michael Nash
86  */

87 public class DBObjSecurity
88         extends SecurityDBObject {
89     /**
90      * field names
91      */

92     public static final String JavaDoc DBOBJECT_NAME = "DBObjectName";
93     public static final String JavaDoc GROUP_NAME = "GroupName";
94     public static final String JavaDoc METHOD_ALLOWED_CODE = "MethodCode";
95
96     //private static Category log = null;
97
private Vector JavaDoc dbObjList = null;
98
99     /**
100      * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject#SecuredDBObject
101      */

102     public DBObjSecurity()
103             throws DBException {
104         super();
105     } /* DBObjSecurity() */
106
107
108     /**
109      * Construct a DBObjSecurity object with the given owner credentials
110      *
111      * @param uid the owner uid
112      */

113     public DBObjSecurity(int uid)
114             throws DBException {
115         super(uid);
116     }
117
118     /**
119      * For using DBObjects within Controllers. Initializes based upon the current
120      * user and the requested db. [Of course this can be modified later]
121      *
122      * @param request - The controller request handed to you by the framework.
123      */

124     public DBObjSecurity(ControllerRequest request)
125             throws DBException {
126         super(request);
127     }
128
129     /**
130      * Extends the checkAllRefs method to check for valid UserGroup
131      */

132     protected void checkAllRefs()
133             throws DBException {
134         checkRef(GROUP_NAME, new UserGroup(SecuredDBObject.SYSTEM_ACCOUNT),
135                 "Invalid " + getString(getMetaData().getDescription(GROUP_NAME)));
136     } /* checkAllRefs() */
137
138
139     /**
140      * Loads the schema and sets the approprate valid values for the schemas
141      * and the member's descriptions
142      *
143      * @param schemaName The schema name to load
144      * @param schemaDescrip The friendly name of the schema
145      * @param oList ??
146      */

147     private void doSchema(String JavaDoc schemaName, String JavaDoc schemaDescrip,
148                           Vector JavaDoc oList)
149             throws DBException {
150         /** Note: If anything goes wrong loading a schema here, we just log
151          * it and skip processing for this schema.
152          */

153         Schema oneSchema = SchemaFactory.getInstance().getSchema(schemaName);
154         if (oneSchema == null) {
155             return;
156         }
157         DBObject oneDBObj = null;
158         ValidValue oneVal = null;
159
160         /* Now add all of the objects in this schema to our list */
161         for (Enumeration JavaDoc e = oneSchema.getMembers(); e.hasMoreElements();) {
162             oneDBObj = (DBObject) e.nextElement();
163             oneVal = new ValidValue(oneDBObj.getClass().getName(),
164                     schemaDescrip + ": " +
165                     oneDBObj.getMetaData().getDescription());
166             oList.addElement(oneVal);
167         }
168     } /* doSchema(String, String, Vector) */
169
170
171     /**
172      * Override the method getValues to provide specific values for our
173      * multi-valued fields
174      *
175      * @param fieldName Fielname to retrieve values for
176      * @return Vector of ValidValue Value/description pairs for this field
177      * @throws DBException If the values cannot be retrieved
178      */

179     public synchronized Vector JavaDoc getValidValues(String JavaDoc fieldName)
180             throws DBException {
181         if (fieldName.equals(METHOD_ALLOWED_CODE)) {
182             Vector JavaDoc myValues = new Vector JavaDoc(4);
183             myValues.addElement(new ValidValue(SecuredDBObject.ADD, "Add"));
184             myValues.addElement(new ValidValue(SecuredDBObject.UPDATE, "Update"));
185             myValues.addElement(new ValidValue(SecuredDBObject.DELETE, "Delete"));
186             myValues.addElement(new ValidValue(SecuredDBObject.SEARCH, "Search"));
187
188             return myValues;
189         } else if (fieldName.equals(DBOBJECT_NAME)) {
190             if (dbObjList == null) {
191                 SchemaList myList = new SchemaList(SecuredDBObject.SYSTEM_ACCOUNT);
192                 myList.setDataContext(getDataContext());
193
194                 SchemaList oneList = null;
195                 dbObjList = new Vector JavaDoc(10);
196                 dbObjList.addElement(new ValidValue("com.jcorporate.expresso." + "core.dbobj.AutoDBObject",
197                         "Expresso: Automatic DB Objects"));
198                 doSchema("com.jcorporate.expresso.core.ExpressoSchema",
199                         "Expresso", dbObjList);
200
201                 /* Get any database objects listed as existing in another */
202
203                 /* database */
204                 DBOtherMap otherList = new DBOtherMap();
205                 otherList.setDataContext(getDataContext());
206
207                 DBOtherMap oneOther = null;
208
209                 for (Iterator JavaDoc e2 = otherList.searchAndRetrieveList().iterator();
210                      e2.hasNext();) {
211                     oneOther = (DBOtherMap) e2.next();
212                     dbObjList.addElement(new ValidValue(oneOther.getField("DBObjName"),
213                             oneOther.getField("Descrip")));
214                 }
215                 /* Now get all of the schemas listed in the database as well */
216                 for (Iterator JavaDoc sl = myList.searchAndRetrieveList().iterator();
217                      sl.hasNext();) {
218                     oneList = (SchemaList) sl.next();
219                     doSchema(oneList.getField("SchemaClass"),
220                             oneList.getField("Descrip"), dbObjList);
221                 } /* for each schema list */
222
223             }
224
225             return dbObjList;
226         }
227
228         return super.getValidValues(fieldName);
229     } /* getValidValues(String) */
230
231
232     /**
233      * @see com.jcorporate.expresso.core.dbobj.SecuredDBObject#setupFields()
234      */

235     protected synchronized void setupFields()
236             throws DBException {
237         setTargetTable("DBOBJSECURITY");
238         setName("DBOBJSECURITY");
239         setDescription("DB Object Security");
240         setCharset("ISO-8859-1");
241         addField(DBOBJECT_NAME, "varchar", 80, false, "dbobjName");
242         addField(GROUP_NAME, "char", 30, false, "groupName");
243         addField(METHOD_ALLOWED_CODE, "char", 1, false, "methodAllowed");
244         addKey(DBOBJECT_NAME);
245         addKey(METHOD_ALLOWED_CODE);
246         addKey(GROUP_NAME);
247         setStringFilter(DBOBJECT_NAME, "stripFilter");
248         setStringFilter(GROUP_NAME, "stripFilter");
249         setStringFilter(METHOD_ALLOWED_CODE, "stripFilter");
250         setMultiValued(GROUP_NAME);
251         setLookupObject(GROUP_NAME, UserGroup.class.getName());
252         setMultiValued(METHOD_ALLOWED_CODE);
253         setMultiValued(DBOBJECT_NAME);
254     } /* setupFields() */
255
256 } /* DBObjSecurity */
257
258
Popular Tags