1 7 package org.jboss.security.jacc; 8 9 import java.security.Permission ; 10 import java.security.PermissionCollection ; 11 import javax.security.jacc.PolicyConfiguration ; 12 import javax.security.jacc.PolicyContextException ; 13 14 import org.jboss.util.state.StateMachine; 15 import org.jboss.util.state.IllegalTransitionException; 16 import org.jboss.util.state.State; 17 import org.jboss.logging.Logger; 18 19 26 public class JBossPolicyConfiguration 27 implements PolicyConfiguration 28 { 29 private static Logger log = Logger.getLogger(JBossPolicyConfiguration.class); 30 31 private String contextID; 32 33 private DelegatingPolicy policy; 34 35 private StateMachine configStateMachine; 36 37 private boolean trace; 38 39 protected JBossPolicyConfiguration(String contextID, DelegatingPolicy policy, 40 StateMachine configStateMachine) 41 throws PolicyContextException 42 { 43 this.contextID = contextID; 44 this.policy = policy; 45 this.configStateMachine = configStateMachine; 46 47 if (contextID == null) 48 throw new IllegalArgumentException ("contextID cannot be null"); 49 if (policy == null) 50 throw new IllegalArgumentException ("policy cannot be null"); 51 if (configStateMachine == null) 52 throw new IllegalArgumentException ("configStateMachine cannot be null"); 53 54 validateState("getPolicyConfiguration"); 55 trace = log.isTraceEnabled(); 56 if( trace ) 57 log.trace("ctor, contextID="+contextID); 58 } 59 60 void initPolicyConfiguration(boolean remove) 61 throws PolicyContextException 62 { 63 validateState("getPolicyConfiguration"); 64 policy.initPolicyConfiguration(contextID, remove); 65 } 66 67 public void addToExcludedPolicy(Permission permission) 68 throws PolicyContextException 69 { 70 if( trace ) 71 log.trace("addToExcludedPolicy, p="+permission); 72 validateState("addToExcludedPolicy"); 73 policy.addToExcludedPolicy(contextID, permission); 74 } 75 76 public void addToExcludedPolicy(PermissionCollection permissions) 77 throws PolicyContextException 78 { 79 if( trace ) 80 log.trace("addToExcludedPolicy, pc="+permissions); 81 validateState("addToExcludedPolicy"); 82 policy.addToExcludedPolicy(contextID, permissions); 83 } 84 85 public void addToRole(String roleName, Permission permission) 86 throws PolicyContextException 87 { 88 if( trace ) 89 log.trace("addToRole, roleName="+roleName+", p="+permission); 90 validateState("addToRole"); 91 policy.addToRole(contextID, roleName, permission); 92 } 93 94 public void addToRole(String roleName, PermissionCollection permissions) 95 throws PolicyContextException 96 { 97 if( trace ) 98 log.trace("addToRole, roleName="+roleName+", pc="+permissions); 99 validateState("addToRole"); 100 policy.addToRole(contextID, roleName, permissions); 101 } 102 103 public void addToUncheckedPolicy(Permission permission) 104 throws PolicyContextException 105 { 106 if( trace ) 107 log.trace("addToUncheckedPolicy, p="+permission); 108 validateState("addToUncheckedPolicy"); 109 policy.addToUncheckedPolicy(contextID, permission); 110 } 111 112 public void addToUncheckedPolicy(PermissionCollection permissions) 113 throws PolicyContextException 114 { 115 if( trace ) 116 log.trace("addToUncheckedPolicy, pc="+permissions); 117 validateState("addToUncheckedPolicy"); 118 policy.addToUncheckedPolicy(contextID, permissions); 119 } 120 121 public void commit() 122 throws PolicyContextException 123 { 124 if( trace ) 125 log.trace("commit"); 126 validateState("commit"); 127 policy.commit(contextID); 128 } 129 130 public void delete() 131 throws PolicyContextException 132 { 133 if( trace ) 134 log.trace("delete"); 135 validateState("delete"); 136 policy.delete(contextID); 137 } 138 139 public String getContextID() 140 throws PolicyContextException 141 { 142 validateState("getContextID"); 143 return contextID; 144 } 145 146 public boolean inService() 147 throws PolicyContextException 148 { 149 validateState("inService"); 150 State state = configStateMachine.getCurrentState(); 151 boolean inService = state.getName().equals("inService"); 152 return inService; 153 } 154 155 public void linkConfiguration(PolicyConfiguration link) 156 throws PolicyContextException 157 { 158 if( trace ) 159 log.trace("linkConfiguration, linkTo: "+link.getContextID()); 160 validateState("linkConfiguration"); 161 policy.linkConfiguration(contextID, link); 162 } 163 164 public void removeExcludedPolicy() 165 throws PolicyContextException 166 { 167 if( trace ) 168 log.trace("removeExcludedPolicy"); 169 validateState("removeExcludedPolicy"); 170 policy.removeExcludedPolicy(contextID); 171 } 172 173 public void removeRole(String roleName) 174 throws PolicyContextException 175 { 176 if( trace ) 177 log.trace("removeRole: "+roleName); 178 validateState("removeRole"); 179 policy.removeRole(contextID, roleName); 180 } 181 182 public void removeUncheckedPolicy() 183 throws PolicyContextException 184 { 185 if( trace ) 186 log.trace("removeUncheckedPolicy"); 187 validateState("removeUncheckedPolicy"); 188 policy.removeUncheckedPolicy(contextID); 189 } 190 191 protected void validateState(String action) 192 throws PolicyContextException 193 { 194 try 195 { 196 configStateMachine.nextState(action); 197 } 198 catch(IllegalTransitionException e) 199 { 200 log.debug("validateState failure", e); 201 throw new PolicyContextException ("Operation not allowed", e); 202 } 203 } 204 } 205 | Popular Tags |