Example usage for javax.naming InvalidNameException toString

List of usage examples for javax.naming InvalidNameException toString

Introduction

In this page you can find the example usage for javax.naming InvalidNameException toString.

Prototype

public String toString() 

Source Link

Document

Generates the string representation of this exception.

Usage

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

/**
 * Deletes a POSIX user from the LDAP directory.
 * /*  ww  w . j ava2 s .  c  o  m*/
 * @param posixUser the {@link PosixUser} to delete
 * @return true if success
 */
public boolean deleteUser(PosixUser posixUser) {
    LdapName userDn = LdapUtils.emptyLdapName();
    try {
        userDn = new LdapName(userBase);
        userDn.add("uid=" + posixUser.getUid());
        log.debug("Delete {}", userDn.toString());
        ldapTemplate.unbind(userDn);

        return true;
    } catch (InvalidNameException ex) {
        log.error("ERROR {}", ex.toString());
        // ex.printStackTrace();
    }
    return false;
}

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

/**
 * Deletes the {@link PosixGroup} from the LDAP directory.
 * //from   w  ww.j av a  2  s. co  m
 * @param group the {@link PosixGroup} to delete
 * @return true if success
 */
public boolean deleteGroup(PosixGroup group) {
    LdapName groupDn = LdapUtils.emptyLdapName();
    try {
        groupDn = new LdapName(groupBase);
        groupDn.add("cn=" + group.getCommonName());
        log.debug("Delete {}", groupDn.toString());
        ldapTemplate.unbind(groupDn);

        return true;
    } catch (InvalidNameException ex) {
        log.error("ERROR {}", ex.toString());
        // ex.printStackTrace();
    }
    return false;
}

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

/**
 * Updates a POSIX group in the LDAP directory.
 * //from   w w  w.  j a  v a2  s  . c om
 * @param group the {@link PosixGroup} to update
 * @return the {@link PosixGroup} updated
 */
public PosixGroup updateGroup(PosixGroup group) {
    BasicAttribute posixGroupBasicAttribute = new BasicAttribute("objectclass");
    posixGroupBasicAttribute.add("posixGroup");

    Attributes posixGroupAttributes = new BasicAttributes();
    posixGroupAttributes.put(posixGroupBasicAttribute);

    if (group.getCommonName() != null) {
        posixGroupAttributes.put("cn", group.getCommonName());
    }
    if (group.getGidNumber() != null) {
        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 groupDn = LdapUtils.emptyLdapName();
    try {
        groupDn = new LdapName(groupBase);
        groupDn.add("cn=" + group.getCommonName());
        log.debug("Update {}", groupDn.toString());
        ldapTemplate.bind(groupDn, null, posixGroupAttributes);

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

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

/**
 * Inserts a new POSIX user into the LDAP directory.
 * /* www .  j  av a 2  s . c  om*/
 * @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:edu.kit.scc.ldap.LdapPosixUserDao.java

/**
 * Updates a POSIX user in the LDAP directory.
 * //from w  w w  .j  a v a2 s . com
 * @param posixUser the {@link PosixUser} to update
 * @return the {@link PosixUser} updated
 */
public PosixUser updateUser(PosixUser posixUser) {
    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);

    if (posixUser.getCommonName() != null) {
        personAttributes.put("cn", posixUser.getCommonName());
    }
    if (posixUser.getSurName() != null) {
        personAttributes.put("sn", posixUser.getSurName());
    }
    if (posixUser.getUid() != null) {
        personAttributes.put("uid", posixUser.getUid());
    }
    if (posixUser.getUidNumber() != null) {
        personAttributes.put("uidNumber", String.valueOf(posixUser.getUidNumber()));
    }
    if (posixUser.getGidNumber() != null) {
        personAttributes.put("gidNumber", String.valueOf(posixUser.getGidNumber()));
    }
    if (posixUser.getHomeDirectory() != null) {
        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 userDn = LdapUtils.emptyLdapName();
    try {
        userDn = new LdapName(userBase);
        userDn.add("uid=" + posixUser.getUid());
        log.debug("Update {}", userDn.toString());
        ldapTemplate.rebind(userDn, null, personAttributes);

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