class LdapRemapper extends RamRemapper
The design assumes that LdapRemapper can be used in very different environments and therefore it must support a number of different approaches which allow mapping between P2J directory as it is seen by the application and underlying LDAP directory.
Following cases are possible:
To support all these different situations following approach is used: implementation maintains P2J directory tree in memory. Each node which is backed by the LDAP has special Object Class "ldapNode". This class represent all information required to properly access LDAP server and map attributes. The mapping is constructed at startup either by loading data from external storage or by scanning LDAP subtree.
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
alias
Certificate alias
|
private java.lang.String |
aliasPass
Certificate password
|
private javax.naming.ldap.LdapContext |
ctx
LDAP directory context used to access LDAP data
|
private static java.lang.String |
EMPTY
Value which will represent empty strings in LDAP
|
private java.util.Hashtable<java.lang.String,java.lang.String> |
env
LDAP context environment
|
private java.lang.String |
keyPass
Keystore password
|
private java.lang.String |
keyStore
Keystore
|
private java.lang.String |
mapping
Mapping mapping (file, URL, CN, etc)
|
private int |
mode
How to handle mapping field.
|
private static int |
MODE_ATTRIBUTE
Mode: mapping saved as attribute in LDAP node
|
private static int |
MODE_FILE
Mode: mapping is XML file
|
private static int |
MODE_SUBTREE
Mode: mapping saved as subtree of LDAP tree
|
private static int |
MODE_URL
Mode: mapping is XML file at specified URL
|
private SchemaMaping |
schemaMap
Mapping data
|
private java.lang.String |
trustPass
Truststore password
|
private java.lang.String |
trustStore
Storage for the private keys
|
mutex, root
Constructor and Description |
---|
LdapRemapper(BootstrapConfig config)
Construct an instance of the LdapRemapper which will work with specified
LDAP server.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
addAttributeValueExt(RamNode node,
java.lang.String name,
java.lang.Object val)
Intercept adding of the value to the attribute.
|
private boolean |
addLdapAttributeValue(RamNode node,
java.lang.String name,
java.lang.Object val)
Add value to the LDAP node attribute.
|
private RamNode |
addLdapNode(RamNode node,
RamNode newNode)
Add new node to LDAP tree.
|
protected boolean |
addNodeExt(RamNode parent,
RamNode newNode)
Intercept adding of the node.
|
private java.lang.String |
composeName(java.lang.String location,
java.lang.String name,
java.lang.String p2jClass)
Compose full name for the given location and node name.
|
private boolean |
deleteLdapNode(RamNode node,
java.lang.String child)
Delete node in LDAP directory.
|
private boolean |
deleteLdapNodeAttribute(RamNode node,
java.lang.String name)
Remove attribute from the LDAP node.
|
private boolean |
deleteLdapNodeAttributeValue(RamNode node,
java.lang.String name,
int index)
Delete node attribute value from LDAP node.
|
protected boolean |
deleteNodeAttributeExt(RamNode node,
java.lang.String name)
Intercept deletion of the attribute.
|
protected boolean |
deleteNodeAttributeValueExt(RamNode node,
java.lang.String name,
int index)
Intercept deletion of the node attribute value.
|
protected boolean |
deleteNodeExt(RamNode parent,
java.lang.String child)
Intercept removing node.All parameters are checked and all what we need
to to is to remove child node from LDAP and call
super.deleteNodeExt() . |
private RamNode |
extractFromLdap(RamNode node)
Extract information from LDAP.
|
private javax.naming.ldap.LdapContext |
getCtx()
Get JNDI LDAP context.
|
private java.lang.String |
getLdapAttribute(RamNode node,
java.lang.String name)
Find a name of the LDAP attribute which corresponds to specified P2J
attribute.
|
private java.lang.String |
getLdapNodeClass(java.lang.String location,
java.lang.String name)
Get LDAP Object Class Name for child node of specified location.
|
private java.lang.String |
getLocation(RamNode node)
Convenience method to retrieve information about LDAP context name
(location) from specified
RamNode instance of "ldapNode"
Object Class. |
private java.lang.String |
getP2jClass(RamNode node)
Get name of P2J Object Class associated with node of "ldapNode"
Object Class.
|
protected void |
load()
Load mapping and initialise directory context to access LDAP.
|
protected RamNode |
locateNode(java.lang.String id)
Replacement for the locateNode.
|
private boolean |
moveLdapNode(RamNode parent,
java.lang.String name,
RamNode newParent,
java.lang.String newName)
Move LDAP node to the new location.
|
protected boolean |
moveNodeExt(RamNode parent,
java.lang.String name,
RamNode newParent,
java.lang.String newName)
Intercept moving node.
|
boolean |
refresh()
No-op implementation.
|
private void |
refreshLdapNode(RamNode node)
Compare existing information about child nodes with stored in mapping
and refresh mapping of necessary.
|
protected void |
save()
Save current tree into XML file.
|
private void |
setCtx(javax.naming.ldap.LdapContext ctx)
Set JNDI LDAP context.
|
private boolean |
setLdapAttributeValue(RamNode node,
java.lang.String name,
java.lang.Object val,
int index)
Set value of the attribute of LDAP node.
|
protected boolean |
setNodeValueExt(RamNode node,
java.lang.String name,
java.lang.Object val,
int index)
Intercept changing node attribute value.
|
addNode, addNodeBitField, addNodeBitSelector, addNodeBoolean, addNodeByteArray, addNodeDate, addNodeDouble, addNodeInteger, addNodeString, addNodeTime, bind, deleteNode, deleteNodeAttribute, deleteNodeAttributeValue, enumerateNodeAttributes, enumerateNodes, getClassDefinition, getClassNames, getNodeBitField, getNodeBitSelector, getNodeBoolean, getNodeByteArray, getNodeClassName, getNodeDate, getNodeDouble, getNodeInteger, getNodeString, getNodeTime, getNodeValueExt, getObjClass, getRoot, isBound, isClassImmutable, isClassLeaf, moveNode, setNodeBitField, setNodeBitSelector, setNodeBoolean, setNodeByteArray, setNodeDate, setNodeDouble, setNodeInteger, setNodeString, setNodeTime, setRoot, unbind, update
private static final java.lang.String EMPTY
private static final int MODE_ATTRIBUTE
private static final int MODE_FILE
private static final int MODE_SUBTREE
private static final int MODE_URL
private java.lang.String alias
private java.lang.String aliasPass
private javax.naming.ldap.LdapContext ctx
private java.util.Hashtable<java.lang.String,java.lang.String> env
private java.lang.String keyPass
private java.lang.String keyStore
private java.lang.String mapping
private int mode
private SchemaMaping schemaMap
private java.lang.String trustPass
private java.lang.String trustStore
LdapRemapper(BootstrapConfig config) throws ConfigurationException
config
- A reference to configuration.ConfigurationException
public boolean refresh()
Current implementation assumes that all external directory changes are reloaded automatically. This is correct, but in some operating modes this might not be enough because mapping information is not reloaded.
refresh
in interface Remapper
refresh
in class RamRemapper
true
if operation was successful.RamRemapper.refresh()
protected boolean addAttributeValueExt(RamNode node, java.lang.String name, java.lang.Object val)
addAttributeValueExt
in class RamRemapper
node
- A node from which attribute value is requested.name
- Name of the attribute.val
- New value which will be added to the attribute.true
is operation is successful and
false
otherwise.protected boolean addNodeExt(RamNode parent, RamNode newNode)
super.addNodeExt()
.addNodeExt
in class RamRemapper
parent
- A node to which newNode
will be added.newNode
- New node which need to be added to parent
.true
if operation was successful and
false
otherwise.protected boolean deleteNodeAttributeExt(RamNode node, java.lang.String name)
deleteNodeAttributeExt
in class RamRemapper
node
- A node from which attribute value is requested.name
- Name of the attribute.true
if operation was successful and
false
otherwise.protected boolean deleteNodeAttributeValueExt(RamNode node, java.lang.String name, int index)
deleteNodeAttributeValueExt
in class RamRemapper
node
- A node from which attribute value will be deleted.name
- Name of the attribute.index
- Attribute value index.true
is operation is successful and
false
otherwise.protected boolean deleteNodeExt(RamNode parent, java.lang.String child)
super.deleteNodeExt()
.deleteNodeExt
in class RamRemapper
parent
- A node to which newNode
will be added.child
- An ID of the child node to remove.true
if operation was successful and
false
otherwise.protected void load() throws java.lang.Exception
load
in class RamRemapper
java.lang.Exception
- Forwarded from various sources and wrapped into
SchemaException
.protected RamNode locateNode(java.lang.String id)
locateNode
in class RamRemapper
id
- Node IDnull
if error
occurred.protected boolean moveNodeExt(RamNode parent, java.lang.String name, RamNode newParent, java.lang.String newName)
moveNodeExt
in class RamRemapper
parent
- A parent node of the node which is about to be moved to new
location.name
- Name of the node which will be moved.newParent
- A node which will be new parent node if operation will be
successful.newName
- New name of the node.true
is operation is successful and
false
otherwise.protected void save() throws java.lang.Exception
save
in class RamRemapper
java.lang.Exception
- If I/O error occurred during operation or
XmlHelper
throws an
ParserConfigurationException
.protected boolean setNodeValueExt(RamNode node, java.lang.String name, java.lang.Object val, int index)
setNodeValueExt
in class RamRemapper
node
- A node which contains the attribute to change.name
- Attribute name.index
- Index of the value to retrieve.val
- New value for the attribute variable.true
is operation is successful and
false
otherwise.private boolean addLdapAttributeValue(RamNode node, java.lang.String name, java.lang.Object val)
node
- A reference to the RamNode
of "ldapNode" object
class.name
- Attribute name.val
- New attribute value.true
is operation is successful and
false
otherwise.private RamNode addLdapNode(RamNode node, RamNode newNode)
node
- RamNode
instance of "ldapNode" Object Class
which contains mapping information.newNode
- New node to add.null
private java.lang.String composeName(java.lang.String location, java.lang.String name, java.lang.String p2jClass)
location
- Starting location.name
- Node name.p2jClass
- An P2J Object Class name for the given node name.private boolean deleteLdapNode(RamNode node, java.lang.String child)
node
- A node of "ldapNode" object class.child
- Name of the child node to remove.true
if operation was successful and
false
otherwise.private boolean deleteLdapNodeAttribute(RamNode node, java.lang.String name)
node
- A node of "ldapNode" Object Class.name
- Attribute name.true
if operation was successful and
false
otherwise.private boolean deleteLdapNodeAttributeValue(RamNode node, java.lang.String name, int index)
node
- A node of "ldapNode" Object Class.name
- Attribute name.index
- Attribute value index.true
is operation is successful and
false
otherwise.private RamNode extractFromLdap(RamNode node)
node
- Source node of "ldapNode" Object Class.private javax.naming.ldap.LdapContext getCtx()
private java.lang.String getLdapAttribute(RamNode node, java.lang.String name)
node
- RamNode
of "ldapNode" Object Class.name
- Name of P2J attribute.private java.lang.String getLdapNodeClass(java.lang.String location, java.lang.String name)
location
- LDAP node location.name
- Name of child node of specified location.private java.lang.String getLocation(RamNode node)
RamNode
instance of "ldapNode"
Object Class.node
- Reference to the RamNode of "ldapNode" Object Class.private java.lang.String getP2jClass(RamNode node)
node
- RamNode
of "ldapNode" Object Class.private boolean moveLdapNode(RamNode parent, java.lang.String name, RamNode newParent, java.lang.String newName)
parent
- Parent node.name
- Node name.newParent
- Target parent node.newName
- Target name.true
is operation is successful and
false
otherwise.private void refreshLdapNode(RamNode node)
node
- Node to refresh.private void setCtx(javax.naming.ldap.LdapContext ctx)
ctx
- The context to set.private boolean setLdapAttributeValue(RamNode node, java.lang.String name, java.lang.Object val, int index)
node
- A node which contains the attribute to change.name
- Attribute name.index
- Index of the value to retrieve.val
- New value for the attribute variable.true
is operation is successful and
false
otherwise.