// The we setup our aop to wrap objects
Aspects aspects = new Aspects();
aspects.interceptor(Pointcuts.instancesOf(SecureObject.class),
Pointcuts.ALL_METHODS, new AccessInterceptor(methodAccessManager));
ProxyFactory proxyFactory = ProxyFactory.getInstance(aspects);
System.out.println("Setting our subject to \"We\" with empty principals.");
Subject subject = new Subject("We");
Set principals = new HashSet();
subject.setPrincipals(principals);
Subject.set(subject);
// We create an object which has protected methods
SecureObject object = (SecureObject) proxyFactory.wrap(new SecureObjectImpl("Dont change me!"));
System.out.print("We try to call setName() on \""+object.getName()+"\" ... ");
try {
object.setName("Changed!");
} catch (Exception e) {
System.out.println("denied.");