The source code is available here!
In Ori, a permission is composed of two String.
This is important, because you will never see any object representing a
permission in Ori.The first String represents a module, while the second
String represents the action you want to perform in this module.
Translated to code this will look like:
boolean result = token.hasPermission("Secret", "read");
So with this code we check if the user (token - see later) has the permission to perform the "read" action in the "Secret" module.
Why two String?
It brings an interesting feature. If you grant a permission
(see later) that look like [ "secret" , Ori.ANY ], the user will be able to perform
any action in the "secret" module.
On the other hand if the permission look like [ Ori.ANY , "read" ], the user
will be able to perform the "read" action in any module.
First of all, you need to create a comain, unfortunately that comes with some coding.
IDomain domain = Ori.createDomain( userRoleListProvider, rolePermissionListProvider, userPermissionListProvider, passwordEncoder, adminLogin, adminEncodedPassword);
Let's see all parameter one by one.
class UserRoleListProvider implements IUserRoleListProvider { public IUserRoleList getUserRoleList() { UserRoleList result = new UserRoleList(); result.addRoleToUser(LOGIN_A, "administrator"); result.addRoleToUser(LOGIN_A, "user"); result.addRoleToUser(LOGIN_B, "user"); result.addRoleToUser(LOGIN_C, "user"); return result; } }
class RolePermissionListProvider implements IRolePermissionListProvider { public IPermissionList getRoleList() { PermissionList pl = new PermissionList(); pl.addPermission("administrator", "Public", "read"); pl.addPermission("administrator", "Public", "write"); pl.addPermission("administrator", "Secret", "read"); pl.addPermission("administrator", "Secret", "write"); pl.addPermission("user", "Public", "read"); pl.addPermission("user", "Public", "write"); return pl; } }
class UserPermissionListProvider implements IUserPermissionListProvider { public IPermissionList getUserPermissionList() { PermissionList pl = new PermissionList(); pl.addPermission(LOGIN_C,"Secret","read"); return pl; } }
This can be done by implementing ori.IPasswordEncoder.
You have to implement the encode function which encode your password.
There is an implementation: ori.impl.encoder.MD5HexaEncoder, it converts the password in
MD5 and then converts it to hexa. So if your password is "test", the result will be
"098f6bcd4621d373cade4e832627b4f6" (which is kind of database friendly). You can test it with
the ori.impl.encoder.Encoder swing tool. The password won't be encoded if you don't
implement it and you pass null!
IPasswordEncoder passwordEncoder = new MD5HexaEncoder();
You can declare a superuser/root/admin user by giving it's login and it's encoded password (so you can store it in a config file) . A user with the same login, won't be able to login! Can be null (so there won't be such a user)! This implicit user has the [ Ori.ANY , Ori.ANY ] permission.