The use of interfaces (such as Permission
above) makes it easy for custom policies to support any security actions. For example:[code] class Policy extends SecurityContext implements DatabaseAccess.Permission, FileAccess.Permission { public boolean isReadable(Table table) { return !table.isPrivate(); } public boolean isWritable(Table table) { return Session.getSession().getUser().isAdministrator(); } public boolean isReadable(File file) { return true; } public boolean isWritable(File file) { return false; } } ... Policy localPolicy = new Policy(); SecurityContext.enter(localPolicy); // Current thread overrides default policy (configurable) try { // (if allowed, ref. SecurityContext.isReplaceable()) ... DatabaseAccess.isReadAllowed(table); ... FileAccess.isWriteAllowed(file); ... } finally { SecurityContext.exit(); }[/code]
The default permissions managed by the {@link #DEFAULT} implementationare the permission to {@link #isReplaceable replace} the current securitycontext by default) and the permission to {@link #isConfigurable configure}the application.
@author Jean-Marie Dautelle @version 5.2, August 5, 2007
|
|