Java当提升数字字符串类型LDAP时:错误代码17 - 未定义的属性类型

时间:2016-10-19 05:59:28

标签: java active-directory ldap

我有一个eDirectory。我必须使用Java更新属性值。为此,我使用下面的代码。

public void updateEntry(User_Objects req) {
    try {
        propFile = LoadProp.getProperties();

        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, propFile.getProperty(Constants.INITIAL_CONTEXT_FACTORY));
        properties.put(Context.PROVIDER_URL, propFile.getProperty(Constants.PROVIDER_URL));
        properties.put(Context.SECURITY_PROTOCOL, propFile.getProperty(Constants.SECURITY_PROTOCOL));
        properties.put(Context.SECURITY_PRINCIPAL, propFile.getProperty(Constants.SECURITY_PRINCIPAL));
        properties.put(Context.SECURITY_CREDENTIALS, propFile.getProperty(Constants.SECURITY_CREDENTIALS));

        DirContext context = new InitialDirContext(properties);
        String valAttrXYZ = "123";

        boolean status = false;
        status = UpdateIntoLdap(context, req.getUserDN(), "givenName", req.getFirstName());
        status = UpdateIntoLdap(context, req.getUserDN(), "attrXYZ", valAttrXYZ);
    } catch (NamingException e) {
    } catch (Exception e) {
    }
}

public boolean UpdateIntoLdap(DirContext context, String userDN, String attName, String value) {
    boolean status = true;
    try {
        if (value != null) {
            Attributes att = context.getAttributes(userDN);
            String attValue = displayAttributes(att, attName);
            Attribute mod0 = new BasicAttribute(attName, value);
            ModificationItem[] item = new ModificationItem[1];

            if (attValue.equals("error")) {
                Attributes attributes = context.getAttributes(userDN);
                item[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod0);
                attributes.put(mod0);
                context.modifyAttributes(userDN, item);
            } else {
                item[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0);
                context.modifyAttributes(userDN, item);
            }
        } else {
            status = false;
        }
    } catch (NamingException e) {
        status = false;
    } catch (Exception e) {
        status = false;
    }
    return status;
}

我成功更新了givenName属性,但问题在于更新attrXYZ属性,它会出现以下错误

javax.naming.directory.InvalidAttributeIdentifierException: [LDAP: error code 17 - Undefined Attribute Type]; remaining name 'cn=user01,ou=users,o=data'

“attrXYZ”的属性类型为Numeric String 我也尝试Integer.parseInt(valFaxExt),但同样的错误。

我在Eclipse中使用Java。

1 个答案:

答案 0 :(得分:0)

eDirectory目录服务器报告此错误,这意味着属性" attrXYZ"未在服务器架构中定义。