PermissionsLoader
John Mazzitelli
mazz at redhat.com
Thu Dec 16 20:56:29 UTC 2010
I introduced a new PermissionsLoader object and refactored all uses of
GWTServiceLookup.getAuthorizationService() so it uses the new loader.
This DOES NOT CACHE any permissions. However, it now provides a single
place where all loading of permissions will/should take place (assuming
everyone uses it now).
to use:
new PermissionsLoader().loadExplicitGlobalPermissions(new
PermissionsLoadedListener() {
public void onPermissionsLoaded(Set<Permissions> perms) {
...do your thing...
}
});
There are some benefits:
1) I looked at all uses of the AuthorizationService and they all had the
same pattern - onFailure() always logged a error message (but some
people duplicated Message.properties, even though they said basically
the same thing). onFailure rarely did anything else - if it did
something else, it was usually small, ~1 line of code. This
PermissionsLoader now provides you the onFailure code so we don't have
to cut-n-paste the same thing everywhere. And it therefore consistently
provides the same error message ("Failed to load the permissions - you
have none" or something like that). if you really need the exception
that occurred, you can get it from getLastError of the loader object
(but in all the usages of AuthorizationService, no one needed the
exception except to log it, which the loader now does for you).
2) You now only have to implement a single callback method -
onPermissionsLoaded. You will be given all permissions that you have as
the argument to that method - see javadoc for more.
3) We now have a single place where all permissions loading will take
place that will allow us to track the loading of permissions in the app
on the client side and will allow us to more easily introduce either a)
some caching in the future if we deem it necessary and/or b) code that
can help limit the amount of times we ask for the same kind of
permissions multiple times in the same request.
4) I cut down the number of lines of code needed and the code around
auth perm loading is now less cluttered.
More information about the rhq-devel
mailing list