1 24 package org.riotfamily.riot.security; 25 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 import org.riotfamily.riot.security.auth.RiotUser; 30 import org.riotfamily.riot.security.policy.AuthorizationPolicy; 31 import org.riotfamily.riot.security.session.AccessControlFilterPlugin; 32 import org.riotfamily.riot.security.session.AccessControlInterceptor; 33 import org.riotfamily.riot.security.session.SecurityContext; 34 35 36 37 44 public final class AccessController { 45 46 private AccessController() { 47 } 48 49 private static List policies; 50 51 56 static void setPolicies(List policies) { 57 AccessController.policies = policies; 58 } 59 60 public static RiotUser getCurrentUser() { 61 return SecurityContext.getCurrentUser(); 62 } 63 64 public static boolean isAuthenticatedUser() { 65 return getCurrentUser() != null; 66 } 67 68 public static boolean isGranted(String action, Object object) { 69 return isGranted(getCurrentUser(), action, object); 70 } 71 72 public static void checkPermission(String action, Object object) { 73 RiotUser subject = getCurrentUser(); 74 if (subject != null) { 75 Iterator it = policies.iterator(); 76 while (it.hasNext()) { 77 AuthorizationPolicy policy = (AuthorizationPolicy) it.next(); 78 int access = policy.checkPermission(subject, action, object); 79 if (access == AuthorizationPolicy.ACCESS_GRANTED) { 80 return; 81 } 82 else if (access == AuthorizationPolicy.ACCESS_DENIED) { 83 throw new AccessDeniedException(subject, action, object, policy); 84 } 85 } 86 } 87 throw new AccessDeniedException(subject, action, object, null); 88 } 89 90 public static boolean isGranted(RiotUser user, String action, Object object) { 91 if (user != null) { 92 Iterator it = policies.iterator(); 93 while (it.hasNext()) { 94 AuthorizationPolicy policy = (AuthorizationPolicy) it.next(); 95 int access = policy.checkPermission(user, action, object); 96 if (access == AuthorizationPolicy.ACCESS_GRANTED) { 97 return true; 98 } 99 else if (access == AuthorizationPolicy.ACCESS_DENIED) { 100 return false; 101 } 102 } 103 } 104 return false; 105 } 106 107 } 108 | Popular Tags |