【发布时间】:2020-08-07 19:15:00
【问题描述】:
我有以下可以使用 LDAP 对用户进行身份验证的工作代码。如您所见,它非常简单。但是我怎样才能以 Spring Boot 的方式做同样的事情呢?
try {
Hashtable<String, Object> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, “ldaps://xxxxxxxx.abcgroup.xyz.com:636”);
env.put(Context.SECURITY_AUTHENTICATION, "simple"); // fixed value
env.put(Context.SECURITY_PRINCIPAL, “myid@abcgroup.xyz.com”);
env.put(Context.SECURITY_CREDENTIALS, "mypassword");
new InitialDirContext(env);
// authentication successful.
} catch (Exception exception) {
// authentication failed.
}
【问题讨论】:
标签: spring-boot spring-security ldap spring-ldap spring-security-ldap