java - 在 Spring Boot 中从 LDAP 中搜索属性
问题描述
我是 LDAP 新手。我使用 LDAP INITIAL_CONTEXT_FACTORY(“com.sun.jndi.ldap.LdapCtxFactory”)进行了身份验证部分。我所做的代码如下。
String url = ldap_url;
String uname = request.getUsername();
String pwd = request.getPassword();
boolean authentication = false;
boolean error = true;
String msg, attributes, search;
String ldapDn = String.format("%s%s", searchFilter,uname);
// create env for initial context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, ldapDn);
env.put(Context.SECURITY_CREDENTIALS, pwd);
try {
DirContext ctx = new InitialDirContext(env);
authentication = true;
error = false;
ctx.close();
} catch (Exception e) {
} finally {
if (!error) {
msg = "Login success!!!";
} else {
msg = "Authentication failed!";
}
}
现在我需要获取与 LDAP 结果一起返回的“employee_id”。我在互联网上浏览了几个例子,但我无法做到。如果有人能建议我一种更好的方法来搜索这个属性,那就太好了。
解决方案
推荐阅读
- bash - Backspace 在 VS Code 的 Bash 终端上不起作用
- nginx - 在 3XX 重定向的情况下不执行 Nginx access_by_lua_block
- csv - sphinx 上 table-csv 内的 reStructuredText 替换
- vimeo-api - 缩略图上传 - 管理规则禁止的请求
- wordpress - 使用 EC2 创建的 Wordpress 实例的 SSL 证书
- javascript - Node.js - ssh2-sftp-client 获取多个文件错误
- python - 无法使用 django 从页面发送邮件,SMTPAuthenticationError
- java - 如何进行更大数量的操作
- python - Google Cloud Run:将多个应用文件打包到一个 docker 映像中
- macos - 如何在 AzureDevops 中安装 Mac 配置文件?