JNDI: Delete only one attribute when there are several different values for the same attribute

Discussion in 'Java' started by bsporb@gmail.com, May 1, 2007.

  1. Guest

    Hi;

    My user entry has several role attributes, each with different values.

    Can I use context.modifyAttributes() to remove only one of these
    values?

    Example:

    DN uid=foo,ou=People,o=us.org

    Attributes:
    ....
    sysRole developer
    sysRole user
    sysRole tester
    ....

    how would I remove only the user role attribute?

    thanks for any help.

    -sporb
    , May 1, 2007
    #1
    1. Advertising

  2. Guest

    There's something creative about posting to usenet :)

    I think i figured it out just after posting the above. What seems to
    work:


    // attribute, value are the values that I want to remove...
    BasicAttribute ba = new BasicAttribute(attribute, value);
    BasicAttributes bas = new BasicAttributes();
    bas.put(ba);
    context.modifyAttributes(dn, DirContext.REMOVE_ATTRIBUTE, bas);


    I would still be interested to hear of other approaches, or thoughts
    on this.

    thanks again
    -sporb
    , May 1, 2007
    #2
    1. Advertising

  3. Re: JNDI: Delete only one attribute when there are several differentvalues for the same attribute

    wrote:
    > There's something creative about posting to usenet :)
    >
    > I think i figured it out just after posting the above. What seems to
    > work:
    >
    >
    > // attribute, value are the values that I want to remove...
    > BasicAttribute ba = new BasicAttribute(attribute, value);
    > BasicAttributes bas = new BasicAttributes();
    > bas.put(ba);
    > context.modifyAttributes(dn, DirContext.REMOVE_ATTRIBUTE, bas);
    >
    >
    > I would still be interested to hear of other approaches, or thoughts
    > on this.
    >
    > thanks again
    > -sporb
    >


    I haven't ever tried your idea with my own app that utilizes JNDI but I
    would think that on the surface, your code would remove the attribute
    and any values it contained but if you say it works then it must be okay.

    I, on the other hand, take the opposite approach. I ignore any values
    that will be removed and create a new BasicAttribute that contains only
    the values that will be kept and write that back to the directory store
    using modifyAttributes().
    Brandon McCombs, May 2, 2007
    #3
  4. Re: JNDI: Delete only one attribute when there are several differentvalues for the same attribute

    wrote:
    > There's something creative about posting to usenet :)
    >
    > I think i figured it out just after posting the above. What seems to
    > work:
    >
    >
    > // attribute, value are the values that I want to remove...
    > BasicAttribute ba = new BasicAttribute(attribute, value);
    > BasicAttributes bas = new BasicAttributes();
    > bas.put(ba);
    > context.modifyAttributes(dn, DirContext.REMOVE_ATTRIBUTE, bas);
    >
    >
    > I would still be interested to hear of other approaches, or thoughts
    > on this.
    >
    > thanks again
    > -sporb
    >


    Just wanted to say that I was re-reading your initial post and was
    originally thinking you were wanting to delete a value from an attribute
    when it had multiple values but it seems you want to delete a whole
    attribute. You seem to have been using the word "value" in multiple ways
    but in LDAP terminology it means something specific so it threw me off
    until I re-read your post.

    Going back to your original post, you wanted to only remove the the
    sysRole user attribute. Given your example, sysRole is the attribute
    but 'user' is the data (you called 'user' an attribute), specifically it
    is the 2nd value for the sysRole attribute based on your example.
    Depending on whether or not I understand you correctly this time and
    whether you correctly used the terms you wanted to use I'll say this:

    You are on the right track but you don't have to specify any value to
    the BasicAttribute() constructor to delete an attribute. It has another
    constructor that takes only an attribute name.
    Brandon McCombs, May 2, 2007
    #4
    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. Mike S
    Replies:
    0
    Views:
    22,988
    Mike S
    Sep 16, 2004
  2. Mick
    Replies:
    2
    Views:
    9,503
    Marcin Grunwald
    Feb 23, 2005
  3. Christopher Brewster
    Replies:
    5
    Views:
    334
    John Machin
    Nov 14, 2008
  4. bluebaron
    Replies:
    3
    Views:
    727
    Jonathan N. Little
    Nov 4, 2009
  5. Replies:
    0
    Views:
    102
Loading...

Share This Page