}
// 根据用户名取得邮箱地址
private String getEmail(String user) {
String mail = null;
LDAPEntry fullEntry = null;
LDAPConnection lc = null;
LDAPAttributeSet set = null;
LDAPSearchResults rs = null;
final String MY_HOST = "localhost";
final int MY_PORT = 389;
final String ENTRYDN = "o=zephyr.com.cn";
final String[] attrNames = { "sn", "mobile", "mail" };
try {
lc = new LDAPConnection();
lc.connect(MY_HOST, MY_PORT);
String password = "secret";
try {
lc.bind(3, "cn=Manager,o=zephyr.com.cn", password
.getBytes("UTF8"));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
rs = lc.search(ENTRYDN, LDAPConnection.SCOPE_SUB, "sn=" + user,
attrNames, false);
while (rs.hasMore()) {
try {
fullEntry = rs.next();
set = fullEntry.getAttributeSet();
Iterator<?> attrs = set.iterator();
while (attrs.hasNext()) {
LDAPAttribute attribute = (LDAPAttribute) attrs.next();
String name = attribute.getName();
String value = attribute.getStringValue();