User documentation

[One minute description]

Two minute tutorial

[Five minute introduction]

Project Info

Team

Feeds

Print
Two minute tutorial

This very short tutorial should get you up to speed with Gabriel in 2 minutes.

Configure permissions

access.acl mapping principals to permissions

ExampleUser  { CHANGE }

methods.acl mapping permissions to method access

CHANGE { example.SecureObject.setName }

Create access components

MethodAccessManager methodAccessManager = new DefaultMethodAccessManager();

Create aspects to wrap our object

// 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);

Set our credentials

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);

Try to access the object

// 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.");
    }
    System.out.println("object.name = " + object.getName());

    System.out.println("Adding \"ExampleUser\" to our principals.");
    // We are now member of group "ExampleUser
    principals.add(new Principal("ExampleUser"));
    // We have to set the principals again as they are copied not referenced
    // inside subject.
    subject.setPrincipals(principals);
    System.out.print("We try to call setName() on \""+object.getName()+"\" ... ");
    object.setName("changed!");
    System.out.println("changed.");
    System.out.println("object.name = " + object.getName());
Powered by Atlassian Confluence