Spring Ldap 2 over ldaps

时间:2014-03-21 10:13:58

标签: ssl spring-ldap

我关注了一个关于springLdap的有趣网络研讨会,我计划将当前的Ldap接口迁移到SpringLdap。但是,我还没有看到任何简单的连接LDAPS服务器的方法。在我目前的实现中,我必须做类似的事情:

String nextToken = stCc.nextToken();
Properties envP = initializeEnv(nextToken, userPassword);
    try
    {
      LdapContext ctx = new InitialLdapContext(envP, null);
      //System.out.println(nextToken + " successfully validation");
      return ctx;
    }

 private Properties initializeEnv(String userName, String userPassword) throws  IOException
{
 Properties envP = new Properties();
envP.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

envP.put(Context.PROVIDER_URL, (String) properties.get("ldap.server.url"));
if (userName != null)
  envP.setProperty(Context.SECURITY_PRINCIPAL, userName);
if (userPassword != null)
  envP.setProperty(Context.SECURITY_CREDENTIALS, userPassword);
envP.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
envP.setProperty("java.naming.security.protocol", "ssl");
envP.setProperty("com.sun.jndi.ldap.connect.pool", "true");
envP.put("java.naming.ldap.factory.socket", "org.mycompany.ldap.CustSSLSocketFactory");
return envP;

}

以及更多:

public EmblSSLSocketFactory()
 {
try
{
  SSLContext ctx = SSLContext.getInstance("TLS");
  ctx.init(null, new TrustManager[]
  {
    new DummyTrustmanager()
  }, new SecureRandom());
  socketFactory = ctx.getSocketFactory();
}
catch (Exception ex)
{
  ex.printStackTrace(System.err); /* handle exception */
}

}

使用SPRING-LDAP 2通过TLS进行此类身份验证的方法是否相同(也可能更容易)?

由于

0 个答案:

没有答案