Example usage for javax.naming.directory BasicAttributes BasicAttributes

List of usage examples for javax.naming.directory BasicAttributes BasicAttributes

Introduction

In this page you can find the example usage for javax.naming.directory BasicAttributes BasicAttributes.

Prototype

public BasicAttributes() 

Source Link

Document

Constructs a new instance of Attributes.

Usage

From source file:com.springsource.insight.plugin.ldap.TestLdapContext.java

public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
    ensureOpen();//ww w . j a v  a 2  s  .  c  om
    logger.info("getAttributes(" + name + ")[" + attrIds + "]");
    return new BasicAttributes();
}

From source file:org.apache.archiva.redback.common.ldap.user.LdapUserMapper.java

public Attributes getCreationAttributes(User user, boolean encodePasswordIfChanged) throws MappingException {
    Attributes userAttrs = new BasicAttributes();

    boolean passwordSet = false;

    if (!passwordSet && (user.getEncodedPassword() != null)) {
        userAttrs.put(getPasswordAttribute(), user.getEncodedPassword());
    }//  www  .  j  a  v  a  2 s.  c  o m

    if (!StringUtils.isEmpty(user.getFullName())) {
        userAttrs.put(getUserFullNameAttribute(), user.getFullName());
    }

    if (!StringUtils.isEmpty(user.getEmail())) {
        userAttrs.put(getEmailAddressAttribute(), user.getEmail());
    }

    return userAttrs;
}

From source file:org.projectforge.business.ldap.LdapDao.java

/**
 * @param ctx//from w ww.j a va  2s  .c o m
 * @param ouBase If organizational units are given by the given obj then this parameter will be ignored, otherwise
 *          this is the ou where the new object will be inserted.
 * @param obj
 * @param args
 * @throws NamingException
 */
public void create(final DirContext ctx, final String ouBase, final T obj, final Object... args)
        throws NamingException {
    final String dn = buildDn(ouBase, obj);
    log.info("Create " + getObjectClass() + ": " + dn + ": " + getLogInfo(obj));
    final Attributes attrs = new BasicAttributes();
    final List<ModificationItem> modificationItems = getModificationItems(new ArrayList<ModificationItem>(),
            obj);
    modificationItems.add(createModificationItem(DirContext.ADD_ATTRIBUTE, "objectClass", getObjectClass()));
    final String[] additionalObjectClasses = getAdditionalObjectClasses(obj);
    if (additionalObjectClasses != null) {
        for (final String objectClass : additionalObjectClasses) {
            modificationItems.add(createModificationItem(DirContext.ADD_ATTRIBUTE, "objectClass", objectClass));
        }
    }
    for (final ModificationItem modItem : modificationItems) {
        final Attribute attr = modItem.getAttribute();
        LdapUtils.putAttribute(attrs, attr.getID(), (String) attr.get());
    }
    LdapUtils.putAttribute(attrs, "cn", LdapUtils.escapeCommonName(obj.getCommonName()));
    onBeforeBind(dn, attrs, args);
    ctx.bind(dn, null, attrs);
}

From source file:edu.kit.scc.ldap.LdapPosixUserDao.java

/**
 * Inserts a new POSIX user into the LDAP directory.
 * // w w  w .j  a va  2 s. co m
 * @param posixUser the {@link PosixUser} to insert
 * @return the {@link PosixUser} inserted
 */
public PosixUser insertUser(PosixUser posixUser) {
    if (posixUser.commonName == null || posixUser.gidNumber == null || posixUser.homeDirectory == null
            || posixUser.surName == null || posixUser.uid == null || posixUser.uidNumber == null) {
        log.warn("PosixUser has missing mandatory attributes");
        return null;
    }

    BasicAttribute personBasicAttribute = new BasicAttribute("objectclass");
    personBasicAttribute.add("extensibleObject");
    personBasicAttribute.add("inetOrgPerson");
    personBasicAttribute.add("organizationalPerson");
    personBasicAttribute.add("person");
    personBasicAttribute.add("posixAccount");

    Attributes personAttributes = new BasicAttributes();
    personAttributes.put(personBasicAttribute);
    personAttributes.put("cn", posixUser.getCommonName());
    personAttributes.put("sn", posixUser.getSurName());
    personAttributes.put("uid", posixUser.getUid());
    personAttributes.put("uidNumber", String.valueOf(posixUser.getUidNumber()));
    personAttributes.put("gidNumber", String.valueOf(posixUser.getGidNumber()));
    personAttributes.put("homeDirectory", posixUser.getHomeDirectory());

    if (posixUser.getUniqueIdentifier() != null) {
        personAttributes.put("uniqueIdentifier", posixUser.getUniqueIdentifier());
    }
    if (posixUser.getDescription() != null) {
        personAttributes.put("description", posixUser.getDescription());
    }
    if (posixUser.getGecos() != null) {
        personAttributes.put("gecos", posixUser.getGecos());
    }
    if (posixUser.getLoginShell() != null) {
        personAttributes.put("loginShell", posixUser.getLoginShell());
    }
    if (posixUser.getUserPassword() != null) {
        personAttributes.put("userPassword", posixUser.getUserPassword());
    }
    if (posixUser.getGivenName() != null) {
        personAttributes.put("givenName", posixUser.getGivenName());
    }
    if (posixUser.getMail() != null) {
        personAttributes.put("mail", posixUser.getMail());
    }

    LdapName newUserDn = LdapUtils.emptyLdapName();
    try {
        newUserDn = new LdapName(userBase);
        newUserDn.add("uid=" + posixUser.getUid());
        log.debug("Insert {}", newUserDn.toString());
        ldapTemplate.bind(newUserDn, null, personAttributes);

        return posixUser;
    } catch (InvalidNameException ex) {
        log.error("ERROR {}", ex.toString());
        // ex.printStackTrace();
    } catch (NameAlreadyBoundException ex) {
        log.error("ERROR {}", ex.toString());
    }
    return null;
}

From source file:com.springsource.insight.plugin.ldap.TestLdapContext.java

public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
    for (ModificationItem item : mods) {
        BasicAttributes attrs = new BasicAttributes();
        attrs.put(item.getAttribute());//  www .j  ava 2 s  . c  o m
        modifyAttributes(name, item.getModificationOp(), attrs);
    }
}

From source file:edu.kit.scc.ldap.LdapPosixGroupDao.java

/**
 * Inserts a new POSIX group into the LDAP directory.
 * //from w  w w. j ava  2 s. c  o m
 * @param group the {@link PosixGroup} to insert
 * @return the {@link PosixGroup} inserted
 */
public PosixGroup insertGroup(PosixGroup group) {
    if (group.commonName == null || group.gidNumber == null) {
        log.warn("PosixGroup has missing mandatory attributes");
        return null;
    }

    BasicAttribute posixGroupBasicAttribute = new BasicAttribute("objectclass");
    posixGroupBasicAttribute.add("posixGroup");

    Attributes posixGroupAttributes = new BasicAttributes();
    posixGroupAttributes.put(posixGroupBasicAttribute);
    posixGroupAttributes.put("cn", group.getCommonName());
    posixGroupAttributes.put("gidNumber", String.valueOf(group.getGidNumber()));

    if (group.getUserPassword() != null) {
        posixGroupAttributes.put("userPassword", group.getUserPassword());
    }
    if (group.getDescription() != null) {
        posixGroupAttributes.put("description", group.getDescription());
    }
    LdapName newGroupDn = LdapUtils.emptyLdapName();
    try {
        newGroupDn = new LdapName(groupBase);
        newGroupDn.add("cn=" + group.getCommonName());
        log.debug("Insert {}", newGroupDn.toString());
        ldapTemplate.bind(newGroupDn, null, posixGroupAttributes);

        return group;
    } catch (NameAlreadyBoundException ex) {
        log.error("ERROR {}", ex.getMessage());
    } catch (InvalidNameException ex) {
        log.error("ERROR {}", ex.getMessage());
    }
    return null;
}

From source file:org.swordess.ldap.util.AttrUtils.java

/**
 * Construct attributes whose ids and values are specified in ordering.
 * <p/>/*from  w w  w.  j  a v a 2  s .c  o m*/
 * NOTE: The length of <tt>ids</tt> and <tt>values</tt> must be equal, otherwise a RuntimeException will be thrown.
 * 
 * @param ids
 *            ids in ordering
 * @param values
 *            values in ordering
 * @return
 */
public static Attributes create(String[] ids, Object[] values) {
    if (ArrayUtils.isEmpty(ids) || ArrayUtils.isEmpty(values) || ids.length != values.length) {
        throw new RuntimeException("length of ids and values are not match");
    }

    Attributes attrs = new BasicAttributes();
    for (int i = 0; i < ids.length; i++) {
        attrs.put(ids[i], values[i]);
    }
    return attrs;
}

From source file:com.springsource.insight.plugin.ldap.TestLdapContext.java

public void rebind(Name name, Object obj) throws NamingException {
    rebind(name, obj, new BasicAttributes());
}

From source file:com.springsource.insight.plugin.ldap.TestLdapContext.java

public void rebind(String name, Object obj) throws NamingException {
    rebind(name, obj, new BasicAttributes());
}

From source file:org.easy.ldap.AuthServiceImpl.java

@Override
public List<String> getAssignedRoles(LdapUser user) {
    List<String> out = null;

    String uniqueMemberDn = namingFactory.createUserDn(user.getTenantId(), user.getUserId()).toString();
    LdapName rolesDn = namingFactory.createRolesDn(user.getTenantId());
    Attributes attributes = new BasicAttributes();
    attributes.put(new BasicAttribute(RdnType.UNIQUE_MEMBER.toString(), uniqueMemberDn));

    out = ldapDao.findRdnValues(rolesDn, attributes, RdnType.CN);

    return out;/*ww  w  . j  a  v  a 2 s .co m*/
}