Examples

First simple example

You would like to define a configuration like the following with the Subversion Authentication Parser Module (SAPM for short).

[/]
* = r
[repository:/test]
harry = rw
brian = rw

First we need an instance of AccessRules class which stores all the rules.

AccessRules accessRules = new AccessRules();

The next step is to create the first rule

[/]
* = r

This can be achieved by using the following code snippet:

User user = UserFactory.createInstance("*");
AccessRule accessRuleRoot = new AccessRule("/");
accessRuleRoot.add(user, AccessLevel.READ);
accessRules.add(accessRuleRoot);

Now you have to create the second rule part.

[repository:/test]
harry = rw
brian = rw

The second part can be done with the following code:

User userHarry = UserFactory.createInstance("harry");
User userBrian = UserFactory.createInstance("brian");

AccessRule accessRule = new AccessRule("repository", "/test/trunk");
accessRule.add(userHarry, AccessLevel.READ_WRITE);
accessRule.add(userMicheal, AccessLevel.READ_WRITE);
accessRules.add(accessRule);

The final step is now that you check a user against the defined rules.

AccessLevel userPermission = accessRules.getAccess(user, repository, accessPath);

The user represents the user which tries to get access to the repository in the given path.

Enhanced Examples

You have defined the following rule set in your configuration file. Either you can load that file by using the AuthenticationFile class or you can create that structure in memory to use this as a permission system.

[groups]
c-developer = harry, brian
d-developer = michael, sally
e-developer = jonas
all-developer = @c-developer, @d-developer, @e-developer
[/]
* = r
[repository:/project-c/trunk]
@c-developer = rw
[repository:/project-d/trunk]
@d-developer = rw
[repository:/project-e/trunk]
@e-developer = rw
[global:/project/trunk]
@all-developer = rw