繁体   English   中英

获取包含属性对象的LDAP属性

[英]Get LDAP Attribute which contains an attribute object

我添加了一个LDAP条目,其中包含一个属性

BasicAttributes basicAttributes = new BasicAttributes();
BasicAttribute basicAttribute = new BasicAttribute("objectclass");
basicAttribute.add("top");
basicAttribute.add("Adapter");
basicAttributes.put(basicAttribute);
basicAttributes.put(new BasicAttribute("Name","testname"));
basicAttributes.put(new BasicAttribute("Topic", "testtopic"));

if (locid.length != 0) {
basicAttribute = new BasicAttribute("LocID");

for (int i = 0; i < locationid.length; i++)
basicAttribute.add(locationid[i]);

basicAttributes.put(basicAttribute);
}

basicAttributes.put(new BasicAttribute("Password", "passw"));

现在密码属性是SHA Hashed Password

但是当我使用像这样的ctx.getAttributes检索属性时

Attributes result = ctx.getAttributes(dn);
NamingEnumeration<?> nm = result.getAll();

while (nm.hasMore()) {
Attribute at = (Attribute) nm.next();
System.out.println(nm.next());
}
}

我得到的输出是

Password: [B@119cca4
Name: testname
Topic: testtopic
LocID: 
objectClass: top, Adapter
cn: test1234

如何重新构造String变量的密码

编辑:我试过这个

while (nm.hasMore()) {
        Attribute at = (Attribute) nm.next();
        if ( at.getID().equals("Password"))
        {
            byte [] a = (byte[] )at.get();
            String b = new String(a);
            System.out.println(b);
        }
    }

现在打印出来 - {SSHA} AvvOJFnG2tjwNTGtDzDnubC / b2B1FbzP5S / LSQ ==

现在我如何让它只打印“passw” - 原始密码。

一旦经过哈希处理,您就无法检索纯文本密码; 这是一种单向哈希。 如果您之后绝对需要恢复纯文本密码,建议将其存储在具有强可逆加密算法的另一个属性中。 并锁定对加密值的访问。 但是,如果您出于某种原因绝对需要纯文本密码(例如,您需要能够将其发布用于某些传统的单点登录过程),请执行此操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM