KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > acl > eventhandler > ACLocalPolicyEventHandler


1 package de.webman.acl.eventhandler;
2
3 import java.util.*;
4
5 import com.teamkonzept.web.*;
6 import com.teamkonzept.lib.*;
7 import com.teamkonzept.webman.*;
8 import com.teamkonzept.webman.mainint.*;
9 import com.teamkonzept.webman.mainint.events.*;
10 import de.webman.acl.*;
11
12 /**
13     Creates, modifies or deletes local policies
14  * @author $Author: alex $
15  * @version $Revision: 1.3 $
16  */

17 public class ACLocalPolicyEventHandler extends DefaultEventHandler implements ParameterTypes, DatabaseDefaults, FrameConstants
18 {
19 private ACLocalPolicyEventHandler() {}
20
21     private static ACLocalPolicyEventHandler instance = new ACLocalPolicyEventHandler();
22
23     public static ACLocalPolicyEventHandler getInstance()
24     {
25         return instance;
26     }
27
28     public void handleEvent(TKEvent evt) throws TKException
29     {
30         try {
31             WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(), ContextConstants.ACCESS_CONTROL);
32
33             String JavaDoc loginId = evt.getParameter( PARAMETER, "LOGIN_ID" );
34             String JavaDoc contextId = evt.getParameter( PARAMETER, "CONTEXT_ID" );
35             String JavaDoc roleId = evt.getParameter( PARAMETER, "ROLE_ID" );
36             String JavaDoc policyId = evt.getParameter( PARAMETER, "POLICY_ID" );
37             String JavaDoc nodeId = evt.getParameter( PARAMETER, "CONTENT_NODE_ID");
38             String JavaDoc modeString = evt.getParameter( PARAMETER, "MODE");
39             boolean mode = (modeString != null && modeString.equals("ALLOW"));
40             String JavaDoc actionString = evt.getParameter( PARAMETER, "ACTION");
41
42             Login theUser = null;
43             Context theContext = null;
44             Role theRole = null;
45             Policy thePolicy = null;
46
47             // get objects
48
if (loginId != null && loginId.length() > 0)
49             {
50                 theUser = LoginFactory.getInstance().getLogin(new Integer JavaDoc(loginId));
51             }
52             if (contextId != null && contextId.length() > 0)
53             {
54                 theContext = ContextFactory.getInstance().getContext(new Integer JavaDoc(contextId));
55             }
56             if (roleId != null && roleId.length() > 0)
57             {
58                 theRole = RoleFactory.getInstance().getRole(new Integer JavaDoc(roleId));
59             }
60             if (policyId != null && policyId.length() > 0)
61             {
62                 thePolicy = PolicyFactory.getInstance().getPolicy(new Integer JavaDoc(policyId));
63             }
64
65             // create a new policy
66
if (actionString != null && actionString.equals("NEW"))
67             {
68                 if (theUser != null && theRole != null && theContext != null && thePolicy == null)
69                 {
70                     PolicyFactory.getInstance().createPolicy(theUser,
71                                                                theRole,
72                                                                theContext,
73                                                                Policy.CONTENT_TREE_ID,
74                                                                new Integer JavaDoc(nodeId),
75                                                                mode);
76                 }
77             }
78             // modify an existing policy ...
79
else if (actionString != null && actionString.equals("MODIFY"))
80             {
81                 if (thePolicy != null)
82                 {
83                     boolean sameLogin = thePolicy.getLoginID().toString().equals(loginId);
84                     boolean sameNode = thePolicy.getObjectReference().toString().equals(nodeId);
85                     // ... but create a new policy if it is inherited
86
if (
87                         // same user but different node
88
(sameLogin && !sameNode)
89                         || // same node but different user
90
(sameNode && !sameLogin)
91                         || // different node and different user
92
(!sameNode && !sameLogin)
93                         // is it possible to make this any simpler?
94
)
95                     {
96                         if (theUser != null && theRole != null && theContext != null)
97                         {
98                             PolicyFactory.getInstance().createPolicy(theUser,
99                                                                        theRole,
100                                                                        theContext,
101                                                                        Policy.CONTENT_TREE_ID,
102                                                                        new Integer JavaDoc(nodeId),
103                                                                        mode);
104                         }
105                     }
106                     // ... modify it
107
else
108                     {
109                         if (mode)
110                             thePolicy.allow();
111                         else
112                             thePolicy.deny();
113
114                         PolicyFactory.getInstance().modifyPolicy(thePolicy);
115                     }
116                 }
117             }
118             else if (actionString != null && actionString.equals("DELETE"))
119             {
120                 if (thePolicy != null && thePolicy.getLoginID().equals(new Integer JavaDoc(loginId)))
121                 {
122                     PolicyFactory.getInstance().deletePolicy(thePolicy);
123                 }
124             }
125             TKHTMLTemplate t = evt.getPrepHTMLTemplate( "f_ac_ce_user.tmpl" );
126             HTMLUtils.fillFrameSet( t, LEFT_FRAME_WIDTH, "AC_CE_NODE_LIST", "AC_CE_RIGHTS" );
127             t.set( evt.getParams().getClass( PARAMETER ) );
128             TreeUtils.keepOpenNodes( evt, t );
129             WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t, ACCESS_CONTROL);
130             evt.finishTemplate(t);
131
132         } catch (Throwable JavaDoc e) {
133             throw WebmanExceptionHandler.getException(e);
134         }
135     }
136
137     public boolean isHandler(TKEvent evt)
138     {
139         return evt.getName().equalsIgnoreCase( "AC_LOCAL_POLICY" );
140     }
141
142 }
143
Popular Tags