Spring LDAP - 绑定成功连接

2023-11-27

我正在尝试使用 Spring LDAP 和 Spring 安全性进行身份验证,然后查询我们的公司 LDAP。我设法使身份验证工作,但当我尝试运行搜索时,我总是遇到以下异常

为了执行此操作,必须在连接上成功完成绑定

经过大量研究后,我有一个理论,即在进行身份验证之后、在可以查询之前,我需要绑定到连接。我只是不知道什么以及如何?

只是提一下 - 我可以使用 JXplorer 成功浏览和搜索我们的 LDAP,因此我的参数是正确的。

这是我的 securityContext.xml 的一部分

<security:http auto-config='true'>
    <security:intercept-url pattern="/reports/goodbye.html" 
            access="ROLE_LOGOUT" />
    <security:intercept-url pattern="/reports/**" access="ROLE_USER" />
    <security:http-basic />
    <security:logout logout-url="/reports/logout" 
            logout-success-url="/reports/goodbye.html" />
</security:http>
<security:ldap-server url="ldap://s140.foo.com:1389/dc=td,dc=foo,dc=com" />
<security:authentication-manager>
    <security:authentication-provider ref="ldapAuthProvider">
</security:authentication-provider>
</security:authentication-manager>
<!-- Security beans -->
<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldap://s140.foo.com:1389/dc=td,dc=foo,dc=com" />
</bean>
<bean id="ldapAuthProvider" 
   class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg>
        <bean class="foo.bar.reporting.server.security.ldap.LdapAuthenticatorImpl">
            <property name="contextFactory" ref="contextSource" />
            <property name="principalPrefix" value="TD\" />
            <property name="employee" ref="employee"></property>
        </bean>
    </constructor-arg>
    <constructor-arg>
      <bean class="foo.bar.reporting.server.security.ldap.LdapAuthoritiesPopulator" />
    </constructor-arg>
</bean>
<!-- DAOs -->
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
  <constructor-arg ref="contextSource" />

这是来自的代码片段LdapAuthenticatorImpl执行身份验证。这里没问题:

@Override
public DirContextOperations authenticate(final Authentication authentication) {
    // Grab the username and password out of the authentication object.
    final String name = authentication.getName();
    final String principal = this.principalPrefix + name;
    String password = "";
    if (authentication.getCredentials() != null) {
        password = authentication.getCredentials().toString();
    }
    if (!("".equals(principal.trim())) && !("".equals(password.trim()))) {
        final InitialLdapContext ldapContext = (InitialLdapContext)
     this.contextFactory.getContext(principal, password);
        // We need to pass the context back out, so that the auth provider 
        // can add it to the Authentication object.
        final DirContextOperations authAdapter = new DirContextAdapter();
        authAdapter.addAttributeValue("ldapContext", ldapContext);
        this.employee.setqId(name);
        return authAdapter;
    } else {
        throw new BadCredentialsException("Blank username and/or password!");
    }
}

这是另一个代码片段EmployeeDao我徒劳地尝试查询:

public List<Employee> queryEmployeesByName(String query) 
   throws BARServerException {
    AndFilter filter = new AndFilter();
    filter.and(new EqualsFilter("objectclass", "person"));
    filter.and(new WhitespaceWildcardsFilter("cn", query));
    try {
        // the following line throws bind exception
        List result = ldapTemplate.search(BASE, filter.encode(), 
            new AttributesMapper() {
            @Override
            public Employee mapFromAttributes(Attributes attrs) 
                throws NamingException {
                Employee emp = new Employee((String) attrs.get("cn").get(), 
                   (String) attrs.get("cn").get(),
                        (String) attrs.get("cn").get());
                return emp;
            }
        });
        return result;
    } catch (Exception e) { 
        throw new BarServerException("Failed to query LDAP", e);
    }
}

最后 - 我遇到的例外

org.springframework.ldap.UncategorizedLdapException: 
    Uncategorized exception occured during LDAP processing; nested exception is 
    javax.naming.NamingException: [LDAP: error code 1 - 00000000: LdapErr: 
    DSID-0C090627, comment: In order to perform this operation a successful bind 
    must be completed on the connection., data 0, vece]; remaining name 
    'DC=TD,DC=FOO,DC=COM'

您的 LDAP 似乎被配置为不允许在未绑定到它的情况下进行搜索(无匿名绑定)。你也已经实施了PasswordComparisonAuthenticator并不是BindAuthenticator to 认证到 LDAP。

你可以尝试修改你的queryEmployeesByName()方法绑定然后搜索,查看中的一些示例doc.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Spring LDAP - 绑定成功连接 的相关文章

随机推荐

  • 如何以编程方式比较 mp3

    我喜欢能够以编程方式比较 mp3 问题我不知道是什么 标头 直方图 渠道 有人有这方面的经验吗 I wrote 我的硕士论文关于音频指纹识别 本文列出了一些针对比较音乐听起来的问题的开源解决方案 并提供了它们之间的性能比较 可能有点矫枉过正
  • 如何更改 Fabric.js 对象的值?

    我有一个 Fabric jscanvas 我还有一个 JavaScript 它有一个在按下按钮时调用的函数 我知道如何获取活动对象 canvas getActiveObject 但我不知道如何更改其中的值 而不必进行克隆并删除原始值 我之所
  • ios 中联系人缺少一些必需的关键描述符

    我已使用以下方法检索所有联系人 void getAllContacts void NSArray array handler CNAuthorizationStatus status CNContactStore authorization
  • QueryDSL 左连接,ON 中带有附加条件

    是否可以在 QueryDSL 中执行以下查询 SELECT p FROM parts table p LEFT JOIN inventory balance table i ON p part no i part no AND i mont
  • 如何在设备的前台应用程序中显示双高绿色状态栏(通话中)?

    这里有很多问题要求在后台显示红色录音栏 很明显我应该使用AVAudioSession类别AVAudioSessionCategoryPlayAndRecord为了那个原因 我的问题是 当我的应用程序中有活动的 VOIP 通话时 如何在前台应
  • 从另一个线程和类更新 C# GUI 中的进度条 [重复]

    这个问题在这里已经有答案了 可能的重复 从另一个线程更新进度条 在我的程序中 我想将非GUI功能分离到另一个类中 并将与GUI相关的东西留在主类中 但是 当工作类中的工作方法之一正在执行其工作时 我在更新进度条时遇到问题 我知道我必须在这里
  • “git Push origin MyBranchName”抛出错误“HTTP Basic:访问被拒绝”

    我是 Git 新手 两天前才开始 我正在尝试创建一个项目来练习我从中学到的基本命令here 到目前为止我在哪里 成功 创建一个新的公共git项目 因为我之前尝试过私有和内部但无法克隆它 我不知道为什么 这里是 Added a README
  • 如何分配具有执行权限的内存?

    我想分配一块具有执行权限的内存 所以我使用 mprotect 来更改权限 为了获得页面对齐的内存 我使用valloc功能 void temp void valloc x and then if mprotect temp BLOCK SIZ
  • 新整数与 valueOf

    我正在使用Sonar让我的代码更干净 它指出我正在使用new Integer 1 代替Integer valueOf 1 因为看起来valueOf不实例化新对象 因此更节省内存 怎么能valueOf不实例化一个新对象 它是如何工作的 对于所
  • Git Rebase 似乎已经起作用,但所有提交仍然显示在日志中......我处于什么状态?

    我想我使用 rebase 压缩了最后 40 次提交 我遵循本指南是为了确保我没有做任何愚蠢的事情 http gitready com advanced 2009 02 10 squashing commits with rebase htm
  • 我可以在编译和链接时将 C++ 主函数和类与 Objective-C 和/或 C 例程分开吗?

    我有一个小型 C 应用程序 我导入了 Objective C 类 它以 Objective C 文件 mm 的形式工作 但任何包含头文件 最终可能包含一些 Objective C 头文件 的 C 文件都必须重命名为 mm 扩展名 以适合正确
  • 大规模并行线程读取的 Azure 表存储性能

    简短版本 我们能否以多线程方式读取数十或数百个表分区 以将性能提高几个数量级 长版 我们正在开发一个在 Azure 表存储中存储数百万行的系统 我们将数据划分为小分区 每个分区包含大约 500 条记录 这代表一个单元一天的数据量 由于 Az
  • 检查 PHP 数组是否为空的最佳方法[关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心以获得指导 这大多是肤浅的 但真正的意
  • iOS 5:我可以让我的应用程序默认处于“通知中心”状态吗?

    我在 App Store 中有一个 iPad 应用程序 其逻辑很大程度上依赖于本地通知 换句话说 应用程序内部发生的许多事情都是由委托方法应用程序 didReceiveLocalNotification 触发的 随着今天发布的 iOS 5
  • grails 文件下载

    我已经成功地制作了一个文件上传系统 该系统基本上是将文件复制到特定文件夹并将其位置保存在数据库中 现在我需要有关下载部分的帮助 想象我的文件位置是 文件 1306242602661 file1 exe 在我看来 我有这样的
  • Material-UI:提供给 createMuiTheme 的阴影数组应支持 25 个高度

    我正在尝试消除 Material UI 主题中的阴影 我找到了这个在这里回答并解决问题 但是我在这个问题的标题中收到错误消息 const theme createMuiTheme palette primary light red 300
  • 有没有办法用JS从渲染的页面中获取所有文本?

    有没有一种 对用户来说不显眼的 方法来使用 Javascript 获取页面中的所有文本 我可以获取 HTML 解析它 删除所有标签等 但我想知道是否有办法从已渲染的页面获取文本 澄清一下 我不想从选择中抓取文本 我想要整个页面 谢谢你 全部
  • ASP.NET MVC 5(VS2013 最终版):使用 OWIN 登录 Facebook 失败(loginInfo 为 null)

    我安装了昨天发布的 VS2013 最终版本 并且我正在尝试获取一个启用外部 Facebook 登录的示例 我的第一个问题 在此控制器代码中 我没有触及并按示例模板中的原样保留 GET Account ExternalLoginCallbac
  • 在 Chrome 中检测访问过的链接

    我正在使用 Chrome 和 Firefox 的用户脚本 并且正在检查用户访问过的链接 我有 a color blue a visited color red important 在我的 css 中 页面加载后就导入了 我访问过的页面上的
  • Spring LDAP - 绑定成功连接

    我正在尝试使用 Spring LDAP 和 Spring 安全性进行身份验证 然后查询我们的公司 LDAP 我设法使身份验证工作 但当我尝试运行搜索时 我总是遇到以下异常 为了执行此操作 必须在连接上成功完成绑定 经过大量研究后 我有一个理