KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > acl > resolver > SequentialResolver


1 package de.webman.acl.resolver;
2
3 import java.util.Hashtable JavaDoc;
4 import com.teamkonzept.lib.TKException;
5 import com.teamkonzept.lib.TKVector;
6 import de.webman.acl.EventFactory;
7 import de.webman.acl.Login;
8 import de.webman.acl.Policy;
9 import de.webman.acl.PolicyFactory;
10 import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
11
12 /**
13  * Resolves access rights for a given login object in a strictly
14  * sequential manner.
15  *
16  * @version 1.0
17  * @since 1.0
18  * @author © 2001 Webman AG
19  */

20 public class SequentialResolver
21     extends ResolverBase
22     implements Checker
23 {
24
25     // $Header: /cvsroot/webman-cms/source/webman/de/webman/acl/resolver/SequentialResolver.java,v 1.1 2001/08/20 08:25:09 mischa Exp $
26

27     // Constructors
28

29     /**
30      * Provide instantion only to package classes or subclasses.
31      *
32      * @param login the initial login object.
33      */

34     protected SequentialResolver (Login login)
35     {
36         super(login);
37     }
38
39
40     // Implementation of 'com.teamkonzept.webman.accesscontrol.resolver.Resolver'.
41

42     /**
43      * Implements a strictly sequential resolution algorithm.
44      * <OL TYPE="1">
45      * <LI> The access rights of the parents are resolved.
46      * <LI> The access rights defined context-wide are resolved.
47      * <LI> If <CODE>type</CODE> and <CODE>reference</CODE> are
48      * specified, the access rights defined object-specific are
49      * resolved.
50      * </OL>
51      *
52      * @param collection the distinct collection of permitted events.
53      * @param context the ID if the current context (<I>required</I>).
54      * @param type the current object type (<I>optional</I>).
55      * @param reference the current object reference (<I>optional</I>).
56      * @exception com.teamkonzept.lib.TKException if an error occured during
57      * access right resolution.
58      */

59     public final void resolve (Hashtable JavaDoc collection,
60                                Integer JavaDoc context,
61                                Integer JavaDoc type,
62                                Integer JavaDoc reference)
63         throws TKException
64     {
65         try
66         {
67             // 1. Resolve access rights of parents.
68
resolveParents(collection, context, type, reference);
69
70             // 2. Resolve access rights defined context-wide.
71
// 2.1 Add context-wide allowed events.
72
processEvents(collection,
73                           resolveEvents(context,
74                                         null,
75                                         null,
76                                         Boolean.TRUE),
77                           true);
78
79             // 2.2 Remove context-wide denied events.
80
processEvents(collection,
81                           resolveEvents(context,
82                                         null,
83                                         null,
84                                         Boolean.FALSE),
85                           false);
86
87             if (type != null && reference != null)
88             {
89                 // 3. Resolve access rights defined object-specific.
90
if (Policy.isGeneric(type))
91                 {
92                     // 3.1a Resolve events from defined policies.
93
ResolverFactory.getInstance()
94                                    .getResolver(this)
95                                    .resolve(collection,
96                                             context,
97                                             type,
98                                             reference);
99                 }
100                 else
101                 {
102                     // 3.1b Add object-specific allowed events.
103
processEvents(collection,
104                                   resolveEvents(context,
105                                                 type,
106                                                 reference,
107                                                 Boolean.TRUE),
108                                   true);
109
110                     // 3.2b Remove object-specific denied events.
111
processEvents(collection,
112                                   resolveEvents(context,
113                                                 type,
114                                                 reference,
115                                                 Boolean.FALSE),
116                                   false);
117                 }
118             }
119         }
120         catch (Exception JavaDoc x)
121         {
122             throw WebmanExceptionHandler.getException(x);
123         }
124     }
125
126
127     // Implementation of 'com.teamkonzept.webman.accesscontrol.resolver.Checker'.
128

129     /**
130      * Implements a strictly sequential checking algorithm.
131      * <OL TYPE="1">
132      * <LI> The access rights of the login are checked.
133      * <LI> If no applicable access rights were found, the access rights
134      * of the parents are checked.
135      * </OL>
136      *
137      * @param event the ID if the event to be checked (<I>required</I>).
138      * @param context the ID if the current context (<I>required</I>).
139      * @param type the current object type (<I>optional</I>).
140      * @param reference the current object reference (<I>optional</I>).
141      * @return <CODE>true</CODE> if the event is permitted explicitely,
142      * otherwise <CODE>false</CODE>.
143      * @exception com.teamkonzept.lib.TKException if an error occured during
144      * access right checking.
145      */

146     public final boolean check (Integer JavaDoc event,
147                                 Integer JavaDoc context,
148                                 Integer JavaDoc type,
149                                 Integer JavaDoc reference)
150         throws TKException
151     {
152         boolean check = false;
153
154         try
155         {
156             // Cache lookup.
157
Boolean JavaDoc value = checkingCacheRead(event,
158                                               context,
159                                               type,
160                                               reference);
161
162             if (value != null)
163             {
164                 // Cache hit: set check value.
165
check = value.booleanValue();
166             }
167             else
168             {
169                 // Cache miss: database lookup.
170
TKVector proxies = PolicyFactory.getInstance()
171                                                   .getPolicyProxies(event,
172                                                                     getLogin().getID(),
173                                                                     context,
174                                                                     type,
175                                                                     reference,
176                                                                     true);
177
178                 if (proxies != null &&
179                     proxies.size() > 0)
180                 {
181                     // Database hit: set check value.
182
check = PolicyFactory.getInstance()
183                                            .getPolicy((Integer JavaDoc) proxies.lastElement())
184                                            .isAllowed();
185                 }
186                 else
187                 {
188                     // Database miss: check parents.
189
check = checkParents(event, context, type, reference);
190                 }
191
192                 // Cache write.
193
checkingCacheWrite(event,
194                                    context,
195                                    type,
196                                    reference,
197                                    check
198                                     ? Boolean.TRUE
199                                     : Boolean.FALSE);
200             }
201         }
202         catch (Exception JavaDoc x)
203         {
204             throw WebmanExceptionHandler.getException(x);
205         }
206
207         return check;
208     }
209
210
211     // Convenience methods
212

213     /**
214      * Performs cache - and in case of failure - database lookup.
215      *
216      * @param context the ID if the current context (<I>required</I>).
217      * @param type the current object type (<I>optional</I>).
218      * @param reference the current object reference (<I>optional</I>).
219      * @param access the current access mode (<I>required</I>).
220      * @return the IDs of the resolved events.
221      * @exception com.teamkonzept.lib.TKException if an error occured during
222      * event retrieval.
223      */

224     private final TKVector resolveEvents (Integer JavaDoc context,
225                                           Integer JavaDoc type,
226                                           Integer JavaDoc reference,
227                                           Boolean JavaDoc access)
228         throws TKException
229     {
230         TKVector proxies = null;
231
232         try
233         {
234             proxies = resolutionCacheRead(context,
235                                           type,
236                                           reference,
237                                           access);
238
239             if (proxies == null)
240             {
241                 proxies = EventFactory.getInstance()
242                                         .getEventProxies(getLogin().getID(),
243                                                          context,
244                                                          type,
245                                                          reference,
246                                                          access.booleanValue());
247
248                 resolutionCacheWrite(context,
249                                      type,
250                                      reference,
251                                      access,
252                                      proxies);
253             }
254         }
255         catch (Exception JavaDoc x)
256         {
257             throw WebmanExceptionHandler.getException(x);
258         }
259
260         return proxies;
261     }
262
263 }
264
Popular Tags