我正在尝试连接在线测试LDAP服务器,下面是我尝试过的代码。
Vertx vertx = Vertx.vertx();
JsonObject shiroConfig = new JsonObject().put("ldap_url", "ldap://ldap.forumsys.com:389")
.put("ldap_user_dn_template", "uid={0},ou=mathematicians,dc=example,dc=com");
ShiroAuthOptions shiroAuthOptions = new ShiroAuthOptions().setType(ShiroAuthRealmType.LDAP)
.setConfig(shiroConfig);
AuthProvider authProvider = ShiroAuth.create(vertx, shiroAuthOptions );
JsonObject authInfo = new JsonObject().put("username", "reimann")
.put("password", "password");
System.out.println("before authenticate");
authProvider.authenticate(authInfo, res -> {
if (res.succeeded()) {
System.out.println("Success");
} else {
System.out.println("failure" );
System.out.println(res);
}
});
以下是我遇到的错误
before authenticate
failure
Future{cause=LDAP authentication failed.}
以下是打印res.cause()。printStackTrace()时的错误:
org.apache.shiro.authc.AuthenticationException: LDAP authentication failed.
at org.apache.shiro.realm.ldap.DefaultLdapRealm.doGetAuthenticationInfo(DefaultLdapRealm.java:300)
at org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:568)
at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:270)
at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:256)
at io.vertx.ext.auth.shiro.impl.ShiroAuthProviderImpl.lambda$authenticate$0(ShiroAuthProviderImpl.java:80)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:316)
at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3135)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3081)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2883)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2797)
at org.apache.shiro.realm.ldap.JndiLdapContextFactory.getLdapContext(JndiLdapContextFactory.java:495)
at org.apache.shiro.realm.ldap.DefaultLdapRealm.queryForAuthenticationInfo(DefaultLdapRealm.java:375)
at org.apache.shiro.realm.ldap.DefaultLdapRealm.doGetAuthenticationInfo(DefaultLdapRealm.java:295)
... 14 more
可能是什么问题?
答案 0 :(得分:0)
随着vert.x 4.0即将发布,Shiro将被标记为“已弃用”,请您移至vertx-auth-ldap
。不同之处在于此新模块将仅使用JDK类。不赞成使用Shiro,因为它无法在异步模型中正常工作(它依赖于线程本地,因此我们不得不破解它的内部结构才能按预期工作)。
使用新模块,您可以通过以下方式连接到ldap服务器:
LdapAuthenticationOptions ldapOptions =
new LdapAuthenticationOptions()
.setUrl("ldap://localhost:port")
.setAuthenticationQuery("uid={0},ou=Users,dc=myorg,dc=com");
您需要从此处进行自定义定制,只需遵循官方Java教程跟踪:https://docs.oracle.com/javase/jndi/tutorial/ldap/security/ldap.html
以下是模块文档:https://github.com/vert-x3/vertx-auth/blob/master/vertx-auth-ldap/src/main/asciidoc/index.adoc