Ich hatte nicht vor, hier solche Diskussionen auszulösen ?
ich auch nicht, aber es nervt, wenn jemand nur nörgelt, anstatt konstruktiv bei der Lösung zu helfen…
hier also mein Vorschlag:
LDAP
public class LDAPClient {
private String mail = "";
private String user = "";
public LDAPClient(String user){
this.user = user;
}
public void search(String uid) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL\_CONTEXT\_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER\_URL, "ldap://ad-service:389");
env.put(Context.SECURITY\_AUTHENTICATION, "none");
DirContext ctx = null;
NamingEnumeration results = null;
try {
ctx = new InitialDirContext(env);
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE\_SCOPE);
constraints.setCountLimit(222);
constraints.setTimeLimit(0);
String name = "ou=people,o=company,ou=corp";
NamingEnumeration answer = ctx.search(name, "(uid="
+ uid + ")", constraints);
while (answer.hasMore()) {
SearchResult sr = (SearchResult) answer.next();
mail = (String) (sr.getAttributes().get("mail")).get();
}
} catch (NamingException e) {
throw new RuntimeException(e);
} finally {
if (results != null) {
try {
results.close();
} catch (Exception e) {
}
}
if (ctx != null) {
try {
ctx.close();
} catch (Exception e) {
}
}
}
}
public String getMail() {
search(this.user);
return mail;
}
public void setUser(String user){
this.user = user;
}
}
Servlet
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String auth = request.getHeader("Authorization");
if (auth == null) {
response.setStatus(response.SC\_UNAUTHORIZED);
response.setHeader("WWW-Authenticate", "NTLM");
response.flushBuffer();
return;
}
if (auth.startsWith("NTLM ")) {
byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth
.substring(5));
int off = 0, length, offset;
if (msg[8] == 1) {
byte z = 0;
byte[] msg1 = { (byte) 'N', (byte) 'T', (byte) 'L', (byte) 'M',
(byte) 'S', (byte) 'S', (byte) 'P', z, (byte) 2, z, z,
z, z, z, z, z, (byte) 40, z, z, z, (byte) 1,
(byte) 130, z, z, z, (byte) 2, (byte) 2, (byte) 2, z,
z, z, z, z, z, z, z, z, z, z, z };
response.setHeader("WWW-Authenticate", "NTLM "
+ new sun.misc.BASE64Encoder().encodeBuffer(msg1));
response.sendError(response.SC\_UNAUTHORIZED);
return;
} else if (msg[8] == 3) {
off = 30;
length = msg[off + 17] \* 256 + msg[off + 16];
offset = msg[off + 19] \* 256 + msg[off + 18];
String remoteHost = new String(msg, offset, length);
length = msg[off + 1] \* 256 + msg[off];
offset = msg[off + 3] \* 256 + msg[off + 2];
String domain = new String(msg, offset, length);
length = msg[off + 9] \* 256 + msg[off + 8];
offset = msg[off + 11] \* 256 + msg[off + 10];
String username = new String(msg, offset, length);
StringBuffer sb = new StringBuffer();
for (int i = 0; i " + s.getMail()
+ "");
}
}
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
}
}
Anstatt einer jsp habe ich ein Servlet benutzt. Die Umsetzung sollte Dir aber keine Probleme bereiten.
Sag mal bescheid, ob es funktioniert.
Gruß, Stephan