Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jasig.portal.groups.filesystem
Class FileSystemGroupStore

    java.lang.Object
      org.jasig.portal.groups.filesystem.FileSystemGroupStore

All Implemented Interfaces:
  IEntityGroupStore, IEntitySearcher, IEntityStore, IGroupConstants

    public class FileSystemGroupStore

extends java.lang.Object
implements IEntityGroupStore, IEntityStore, IEntitySearcher

This class is an `IEntityGroupStore` that uses the native file system for its back end. It also implements `IEntityStore` and a no-op `IEntitySearcher`. You can substitute a functional entity searcher by adding it to the group service element for this component in the configuration document, `compositeGroupServices.xml`.

A groups file system looks like this:

``

-- groups root

> -- org.jasig.portal.ChannelDefinition

> > -- channel definition file
> > -- channel definition file
> > ...

> -- org.jasig.portal.security.IPerson

> > -- person directory

> > > -- person file
> > > -- person file
> > > ...

> > -- person directory

> etc.

The groups root is a file system directory declared in the group service configuration document, where it is an attribute of the filesystem group service element. This directory has sub-directories, each named for the underlying entity type that groups in that sub-directory contain. If a service only contains groups of IPersons, the groups root would have 1 sub-directory named org.jasig.portal.security.IPerson.

A directory named for a type may contain both sub-directories and files. The sub-directories represent groups that can contain other groups. The files represent groups that can contain entity as well as group members. The files contain keys, one to a line, and look like this:

``

# this is a comment
# another comment
key1 Key One
key2
group:org$jasig$portal$security$IPerson/someDirectory/someFile
key3
# comment

Blank lines and lines that start with the `COMMENT` String (here `#`) are ignored. The first token on a non-ignored line is assumed to be a group member key. If the key starts with the `GROUP_PREFIX` (here `:group`), it is treated as a local group key. Otherwise, it is assumed to be an entity key. The rest of the tokens on the line are ignored.

The file above contains 3 entity keys, `key1`, `key2`, and `key3`, and 1 group key, `org$jasig$portal$security$IPerson/someDirectory/someFile`. It represents a group with 3 entity members and 1 group member. The local key of a group is its file path starting at the type name, with the `FileSystemGroupStore.SUBSTITUTE_PERIOD` character substituted for the real period character.

The store is not implemented as a singleton, so you can have multiple concurrent instances pointing to different groups root directories.

Version:
  $Revision: 1.17.2.1 $
Author:
  Dan Ellentuck

Nested Class Summary
`private class` | `FileSystemGroupStore.FileFilter`
`private class` | `FileSystemGroupStore.GroupHolder`

Field Summary
`protected static char` | `BACK_SLASH`
`protected char` | `badSeparator`
`private java.util.Map` | `cache`
`protected static java.lang.String` | `COMMENT`
`private static java.lang.String` | `DEBUG_CLASS_NAME`
`private java.lang.Class` | `defaultEntityType`
`private java.io.FilenameFilter` | `fileFilter`
`protected static char` | `FORWARD_SLASH`
`protected char` | `goodSeparator`
`protected static java.lang.String` | `GROUP_PREFIX`
`private java.lang.String` | `groupsRootPath`
`private static org.apache.commons.logging.Log` | `log`
`protected static char` | `PERIOD`
`protected static char` | `SUBSTITUTE_PERIOD`
`protected boolean` | `useSubstitutePeriod`

Fields inherited from interface org.jasig.portal.groups.IGroupConstants
`CHANNEL_CATEGORIES, CONTAINS, ENDS_WITH, EVERYONE, IS, NODE_SEPARATOR, PORTAL_ADMINISTRATORS, STARTS_WITH`

Constructor Summary
`FileSystemGroupStore()` FileSystemGroupStore constructor.
`FileSystemGroupStore(GroupServiceConfiguration cfg)` FileSystemGroupStore constructor.

Method Summary
`protected FileSystemGroupStore.GroupHolder` | `cacheGet(java.lang.String key)`
`protected void` | `cachePut(java.lang.String key, java.lang.Object val)`
`protected java.lang.String` | `conformSeparatorChars(java.lang.String s)`
`boolean` | `contains(IEntityGroup group, IGroupMember member)` Answers if `group` contains `member`.
`boolean` | `containsGroupNamed(IEntityGroup group, java.lang.String name)` Answers if `group` contains a member group named `name`.
`void` | `delete(IEntityGroup group)` Delete this `IEntityGroup` from the data store.
`private boolean` | `directoryContains(java.io.File directory, IGroupMember member)` Answers if `directory` contains `member`.
`private boolean` | `fileContains(java.io.File file, IGroupMember member)` Answers if `file` contains `member`.
`private IEntityGroup` | `find(java.io.File file)` Returns an instance of the `IEntityGroup` from the data store.
`IEntityGroup` | `find(java.lang.String key)` Returns an instance of the `IEntityGroup` from the data store.
`protected java.util.Iterator` | `findContainingGroups(IEntity ent)` Returns an `Iterator` over the `Collection` of `IEntityGroups` that the `IEntity` belongs to.
`protected java.util.Iterator` | `findContainingGroups(IEntityGroup group)` Returns an `Iterator` over the `Collection` of `IEntityGroups` that the `IGroupMember` belongs to.
`java.util.Iterator` | `findContainingGroups(IGroupMember gm)` Returns an `Iterator` over the `Collection` of `IEntityGroups` that the `IGroupMember` belongs to.
`java.util.Iterator` | `findEntitiesForGroup(IEntityGroup group)` Returns an `Iterator` over the `Collection` of `IEntities` that are members of this `IEntityGroup`.
`ILockableEntityGroup` | `findLockable(java.lang.String key)` Returns an instance of the `ILockableEntityGroup` from the data store.
`java.lang.String[]` | `findMemberGroupKeys(IEntityGroup group)` Returns a `String[]` containing the keys of `IEntityGroups` that are members of this `IEntityGroup`.
`java.util.Iterator` | `findMemberGroups(IEntityGroup group)` Returns an `Iterator` over the `Collection` of `IEntityGroups` that are members of this `IEntityGroup`.
`java.util.Set` | `getAllDirectoriesBelow(java.io.File dir)` Recursive search of directories underneath dir for files that match filter.
`java.io.File[]` | `getAllFilesBelow(java.io.File dir)` Recursive search of directories underneath dir for files that match filter.
`protected char` | `getBadSeparator()` Returns the filesystem separator character NOT in use.
`protected java.util.Map` | `getCache()`
`protected java.lang.Class` | `getDefaultEntityType()` Returns a Class representing the default entity type.
`protected java.util.Collection` | `getEntitiesFromFile(java.io.File idFile)`
`protected java.util.Collection` | `getEntityIdsFromFile(java.io.File idFile)`
`protected java.lang.Class` | `getEntityType(java.io.File f)`
`protected java.io.File` | `getFile(IEntityGroup group)`
`protected java.lang.String` | `getFilePathFromKey(java.lang.String key)`
`protected java.io.File` | `getFileRoot(java.lang.Class type)` Returns a File that is the root for groups of the given type.
`protected char` | `getGoodSeparator()` Returns the filesystem separator character in use.
`protected java.util.Collection` | `getGroupIdsFromFile(java.io.File idFile)`
`java.lang.String` | `getGroupsRootPath()`
`protected java.util.Collection` | `getIdsFromFile(java.io.File idFile, boolean groupIds)`
`protected java.lang.String` | `getKeyFromFile(java.io.File f)`
`protected void` | `initialize(GroupServiceConfiguration cfg)`
`IEntityGroup` | `newInstance(java.lang.Class entityType)`
`private IEntityGroup` | `newInstance(java.io.File f)`
`IEntity` | `newInstance(java.lang.String key)`
`IEntity` | `newInstance(java.lang.String key, java.lang.Class type)`
`private IEntityGroup` | `newInstance(java.lang.String newKey, java.lang.Class newType, java.lang.String newName)`
`private void` | `primGetAllDirectoriesBelow(java.io.File dir, java.util.Set allDirectories)` Returns all directories under dir.
`private void` | `primGetAllFilesBelow(java.io.File dir, java.util.Set allFiles)` Returns all files (not directories) underneath dir.
`EntityIdentifier[]` | `searchForEntities(java.lang.String query, int method, java.lang.Class type)` Find EntityIdentifiers for entities whose name matches the query string according to the specified method and is of the specified type
`EntityIdentifier[]` | `searchForGroups(java.lang.String query, int searchMethod, java.lang.Class leafType)` Returns an EntityIdentifier[] of groups of the given leaf type whose names match the query string according to the search method.
`protected void` | `setCache(java.util.Map newCache)`
`protected void` | `setGroupsRootPath(java.lang.String newGroupsRootPath)`
`void` | `update(IEntityGroup group)` Adds or updates the `IEntityGroup` AND ITS MEMBERSHIPS to the data store, as appropriate.
`void` | `updateMembers(IEntityGroup group)` Commits the group memberships of the `IEntityGroup` to the data store.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### log

    private static final org.apache.commons.logging.Log log

### FORWARD_SLASH

    protected static char FORWARD_SLASH

### BACK_SLASH

    protected static char BACK_SLASH

### COMMENT

    protected static java.lang.String COMMENT

### GROUP_PREFIX

    protected static java.lang.String GROUP_PREFIX

### PERIOD

    protected static char PERIOD

### SUBSTITUTE_PERIOD

    protected static char SUBSTITUTE_PERIOD

### useSubstitutePeriod

    protected boolean useSubstitutePeriod

### DEBUG_CLASS_NAME

    private static java.lang.String DEBUG_CLASS_NAME

### groupsRootPath

    private java.lang.String groupsRootPath

### goodSeparator

    protected char goodSeparator

### badSeparator

    protected char badSeparator

### cache

    private java.util.Map cache

### fileFilter

    private java.io.FilenameFilter fileFilter

### defaultEntityType

    private java.lang.Class defaultEntityType

Constructor Detail

### FileSystemGroupStore

    public FileSystemGroupStore()

  FileSystemGroupStore constructor.

### FileSystemGroupStore

    public FileSystemGroupStore(GroupServiceConfiguration cfg)

  FileSystemGroupStore constructor.

Method Detail

### cacheGet

    protected FileSystemGroupStore.GroupHolder cacheGet(java.lang.String key)

  Returns:
    GroupHolder

### cachePut

    protected void cachePut(java.lang.String key,
                            java.lang.Object val)

### conformSeparatorChars

    protected java.lang.String conformSeparatorChars(java.lang.String s)

### delete

    public void delete(IEntityGroup group)
                throws GroupsException

  Delete this `IEntityGroup` from the data store. We assume that groups will be deleted via the file system, not the group service.

  Specified by:
    `delete` in interface `IEntityGroupStore`
  Parameters:
    `group` - org.jasig.portal.groups.IEntityGroup
  Throws:
    `GroupsException`

### find

    private IEntityGroup find(java.io.File file)
                       throws GroupsException

  Returns an instance of the `IEntityGroup` from the data store.

  Parameters:
    `file` - java.io.File
  Returns:
    org.jasig.portal.groups.IEntityGroup
  Throws:
    `GroupsException`

### find

    public IEntityGroup find(java.lang.String key)
                      throws GroupsException

  Returns an instance of the `IEntityGroup` from the data store.

  Specified by:
    `find` in interface `IEntityGroupStore`
  Parameters:
    `key` - java.lang.String
  Returns:
    org.jasig.portal.groups.IEntityGroup
  Throws:
    `GroupsException`

### findContainingGroups

    protected java.util.Iterator findContainingGroups(IEntity ent)
                                               throws GroupsException

  Returns an `Iterator` over the `Collection` of `IEntityGroups` that the `IEntity` belongs to.

  Parameters:
    `ent` - org.jasig.portal.groups.IEntityGroup
  Returns:
    java.util.Iterator
  Throws:
    `GroupsException`

### findContainingGroups

    protected java.util.Iterator findContainingGroups(IEntityGroup group)
                                               throws GroupsException

  Returns an `Iterator` over the `Collection` of `IEntityGroups` that the `IGroupMember` belongs to.

  Parameters:
    `group` - org.jasig.portal.groups.IEntityGroup
  Returns:
    java.util.Iterator
  Throws:
    `GroupsException`

### findContainingGroups

    public java.util.Iterator findContainingGroups(IGroupMember gm)
                                            throws GroupsException

  Returns an `Iterator` over the `Collection` of `IEntityGroups` that the `IGroupMember` belongs to.

  Specified by:
    `findContainingGroups` in interface `IEntityGroupStore`
  Parameters:
    `gm` - org.jasig.portal.groups.IEntityGroup
  Returns:
    java.util.Iterator
  Throws:
    `GroupsException`

### findEntitiesForGroup

    public java.util.Iterator findEntitiesForGroup(IEntityGroup group)
                                            throws GroupsException

  Returns an `Iterator` over the `Collection` of `IEntities` that are members of this `IEntityGroup`.

  Specified by:
    `findEntitiesForGroup` in interface `IEntityGroupStore`
  Parameters:
    `group` - org.jasig.portal.groups.IEntityGroup
  Returns:
    java.util.Iterator
  Throws:
    `GroupsException`

### findLockable

    public ILockableEntityGroup findLockable(java.lang.String key)
                                      throws GroupsException

  Returns an instance of the `ILockableEntityGroup` from the data store.

  Specified by:
    `findLockable` in interface `IEntityGroupStore`
  Parameters:
    `key` - java.lang.String
  Returns:
    org.jasig.portal.groups.IEntityGroup
  Throws:
    `GroupsException`

### findMemberGroupKeys

    public java.lang.String[] findMemberGroupKeys(IEntityGroup group)
                                           throws GroupsException

  Returns a `String[]` containing the keys of `IEntityGroups` that are members of this `IEntityGroup`. In a composite group system, a group may contain a member group from a different service. This is called a foreign membership, and is only possible in an internally-managed service. A group store in such a service can return the key of a foreign member group, but not the group itself, which can only be returned by its local store.

  Specified by:
    `findMemberGroupKeys` in interface `IEntityGroupStore`
  Parameters:
    `group` - org.jasig.portal.groups.IEntityGroup
  Returns:
    String[]
  Throws:
    `GroupsException`

### findMemberGroups

    public java.util.Iterator findMemberGroups(IEntityGroup group)
                                        throws GroupsException

  Returns an `Iterator` over the `Collection` of `IEntityGroups` that are members of this `IEntityGroup`.

  Specified by:
    `findMemberGroups` in interface `IEntityGroupStore`
  Parameters:
    `group` - org.jasig.portal.groups.IEntityGroup
  Returns:
    java.util.Iterator
  Throws:
    `GroupsException`

### getAllDirectoriesBelow

    public java.util.Set getAllDirectoriesBelow(java.io.File dir)

  Recursive search of directories underneath dir for files that match filter.

  Returns:
    java.util.Set

### getAllFilesBelow

    public java.io.File[] getAllFilesBelow(java.io.File dir)

  Recursive search of directories underneath dir for files that match filter.

### getBadSeparator

    protected char getBadSeparator()

  Returns the filesystem separator character NOT in use.

  Returns:
    char

### getCache

    protected java.util.Map getCache()

  Returns:
    java.util.Map

### getDefaultEntityType

    protected java.lang.Class getDefaultEntityType()

  Returns a Class representing the default entity type.

  Returns:
    Class

### getEntitiesFromFile

    protected java.util.Collection getEntitiesFromFile(java.io.File idFile)
                                                throws GroupsException

  Parameters:
    `idFile` - java.io.File - a file of ids.
  Returns:
    entities Collection.
  Throws:
    `GroupsException`

### getEntityIdsFromFile

    protected java.util.Collection getEntityIdsFromFile(java.io.File idFile)
                                                 throws java.io.IOException,
                                                        java.io.FileNotFoundException

  Parameters:
    `idFile` - java.io.File - a file of ids.
  Returns:
    String[] ids.
  Throws:
    `java.io.IOException`
    `java.io.FileNotFoundException`

### getEntityType

    protected java.lang.Class getEntityType(java.io.File f)

  Parameters:
    `f` - File
  Returns:
    java.lang.Class The Class is the first node of the full path name.

### getFile

    protected java.io.File getFile(IEntityGroup group)

  Parameters:
    `group` - IEntityGroup.
  Returns:
    File

### getFilePathFromKey

    protected java.lang.String getFilePathFromKey(java.lang.String key)

### getFileRoot

    protected java.io.File getFileRoot(java.lang.Class type)

  Returns a File that is the root for groups of the given type.

### getGoodSeparator

    protected char getGoodSeparator()

  Returns the filesystem separator character in use.

  Returns:
    char

### getGroupIdsFromFile

    protected java.util.Collection getGroupIdsFromFile(java.io.File idFile)
                                                throws java.io.IOException,
                                                       java.io.FileNotFoundException

  Parameters:
    `idFile` - java.io.File - a file of ids.
  Returns:
    String[] ids.
  Throws:
    `java.io.IOException`
    `java.io.FileNotFoundException`

### getGroupsRootPath

    public java.lang.String getGroupsRootPath()

  Returns:
    java.lang.String

### getIdsFromFile

    protected java.util.Collection getIdsFromFile(java.io.File idFile,
                                                  boolean groupIds)
                                           throws java.io.IOException,
                                                  java.io.FileNotFoundException

  Parameters:
    `idFile` - java.io.File - a file of ids.
  Returns:
    String[] ids.
  Throws:
    `java.io.IOException`
    `java.io.FileNotFoundException`

### getKeyFromFile

    protected java.lang.String getKeyFromFile(java.io.File f)

### initialize

    protected void initialize(GroupServiceConfiguration cfg)

### newInstance

    private IEntityGroup newInstance(java.io.File f)
                              throws GroupsException

  Returns:
    org.jasig.portal.groups.IEntityGroup
  Throws:
    `GroupsException`

### newInstance

    public IEntityGroup newInstance(java.lang.Class entityType)
                             throws GroupsException

  Specified by:
    `newInstance` in interface `IEntityGroupStore`
  Returns:
    org.jasig.portal.groups.IEntityGroup We assume that new groups will be created updated via the file system, not the group service.
  Throws:
    `GroupsException`

### newInstance

    public IEntity newInstance(java.lang.String key)
                        throws GroupsException

  Specified by:
    `newInstance` in interface `IEntityStore`
  Parameters:
    `key` - java.lang.String
  Returns:
    org.jasig.portal.groups.IEntity
  Throws:
    `GroupsException`

### newInstance

    public IEntity newInstance(java.lang.String key,
                               java.lang.Class type)
                        throws GroupsException

  Specified by:
    `newInstance` in interface `IEntityStore`
  Parameters:
    `key` - java.lang.String - the entity's key
    `type` - java.lang.Class - the entity's Type
  Returns:
    org.jasig.portal.groups.IEntity
  Throws:
    `GroupsException`

### newInstance

    private IEntityGroup newInstance(java.lang.String newKey,
                                     java.lang.Class newType,
                                     java.lang.String newName)
                              throws GroupsException

  Returns:
    org.jasig.portal.groups.IEntityGroup
  Throws:
    `GroupsException`

### primGetAllDirectoriesBelow

    private void primGetAllDirectoriesBelow(java.io.File dir,
                                            java.util.Set allDirectories)

  Returns all directories under dir.

### primGetAllFilesBelow

    private void primGetAllFilesBelow(java.io.File dir,
                                      java.util.Set allFiles)

  Returns all files (not directories) underneath dir.

### searchForEntities

    public EntityIdentifier[] searchForEntities(java.lang.String query,
                                                int method,
                                                java.lang.Class type)
                                         throws GroupsException

  Find EntityIdentifiers for entities whose name matches the query string according to the specified method and is of the specified type

  Specified by:
    `searchForEntities` in interface `IEntitySearcher`
  Throws:
    `GroupsException`

### searchForGroups

    public EntityIdentifier[] searchForGroups(java.lang.String query,
                                              int searchMethod,
                                              java.lang.Class leafType)
                                       throws GroupsException

  Returns an EntityIdentifier[] of groups of the given leaf type whose names match the query string according to the search method.

  Specified by:
    `searchForGroups` in interface `IEntityGroupStore`
  Parameters:
    `query` - String the string used to match group names.
    `searchMethod` - see org.jasig.portal.groups.IGroupConstants.
    `leafType` - the leaf type of the groups we are searching for.
  Returns:
    EntityIdentifier[]
  Throws:
    `GroupsException`

### setCache

    protected void setCache(java.util.Map newCache)

  Parameters:
    `newCache` - java.util.Map

### setGroupsRootPath

    protected void setGroupsRootPath(java.lang.String newGroupsRootPath)

  Parameters:
    `newGroupsRootPath` - java.lang.String

### update

    public void update(IEntityGroup group)
                throws GroupsException

  Adds or updates the `IEntityGroup` AND ITS MEMBERSHIPS to the data store, as appropriate. We assume that groups will be updated via the file system, not the group service.

  Specified by:
    `update` in interface `IEntityGroupStore`
  Parameters:
    `group` - org.jasig.portal.groups.IEntityGroup
  Throws:
    `GroupsException`

### updateMembers

    public void updateMembers(IEntityGroup group)
                       throws GroupsException

  Commits the group memberships of the `IEntityGroup` to the data store. We assume that groups will be updated via the file system, not the group service.

  Specified by:
    `updateMembers` in interface `IEntityGroupStore`
  Parameters:
    `group` - org.jasig.portal.groups.IEntityGroup
  Throws:
    `GroupsException`

### contains

    public boolean contains(IEntityGroup group,
                            IGroupMember member)
                     throws GroupsException

  Answers if `group` contains `member`.

  Specified by:
    `contains` in interface `IEntityGroupStore`
  Parameters:
    `group` - org.jasig.portal.groups.IEntityGroup
    `member` - org.jasig.portal.groups.IGroupMember
  Returns:
    boolean
  Throws:
    `GroupsException`

### fileContains

    private boolean fileContains(java.io.File file,
                                 IGroupMember member)
                          throws GroupsException

  Answers if `file` contains `member`.

  Parameters:
    `file` -
    `member` -
  Returns:
    boolean
  Throws:
    `GroupsException`

### directoryContains

    private boolean directoryContains(java.io.File directory,
                                      IGroupMember member)

  Answers if `directory` contains `member`. A directory can only contain (other) groups.

  Parameters:
    `directory` - java.io.File
    `member` -
  Returns:
    boolean

### containsGroupNamed

    public boolean containsGroupNamed(IEntityGroup group,
                                      java.lang.String name)
                               throws GroupsException

  Answers if `group` contains a member group named `name`.

  Parameters:
    `group` - org.jasig.portal.groups.IEntityGroup
    `name` - java.lang.String
  Returns:
    boolean
  Throws:
    `GroupsException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD