Example usage for javax.naming.ldap Rdn toString

List of usage examples for javax.naming.ldap Rdn toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns this Rdn as a string represented in a format defined by <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a> and described in the class description for javax.naming.ldap.LdapName LdapName .

Usage

From source file:RdntoString.java

public static void main(String args[]) throws Exception {
    Rdn rdn = new Rdn("cn=Juicy\\,Fruit");
    String str = rdn.toString();
    System.out.println(str);/*from www  .j  a v a 2s  .  c  o m*/
    Rdn rdn2 = new Rdn(str);
    System.out.println(rdn.equals(rdn2)); // true
}

From source file:RdnConstructors.java

public static void main(String args[]) throws Exception {
    /**/*from w w w.j av  a 2s  .  co m*/
     * There are four ways of constructing an Rdn
     */
    Rdn rdn1 = new Rdn("ou= Juicy\\, Fruit");
    System.out.println("rdn1:" + rdn1.toString());

    Rdn rdn2 = new Rdn(rdn1);
    System.out.println("rdn2:" + rdn2.toString());

    Attributes attrs = new BasicAttributes();
    attrs.put("ou", "Juicy, Fruit");
    attrs.put("cn", "Mango");
    Rdn rdn3 = new Rdn(attrs);
    System.out.println("rdn3:" + rdn3.toString());

    Rdn rdn4 = new Rdn("ou", "Juicy, Fruit");
    System.out.println("rdn4:" + rdn4.toString());
}

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

/**
 * @param parentDn// w  w w  .ja v a2  s .  c o  m
 * @param subContextName
 * @param attributes
 */
public void createSubContext(final LdapName parentDn, final Rdn subContextRdn, final Attributes attributes) {
    DirContext ctx = null;

    try {
        LdapName subContextName = NamingFactory.createName(subContextRdn);
        ctx = contextFactory.createContext(parentDn.toString());
        ctx.createSubcontext(subContextName.toString(), attributes);
    } catch (NamingException e) {
        throw new java.lang.RuntimeException(subContextRdn.toString() + "," + parentDn.toString(), e);
    }
}

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

/**
 * @param parentDn/*from   www.  j a v a2 s.co  m*/
 * @param subContextRdn
 */
public void deleteSubContext(LdapName parentDn, Rdn subContextToDelete) {
    DirContext ctx = null;

    try {
        ctx = contextFactory.createContext(parentDn.toString());
        ctx.destroySubcontext(subContextToDelete.toString());
    } catch (NamingException e) {
        throw new RuntimeException(subContextToDelete.toString() + "," + parentDn.toString(), e);
    } finally {
        if (contextFactory != null)
            contextFactory.closeContext(ctx);
    }

}

From source file:org.tolven.gatekeeper.CertificateHelper.java

public static X500Principal getX500Principal(String email, String commonName, String organizationUnitName,
        String organizationName, String stateOrProvince) {
    if (null == email || null == commonName || null == organizationUnitName || null == organizationName
            || null == stateOrProvince) {
        throw new RuntimeException(
                "Certificate requires EmailAddress, Common Name, organizationUnitName, organizationName, stateOrProvince");
    }//from w  w w .j a  v a  2  s .  co m
    Attributes attributes = new BasicAttributes();
    attributes.put(X509Name.EmailAddress.toString(), email);
    attributes.put(X509Name.CN.toString(), commonName);
    attributes.put(X509Name.OU.toString(), organizationUnitName);
    attributes.put(X509Name.O.toString(), organizationName);
    attributes.put(X509Name.ST.toString(), stateOrProvince);
    Rdn rdn;
    try {
        rdn = new Rdn(attributes);
    } catch (InvalidNameException ex) {
        throw new RuntimeException("Failed to obtain a Relative Distinguised Name", ex);
    }
    return new X500Principal(rdn.toString());
}