1 10 package org.mmbase.security; 11 12 import java.util.Set ; 13 import java.util.HashSet ; 14 15 import org.mmbase.bridge.Query; 16 import org.mmbase.storage.search.Constraint; 17 18 26 public abstract class Authorization extends Configurable { 27 28 39 public abstract void create(UserContext user, int nodeid); 40 41 50 public abstract void update(UserContext user, int nodeid); 51 52 64 public abstract void remove(UserContext user, int nodeid); 65 66 77 public abstract boolean check(UserContext user, int nodeid, Operation operation); 78 79 80 81 90 public void verify(UserContext user, int nodeid, Operation operation) throws SecurityException { 91 if (!check(user, nodeid, operation)) { 92 throw new SecurityException ("Operation '" + operation + "' on " + nodeid + " was NOT permitted to " + user.getIdentifier()); 93 } 94 } 95 96 114 public abstract boolean check(UserContext user, int nodeid, int srcnodeid, int dstnodeid, Operation operation); 115 116 125 public void verify(UserContext user, int nodeid, int srcnodeid, int dstnodeid, Operation operation) throws SecurityException { 126 if (!check(user, nodeid, srcnodeid, dstnodeid, operation)) { 127 throw new SecurityException ("Operation '" + operation + "' on " + nodeid + " was NOT permitted to " + user.getIdentifier()); 128 } 129 } 130 131 139 public abstract String getContext(UserContext user, int nodeid) throws SecurityException ; 140 141 152 public abstract void setContext(UserContext user, int nodeid, String context) throws SecurityException ; 153 154 165 public abstract Set getPossibleContexts(UserContext user, int nodeid) throws SecurityException ; 166 167 168 178 public Set getPossibleContexts(UserContext user) throws SecurityException { 179 Set contexts = new HashSet (); 180 contexts.add(user.getOwnerField()); 181 return contexts; 182 } 183 184 200 201 public QueryCheck check(UserContext user, Query query, Operation operation) { 202 return NO_CHECK; 203 } 204 205 206 212 public static final QueryCheck NO_CHECK = new QueryCheck(false, null); 213 214 222 public static final QueryCheck COMPLETE_CHECK = new QueryCheck(true, null); 223 224 225 233 234 public static class QueryCheck { 235 Constraint constraint; 236 boolean check; 237 public QueryCheck(boolean ch, Constraint co) { 238 check = ch; constraint = co; 239 } 240 243 public boolean isChecked() { 244 return check; 245 } 246 250 public Constraint getConstraint() { 251 return constraint; 252 } 253 258 public String toString() { 259 return (check ? "CHECKED: " : "NOT CHECKED: ") + constraint; 260 } 261 262 263 } 264 } 265 | Popular Tags |