다음 예제 코드의 의미는 중요하지 않습니다. 내가 물어보고 싶은 것은 socketFactory에 "certFileName"을 params로 보내는 방법입니다. 다른 certFile을 사용해야합니다. 다른 엔드 포인트, 덕분에Ldap에서 SocketFactory에 매개 변수를 보내는 방법
public class LdapConnection
{
private String host = "1.2.3.4"; //the correct ip...
private String baseDn = "dc=x,dc=y,dc=com"; //the correct base DN
private String username = "myUsername";
private String password = "myPassword";
private String connectionUrl = null;
public void connectLdaps() throws Exception
{
connectionUrl = "ldaps://" + host + "/" + baseDn;
System.out.println("Trying to connect to " + connectionUrl + " using LDAPS protocol");
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put("java.naming.ldap.derefAliases", "finding");
env.put(Context.PROVIDER_URL, connectionUrl);
env.put(Context.SECURITY_AUTHENTICATION, "Simple");
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);
env.put("java.naming.ldap.factory.socket", MySocketFactory.class.getName());
new InitialLdapContext(env, null);
System.out.println("Connected successfully!");
}
public static void main(String[] args) throws Exception
{
LdapConnection ldapConnection = new LdapConnection();
ldapConnection.connectLdaps();
}
}
public class MySocketFactory extends SocketFactory
{
private static MySocketFactory instance = null;
private SSLContext sslContext = null;
//I want to send this var from outside
**private static String certFileName = "C:\\certs\\cert_by_hostname.cer";**
public static SocketFactory getDefault()
{
if (instance == null)
{
try
{
instance = new MySocketFactory();
instance.initFactory();
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Returning null socket factory");
}
}
return instance;
}
}
이런 식으로 같이 할 수있다 : 나는
public class MySocketFactory extends SocketFactory
{
private MySocketFactory instance = null;
private SSLContext sslContext = null;
//I want to send this var from outside
private String certFileName = null
public MySocketFactory(String varCert)
{
certFileName = varCert;
}
}
감사는 "외부"코드에서 무엇을해야!
@TerryGardner, 왜 [ldap] 태그를 계속 제거합니까 ([메타에 관한이 질문 (http://meta.stackexchange.com/q/118827/148833)를 참조하십시오)? – Bruno
@Bruno 이러한 제거 중 일부는 의미가 있습니다. 질문은 실제로 OpenLDAP와 같은 특정 서버를 구성하는 방법에 관한 것이고 LDAP 자체와 관련이 없습니다. 이것은 또 다른 합리적인 경우입니다. JSSE와 JNDI 간의 상호 작용에 관한 것이고 실제로 LDAP *와는 전혀 관련이 없습니다. 나는이 질문에 대한 태그를 직접 편집했다고 생각한다. – EJP
@downvoter 설명해주십시오. 그렇지 않으면 아무도 아무것도 배웁니다. – EJP