Javolution 6.0.0 java
javolution.context.internal.SecurityContextImpl Class Reference
Inheritance diagram for javolution.context.internal.SecurityContextImpl:
[legend]
Collaboration diagram for javolution.context.internal.SecurityContextImpl:
[legend]

Classes

class  Action
 

Public Member Functions

boolean isGranted (Permission<?> permission)
 
void grant (Permission<?> permission, Object certificate) throws SecurityException
 
void revoke (Permission<?> permission, Object certificate) throws SecurityException
 
final void grant (Permission<?> permission)
 
final void revoke (Permission<?> permission)
 
void exit ()
 

Static Public Member Functions

static SecurityContext enter ()
 
static< T extends AbstractContext > T enter (Class< T > custom)
 
static void check (Permission<?> permission)
 
static AbstractContext current ()
 
static void inherit (AbstractContext ctx)
 

Protected Member Functions

SecurityContext inner ()
 
AbstractContext enterInner ()
 
AbstractContext getOuter ()
 

Static Protected Member Functions

static< T extends AbstractContext > T current (Class< T > type)
 

Static Private Member Functions

static SecurityContext currentSecurityContext ()
 

Private Attributes

FastTable< Actionactions = new FastTable<Action>()
 
AbstractContext outer
 

Static Private Attributes

static final ThreadLocal< AbstractContextCURRENT = new ThreadLocal<AbstractContext>()
 

Detailed Description

Holds the default implementation of SecurityContext.

Definition at line 17 of file SecurityContextImpl.java.

Member Function Documentation

◆ check()

static void javolution.context.SecurityContext.check ( Permission<?>  permission)
staticinherited

Checks if the specified permission is granted.

Parameters
permissionthe permission to check.
Exceptions
SecurityExceptionif the specified permission is not granted.

Definition at line 195 of file SecurityContext.java.

195  {
196  if (!currentSecurityContext().isGranted(permission))
197  throw new SecurityException(permission + " is not granted.");
198  }

References javolution.context.SecurityContext.currentSecurityContext(), and javolution.context.SecurityContext.isGranted().

Referenced by javolution.context.AbstractContext.enter(), and javolution.lang.Configurable< javolution.context.LogContext.Level >.reconfigure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ current() [1/2]

static AbstractContext javolution.context.AbstractContext.current ( )
staticinherited

Returns the current context for the current thread or

null

if this thread has no context (default).

Definition at line 61 of file AbstractContext.java.

61  {
62  return AbstractContext.CURRENT.get();
63  }

References javolution.context.AbstractContext.CURRENT.

Referenced by javolution.context.LogContext.currentLogContext(), javolution.context.SecurityContext.currentSecurityContext(), javolution.text.TextContext.currentTextContext(), javolution.xml.XMLContext.currentXMLContext(), javolution.context.LocalContext.enter(), javolution.context.ConcurrentContext.enter(), and javolution.context.LocalContext.Parameter< T >.get().

Here is the caller graph for this function:

◆ current() [2/2]

static <T extends AbstractContext> T javolution.context.AbstractContext.current ( Class< T >  type)
staticprotectedinherited

Returns the current context of specified type or

null

if none.

Definition at line 69 of file AbstractContext.java.

69  {
70  AbstractContext ctx = AbstractContext.CURRENT.get();
71  while (ctx != null) {
72  if (type.isInstance(ctx))
73  return (T) ctx;
74  ctx = ctx.outer;
75  }
76  return null;
77  }

References javolution.context.AbstractContext.CURRENT, and javolution.context.AbstractContext.outer.

◆ currentSecurityContext()

static SecurityContext javolution.context.SecurityContext.currentSecurityContext ( )
staticprivateinherited

Returns the current security context.

Definition at line 250 of file SecurityContext.java.

250  {
252  if (ctx != null)
253  return ctx;
254  return OSGiServices.getSecurityContext();
255  }

References javolution.context.AbstractContext.current(), and javolution.osgi.internal.OSGiServices.getSecurityContext().

Referenced by javolution.context.SecurityContext.check(), and javolution.context.SecurityContext.enter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enter() [1/2]

static SecurityContext javolution.context.SecurityContext.enter ( )
staticinherited

Enters and returns a new security context instance.

Returns
the new security context implementation entered.

Definition at line 185 of file SecurityContext.java.

185  {
187  }

References javolution.context.SecurityContext.currentSecurityContext(), and javolution.context.AbstractContext.enterInner().

Here is the call graph for this function:

◆ enter() [2/2]

static <T extends AbstractContext> T javolution.context.AbstractContext.enter ( Class< T >  custom)
staticinherited

Enters the scope of a custom context. This method raises a SecurityException if the permission to enter contexts of the specified class is not granted. For example, the following disallow entering any custom context. [code] SecurityContext ctx = SecurityContext.enter(); try { ctx.revoke(new SecurityContext.Permission(AbstractContext.class, "enter")); ... // Cannot enter any custom context. } finally { ctx.exit(); // Back to previous security settings. }[/code]


Parameters
customthe custom context to enter.
Exceptions
IllegalArgumentExceptionif the specified class default constructor cannot be instantiated.
SecurityExceptionif
SecurityContext.Permission(custom, "enter")

is not granted.
See also
SecurityContext.Permission

Definition at line 101 of file AbstractContext.java.

101  {
102  SecurityContext.check(new Permission<T>(custom, "enter"));
103  try {
104  return (T) custom.newInstance().enterInner();
105  } catch (InstantiationException e) {
106  throw new IllegalArgumentException(
107  "Cannot instantiate instance of " + custom, e);
108  } catch (IllegalAccessException e) {
109  throw new IllegalArgumentException("Cannot access " + custom, e);
110  }
111  }

References javolution.context.SecurityContext.check().

Here is the call graph for this function:

◆ enterInner()

AbstractContext javolution.context.AbstractContext.enterInner ( )
protectedinherited

Enters the scope of an inner context which becomes the current context; the previous current context becomes the outer of this context.

Returns
the inner context entered.

Definition at line 141 of file AbstractContext.java.

141  {
143  inner.outer = AbstractContext.CURRENT.get();
144  AbstractContext.CURRENT.set(inner);
145  return inner;
146  }

References javolution.context.AbstractContext.CURRENT, and javolution.context.AbstractContext.outer.

Referenced by javolution.xml.XMLContext.enter(), javolution.text.TextContext.enter(), javolution.context.LogContext.enter(), javolution.context.LocalContext.enter(), javolution.context.SecurityContext.enter(), and javolution.context.ConcurrentContext.enter().

Here is the caller graph for this function:

◆ exit()

void javolution.context.AbstractContext.exit ( )
inherited

Exits the scope of this context; the outer of this context becomes
the current context.

Exceptions
IllegalStateExceptionif this context is not the current context.

Reimplemented in javolution.context.ConcurrentContext, and javolution.context.internal.ConcurrentContextImpl.

Definition at line 155 of file AbstractContext.java.

155  {
156  if (this != AbstractContext.CURRENT.get())
157  throw new IllegalStateException(
158  "This context is not the current context");
159  AbstractContext.CURRENT.set(outer);
160  outer = null;
161  }

References javolution.context.AbstractContext.CURRENT.

◆ getOuter()

AbstractContext javolution.context.AbstractContext.getOuter ( )
protectedinherited

Returns the outer context of this context or

null

if this context has no outer context.

Definition at line 167 of file AbstractContext.java.

167  {
168  return outer;
169  }

◆ grant() [1/2]

final void javolution.context.SecurityContext.grant ( Permission<?>  permission)
inherited

Grants the specified permission (convenience method).

Parameters
permissionthe permission to grant.
Exceptions
SecurityExceptionif the specified permission cannot be granted.

Definition at line 233 of file SecurityContext.java.

233  {
234  grant(permission, null);
235  }

References javolution.context.SecurityContext.grant().

Here is the call graph for this function:

◆ grant() [2/2]

void javolution.context.internal.SecurityContextImpl.grant ( Permission<?>  permission,
Object  certificate 
) throws SecurityException

Grants the specified permission.

Parameters
permissionthe permission to grant.
certificatethe certificate used to grant that permission or null if none.
Exceptions
SecurityExceptionif the specified permission cannot be granted.

Reimplemented from javolution.context.SecurityContext.

Definition at line 32 of file SecurityContextImpl.java.

33  {
34  Action a = new Action();
35  a.grant = true;
36  a.permission = permission;
37  actions.add(a);
38  }

References javolution.context.internal.SecurityContextImpl.actions, javolution.context.internal.SecurityContextImpl.Action.grant, and javolution.context.internal.SecurityContextImpl.Action.permission.

◆ inherit()

static void javolution.context.AbstractContext.inherit ( AbstractContext  ctx)
staticinherited

Inherits the specified context which becomes the context of the current thread. This method is particularly useful when creating new threads to make them inherits from the context stack of the parent thread. [code] //Spawns a new thread inheriting the context of the current thread. MyThread myThread = new MyThread(); myThread.inherited = AbstractContext.current(); myThread.start(); ... class MyThread extends Thread { AbstractContext inherited; public void run() { AbstractContext.inherit(inherited); // Sets current context. ... } }[/code]

Definition at line 131 of file AbstractContext.java.

131  {
132  CURRENT.set(ctx);
133  }

Referenced by javolution.context.internal.ConcurrentThreadImpl.run().

Here is the caller graph for this function:

◆ inner()

SecurityContext javolution.context.internal.SecurityContextImpl.inner ( )
protected

Returns a new inner instance of this context inheriting the properties of this context. The new instance can be configured independently from its parent.

Reimplemented from javolution.context.AbstractContext.

Definition at line 50 of file SecurityContextImpl.java.

50  {
51  SecurityContextImpl ctx = new SecurityContextImpl();
52  ctx.actions.addAll(actions);
53  return ctx;
54  }

References javolution.context.internal.SecurityContextImpl.actions.

◆ isGranted()

boolean javolution.context.internal.SecurityContextImpl.isGranted ( Permission<?>  permission)

Indicates if the specified permission is granted.

Parameters
permissionthe permission to check.

Reimplemented from javolution.context.SecurityContext.

Definition at line 22 of file SecurityContextImpl.java.

22  {
23  boolean isGranted = true;
24  for (Action a : actions) {
25  if (a.permission.implies(permission))
26  isGranted = a.grant;
27  }
28  return isGranted;
29  }

References javolution.context.internal.SecurityContextImpl.actions.

◆ revoke() [1/2]

final void javolution.context.SecurityContext.revoke ( Permission<?>  permission)
inherited

Revokes the specified permission (convenience method).

Parameters
permissionthe permission to grant.
Exceptions
SecurityExceptionif the specified permission cannot be revoked.

Definition at line 243 of file SecurityContext.java.

243  {
244  revoke(permission, null);
245  }

References javolution.context.SecurityContext.revoke().

Here is the call graph for this function:

◆ revoke() [2/2]

void javolution.context.internal.SecurityContextImpl.revoke ( Permission<?>  permission,
Object  certificate 
) throws SecurityException

Revokes the specified permission.

Parameters
permissionthe permission to grant.
certificatethe certificate used to grant that permission or null if none.
Exceptions
SecurityExceptionif the specified permission cannot be revoked.

Reimplemented from javolution.context.SecurityContext.

Definition at line 41 of file SecurityContextImpl.java.

42  {
43  Action a = new Action();
44  a.grant = false;
45  a.permission = permission;
46  actions.add(a);
47  }

References javolution.context.internal.SecurityContextImpl.actions, javolution.context.internal.SecurityContextImpl.Action.grant, and javolution.context.internal.SecurityContextImpl.Action.permission.

Member Data Documentation

◆ actions

◆ CURRENT

final ThreadLocal<AbstractContext> javolution.context.AbstractContext.CURRENT = new ThreadLocal<AbstractContext>()
staticprivateinherited

◆ outer

AbstractContext javolution.context.AbstractContext.outer
privateinherited

Holds the outer context or

null

if none (top context).

Definition at line 50 of file AbstractContext.java.

Referenced by javolution.context.AbstractContext.current(), and javolution.context.AbstractContext.enterInner().


The documentation for this class was generated from the following file:
javolution.context.SecurityContext.revoke
abstract void revoke(Permission<?> permission, Object certificate)
javolution.context.SecurityContext.grant
abstract void grant(Permission<?> permission, Object certificate)
javolution.context.AbstractContext.CURRENT
static final ThreadLocal< AbstractContext > CURRENT
Definition: AbstractContext.java:45
javolution.context.internal.SecurityContextImpl.isGranted
boolean isGranted(Permission<?> permission)
Definition: SecurityContextImpl.java:22
javolution.context.AbstractContext.inner
abstract AbstractContext inner()
javolution.context.SecurityContext.isGranted
abstract boolean isGranted(Permission<?> permission)
javolution.context.internal.SecurityContextImpl.actions
FastTable< Action > actions
Definition: SecurityContextImpl.java:19
javolution.context.AbstractContext.outer
AbstractContext outer
Definition: AbstractContext.java:50
javolution.context.AbstractContext.current
static AbstractContext current()
Definition: AbstractContext.java:61
javolution.context.AbstractContext.enterInner
AbstractContext enterInner()
Definition: AbstractContext.java:141
javolution.context.SecurityContext.currentSecurityContext
static SecurityContext currentSecurityContext()
Definition: SecurityContext.java:250
javolution.context.AbstractContext.AbstractContext
AbstractContext()
Definition: AbstractContext.java:55
javolution.context.SecurityContext.SecurityContext
SecurityContext()
Definition: SecurityContext.java:178