1 18 19 package org.objectweb.jac.aspects.authentication; 20 21 import java.util.HashSet ; 22 import java.util.Set ; 23 import org.objectweb.jac.core.AspectComponent; 24 import org.objectweb.jac.core.rtti.ClassItem; 25 import org.objectweb.jac.core.rtti.MethodItem; 26 import org.objectweb.jac.util.ExtArrays; 27 import org.objectweb.jac.util.Log; 28 29 39 40 public class AuthenticationAC extends AspectComponent 41 implements AuthenticationConf { 42 43 45 public static final String USER = "AuthenticationAC.USER"; 46 47 48 protected HashSet trustedUsers = new HashSet (); 49 50 56 57 public boolean isTrustedUser(String username) 58 { 59 Log.trace("authentication","isTrustedUser("+username+")"); 60 return trustedUsers.contains(username); 61 } 62 63 67 68 public Set getTrustedUsers() { 69 return trustedUsers; 70 } 71 72 AuthenticationWrapper wrapper; 73 AuthenticationWrapper getWrapper() { 74 if (wrapper==null) { 75 wrapper = new AuthenticationWrapper(this,authenticator,null); 76 } 78 return wrapper; 79 } 80 81 83 public void addTrustedUser(String username) { 84 Log.trace("authentication","addTrustedUser("+username+")"); 85 trustedUsers.add(username); 86 } 87 88 public void setController(String classes, 89 String methods, 90 MethodItem controller) { 91 Log.trace("authentication","setController("+ 92 classes+","+methods+","+controller+")"); 93 getWrapper().setController(controller); 94 pointcut("ALL",classes,methods, 96 wrapper,null); 97 } 98 99 public void setDisplayController(MethodItem controller) { 100 setController("org.objectweb.jac.core.Display", 101 ".*showCustomized.* || .*fullRefresh.*", 102 controller); 103 } 104 105 public void setAccessDeniedMessage(String message) { 106 getWrapper().setAccessDeniedMessage(message); 107 } 108 109 public void addRestrictedMethods(String classes, 110 String methods, 111 String objects ) { 112 Log.trace("authentication","addRestrictedMethods("+ 113 classes+","+methods+","+objects+")"); 114 pointcut(objects,classes,methods, 115 getWrapper(),null); 116 } 117 118 public void addRestrictedObjects(String objects) { 119 pointcut(objects,"ALL","ALL", 120 getWrapper(),null); 121 } 122 123 public void addRestrictedObjects(String objects, String classes) { 124 pointcut(objects,classes,"ALL", 125 getWrapper(),null); 126 } 127 128 Authenticator authenticator; 129 130 public void setAuthenticator(ClassItem authenticatorClass) { 131 setAuthenticator(authenticatorClass, ExtArrays.emptyStringArray); 132 } 133 134 public void setAuthenticator(ClassItem authenticatorClass, String [] parameters) { 135 Log.trace("authentication","setAuthenticator("+authenticatorClass+")"); 136 try { 137 authenticator = (Authenticator)authenticatorClass.newInstance(parameters); 138 } catch(Exception e) { 139 throw new RuntimeException ("Failed to instanciate authenticator "+ 140 authenticatorClass+": "+e); 141 } 142 getWrapper().setAuthenticator(authenticator); 143 } 144 145 } 146 | Popular Tags |