|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jasig.portal.groups.filesystem.FileSystemGroupStore
public class FileSystemGroupStore
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
-- org.jasig.portal.security.IPerson
-- channel definition file
...
-- person directory
etc.
-- person file
-- person directory
-- person file
...
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.
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 |
---|
private static final org.apache.commons.logging.Log log
protected static char FORWARD_SLASH
protected static char BACK_SLASH
protected static java.lang.String COMMENT
protected static java.lang.String GROUP_PREFIX
protected static char PERIOD
protected static char SUBSTITUTE_PERIOD
protected boolean useSubstitutePeriod
private static java.lang.String DEBUG_CLASS_NAME
private java.lang.String groupsRootPath
protected char goodSeparator
protected char badSeparator
private java.util.Map cache
private java.io.FilenameFilter fileFilter
private java.lang.Class defaultEntityType
Constructor Detail |
---|
public FileSystemGroupStore()
public FileSystemGroupStore(GroupServiceConfiguration cfg)
Method Detail |
---|
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)
public void delete(IEntityGroup group) throws GroupsException
IEntityGroup
from the data store. We assume that
groups will be deleted via the file system, not the group service.
delete
in interface IEntityGroupStore
group
- org.jasig.portal.groups.IEntityGroup
GroupsException
private IEntityGroup find(java.io.File file) throws GroupsException
IEntityGroup
from the data store.
file
- java.io.File
GroupsException
public IEntityGroup find(java.lang.String key) throws GroupsException
IEntityGroup
from the data store.
find
in interface IEntityGroupStore
key
- java.lang.String
GroupsException
protected java.util.Iterator findContainingGroups(IEntity ent) throws GroupsException
Iterator
over the Collection
of
IEntityGroups
that the IEntity
belongs to.
ent
- org.jasig.portal.groups.IEntityGroup
GroupsException
protected java.util.Iterator findContainingGroups(IEntityGroup group) throws GroupsException
Iterator
over the Collection
of
IEntityGroups
that the IGroupMember
belongs to.
group
- org.jasig.portal.groups.IEntityGroup
GroupsException
public java.util.Iterator findContainingGroups(IGroupMember gm) throws GroupsException
Iterator
over the Collection
of
IEntityGroups
that the IGroupMember
belongs to.
findContainingGroups
in interface IEntityGroupStore
gm
- org.jasig.portal.groups.IEntityGroup
GroupsException
public java.util.Iterator findEntitiesForGroup(IEntityGroup group) throws GroupsException
Iterator
over the Collection
of
IEntities
that are members of this IEntityGroup
.
findEntitiesForGroup
in interface IEntityGroupStore
group
- org.jasig.portal.groups.IEntityGroup
GroupsException
public ILockableEntityGroup findLockable(java.lang.String key) throws GroupsException
ILockableEntityGroup
from the data store.
findLockable
in interface IEntityGroupStore
key
- java.lang.String
GroupsException
public java.lang.String[] findMemberGroupKeys(IEntityGroup group) throws GroupsException
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.
findMemberGroupKeys
in interface IEntityGroupStore
group
- org.jasig.portal.groups.IEntityGroup
GroupsException
public java.util.Iterator findMemberGroups(IEntityGroup group) throws GroupsException
Iterator
over the Collection
of
IEntityGroups
that are members of this IEntityGroup
.
findMemberGroups
in interface IEntityGroupStore
group
- org.jasig.portal.groups.IEntityGroup
GroupsException
public java.util.Set getAllDirectoriesBelow(java.io.File dir)
public java.io.File[] getAllFilesBelow(java.io.File dir)
protected char getBadSeparator()
protected java.util.Map getCache()
protected java.lang.Class getDefaultEntityType()
protected java.util.Collection getEntitiesFromFile(java.io.File idFile) throws GroupsException
idFile
- java.io.File - a file of ids.
GroupsException
protected java.util.Collection getEntityIdsFromFile(java.io.File idFile) throws java.io.IOException, java.io.FileNotFoundException
idFile
- java.io.File - a file of ids.
java.io.IOException
java.io.FileNotFoundException
protected java.lang.Class getEntityType(java.io.File f)
f
- File
protected java.io.File getFile(IEntityGroup group)
group
- IEntityGroup.
protected java.lang.String getFilePathFromKey(java.lang.String key)
protected java.io.File getFileRoot(java.lang.Class type)
protected char getGoodSeparator()
protected java.util.Collection getGroupIdsFromFile(java.io.File idFile) throws java.io.IOException, java.io.FileNotFoundException
idFile
- java.io.File - a file of ids.
java.io.IOException
java.io.FileNotFoundException
public java.lang.String getGroupsRootPath()
protected java.util.Collection getIdsFromFile(java.io.File idFile, boolean groupIds) throws java.io.IOException, java.io.FileNotFoundException
idFile
- java.io.File - a file of ids.
java.io.IOException
java.io.FileNotFoundException
protected java.lang.String getKeyFromFile(java.io.File f)
protected void initialize(GroupServiceConfiguration cfg)
private IEntityGroup newInstance(java.io.File f) throws GroupsException
GroupsException
public IEntityGroup newInstance(java.lang.Class entityType) throws GroupsException
newInstance
in interface IEntityGroupStore
GroupsException
public IEntity newInstance(java.lang.String key) throws GroupsException
newInstance
in interface IEntityStore
key
- java.lang.String
GroupsException
public IEntity newInstance(java.lang.String key, java.lang.Class type) throws GroupsException
newInstance
in interface IEntityStore
key
- java.lang.String - the entity's keytype
- java.lang.Class - the entity's Type
GroupsException
private IEntityGroup newInstance(java.lang.String newKey, java.lang.Class newType, java.lang.String newName) throws GroupsException
GroupsException
private void primGetAllDirectoriesBelow(java.io.File dir, java.util.Set allDirectories)
private void primGetAllFilesBelow(java.io.File dir, java.util.Set allFiles)
public EntityIdentifier[] searchForEntities(java.lang.String query, int method, java.lang.Class type) throws GroupsException
searchForEntities
in interface IEntitySearcher
GroupsException
public EntityIdentifier[] searchForGroups(java.lang.String query, int searchMethod, java.lang.Class leafType) throws GroupsException
searchForGroups
in interface IEntityGroupStore
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.
GroupsException
protected void setCache(java.util.Map newCache)
newCache
- java.util.Mapprotected void setGroupsRootPath(java.lang.String newGroupsRootPath)
newGroupsRootPath
- java.lang.Stringpublic void update(IEntityGroup group) throws GroupsException
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.
update
in interface IEntityGroupStore
group
- org.jasig.portal.groups.IEntityGroup
GroupsException
public void updateMembers(IEntityGroup group) throws GroupsException
IEntityGroup
to
the data store. We assume that groups will be updated via the
file system, not the group service.
updateMembers
in interface IEntityGroupStore
group
- org.jasig.portal.groups.IEntityGroup
GroupsException
public boolean contains(IEntityGroup group, IGroupMember member) throws GroupsException
group
contains member
.
contains
in interface IEntityGroupStore
group
- org.jasig.portal.groups.IEntityGroupmember
- org.jasig.portal.groups.IGroupMember
GroupsException
private boolean fileContains(java.io.File file, IGroupMember member) throws GroupsException
file
contains member
.
file
- member
-
GroupsException
private boolean directoryContains(java.io.File directory, IGroupMember member)
directory
contains member
. A
directory can only contain (other) groups.
directory
- java.io.Filemember
-
public boolean containsGroupNamed(IEntityGroup group, java.lang.String name) throws GroupsException
group
contains a member group named
name
.
group
- org.jasig.portal.groups.IEntityGroupname
- java.lang.String
GroupsException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |