JNDI problem adding multiple attribute in MSAD

Discussion in 'Java' started by nospam, Jan 6, 2006.

  1. nospam

    nospam Guest

    Hi, I'm using JNDI to update an Active Directory. Now I'm facing the
    following problem:

    When I try to add a value to a multiple attribute (department), I get
    the following error:

    20:59:11,390 FATAL [LdapSlave.java:95] [LDAP: error code 19 - 00002081:
    AtrErr: DSID-031D0809, #1:
    0: 00002081: DSID-031D0809, problem 1005 (CONSTRAINT_ATT_TYPE), data 0,
    Att d (description)

    It doesn't happen when I add or update a single value attribute.

    The snippet for the update is as follows:

    private void UpdateRegister(Hashtable db2Hash,String dn) {

    for (Iterator it=db2Hash.entrySet().iterator(); it.hasNext(); ) {

    Map.Entry entry = (Map.Entry)it.next();
    String key = (String)entry.getKey();
    String value = (String)entry.getValue();
    String ldapvalue = (String)ldapValsTable.get(key);
    ModificationItem[] mods=null;
    boolean doMod = false;

    if ( value.length() == 0 && ldapvalue == null ) {
    continue;
    }
    if ( ldapvalue == null && value.length() > 0 ){
    l.info("atributo \""+key+"\" no existe, creandolo con valor
    \""+value+"\"");

    //agregar atributo a ldap ... funciona solo con single-valued
    mods = new ModificationItem[1];
    mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new
    BasicAttribute(key, value));
    doMod=true;
    }
    else if ( value.length() == 0 && ldapvalue != null ){
    mods = new ModificationItem[1];
    mods[0] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE,
    new BasicAttribute(key));
    l.debug("Borrando atributo: "+key);
    doMod=true;
    }
    else if ( value.compareTo(ldapvalue) != 0) {
    mods = new ModificationItem[1];
    mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
    new BasicAttribute(key, value));
    doMod=true;
    l.info("Diferencia encontrada: "+key+":"+value+"/"+ldapvalue);
    }
    else
    l.info("No se encontraron diferencias para : "+key+":"+value);

    try {
    if ( doMod && !isPreviewOnly )
    ctx.modifyAttributes(dn, mods);
    } catch (NamingException e) {
    l.fatal(e.getLocalizedMessage());
    }

    }


    Any ideas?

    Thanks in advance
     
    nospam, Jan 6, 2006
    #1
    1. Advertising

  2. In general this error means that the value you are trying to set for the
    attribute is invalid. A very common case of this error is changing
    password. In your case, display the actual value of the attribute that
    you are using for that attribute. Check to see whether it is a valid
    value. You can AD admin tool to set the attribute to the same valeu and
    see whether you are able to...
    =

    nospam wrote:
    > Hi, I'm using JNDI to update an Active Directory. Now I'm facing the
    > following problem:
    >
    > When I try to add a value to a multiple attribute (department), I get
    > the following error:
    >
    > 20:59:11,390 FATAL [LdapSlave.java:95] [LDAP: error code 19 - 00002081:
    > AtrErr: DSID-031D0809, #1:
    > 0: 00002081: DSID-031D0809, problem 1005 (CONSTRAINT_ATT_TYPE), data
    > 0, Att d (description)
    >
    > It doesn't happen when I add or update a single value attribute.
    >
    > The snippet for the update is as follows:
    >
    > private void UpdateRegister(Hashtable db2Hash,String dn) {
    >
    > for (Iterator it=db2Hash.entrySet().iterator(); it.hasNext(); ) {
    >
    > Map.Entry entry = (Map.Entry)it.next();
    > String key = (String)entry.getKey();
    > String value = (String)entry.getValue();
    > String ldapvalue = (String)ldapValsTable.get(key);
    > ModificationItem[] mods=null;
    > boolean doMod = false;
    >
    > if ( value.length() == 0 && ldapvalue == null ) {
    > continue;
    > }
    > if ( ldapvalue == null && value.length() > 0 ){
    > l.info("atributo \""+key+"\" no existe, creandolo con
    > valor \""+value+"\"");
    >
    > //agregar atributo a ldap ... funciona solo con
    > single-valued
    > mods = new ModificationItem[1];
    > mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
    > new BasicAttribute(key, value));
    > doMod=true;
    > }
    > else if ( value.length() == 0 && ldapvalue != null ){
    > mods = new ModificationItem[1];
    > mods[0] = new
    > ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute(key));
    > l.debug("Borrando atributo: "+key);
    > doMod=true;
    > }
    > else if ( value.compareTo(ldapvalue) != 0) {
    > mods = new ModificationItem[1];
    > mods[0] = new
    > ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(key,
    > value));
    > doMod=true;
    > l.info("Diferencia encontrada:
    > "+key+":"+value+"/"+ldapvalue);
    > }
    > else
    > l.info("No se encontraron diferencias para :
    > "+key+":"+value);
    >
    > try {
    > if ( doMod && !isPreviewOnly )
    > ctx.modifyAttributes(dn, mods);
    > } catch (NamingException e) {
    > l.fatal(e.getLocalizedMessage());
    > }
    >
    > }
    >
    >
    > Any ideas?
    >
    > Thanks in advance
     
    Lord of the Union, Jan 6, 2006
    #2
    1. Advertising

  3. nospam

    Guest

    I solved it this way:

    If the attribute is multiple, the operation MUST be REPLACE_ATTRIBUTE
    even if its empty (!!!), otherwise you can use ADD_ATTRIBUTE.

    Regards

    Lord of the Union wrote:
    > In general this error means that the value you are trying to set for the
    > attribute is invalid. A very common case of this error is changing
    > password. In your case, display the actual value of the attribute that
    > you are using for that attribute. Check to see whether it is a valid
    > value. You can AD admin tool to set the attribute to the same valeu and
    > see whether you are able to...
    > =
    >
    > nospam wrote:
    > > Hi, I'm using JNDI to update an Active Directory. Now I'm facing the
    > > following problem:
    > >
    > > When I try to add a value to a multiple attribute (department), I get
    > > the following error:
    > >
    > > 20:59:11,390 FATAL [LdapSlave.java:95] [LDAP: error code 19 - 00002081:
    > > AtrErr: DSID-031D0809, #1:
    > > 0: 00002081: DSID-031D0809, problem 1005 (CONSTRAINT_ATT_TYPE), data
    > > 0, Att d (description)
    > >
    > > It doesn't happen when I add or update a single value attribute.
    > >
    > > The snippet for the update is as follows:
    > >
    > > private void UpdateRegister(Hashtable db2Hash,String dn) {
    > >
    > > for (Iterator it=db2Hash.entrySet().iterator(); it.hasNext(); ) {
    > >
    > > Map.Entry entry = (Map.Entry)it.next();
    > > String key = (String)entry.getKey();
    > > String value = (String)entry.getValue();
    > > String ldapvalue = (String)ldapValsTable.get(key);
    > > ModificationItem[] mods=null;
    > > boolean doMod = false;
    > >
    > > if ( value.length() == 0 && ldapvalue == null ) {
    > > continue;
    > > }
    > > if ( ldapvalue == null && value.length() > 0 ){
    > > l.info("atributo \""+key+"\" no existe, creandolo con
    > > valor \""+value+"\"");
    > >
    > > //agregar atributo a ldap ... funciona solo con
    > > single-valued
    > > mods = new ModificationItem[1];
    > > mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
    > > new BasicAttribute(key, value));
    > > doMod=true;
    > > }
    > > else if ( value.length() == 0 && ldapvalue != null ){
    > > mods = new ModificationItem[1];
    > > mods[0] = new
    > > ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute(key));
    > > l.debug("Borrando atributo: "+key);
    > > doMod=true;
    > > }
    > > else if ( value.compareTo(ldapvalue) != 0) {
    > > mods = new ModificationItem[1];
    > > mods[0] = new
    > > ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(key,
    > > value));
    > > doMod=true;
    > > l.info("Diferencia encontrada:
    > > "+key+":"+value+"/"+ldapvalue);
    > > }
    > > else
    > > l.info("No se encontraron diferencias para :
    > > "+key+":"+value);
    > >
    > > try {
    > > if ( doMod && !isPreviewOnly )
    > > ctx.modifyAttributes(dn, mods);
    > > } catch (NamingException e) {
    > > l.fatal(e.getLocalizedMessage());
    > > }
    > >
    > > }
    > >
    > >
    > > Any ideas?
    > >
    > > Thanks in advance
     
    , Jan 11, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cram TeXeD
    Replies:
    0
    Views:
    790
    Cram TeXeD
    Feb 4, 2004
  2. Mike S
    Replies:
    0
    Views:
    23,107
    Mike S
    Sep 16, 2004
  3. Mick
    Replies:
    2
    Views:
    9,669
    Marcin Grunwald
    Feb 23, 2005
  4. nospam
    Replies:
    0
    Views:
    430
    nospam
    Jan 10, 2006
  5. Replies:
    3
    Views:
    1,610
    Brandon McCombs
    May 2, 2007
Loading...

Share This Page