使用 objectGUID 进行查询 - Spring LDAP 模板

2024-05-24

我正在尝试获取、存储并依次使用 objectGUID 来查询 Active Directory。 为了获取用户属性我正在使用以下

public static class MyDnKeyValueAttMapper implements AttributesMapper<Object> {
        @Override
        public List<LdapKeyValueList> mapFromAttributes(Attributes attributes)
                throws NamingException, javax.naming.NamingException {
            List<LdapKeyValueList> attributeKeyValMap = new ArrayList<LdapKeyValueList>();
            NamingEnumeration<String> namingEnumeration = attributes.getIDs();

            while (namingEnumeration.hasMoreElements()) {
                String attributeName = (String) namingEnumeration.nextElement();
                String AttributeValue = attributes.get(attributeName).get().toString();
                attributeKeyValMap.add(new LdapKeyValueList(attributeName, AttributeValue));
            }
            return attributeKeyValMap;
        }
    }

objectGuid 似乎总是以字符串格式返回。 我也尝试过——

UUID guid = (UUID) attributes.get("objectGUID").get();

这会引发“无法将字符串转换为 uuid”错误

似乎在我可以做任何事情之前,ldaptemplate 搜索总是以字符串格式返回属性。

我如何获取“objectGUID”的格式,以便我可以存储它并在 ldapTemplate 搜索查询中使用。

提前致谢。


对于 Spring,将“java.naming.ldap.attributes.binary”属性注入 ldapTemplate

@Bean
public LdapTemplate ldapTemplate() {
  return new LdapTemplate(contextSource());
}

@Bean
public ContextSource contextSource() {
  final LdapContextSource contextSource = new LdapContextSource();
  contextSource.setUrl(env.getRequiredProperty("ldap.url"));
  contextSource.setBase(env.getRequiredProperty("ldap.base"));
  contextSource.setUserDn(env.getRequiredProperty("ldap.user"));
  contextSource.setPassword(env.getRequiredProperty("ldap.password"));

  // Important!!! Tell ldapTemplate to retrieve AD field
  // "objectGUID" as binary. Otherwise it will be
  // retrieved as a String, thus, modifying the byte[] array
  final Map<String, Object> envProps = new HashMap<>();
  envProps.put("java.naming.ldap.attributes.binary","objectGUID");
  contextSource.setBaseEnvironmentProperties(envProps);

  return contextSource;
}

...

// Will not complain about the String to byte[] conversion and
// Has to be 16 in length. If not, you did something 
// wrong. For example ldapTemplate still retrieves objectGUID
// as String, modifying the value
byte[] guidBytes = (byte[]) attributes.get("objectGUID").get();
if (guidBytes.length == 16) {
  // Convert encoded AD objectGUID to UUID
  // objectGUID is not storing bits sequentially, so do the dance
  UUID uuid = UUID.fromString(
    String.format("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", 
    guidBytes[3] & 255, 
    guidBytes[2] & 255, 
    guidBytes[1] & 255, 
    guidBytes[0] & 255, 
    guidBytes[5] & 255, 
    guidBytes[4] & 255, 
    guidBytes[7] & 255, 
    guidBytes[6] & 255, 
    guidBytes[8] & 255, 
    guidBytes[9] & 255, 
    guidBytes[10] & 255, 
    guidBytes[11] & 255, 
    guidBytes[12] & 255, 
    guidBytes[13] & 255, 
    guidBytes[14] & 255, 
    guidBytes[15] & 255));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 objectGUID 进行查询 - Spring LDAP 模板 的相关文章

随机推荐

  • 下界比较函数

    我有以下结构 enum quality good 0 bad uncertain struct Value int time int value quality qual class MyClass public MyClass Inser
  • Linux中使用管道进行进程间通信

    我已经编写了在 linux 中写入数字以进行管道传输的代码 如下所示 但显示错误 任何人都可以帮助我解决这个问题 基本上该程序的问题陈述如下 一个程序将打开一个管道 向管道写入一个数字 其他程序将打开同一管道 读取数字并打印它们 关闭两个管
  • 如何从现有存储库中的分支创建新的 GitHub 存储库?

    I have master and 新项目分支机构 现在我想创建一个全新的存储库及其基于新项目分支的主存储库 背景 我有一个存储库 其中包含三个独立的应用程序 事情并不是这样开始的 仓库中最初只有一个应用程序 然而 随着时间的推移 业务需求
  • Windows Azure 上的多租户应用程序

    我们想要创建具有共享数据库表结构的多租户应用程序 目前 使用标准 SQL Server 我们可以通过为每个表提供 TenantID 来实现这一点 我们能否在 Windows Azure 上实现相同的目标 但无需 TenantID 此致 阿列
  • 连接管理 ASP.net

    如何管理 ASP Net 应用程序中的数据库连接 我的理解告诉我 最好 的方法是打开连接 进行查询 关闭连接 并多次执行此操作 因为连接池使成本可以忽略不计 当我有一个 DAL 时 问题就出现了 其中每个方法都管理自己的连接 例如 User
  • Azure B2C 中的 KMSI 实际上有什么作用?

    我们提供了此文档 说明如何使用自定义策略设置 保持登录状态 KMSI https learn microsoft com en us azure active directory b2c custom policy keep me sign
  • Doctrine - 使用查询生成器时如何水合集合

    A 我问的上一个问题 https stackoverflow com questions 27572139 doctrine how to extract results and their relationships as array 2
  • 如何使用Google API PHP SDK获取用户信息

    我正在尝试为拥有 Google 帐户的用户添加登录选项到我的网站 我已经能够实现这个 Facebook 但在使用 Google 获取用户帐户信息时遇到问题 我正在使用位于此处的 Google PHP SDK https github com
  • iOS 9 + Xcode 7 的 Segue 上的应用程序导致整个设备崩溃

    更新 我已经在这一年中使用了我的一个 DTS 目前与 Apple 支持工程师合作 根据他的建议 我还为此创建了一个错误报告 随着时间的推移 我将更新此线程 希望能产生最终的解决方案 不知何故 我找到了一种方法来创建一个可以真正重新启动模拟器
  • 如何使用 blazor 前端 http 请求附加令牌

    我使用 blazor 作为前端 api 已完成 JWT 配置 前端可以创建用户帐户并登录API 但现在我的前端httpclient没有设置JWT令牌 所以如果我在Api控制器中设置 授权 前端将无法访问它 api程序代码如下 builder
  • UITableview Cell 异常 - '必须将自动调整大小掩码转换为约束才能具有 _setHostsLayoutEngine:YES

    我正在使用 UITableView CategoryCell cell tableView dequeueReusableCellWithIdentifier CellIdentifierLink 这是我收到错误的行 它在 IOS 7 中工
  • MS Batch:检查驱动器是否正在使用

    我需要检查驱动器 Z 是否正在使用 例如 正在由应用程序使用 已打开 我的批处理文件如下所示 Mount Z wait 15 minutes check if drive Z is in use IF NOT unmount Z ELSE
  • 聚合物中的主机属性和属性有什么区别?

    我正在从 0 5 迁移到 1 0 在阅读时 我注意到声明属性有两种不同的方式 使用hostAttributes and properties 这两个有什么区别 宿主属性是与元素相应的 Javascript 属性 您在其中声明的 不匹配的属性
  • 使用 libpqxx 批量存储数据或如何在 libpqxx 中使用 COPY 语句

    要在 PostgreSQL 中插入批量数据 填充数据库 最快的方法是使用 COPY Source https stackoverflow com questions 758945 whats the fastest way to do a
  • Wikipedia API:如何获取页面的修订次数?

    有人知道如何使用 mediawiki API 获取维基百科页面的修订次数吗 我已经阅读了这个API文档 但找不到相关的API 修订API http www mediawiki org wiki API Properties revision
  • Firebase Cloud Storage - 使用元数据上传 -

    我希望从浏览器上传带有元数据的文件 以便通过云功能正确识别和处理文件 在客户端上 我的上传器代码如下所示 uploadTaskPromise async function file return new Promise resolve re
  • 什么是 NPM?为什么需要它? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 以前 我用记事本制作了一些网站 所以我们必须创建一个文件夹 TREE 并在其中放入一个 htm 文件 以及一些文件夹 其中包含 Jav
  • Spring - 拦截 bean 创建并注入自定义代理

    我有一个 Controller with Autowired我想用自定义注释来注释的字段和处理程序方法 例如 Controller public class MyController Autowired public MyDao myDao
  • 带有条件小部件的 Flutter Hero 事务容器

    我正在尝试实现一个进展顺利的英雄事务 但是我正在转换的容器有两个变体 小 大 Big Small 正如您所看到的 小版本与大版本相同 但缺少一些元素 需要渲染的版本通过属性设置isSmall 该组件如下所示 class TicPackage
  • 使用 objectGUID 进行查询 - Spring LDAP 模板

    我正在尝试获取 存储并依次使用 objectGUID 来查询 Active Directory 为了获取用户属性我正在使用以下 public static class MyDnKeyValueAttMapper implements Att