wip made remote ejb working over http
This commit is contained in:
parent
d4e537a2bf
commit
2a0d992642
393 changed files with 8916 additions and 3872 deletions
|
|
@ -3,11 +3,11 @@
|
|||
<parent>
|
||||
<artifactId>vasc-backend</artifactId>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<version>0.3.5-SNAPSHOT</version>
|
||||
<version>0.4.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>net.forwardfire.vasc</groupId>
|
||||
<artifactId>vasc-backend-ldap</artifactId>
|
||||
<version>0.3.5-SNAPSHOT</version>
|
||||
<version>0.4.1-SNAPSHOT</version>
|
||||
<name>vasc-backend-ldap</name>
|
||||
<description>vasc-backend-ldap</description>
|
||||
<dependencies>
|
||||
|
|
|
|||
|
|
@ -25,11 +25,12 @@ package net.forwardfire.vasc.backend.ldap;
|
|||
import com.novell.ldap.LDAPConnection;
|
||||
|
||||
/**
|
||||
* LdapConnectionProvider gets ldap connection.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Sep 4, 2008
|
||||
*/
|
||||
public interface LdapConnectionProvider {
|
||||
|
||||
public LDAPConnection getLdapConnection();
|
||||
}
|
||||
LDAPConnection getLdapConnection();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ package net.forwardfire.vasc.backend.ldap;
|
|||
import com.novell.ldap.LDAPConnection;
|
||||
|
||||
/**
|
||||
* LdapConnectionProviderImpl provides an ldap connection.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Sep 4, 2008
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ import net.forwardfire.vasc.backend.data.MapVascEntryFieldValue;
|
|||
import net.forwardfire.vasc.backend.data.MapVascEntryRecordCreator;
|
||||
import net.forwardfire.vasc.core.VascEntry;
|
||||
import net.forwardfire.vasc.core.VascEntryField;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryFieldValue;
|
||||
import net.forwardfire.vasc.core.entry.VascEntryRecordCreator;
|
||||
import net.forwardfire.vasc.core.VascException;
|
||||
|
||||
|
||||
import com.novell.ldap.LDAPAttribute;
|
||||
|
|
@ -60,7 +60,7 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
private String baseDN = null;
|
||||
private String keyAttribute = null;
|
||||
private String ldapFilter = null;
|
||||
|
||||
private String createObjectClass = null;
|
||||
|
||||
/**
|
||||
* @return the ldapConnectionProvider
|
||||
|
|
@ -91,43 +91,43 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
|
||||
LDAPSearchConstraints cons = new LDAPSearchConstraints();
|
||||
cons.setBatchSize( 0 );
|
||||
cons.setTimeLimit( 10000 ) ;
|
||||
cons.setReferralFollowing(true);
|
||||
connection.setConstraints(cons);
|
||||
cons.setTimeLimit( 10000 ) ;
|
||||
cons.setReferralFollowing(true);
|
||||
connection.setConstraints(cons);
|
||||
|
||||
int searchScope = LDAPConnection.SCOPE_ONE;
|
||||
String searchBase = baseDN;
|
||||
int searchScope = LDAPConnection.SCOPE_ONE;
|
||||
String searchBase = baseDN;
|
||||
|
||||
//System.out.println("Reading object :" + searchBase + " with filter: " + ldapFilter);
|
||||
LDAPSearchResults searchResults = connection.search(
|
||||
searchBase, // object to read
|
||||
searchScope, // scope - read single object
|
||||
ldapFilter, // search filter
|
||||
null, // return all attributes
|
||||
false); // return attrs and values
|
||||
|
||||
while (searchResults.hasMore()) {
|
||||
LDAPEntry entry = searchResults.next();
|
||||
Map<String,Object> map = new HashMap<String,Object>(10);
|
||||
|
||||
LDAPAttributeSet attributeSet = entry.getAttributeSet();
|
||||
Iterator<LDAPAttribute> i = attributeSet.iterator();
|
||||
while (i.hasNext()) {
|
||||
LDAPAttribute attr = i.next();
|
||||
//System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue());
|
||||
String[] s = attr.getStringValueArray();
|
||||
if (s.length==1) {
|
||||
map.put(attr.getName(), attr.getStringValue());
|
||||
} else {
|
||||
List<String> multiValue = new ArrayList<String>(s.length);
|
||||
for (String ss:s) {
|
||||
multiValue.add(ss);
|
||||
}
|
||||
map.put(attr.getName(), multiValue );
|
||||
}
|
||||
}
|
||||
result.add(map);
|
||||
}
|
||||
//System.out.println("Reading object :" + searchBase + " with filter: " + ldapFilter);
|
||||
LDAPSearchResults searchResults = connection.search(
|
||||
searchBase, // object to read
|
||||
searchScope, // scope - read single object
|
||||
ldapFilter, // search filter
|
||||
null, // return all attributes
|
||||
false); // return attrs and values
|
||||
|
||||
while (searchResults.hasMore()) {
|
||||
LDAPEntry entry = searchResults.next();
|
||||
Map<String,Object> map = new HashMap<String,Object>(10);
|
||||
|
||||
LDAPAttributeSet attributeSet = entry.getAttributeSet();
|
||||
Iterator<LDAPAttribute> i = attributeSet.iterator();
|
||||
while (i.hasNext()) {
|
||||
LDAPAttribute attr = i.next();
|
||||
//System.out.println("ATTR: "+attr.getName()+" value: "+attr.getStringValue());
|
||||
String[] s = attr.getStringValueArray();
|
||||
if (s.length==1) {
|
||||
map.put(attr.getName(), attr.getStringValue());
|
||||
} else {
|
||||
List<String> multiValue = new ArrayList<String>(s.length);
|
||||
for (String ss:s) {
|
||||
multiValue.add(ss);
|
||||
}
|
||||
map.put(attr.getName(), multiValue );
|
||||
}
|
||||
}
|
||||
result.add(map);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new VascException(e);
|
||||
} finally {
|
||||
|
|
@ -149,68 +149,68 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
String keyValue = (String)map.get(keyAttribute);
|
||||
LDAPSearchConstraints cons = new LDAPSearchConstraints();
|
||||
cons.setBatchSize( 0 );
|
||||
cons.setTimeLimit( 10000 ) ;
|
||||
cons.setReferralFollowing(true);
|
||||
connection.setConstraints(cons);
|
||||
cons.setTimeLimit( 10000 ) ;
|
||||
cons.setReferralFollowing(true);
|
||||
connection.setConstraints(cons);
|
||||
|
||||
int searchScope = LDAPConnection.SCOPE_ONE;
|
||||
String searchBase = baseDN;
|
||||
String filter = "(&("+keyAttribute+"="+keyValue+"))";
|
||||
System.out.println("ldap filter: "+filter);
|
||||
LDAPSearchResults searchResults = connection.search(
|
||||
searchBase, // object to read
|
||||
searchScope, // scope - read single object
|
||||
filter, // search filter
|
||||
null, // return all attributes
|
||||
false); // return attrs and values
|
||||
|
||||
if (searchResults.hasMore()==false) {
|
||||
// no result to mod
|
||||
return object;
|
||||
}
|
||||
LDAPEntry entry = searchResults.next();
|
||||
int searchScope = LDAPConnection.SCOPE_ONE;
|
||||
String searchBase = baseDN;
|
||||
String filter = "(&("+keyAttribute+"="+keyValue+"))";
|
||||
System.out.println("ldap filter: "+filter);
|
||||
LDAPSearchResults searchResults = connection.search(
|
||||
searchBase, // object to read
|
||||
searchScope, // scope - read single object
|
||||
filter, // search filter
|
||||
null, // return all attributes
|
||||
false); // return attrs and values
|
||||
|
||||
if (searchResults.hasMore()==false) {
|
||||
// no result to mod
|
||||
return object;
|
||||
}
|
||||
LDAPEntry entry = searchResults.next();
|
||||
List<LDAPModification> mods = new ArrayList<LDAPModification>(20);
|
||||
for (String key:map.keySet()) {
|
||||
Object value = map.get(key);
|
||||
LDAPAttribute attr = entry.getAttribute(key);
|
||||
if (attr==null) {
|
||||
LDAPModification mod = new LDAPModification(LDAPModification.ADD,new LDAPAttribute(key,(String)value));
|
||||
mods.add(mod);
|
||||
continue;
|
||||
}
|
||||
String[] s = attr.getStringValueArray();
|
||||
if (s.length==1) {
|
||||
String v = (String)value;
|
||||
if (attr.getStringValue().equals(v)==false) {
|
||||
LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,new LDAPAttribute(key,v));
|
||||
mods.add(mod);
|
||||
}
|
||||
map.put(attr.getName(), attr.getStringValue());
|
||||
} else {
|
||||
List<String> multiValue = new ArrayList<String>(s.length);
|
||||
for (String ss:s) {
|
||||
multiValue.add(ss);
|
||||
}
|
||||
List<String> v = null;
|
||||
if (value instanceof String) {
|
||||
v = new ArrayList<String>(1);
|
||||
v.add((String)value);
|
||||
} else {
|
||||
v = (List<String>)value;
|
||||
}
|
||||
if (v.equals(multiValue)==false) {
|
||||
LDAPAttribute a = new LDAPAttribute(key);
|
||||
for (String vv:v) {
|
||||
a.addValue(vv);
|
||||
}
|
||||
LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,a);
|
||||
mods.add(mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LDAPModification[] m = new LDAPModification[mods.size()];
|
||||
mods.toArray(m);
|
||||
for (String key:map.keySet()) {
|
||||
Object value = map.get(key);
|
||||
LDAPAttribute attr = entry.getAttribute(key);
|
||||
if (attr==null) {
|
||||
LDAPModification mod = new LDAPModification(LDAPModification.ADD,new LDAPAttribute(key,(String)value));
|
||||
mods.add(mod);
|
||||
continue;
|
||||
}
|
||||
String[] s = attr.getStringValueArray();
|
||||
if (s.length==1) {
|
||||
String v = (String)value;
|
||||
if (attr.getStringValue().equals(v)==false) {
|
||||
LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,new LDAPAttribute(key,v));
|
||||
mods.add(mod);
|
||||
}
|
||||
map.put(attr.getName(), attr.getStringValue());
|
||||
} else {
|
||||
List<String> multiValue = new ArrayList<String>(s.length);
|
||||
for (String ss:s) {
|
||||
multiValue.add(ss);
|
||||
}
|
||||
List<String> v = null;
|
||||
if (value instanceof String) {
|
||||
v = new ArrayList<String>(1);
|
||||
v.add((String)value);
|
||||
} else {
|
||||
v = (List<String>)value;
|
||||
}
|
||||
if (v.equals(multiValue)==false) {
|
||||
LDAPAttribute a = new LDAPAttribute(key);
|
||||
for (String vv:v) {
|
||||
a.addValue(vv);
|
||||
}
|
||||
LDAPModification mod = new LDAPModification(LDAPModification.REPLACE,a);
|
||||
mods.add(mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LDAPModification[] m = new LDAPModification[mods.size()];
|
||||
mods.toArray(m);
|
||||
connection.modify(entry.getDN(), m);
|
||||
return object;
|
||||
} catch (Exception e) {
|
||||
|
|
@ -226,12 +226,29 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
* @see net.forwardfire.vasc.backend.VascBackend#persist(java.lang.Object)
|
||||
*/
|
||||
public void persist(Object object) throws VascException {
|
||||
Map<String,Object> map = (Map)object;
|
||||
LdapConnectionProvider prov = getLdapConnectionProvider();
|
||||
LDAPConnection connection = prov.getLdapConnection();
|
||||
try {
|
||||
LDAPEntry entry = new LDAPEntry();
|
||||
// entry.getAttributeSet().
|
||||
String keyValue = (String)map.get(keyAttribute);
|
||||
LDAPEntry entry = new LDAPEntry(keyAttribute+"="+keyValue+","+baseDN);
|
||||
|
||||
LDAPAttribute ob = new LDAPAttribute("objectClass");
|
||||
String[] obs = createObjectClass.split(",");
|
||||
for (String o:obs) {
|
||||
ob.addValue(o);
|
||||
}
|
||||
entry.getAttributeSet().add(ob);
|
||||
|
||||
for (String key:map.keySet()) {
|
||||
Object value = map.get(key);
|
||||
if (value==null) {
|
||||
continue;
|
||||
}
|
||||
LDAPAttribute attr = new LDAPAttribute(key);
|
||||
attr.addValue(""+value);
|
||||
entry.getAttributeSet().add(attr);
|
||||
}
|
||||
connection.add(entry);
|
||||
} catch (Exception e) {
|
||||
throw new VascException(e);
|
||||
|
|
@ -251,22 +268,22 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
try {
|
||||
Map<String,Object> map = (Map)object;
|
||||
String keyValue = (String)map.get(keyAttribute);
|
||||
int searchScope = LDAPConnection.SCOPE_ONE;
|
||||
String searchBase = baseDN;
|
||||
String filter = "(&("+ldapFilter+")("+keyAttribute+"="+keyValue+"))";
|
||||
LDAPSearchResults searchResults = connection.search(
|
||||
searchBase, // object to read
|
||||
searchScope, // scope - read single object
|
||||
filter, // search filter
|
||||
null, // return all attributes
|
||||
false); // return attrs and values
|
||||
|
||||
if (searchResults.hasMore()==false) {
|
||||
// no result to mod
|
||||
return;
|
||||
}
|
||||
LDAPEntry entry = searchResults.next();
|
||||
connection.delete(entry.getDN());
|
||||
int searchScope = LDAPConnection.SCOPE_ONE;
|
||||
String searchBase = baseDN;
|
||||
String filter = "(&("+ldapFilter+")("+keyAttribute+"="+keyValue+"))";
|
||||
LDAPSearchResults searchResults = connection.search(
|
||||
searchBase, // object to read
|
||||
searchScope, // scope - read single object
|
||||
filter, // search filter
|
||||
null, // return all attributes
|
||||
false); // return attrs and values
|
||||
|
||||
if (searchResults.hasMore()==false) {
|
||||
// no result to mod
|
||||
return;
|
||||
}
|
||||
LDAPEntry entry = searchResults.next();
|
||||
connection.delete(entry.getDN());
|
||||
} catch (Exception e) {
|
||||
throw new VascException(e);
|
||||
} finally {
|
||||
|
|
@ -331,4 +348,18 @@ public class LdapVascBackend extends AbstractVascBackend {
|
|||
public void setLdapFilter(String ldapFilter) {
|
||||
this.ldapFilter = ldapFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the createObjectClass
|
||||
*/
|
||||
public String getCreateObjectClass() {
|
||||
return createObjectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param createObjectClass the createObjectClass to set
|
||||
*/
|
||||
public void setCreateObjectClass(String createObjectClass) {
|
||||
this.createObjectClass = createObjectClass;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<eld:root xmlns:eld="http://eld.x4o.org/eld/eld-lang.eld">
|
||||
<eld:elementClass tag="ldapBackend" objectClassName="net.forwardfire.vasc.backend.ldap.LdapVascBackend"/>
|
||||
<eld:elementClass tag="ldapConnectionProvider" objectClassName="net.forwardfire.vasc.backend.ldap.LdapConnectionProviderImpl"/>
|
||||
</eld:root>
|
||||
<root:module
|
||||
xmlns="http://eld.x4o.org/xml/ns/eld-lang"
|
||||
xmlns:root="http://eld.x4o.org/xml/ns/eld-root"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://eld.x4o.org/xml/ns/eld-root http://eld.x4o.org/xml/ns/eld-root-1.0.xsd"
|
||||
providerName="vasc.forwardfire.net"
|
||||
name="Vasc Backend LDAP"
|
||||
id="vasc-backend-ldap"
|
||||
>
|
||||
<description>Provides VASC LDAP backend support.</description>
|
||||
<namespace uri="http://vasc.forwardfire.net/xml/ns/vasc-backend-ldap"
|
||||
schemaUri="http://vasc.forwardfire.net/xml/ns/vasc-backend-ldap-1.0.xsd"
|
||||
schemaResource="vasc-backend-ldap-1.0.xsd"
|
||||
schemaPrefix="ldap"
|
||||
name="Vasc Backend LDAP"
|
||||
id="ns-vasc-backend-ldap"
|
||||
>
|
||||
<description>Provides backend and connection provider support.</description>
|
||||
<element tag="ldapBackend" objectClass="net.forwardfire.vasc.backend.ldap.LdapVascBackend"/>
|
||||
<element tag="ldapConnectionProvider" objectClass="net.forwardfire.vasc.backend.ldap.LdapConnectionProviderImpl"/>
|
||||
</namespace>
|
||||
</root:module>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<modules version="1.0"
|
||||
xmlns="http://language.x4o.org/xml/ns/modules"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://language.x4o.org/xml/ns/modules http://language.x4o.org/xml/ns/modules-1.0.xsd"
|
||||
>
|
||||
<language version="1.0">
|
||||
<eld-resource>vasc-backend-ldap.eld</eld-resource>
|
||||
</language>
|
||||
</modules>
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties>
|
||||
<comment>
|
||||
Vasc namespace for the ldap backend
|
||||
</comment>
|
||||
<entry key="eld.http://vasc.forwardfire.net/eld/vasc-backend-ldap.eld">vasc-backend-ldap.eld</entry>
|
||||
</properties>
|
||||
Loading…
Add table
Add a link
Reference in a new issue