|
J avolution v5.2 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavolution.context.Context
javolution.context.SecurityContext
public abstract class SecurityContext
This class represents a high-level security context (low level security being addressed by the system security manager).
Applications may extend this base class to address specific security
requirements. For example:
// This class defines custom policy with regards to database access.
public abstract class DatabaseAccess extends SecurityContext {
public static boolean isReadAllowed(Table table) {
SecurityContext policy = SecurityContext.current();
return (policy instanceof DatabaseAccess.Permission) ?
((DatabaseAccess.Permission)policy).isReadable(table) : false;
}
public interface Permission {
boolean isReadable(Table table);
boolean isWritable(Table table);
}
}
The use of interfaces (such as Permission above) makes
it easy for custom policies to support any security actions.
For example:
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();
}
The default permissions managed by the DEFAULT implementation
are the permission to replace the current security
context by default) and the permission to modify
all the application configuration settings.
| Field Summary | |
|---|---|
static Configurable<java.lang.Class<? extends SecurityContext>> |
DEFAULT
Holds the default security context implementation (configurable). |
| Fields inherited from class javolution.context.Context |
|---|
ROOT |
| Constructor Summary | |
|---|---|
protected |
SecurityContext()
Default constructor. |
| Method Summary | |
|---|---|
protected void |
enterAction()
The action to be performed after this context becomes the current context. |
protected void |
exitAction()
The action to be performed before this context is no more the current context. |
static SecurityContext |
getCurrent()
Returns the current security context. |
static SecurityContext |
getDefault()
Returns the default instance ( DEFAULT implementation). |
boolean |
isModifiable(Configurable cfg)
Indicates if this security context allows modification of the configuration settings
(default true). |
boolean |
isReplaceable()
Indicates if a new security context can be entered (default true). |
| Methods inherited from class javolution.context.Context |
|---|
enter, enter, exit, exit, getOuter, getOwner, setCurrent, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Configurable<java.lang.Class<? extends SecurityContext>> DEFAULT
| Constructor Detail |
|---|
protected SecurityContext()
| Method Detail |
|---|
public static SecurityContext getCurrent()
getDefault() is returned.
public static SecurityContext getDefault()
DEFAULT implementation).
protected final void enterAction()
Context
enterAction in class Contextprotected final void exitAction()
Context
exitAction in class Contextpublic boolean isReplaceable()
true). Applications may return false and
prevent untrusted code to increase their privileges. Usually,
such security setting should also prevent reconfiguring of the
default context by making DEFAULT not
modifiable.
true if a new security context can be entered;
false otherwise.public boolean isModifiable(Configurable cfg)
configuration settings
(default true). Applications may override this method
to return false and prevent untrusted code to update the
some/all configuration parameters.
cfg - the configurable to check if modifiable.
true if the specified configurable can be modified;
false otherwise.
|
J avolution v5.2 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||