public class LdapMapGen
extends java.lang.Object
The mapping contains two main parts: schema-level mapping and node-level mapping. The schema-level mapping defines how particular LDAP object class and its attributes corresponds to P2J object classes and attributes. The node-level mapping defines which LDAP node represents particular node in P2J directory.
The LDAP back-end supports two major modes of operation: when only schema-level mapping is defined and when both schema-level and node-level mapping are provided. The difference between them is that first one assumes that LDAP server already provides hierarchy suitable for use by P2J and LDAP back-end just uses it as is. In second mode there is no need to have such a hierarchy, each P2J node can be individually mapped into LDAP node and some nodes may not have corresponding LDAP node at all.
Since writing mapping information manually is complicated and error prone
procedure, LdapMapGen
utility is provided to simplify it.
The main purpose of the LdapMapGen
utility is to generate
mapping information required for use of P2J DirectoryService subsystem with
LDAP server. The resulting mapping information can be stored in the map
file in XML format recognized by LDAP back-end or at the LDAP server in
specified location. Beside that, utility in some cases can generate schema
file suitable for use with LDAP server.
Modifier and Type | Field and Description |
---|---|
private java.lang.String[] |
args
Command line parameters
|
private java.util.HashMap |
configNodeList
Mapping between LDAP and P2J nodes as it defined in configuration file.
|
private javax.naming.directory.DirContext |
context
LDAP directory context
|
private java.lang.String |
ldapCredentials
Configuration parameter: LDAP credentials
|
private java.lang.String |
ldapPrincipal
Configuration parameter: LDAP principal
|
private java.lang.String |
ldapSchemaHeader
Heading text for the LDAP schema
|
private java.lang.String |
ldapUrl
Configuration parameter: LDAP URL
|
private static int |
MAP_NODE
Node-to-node mapping
|
private static int |
MAP_SUBTREE
One-to-one mapping between LDAP and P2J directories
|
private java.lang.String |
mapAttribute
LDAP node attribute name where mapping will be stored
|
private java.lang.String |
mapObjClass
LDAP object class of the node where mapping will be stored
|
private SchemaMaping |
mapping
Mapping data
|
private int |
mappingMode
Mapping mode between LDAP and P2J
|
private java.lang.String |
mappingNode
Root of the mapping if saving to subtree is desired
|
private java.util.HashMap |
nodeList
Complete expanded mapping between P2J and LDAP nodes
|
Constructor and Description |
---|
LdapMapGen(java.lang.String[] args)
Construct an instance for specified command line parameters.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
createNode(RamRemapper remapper,
java.lang.String nodeId)
Create node of "ldapNode" type for specified P2J node and class.
|
(package private) void |
expandNodeMappings()
Expand all subtree to subtree mappings into explicit node-to-node
mappings.
|
(package private) void |
expandWildcard(java.util.HashMap result,
java.lang.String cn,
java.lang.String nodeId)
Expand subtree node ID with wildcards and return a list of all nodes in
the subtree.
|
(package private) void |
expandWorker(java.util.HashMap result,
javax.naming.directory.DirContext ctx,
java.lang.String cn,
java.lang.String nodeId)
Recursive worker routine for the
expandWildcard() method. |
(package private) java.lang.String |
getNodeClass(java.lang.String nodeId)
Return LDAP Object Class name for specified P2J node.
|
(package private) void |
loadConfig(java.lang.String file)
Load map configuration file.
|
static void |
main(java.lang.String[] args)
Command line driver.
|
private static java.lang.String |
mkAttrName(java.lang.String cls,
java.lang.String attr)
Make LDAP attribute name from object class name and attribute name.
|
(package private) javax.naming.directory.DirContext |
prepareContext()
Prepare DirContext using LDAP configuration parameters obtained from
configuration file.
|
private void |
replaceRoot(RamRemapper remapper,
java.lang.String cn,
java.lang.String p2jClass)
Replace root node with one of type "ldapNode".
|
(package private) void |
run()
Main application worker.
|
(package private) static void |
say(java.lang.String msg)
Shortcut for the System.out.prinln()
|
private void |
selfMap()
Generate mapping using only P2J schema data.
|
private static java.lang.String[] |
sortArray(java.lang.String[] src)
Sort array of strings.
|
(package private) static boolean |
str2bool(java.lang.String str)
Convert string into boolean value.
|
private static java.lang.String |
vec2str(java.util.Vector req)
Build list of attributes from the vector.
|
private void |
writeLdap()
Write mapping into LDAP node/attribute.
|
private void |
writeLdapSchema(java.lang.String outFile)
Write LDAP schema file into
|
(package private) void |
writeMap(java.lang.String file)
Write resulting XML map file.
|
private static final int MAP_SUBTREE
private static final int MAP_NODE
private java.lang.String[] args
private java.util.HashMap configNodeList
private javax.naming.directory.DirContext context
private java.lang.String ldapCredentials
private java.lang.String ldapPrincipal
private java.lang.String ldapUrl
private SchemaMaping mapping
private int mappingMode
private java.util.HashMap nodeList
private java.lang.String ldapSchemaHeader
private java.lang.String mappingNode
private java.lang.String mapAttribute
private java.lang.String mapObjClass
LdapMapGen(java.lang.String[] args)
args
- Command line parameters passed to main()private static java.lang.String mkAttrName(java.lang.String cls, java.lang.String attr)
cls
- Object class name.attr
- Attribute name.private static java.lang.String[] sortArray(java.lang.String[] src)
src
- Source array.private static java.lang.String vec2str(java.util.Vector req)
req
- Vector with attribute names.static void say(java.lang.String msg)
msg
- Message to print to standard output.static boolean str2bool(java.lang.String str)
true
str
- Source string.boolean
value for given string.void createNode(RamRemapper remapper, java.lang.String nodeId) throws javax.naming.NamingException
remapper
- XML back-end reference.nodeId
- P2J node ID.javax.naming.NamingException
- Forwarded from getNodeClass()
.void expandNodeMappings() throws javax.naming.NamingException
javax.naming.NamingException
- Forwarded from expandWildcard()
method.void expandWildcard(java.util.HashMap result, java.lang.String cn, java.lang.String nodeId) throws javax.naming.NamingException
result
- Storage for the node to node mapping.cn
- LDAP node ID.nodeId
- P2J node IDjavax.naming.NamingException
- Forwarded from the JNDI methods.void expandWorker(java.util.HashMap result, javax.naming.directory.DirContext ctx, java.lang.String cn, java.lang.String nodeId) throws javax.naming.NamingException
expandWildcard()
method.result
- Vector with collected nodes.ctx
- LDAP Directory context to scan.cn
- Node ID to start scan from.nodeId
- P2J node ID.javax.naming.NamingException
- Forwarded from DirContext.list()
method.java.lang.String getNodeClass(java.lang.String nodeId) throws javax.naming.NamingException
nodeId
- LDAP node ID.javax.naming.NamingException
- Forwarded from the JNDI classes.void loadConfig(java.lang.String file) throws java.lang.Exception
file
- Source file name.java.lang.Exception
- Forwarded from the various classes used my method.javax.naming.directory.DirContext prepareContext() throws javax.naming.NamingException
javax.naming.NamingException
- Forwarded from InitialDirContext()
.void run()
void writeMap(java.lang.String file) throws java.lang.Exception
file
- XML file name.java.lang.Exception
- Forwarded from createNode()
method.private void replaceRoot(RamRemapper remapper, java.lang.String cn, java.lang.String p2jClass)
remapper
- Back-end to perform operation on.cn
- LDAP node location.p2jClass
- private void writeLdapSchema(java.lang.String outFile)
outFile
- File name where LDAP schema will be saved.private void selfMap()
private void writeLdap() throws ConfigurationException
ConfigurationException
- In case of configuration error.public static void main(java.lang.String[] args)
args
- Application command line parameters. File name is the only one
expected.