Methods Summary |
---|
public void | ejbActivate()
getPeopleContext();
|
public java.util.Collection | ejbFindByName(java.lang.String firstName, java.lang.String lastName)
try {
String ldapString = null;
if (firstName != null && lastName != null) {
ldapString = "& (cn=" + firstName + ") (sn=" + lastName + ")";
} else if (firstName != null) {
ldapString = "(cn=" + firstName + ")";
} else if (lastName != null) {
ldapString = "(sn=" + lastName + ")";
} else {
ldapString = "(objectClass=person)";
}
return ldapFind(ldapString);
} catch(NamingException ne) {
throw new FinderException("Error in find: " + ne);
}
|
public java.lang.String | ejbFindByPrimaryKey(java.lang.String key)
try {
loadFromLdap(key);
return (key);
} catch(NamingException ne) {
throw new FinderException("Error finding " + key + " : " + ne);
}
|
public void | ejbLoad()
String key = (String)context.getPrimaryKey();
try {
loadFromLdap(key);
} catch(NamingException ne) {
throw new EJBException("Error loading " + key, ne);
}
|
public void | ejbPassivate()
if (peopleContext != null) {
try {
peopleContext.close();
} catch(NamingException ne) {
throw new EJBException("Error passivating bean: " + ne, ne);
} finally {
peopleContext = null;
}
}
|
public void | ejbRemove()
|
public void | ejbStore()
|
public java.lang.String | getFirstName()
return firstName;
|
public java.lang.String | getLastName()
return lastName;
|
private javax.naming.directory.DirContext | getPeopleContext()
if (peopleContext != null)
return (peopleContext);
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost/o=jndiTest");
env.put(Context.SECURITY_PRINCIPAL, "cn=Manager, o=jndiTest");
env.put(Context.SECURITY_CREDENTIALS, "secret");
try {
DirContext initalContext = new InitialDirContext(env);
peopleContext = (DirContext)initalContext.lookup("ou=people");
return peopleContext;
} catch(NamingException ne) {
throw new EJBException("Error activating bean: " + ne, ne);
}
|
public java.lang.String | getPhoneNumber()
return phoneNumber;
|
private java.util.Collection | ldapFind(java.lang.String filter)
Collection out = new Vector();
NamingEnumeration people = ldapSearch(filter);
while(people.hasMore()) {
NameClassPair personName = (NameClassPair)people.next();
Attributes personAttrs =
peopleContext.getAttributes(personName.getName());
Attribute cn = personAttrs.get("cn");
out.add(cn.get());
}
return out;
|
private javax.naming.NamingEnumeration | ldapSearch(java.lang.String filter)
SearchControls sc = new SearchControls();
sc.setSearchScope(SearchControls.ONELEVEL_SCOPE);
NamingEnumeration people = getPeopleContext().search("", filter, sc);
return people;
|
private void | loadFromLdap(java.lang.String key)
NamingEnumeration people = ldapSearch("cn=" + key);
if (!people.hasMore())
throw new NamingException("No entries found matching " + key);
NameClassPair personName = (NameClassPair)people.next();
Attributes personAttrs =
peopleContext.getAttributes(personName.getName());
Attribute cn = personAttrs.get("cn");
Attribute sn = personAttrs.get("sn");
Attribute phone = personAttrs.get("telephoneNumber");
firstName = (String)cn.get();
lastName = (String)sn.get();
phoneNumber = (String)phone.get();
|
public void | setEntityContext(EntityContext aContext)
context=aContext;
|
public void | unsetEntityContext()
context=null;
|