(Socket.java:283) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at java.net.Socket.(Socket.java:121) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at com.sun.jndi.ldap.Connection.(Connection.java:215) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at com.sun.jndi.ldap.LdapClient.(LdapClient.java:127) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2398) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at com.sun.jndi.ldap.LdapCtx.(LdapCtx.java:258) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:91) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at javax.naming.InitialContext.init(InitialContext.java:231) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at javax.naming.InitialContext.(InitialContext.java:207) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at javax.naming.directory.InitialDirContext.(InitialDirContext.java:92) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at LDAPAuth.getAnonymousDir(LDAPAuth.java:48) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at LDAPAuth.(LDAPAuth.java:36) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at JavaAgent.NotesMain(JavaAgent.java:14) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at lotus.domino.AgentBase.runNotes(Unknown Source) 04/10/2006 11:23:30 AM AMgr: Agent ('ST prova LDAP' in 'names.nsf') error message: at lotus.domino.NotesThread.run(Unknown Source) CODICE: import lotus.domino.*; import javax.naming.ldap.*; import javax.naming.directory.SearchResult; import javax.naming.*; public class JavaAgent extends AgentBase { public void NotesMain() { try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); LDAPAuth ldap=new LDAPAuth("ldap://164.130.4.78","ou=People,dc=st,dc=com"); System.out.println("Sarca"); /* SearchResult sr=ldap.getUserInfo("fabio aquilini"); if (sr==null) System.out.println("result "+sr.toString()); else System.out.println(" no result ");*/ }catch(CommunicationException ce) { System.out.println(" EXPLAN "+ce.getExplanation()); ce.printStackTrace(); } catch(Exception e) { System.out.println("MSG "+e.getMessage()); e.printStackTrace(); } } } /* * Created on Dec 3, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ import java.util.Hashtable; import javax.naming.Context; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttributes; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; import javax.naming.directory.SearchResult; /** * @author ladmin * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public final class LDAPAuth { private final String ldapurl; private final String ldapbase; private final DirContext dir; /** * @param ldapurl the URL string of the LDAP * @param ldapbase the base search string * @throws NamingException */ public LDAPAuth(final String ldapurl,final String ldapbase)throws NamingException{ this.ldapurl=ldapurl; this.ldapbase=ldapbase; this.dir=getAnonymousDir(); } /** * connect anonymously (necessary to retrieve dn) * @return an anonymous bind context to the ldap * @throws NamingException */ protected final DirContext getAnonymousDir() throws NamingException{ final Hashtable env =new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapurl); return new InitialDirContext(env); } /** * connect with a dn / password pair * @param dn the ldap distinguished name * @param password the user password * @return an authenticated bind context to the ldap * @throws NamingException */ protected final DirContext getAuthenticatedDir(final String dn, final String password) throws NamingException{ final Hashtable env =new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapurl); env.put(Context.SECURITY_AUTHENTICATION,"simple"); env.put(Context.SECURITY_PRINCIPAL, dn); env.put(Context.SECURITY_CREDENTIALS, password); return new InitialDirContext(env); } /** * retrieves the dn of an user * @param user the username * @return the first object matching the name * @throws NamingException */ public final SearchResult getUserInfo(final String user) throws NamingException{ final Attributes attr=new BasicAttributes(); attr.put("cn",user); NamingEnumeration result=this.dir.search(this.ldapbase, attr); return (SearchResult)result.next(); } /** * @param user the username to authenticate * @param password * @return a value if the user is authenticated * @throws NamingException */ public final SearchResult authenticate(final String user,final String password) throws NamingException{ final SearchResult info=getUserInfo(user); final String dn=info.getName()+","+this.ldapbase; this.getAuthenticatedDir(dn,password); return info; } } ">
> |  
Accedere LDAP aziendale tramite Java
aquila
Ciao,
ho un problema ad accedere all LDAP della mia azienda tramite java.
Mi da\' una eccezione SecurityException... ho provato anche ad aggiungere
in java.policy le seguenti policy ma non e\' cambiato nulla
permission java.net.SocketPermission "*:1-", "connect";
permission java.net.SocketPermission "*:1-", "resolve";

Vi allego il codice e l\'eccezione che lancia... se qualcuno mi puo\' dare una
dritta... gli sarei molto grato :)
Grazie
Fabio

ECCEZIONE:
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') printing:
EXPLAN 164.130.4.78:389
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: javax.naming.CommunicationException: 164.130.4.78:389. Root exception
is
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: java.lang.SecurityException: 164.130.4.78,389
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at
lotus.notes.AgentSecurityManager.checkConnect(AgentSecurityManager.java:172)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at java.net.Socket.<init>(Socket.java:283)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at java.net.Socket.<init>(Socket.java:121)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at com.sun.jndi.ldap.Connection.<init>(Connection.java:215)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:127)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2398)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:258)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at
com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:91)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:255)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at javax.naming.InitialContext.init(InitialContext.java:231)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at javax.naming.InitialContext.<init>(InitialContext.java:207)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at
javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:92)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at LDAPAuth.getAnonymousDir(LDAPAuth.java:48)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at LDAPAuth.<init>(LDAPAuth.java:36)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at JavaAgent.NotesMain(JavaAgent.java:14)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at lotus.domino.AgentBase.runNotes(Unknown Source)
04/10/2006 11:23:30 AM AMgr: Agent (\'ST prova LDAP\' in \'names.nsf\') error
message: at lotus.domino.NotesThread.run(Unknown Source)

CODICE:

import lotus.domino.*;
import javax.naming.ldap.*;
import javax.naming.directory.SearchResult;
import javax.naming.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {

try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();

LDAPAuth ldap=new
LDAPAuth("ldap://164.130.4.78","ou=People,dc=st,dc=com");
System.out.println("Sarca");
/*
SearchResult sr=ldap.getUserInfo("fabio aquilini");
if (sr==null) System.out.println("result "+sr.toString());
else System.out.println(" no result ");*/
}catch(CommunicationException ce) {
System.out.println(" EXPLAN "+ce.getExplanation());
ce.printStackTrace();
}
catch(Exception e) {
System.out.println("MSG "+e.getMessage());
e.printStackTrace();
}
}
}


/*
* Created on Dec 3, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchResult;

/**
* @author ladmin
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public final class LDAPAuth {
private final String ldapurl;
private final String ldapbase;
private final DirContext dir;
/**
* @param ldapurl the URL string of the LDAP
* @param ldapbase the base search string
* @throws NamingException
*/
public LDAPAuth(final String ldapurl,final String ldapbase)throws
NamingException{
this.ldapurl=ldapurl;
this.ldapbase=ldapbase;
this.dir=getAnonymousDir();
}

/**
* connect anonymously (necessary to retrieve dn)
* @return an anonymous bind context to the ldap
* @throws NamingException
*/
protected final DirContext getAnonymousDir() throws NamingException{
final Hashtable env =new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapurl);
return new InitialDirContext(env);
}

/**
* connect with a dn / password pair
* @param dn the ldap distinguished name
* @param password the user password
* @return an authenticated bind context to the ldap
* @throws NamingException
*/
protected final DirContext getAuthenticatedDir(final String dn, final
String password) throws NamingException{
final Hashtable env =new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapurl);
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
return new InitialDirContext(env);
}

/**
* retrieves the dn of an user
* @param user the username
* @return the first object matching the name
* @throws NamingException
*/
public final SearchResult getUserInfo(final String user) throws
NamingException{
final Attributes attr=new BasicAttributes();
attr.put("cn",user);
NamingEnumeration result=this.dir.search(this.ldapbase, attr);
return (SearchResult)result.next();
}

/**
* @param user the username to authenticate
* @param password
* @return a value if the user is authenticated
* @throws NamingException
*/
public final SearchResult authenticate(final String user,final String
password) throws NamingException{
final SearchResult info=getUserInfo(user);
final String dn=info.getName()+","+this.ldapbase;
this.getAuthenticatedDir(dn,password);
return info;
}

}







You are here Accedere LDAP aziendale tramite Java - aquila -
    re : Accedere LDAP aziendale tramite Java - gabrielesh -
    re : Accedere LDAP aziendale tramite Java - aquila -