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 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 loginId = evt.getParameter( PARAMETER, "LOGIN_ID" ); 34 String contextId = evt.getParameter( PARAMETER, "CONTEXT_ID" ); 35 String roleId = evt.getParameter( PARAMETER, "ROLE_ID" ); 36 String policyId = evt.getParameter( PARAMETER, "POLICY_ID" ); 37 String nodeId = evt.getParameter( PARAMETER, "CONTENT_NODE_ID"); 38 String modeString = evt.getParameter( PARAMETER, "MODE"); 39 boolean mode = (modeString != null && modeString.equals("ALLOW")); 40 String actionString = evt.getParameter( PARAMETER, "ACTION"); 41 42 Login theUser = null; 43 Context theContext = null; 44 Role theRole = null; 45 Policy thePolicy = null; 46 47 if (loginId != null && loginId.length() > 0) 49 { 50 theUser = LoginFactory.getInstance().getLogin(new Integer (loginId)); 51 } 52 if (contextId != null && contextId.length() > 0) 53 { 54 theContext = ContextFactory.getInstance().getContext(new Integer (contextId)); 55 } 56 if (roleId != null && roleId.length() > 0) 57 { 58 theRole = RoleFactory.getInstance().getRole(new Integer (roleId)); 59 } 60 if (policyId != null && policyId.length() > 0) 61 { 62 thePolicy = PolicyFactory.getInstance().getPolicy(new Integer (policyId)); 63 } 64 65 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 (nodeId), 75 mode); 76 } 77 } 78 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 if ( 87 (sameLogin && !sameNode) 89 || (sameNode && !sameLogin) 91 || (!sameNode && !sameLogin) 93 ) 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 (nodeId), 103 mode); 104 } 105 } 106 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 (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 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 |