public abstract class SecurityContext extends AbstractContext
A high-level security context integrated with OSGi.
When granting/revoking permission the order is important. For example, the following code revokes all configurable permissions except for setting the concurrency level.
SecurityContext ctx = SecurityContext.enter(); try { ctx.revoke(Configurable.RECONFIGURE_PERMISSION); ctx.grant(ConcurrentContext.CONCURRENCY.getReconfigurePermission()); ... ConcurrentContext.CONCURRENCY.reconfigure(0); // Ok (permission specifically granted). ... } finally { ctx.exit(); // Back to previous security settings. }
Modifier and Type | Class and Description |
---|---|
static class |
SecurityContext.Permission<T>
A permission associated to a specific class/action/instance.
|
Modifier | Constructor and Description |
---|---|
protected |
SecurityContext()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
check(SecurityContext.Permission<?> permission)
Checks if the specified permission is granted.
|
static SecurityContext |
enter()
Enters and returns a new security context instance.
|
void |
grant(SecurityContext.Permission<?> permission)
Grants the specified permission (convenience method).
|
abstract void |
grant(SecurityContext.Permission<?> permission,
Object certificate)
Grants the specified permission.
|
abstract boolean |
isGranted(SecurityContext.Permission<?> permission)
Indicates if the specified permission is granted.
|
void |
revoke(SecurityContext.Permission<?> permission)
Revokes the specified permission (convenience method).
|
abstract void |
revoke(SecurityContext.Permission<?> permission,
Object certificate)
Revokes the specified permission.
|
current, current, enter, enterInner, exit, getOuter, inherit, inner
public static SecurityContext enter()
public static void check(SecurityContext.Permission<?> permission)
permission
- the permission to check.SecurityException
- if the specified permission is not granted.public abstract boolean isGranted(SecurityContext.Permission<?> permission)
permission
- the permission to check.public abstract void grant(SecurityContext.Permission<?> permission, Object certificate)
permission
- the permission to grant.certificate
- the certificate used to grant that permission or
null
if none.SecurityException
- if the specified permission cannot be granted.public abstract void revoke(SecurityContext.Permission<?> permission, Object certificate)
permission
- the permission to grant.certificate
- the certificate used to grant that permission or
null
if none.SecurityException
- if the specified permission cannot be revoked.public final void grant(SecurityContext.Permission<?> permission)
permission
- the permission to grant.SecurityException
- if the specified permission cannot be granted.public final void revoke(SecurityContext.Permission<?> permission)
permission
- the permission to grant.SecurityException
- if the specified permission cannot be revoked.Copyright © 2005-2013 Javolution. All Rights Reserved.