org.jboss.naming
Class JndiPermission

java.lang.Object
  extended by java.security.Permission
      extended by org.jboss.naming.JndiPermission
All Implemented Interfaces:
Serializable, Guard

public final class JndiPermission
extends Permission
implements Serializable

This class represents access to a path in the JNDI tree. A JndiPermission consists of a pathname and a set of actions valid for that pathname.

Pathname is the pathname of the file or directory granted the specified actions. A pathname that ends in "/*" indicates all the files and directories contained in that directory. A pathname that ends with "/-" indicates (recursively) all files and subdirectories contained in that directory. A pathname consisting of the special token "<<ALL BINDINGS>>" matches any file.

The actions to be granted are passed to the constructor in a string containing a list of one or more comma-separated keywords. The possible keywords are "bind", "rebind", "unbind", "lookup", "list", "listBindings", and "createSubcontext". Their meaning is defined as follows:

bind
Context.bind permission
rebind
Context.rebind permission
unbind
Context.unbind permission.
lookup
Context.lookup permission.
list
Context.list permission.
listBindings
Context.listBindings permission.
createSubcontext
Context.createSubcontext permission.

The actions string is converted to lowercase before processing.

Be careful when granting JndiPermissions. Think about the implications of granting read and especially write access to various files and directories. The "<<ALL BINDINGS>>" permission with write action is especially dangerous. This grants permission to write to the entire file system. One thing this effectively allows is replacement of the system binary, including the JVM runtime environment.

Please note: Code can always read a file from the same directory it's in (or a subdirectory of that directory); it does not need explicit permission to do so.

Version:
$Revision: 81310 $
Author:
Marianne Mueller, Roland Schemers, Scott.Stark@jboss.org
See Also:
Permission, Permissions, PermissionCollection

Field Summary
static int ALL
          All actions (bind, rebind, unbind, lookup, list, listBindings, createSubcontext)
static String ALL_ACTION
           
static int BIND
          bind action.
static String BIND_ACTION
           
static int CREATE_SUBCONTEXT
           
static String CREATE_SUBCONTEXT_ACTION
           
static int LIST
          list action.
static String LIST_ACTION
           
static int LIST_BINDINGS
           
static String LIST_BINDINGS_ACTION
           
static int LOOKUP
          lookup action.
static String LOOKUP_ACTION
           
static int NONE
          No actions.
static int REBIND
          rebind action.
static String REBIND_ACTION
           
static int UNBIND
          unbind action.
static String UNBIND_ACTION
           
 
Constructor Summary
JndiPermission(Name path, int mask)
           
JndiPermission(Name path, String actions)
           
JndiPermission(String path, String actions)
          Creates a new JndiPermission object with the specified actions.
 
Method Summary
 boolean equals(Object obj)
          Checks two JndiPermission objects for equality.
 String getActions()
          Returns the "canonical string representation" of the actions.
 int hashCode()
          Returns the hash code value for this object.
 boolean implies(Permission p)
          Checks if this JndiPermission object "implies" the specified permission.
 PermissionCollection newPermissionCollection()
          Returns a new PermissionCollection object for storing JndiPermission objects.
 
Methods inherited from class java.security.Permission
checkGuard, getName, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BIND

public static final int BIND
bind action.

See Also:
Constant Field Values

REBIND

public static final int REBIND
rebind action.

See Also:
Constant Field Values

UNBIND

public static final int UNBIND
unbind action.

See Also:
Constant Field Values

LOOKUP

public static final int LOOKUP
lookup action.

See Also:
Constant Field Values

LIST

public static final int LIST
list action.

See Also:
Constant Field Values

LIST_BINDINGS

public static final int LIST_BINDINGS
See Also:
Constant Field Values

CREATE_SUBCONTEXT

public static final int CREATE_SUBCONTEXT
See Also:
Constant Field Values

ALL

public static final int ALL
All actions (bind, rebind, unbind, lookup, list, listBindings, createSubcontext)

See Also:
Constant Field Values

NONE

public static final int NONE
No actions.

See Also:
Constant Field Values

BIND_ACTION

public static final String BIND_ACTION
See Also:
Constant Field Values

REBIND_ACTION

public static final String REBIND_ACTION
See Also:
Constant Field Values

UNBIND_ACTION

public static final String UNBIND_ACTION
See Also:
Constant Field Values

LOOKUP_ACTION

public static final String LOOKUP_ACTION
See Also:
Constant Field Values

LIST_ACTION

public static final String LIST_ACTION
See Also:
Constant Field Values

LIST_BINDINGS_ACTION

public static final String LIST_BINDINGS_ACTION
See Also:
Constant Field Values

ALL_ACTION

public static final String ALL_ACTION
See Also:
Constant Field Values

CREATE_SUBCONTEXT_ACTION

public static final String CREATE_SUBCONTEXT_ACTION
See Also:
Constant Field Values
Constructor Detail

JndiPermission

public JndiPermission(String path,
                      String actions)
Creates a new JndiPermission object with the specified actions. path is the pathname of a file or directory, and actions contains a comma-separated list of the desired actions granted on the file or directory. Possible actions are "bind", "rebind", "unbind", "lookup", "list", "listBindings", and "createSubcontext".

A pathname that ends in "/*" (where "/" is the file separator character, '/') indicates all the files and directories contained in that directory. A pathname that ends with "/-" indicates (recursively) all files and subdirectories contained in that directory. The special pathname "<<ALL BINDINGS>>" matches any file.

A pathname consisting of a single "*" indicates all the files in the current directory, while a pathname consisting of a single "-" indicates all the files in the current directory and (recursively) all files and subdirectories contained in the current directory.

A pathname containing an empty string represents an empty path.

Parameters:
path - the pathname of the file/directory.
actions - the action string.
Throws:
IllegalArgumentException - If actions is null, empty or contains an action other than the specified possible actions.

JndiPermission

public JndiPermission(Name path,
                      String actions)

JndiPermission

public JndiPermission(Name path,
                      int mask)
Method Detail

implies

public boolean implies(Permission p)
Checks if this JndiPermission object "implies" the specified permission.

More specifically, this method returns true if:

Specified by:
implies in class Permission
Parameters:
p - the permission to check against.
Returns:
true if the specified permission is not null and is implied by this object, false otherwise.

equals

public boolean equals(Object obj)
Checks two JndiPermission objects for equality. Checks that obj is a JndiPermission, and has the same pathname and actions as this object.

Specified by:
equals in class Permission
Parameters:
obj - the object we are testing for equality with this object.
Returns:
true if obj is a JndiPermission, and has the same pathname and actions as this JndiPermission object, false otherwise.

hashCode

public int hashCode()
Returns the hash code value for this object.

Specified by:
hashCode in class Permission
Returns:
a hash code value for this object.

getActions

public String getActions()
Returns the "canonical string representation" of the actions. That is, this method always returns present actions in the following order: bind, rebind, unbind, lookup, list, listBindings, createSubcontext. For example, if this JndiPermission object allows both unbind and bind actions, a call to getActions will return the string "bind,unbind".

Specified by:
getActions in class Permission
Returns:
the canonical string representation of the actions.

newPermissionCollection

public PermissionCollection newPermissionCollection()
Returns a new PermissionCollection object for storing JndiPermission objects.

JndiPermission objects must be stored in a manner that allows them to be inserted into the collection in any order, but that also enables the PermissionCollection implies method to be implemented in an efficient (and consistent) manner.

For example, if you have two JndiPermissions:

  1. "/tmp/-", "bind"
  2. "/tmp/scratch/foo", "unbind"

and you are calling the implies method with the JndiPermission:

   "/tmp/scratch/foo", "bind,unbind",
 
then the implies function must take into account both the "/tmp/-" and "/tmp/scratch/foo" permissions, so the effective permission is "bind,unbind", and implies returns true. The "implies" semantics for JndiPermissions are handled properly by the PermissionCollection object returned by this newPermissionCollection method.

Overrides:
newPermissionCollection in class Permission
Returns:
a new PermissionCollection object suitable for storing JndiPermissions.


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.