com.ca.jcs.sdk
Class SDKAttributeStyleOpProcessor

java.lang.Object
  extended by com.ca.jcs.processor.AbstractBaseProcessor
      extended by com.ca.jcs.processor.AbstractAttributeStyleOpProcessor
          extended by com.ca.jcs.processor.AbstractAttributeStyleOpProcessorAssocDirect
              extended by com.ca.jcs.assoc.DefaultAssocDirectAttributeOpProcessor
                  extended by com.ca.jcs.sdk.SDKAttributeStyleOpProcessor
All Implemented Interfaces:
Activatable, AssocAttributeOpProcessor, AssocDirectAttributeOpProcessor, AttributeStyleOpProcessor, OpProcessor, PostQueryAttributesProcessor

public class SDKAttributeStyleOpProcessor
extends DefaultAssocDirectAttributeOpProcessor

Implements the mapping of LDAP account/group attributes onto local flat or hierarchical files, and back again when querying.

Note that for educational reasons this class includes examples of how association related attributes can be processed separately from normal attributes, but such code is unlikely to be required in custom connectors due to the framework support offered by AssocAttributeOpProcessorProxy which can make all these calls automatically for you (note the SDKSCRIPT connector makes use of this support). Making these calls explicitly also provides the opportunity to show the use of AbstractAttributeStyleOpProcessor.proxiedSelf and AbstractAttributeStyleOpProcessorAssocDirect.proxiedAssocSelf so that if any opbindings are registered, then they will be run.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.ca.jcs.assoc.DefaultAssocDirectAttributeOpProcessor
DefaultAssocDirectAttributeOpProcessor.AssocAttrValue, DefaultAssocDirectAttributeOpProcessor.AssociationStyle
 
Nested classes/interfaces inherited from interface com.ca.jcs.processor.OpProcessor
OpProcessor.MethodName
 
Field Summary
static String ACCOUNT_EXT
          Extension used for file storing information about an account.
static String ACCOUNT_TYPE
           
static String CONTAINER_TYPE
           
static String FILE_SEP_REPLACEMENT
           
static String GROUP_EXT
          Extension used for file storing information about a group.
static String GROUP_TYPE
           
 boolean isStreaming
          Change this value and recompile to use the streaming approach to searching.
static HashMap<String,String> TYPE_TO_EXT
           
 
Fields inherited from class com.ca.jcs.assoc.DefaultAssocDirectAttributeOpProcessor
metaConnector
 
Fields inherited from class com.ca.jcs.processor.AbstractAttributeStyleOpProcessorAssocDirect
proxiedAssocSelf
 
Fields inherited from class com.ca.jcs.processor.AbstractAttributeStyleOpProcessor
proxiedSelf
 
Fields inherited from class com.ca.jcs.processor.AbstractBaseProcessor
ldapExceptionPrefix
 
Constructor Summary
SDKAttributeStyleOpProcessor(SDKMetaConnector connector)
          Create connector.
 
Method Summary
 void activate()
          Sets proxiedSelf to OpBindings-aware proxy if any OpBindings are configured, otherwise left assigned to "this".
 void deactivate()
          We also define this for symmetry as activate() is defined.
 void doAdd(ObjectInfo objInfo, Attributes attrs)
          Create an account or a group by creating a properties file and and persisting the provided attributes to it (account files have the extension .sdk eand groups file the .grp extention.
 void doDelete(ObjectInfo objInfo)
          Deletes account or group by removing its file.
 Attributes doLookUp(ObjectInfo objInfo, String[] attrIds)
          Handles base level searches.
 Attribute doLookupExpensiveStub(ObjectInfo objInfo, String attrId)
          In some cases it may be possible to test for a value for an expensive attribute's presence without retrieving its full value, in which case this method can be used to populate stub with the matching number of values cheaply.
 void doModify(ObjectInfo objInfo, ModificationItem[] modItems)
          Modify an account or a group object, and persist changes to a .properties file.
 void doModifyRn(ObjectInfo objInfo, Rdn newRdn)
          Delete an account or a group by removing its file, and then add it again with a new name.
 void doMove(ObjectInfo objInfo, Name newParentName, Rdn newRn)
          Note: You only implement this method if you are creating a hierarchical connector such as a directory that supports moving objects to different containers in the tree structure.
 NamingEnumeration<SearchResult> doSearch(ObjectInfo baseObjInfo, FilterInfo filterInfo, Map<String,String> environment, SearchControls searchControls)
          Handles all searches, or only onelevel and subtree searches if the connector defines isBehaviourSearchObjAsLookup() to return true (which SDKMetaConnector does).
 DataModel getMetaData()
          Just a stub as this processor has no specific requirement to store metadata.
static String namingValueToFileName(String nameValue)
          Convert provided name to valid file name, i.e. handle file system separator specially.
 void searchFiles(File parentDir, FilenameFilter filenameFilter, ArrayList<File> list, SearchControls searchControls)
          recursively look through all levels in the parentDir when the isSubtree flag is true, otherwise only search one level.
 void setMetaData(DataModel dataModel)
          Just a stub as this processor has no specific requirement to store metadata.
static Map<String,String> toSimpleRegexMap(FilterInfo filterInfo)
          Similar to FilterUtil.toSimpleMap, but prepares a map containing regex expressions from the given filter to perform matching on.
 
Methods inherited from class com.ca.jcs.assoc.DefaultAssocDirectAttributeOpProcessor
addAttrAssocs, doAssocSearchForReferencesTo, doAssocUpdateReferencesTo, doDeleteAssocs, doLookupAssocs, doModifyAssocs, doModifyRnAssocs, doMoveAssocs, doSearchAssocs, expandTemplateValues, getAssocClassMap, getAssocConnAttrId, getAssocConnAttrIds, getAssocConnectorAttrIds, getAssocDataModelProp, getAssocLdapAttr, getAssocObjectClass, getAttrProc, getMetaConnector, removeAttrAssocs, updateAttrAssocs
 
Methods inherited from class com.ca.jcs.processor.AbstractAttributeStyleOpProcessorAssocDirect
convertConnectorDNToKey, convertConnectorDNToKeys, convertKeyToConnectorDN
 
Methods inherited from class com.ca.jcs.processor.AbstractAttributeStyleOpProcessor
isPostQueryPocessingActive, processPostQueryAttributes, processPostQuerySearchResult, setPostQueryPocessingActive
 
Methods inherited from class com.ca.jcs.processor.AbstractBaseProcessor
getBaseConnector, makeNamingException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isStreaming

public boolean isStreaming
Change this value and recompile to use the streaming approach to searching.


ACCOUNT_TYPE

public static final String ACCOUNT_TYPE
See Also:
Constant Field Values

GROUP_TYPE

public static final String GROUP_TYPE
See Also:
Constant Field Values

CONTAINER_TYPE

public static final String CONTAINER_TYPE
See Also:
Constant Field Values

ACCOUNT_EXT

public static final String ACCOUNT_EXT
Extension used for file storing information about an account.

See Also:
Constant Field Values

GROUP_EXT

public static final String GROUP_EXT
Extension used for file storing information about a group.

See Also:
Constant Field Values

FILE_SEP_REPLACEMENT

public static final String FILE_SEP_REPLACEMENT

TYPE_TO_EXT

public static final HashMap<String,String> TYPE_TO_EXT
Constructor Detail

SDKAttributeStyleOpProcessor

public SDKAttributeStyleOpProcessor(SDKMetaConnector connector)
Create connector. Note that AbstractBaseProcessor.ldapExceptionPrefix should be prefixed onto any LdapNameingExceptions thrown so that clients can easily distinguish between exceptions raised (and hence understand the exception more clearly):
  1. in the code for this connector
  2. in the JCS framework code
  3. in the ApacheDS code

Parameters:
connector -
Method Detail

getMetaData

public DataModel getMetaData()
Just a stub as this processor has no specific requirement to store metadata.

Specified by:
getMetaData in interface AttributeStyleOpProcessor
Overrides:
getMetaData in class DefaultAssocDirectAttributeOpProcessor
Returns:
Metadata used to configure this processor.

setMetaData

public void setMetaData(DataModel dataModel)
Just a stub as this processor has no specific requirement to store metadata.

Parameters:
dataModel - New metadata to be internalised.

doLookupExpensiveStub

public Attribute doLookupExpensiveStub(ObjectInfo objInfo,
                                       String attrId)
                                throws NamingException
In some cases it may be possible to test for a value for an expensive attribute's presence without retrieving its full value, in which case this method can be used to populate stub with the matching number of values cheaply. However, it is not relevant to this connector.

Specified by:
doLookupExpensiveStub in interface AttributeStyleOpProcessor
Overrides:
doLookupExpensiveStub in class DefaultAssocDirectAttributeOpProcessor
Parameters:
objInfo - Object for which attribute should be looked up.
attrId - Id for expensive attribute.
Returns:
Possibly less expensive placeholder for expensive attribute, if its possible to avoid looking it up fully.
Throws:
NamingException
See Also:
ValidationLazyAttributesProxy

activate

public void activate()
              throws NamingException
Description copied from class: AbstractAttributeStyleOpProcessor
Sets proxiedSelf to OpBindings-aware proxy if any OpBindings are configured, otherwise left assigned to "this".

Specified by:
activate in interface Activatable
Specified by:
activate in interface AttributeStyleOpProcessor
Overrides:
activate in class AbstractAttributeStyleOpProcessorAssocDirect
Throws:
NamingException

deactivate

public void deactivate()
                throws NamingException
Description copied from class: AbstractAttributeStyleOpProcessor
We also define this for symmetry as activate() is defined.

Specified by:
deactivate in interface Activatable
Specified by:
deactivate in interface AttributeStyleOpProcessor
Overrides:
deactivate in class AbstractAttributeStyleOpProcessor
Throws:
NamingException

namingValueToFileName

public static String namingValueToFileName(String nameValue)
Convert provided name to valid file name, i.e. handle file system separator specially.


doAdd

public void doAdd(ObjectInfo objInfo,
                  Attributes attrs)
           throws NamingException
Create an account or a group by creating a properties file and and persisting the provided attributes to it (account files have the extension .sdk eand groups file the .grp extention.

Parameters:
objInfo - Contains the target object's class type information. Use it to distinguish account objects and group objects or other types of objects, as well as accessing metadata settings (and fields calculated from them allowing fast lookup) via objInfo.getObjectClassMapping() where required.
attrs - Attributes to be persisted for the target object.
Throws:
LdapNameAlreadyBoundException - Should be thrown if an object with the specified name already exists, other NamingExceptions (preferably implementing LdapException) may also be thrown. Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

doDelete

public void doDelete(ObjectInfo objInfo)
              throws NamingException
Deletes account or group by removing its file. However, if deleting groups, also need to remove the group membership from each account. This is being done through the association. In the metadata file, the groupMembers attribute in Account is associated to Group.

Parameters:
objInfo - References managed object to be deleted.
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

doModify

public void doModify(ObjectInfo objInfo,
                     ModificationItem[] modItems)
              throws NamingException
Modify an account or a group object, and persist changes to a .properties file. For the multi-valued eTSDKGroupMembers attribute, the forceModificationMode=REPLACE metadata setting (refer to sdk_metadata.xml) means the attribute values received here are the complete list of required REPLACE values (not the equivalent ADD or REMOVE deltas against the existing set of values). Also all of these values have been concatenated into a single string value through the triggering of DemoFlattenPropertyConverter via the flattenSeparator setting in sdk_metadata.xml combined with the related plug-in configuration in conf/connector.xml, which is done because Properties files don't accept duplicated keys.

Parameters:
objInfo - References managed object which is to be modified.
modItems - Items to be modified.
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

toSimpleRegexMap

public static Map<String,String> toSimpleRegexMap(FilterInfo filterInfo)
Similar to FilterUtil.toSimpleMap, but prepares a map containing regex expressions from the given filter to perform matching on.

Parameters:
filterInfo -
Returns:

doSearch

public NamingEnumeration<SearchResult> doSearch(ObjectInfo baseObjInfo,
                                                FilterInfo filterInfo,
                                                Map<String,String> environment,
                                                SearchControls searchControls)
                                         throws NamingException
Handles all searches, or only onelevel and subtree searches if the connector defines isBehaviourSearchObjAsLookup() to return true (which SDKMetaConnector does). See the super class OpProcessor Java Doc for details. Note that normally enumerations extending RawNamingEnumeration are returned as it handles the case where searchControls specifies a size limit and / or time limit. In such cases search results are returned back to the LDAP client up until the limit is exceeded and then a non-fatal informative exception is thrown *after* these results have already been delivered back to the client.

Parameters:
baseObjInfo - Specifies base object for the search, scope in searchControls is relative to this object.
filterInfo - Information regarding the filter to be used for the search, including referenced objectClass= values. Note that attribute names have been converted to connector-speak and any required validators/converters have been run by the framework prior to this method being invoked. The filter's text can be retrieved via ExprNode.printToBuffer(StringBuffer) on contained mappedFilter. If required this mappedFilter can be converted to a different syntax, refer to SimpleFilterVisitor / FilterVisitor and related classes.
environment - Defines any values effecting how the search is performed (eg whether to follow referrals etc). Can usually be ignored.
searchControls - Defines important information about the search itself, for instance what scope the search should have under baseName and which attributes should be returned for each object matching the provided filter. Note that specifying a null String[] for the returned attributes will cause all non-expensive attributes to be returned for each matching objects, whereas specifying String[0] will cause not attributes to be returned except for the DNs of matching objects.
Returns:
Enumeration of SearchResult objects, one per object falling within the specified scope under baseName which matches the provided filter. Results can be handled in two different manners depending on the connector's requirement (indeed, an advanced connector can implement both and choose the best one based on heuristics and a threshold):
  1. Pass back results "all at once" (faster, but impractical for very large numbers of matching objects) or
  2. "stream" results back one at a time by wrapping in a NamingEnumeration that actually extracts results after this doSearch() call has returned.
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

searchFiles

public void searchFiles(File parentDir,
                        FilenameFilter filenameFilter,
                        ArrayList<File> list,
                        SearchControls searchControls)
recursively look through all levels in the parentDir when the isSubtree flag is true, otherwise only search one level. All files meeting the filter requirement will be put in the list

Parameters:
parentDir - directory in which files should be found.
filenameFilter - filter to be applied to files under parentDir
list - the list passed by the caller
searchControls - specifies parameters for search, such as scope and count limit.

doLookUp

public Attributes doLookUp(ObjectInfo objInfo,
                           String[] attrIds)
                    throws NamingException
Handles base level searches. See the super class OpProcessor Java Doc for detials

Parameters:
objInfo - Managed object for which attributes are to be looked up.
attrIds - Connector-speak identifiers of attributes which are to be returned, null means return all attributes and a zero length array means return no attributes (just a way to check an object's existance).
Returns:
Attributes values on specified managed object, where connector-speak mappings exist for specified attrIds, can be null when the target object exists but has none of the requested
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

doModifyRn

public void doModifyRn(ObjectInfo objInfo,
                       Rdn newRdn)
                throws NamingException
Delete an account or a group by removing its file, and then add it again with a new name. Note that newRdn has format attribute=value.

Parameters:
objInfo - References managed object.
newRdn - New terminal name (having form "attr=val") for managed object.
Throws:
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.
NamingException - (usually exception should implement LdapException or arrangements to map it into such an exception should be in place). Pay attention to retriable exceptions as documented in RetryOpProcessorProxy.

doMove

public void doMove(ObjectInfo objInfo,
                   Name newParentName,
                   Rdn newRn)
            throws NamingException
Note: You only implement this method if you are creating a hierarchical connector such as a directory that supports moving objects to different containers in the tree structure. Relying on the base class implementation for flat connectors will result in the default LdapOperationNotSupportedException being thrown.

Parameters:
objInfo - Information about target object to be moved.
newParentName - DN of container to which target object should be moved.
newRn - Null when object is simply being moved to a new container, otherwise object is being both moved and renamed in one operation.
Throws:
NamingException
LdapNameNotFoundException - (or NameNotFoundException) when target object doesn't exist.


Created 2011-07-14 13:27 EST