Java 8 X500Principal - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 X500Principal class.

This code example shows how to use the following methods:getName
        p = new X500Principal("CN=user");
        p.getName("RFC2253", m1);
 
        // override builtin OIDs 
        m1 = Collections.singletonMap("2.5.4.3", "FOO");
        p = new X500Principal("CN=user");
        if (!p.getName("RFC2253", m1).startsWith("FOO")) {
            throw new Exception("mapping did not override builtin OID");
        } 
 
        // disallow CANONICAL format 
        try { 
            p.getName("CANONICAL", m1);
            throw new Exception
                ("expected IllegalArgumentException for CANONICAL format"); 
        } catch (IllegalArgumentException iae) {}
        // disallow invalid format 
        try { 
            p.getName("YABBADABBADOO", m1);
            throw new Exception

7
CodeRank
This code example shows how to use the following methods:getName
public class EscapedChars { 
 
    public static void main(String[] args) throws Exception {
 
        String dn="CN=\\#user";
        X500Principal xp = new X500Principal(dn);
 
        System.out.println("RFC2253 DN is " +
            xp.getName(X500Principal.RFC2253));
        System.out.println("CANONICAL DN is is " +
            xp.getName(X500Principal.CANONICAL));
 
        String dn1 = xp.getName(X500Principal.CANONICAL);
        if (!(dn1.substring(3,5).equals("\\#")))
            throw new Exception("Leading # not escaped");
 
        X500Principal xp1 = new X500Principal(dn1);
        System.out.println("CANONICAL DN is " +
            xp1.getName(X500Principal.CANONICAL));
    } 
7
CodeRank
This code example shows how to use the following methods:equals, getEncoded
    public static void main(String[] args) {
 
        try { 
 
            // create 2 different X500Principals 
            X500Principal p = new X500Principal("o=sun, cn=duke");
            X500Principal p2 = new X500Principal("o=sun, cn=dukette");
 
            // get the encoded bytes for the 2 principals 
            byte[] encoded = p.getEncoded();
            byte[] encoded2 = p2.getEncoded();
 
            // create a ByteArrayInputStream with the 
            // encodings from the 2 principals 
            byte[] all = new byte[encoded.length + encoded2.length];
            System.arraycopy(encoded, 0, all, 0, encoded.length);
            System.arraycopy(encoded2, 0, all, encoded.length, encoded2.length);
            ByteArrayInputStream bais = new ByteArrayInputStream(all);
 
            // create 2 new X500Principals from the ByteArrayInputStream 

7
CodeRank
This code example shows how to use the following methods:getName, toString
 
    static void printName(String heading, String input, X500Principal p) {
        System.out.println(heading);
        System.out.println(" input:\t\t" + input);
        System.out.println();
        System.out.println(" toString:\t" + p.toString());
        System.out.println();
        System.out.println(" getName:\t" + p.getName());
        System.out.println();
        System.out.println(" getName 1779:\t" + p.getName("rfc1779"));
        System.out.println();
        System.out.println(" getName 2253:\t" + p.getName("rfc2253"));
        System.out.println();
        System.out.println(" getName canon:\t" + p.getName("canonical"));
        System.out.println();
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getName
    public void test_getNameLjava_lang_String_java_util_Map() { 
        Map<String, String> keyword = new HashMap<String, String>();
        keyword.put("CN", "2.19");
        keyword.put("OU", "1.2.5.19");
        keyword.put("O", "1.2.5");
        X500Principal X500p = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US ,CN=DD",keyword);
        keyword = new HashMap<String, String>();
        keyword.put("2.19", "mystring");
        String rfc1779Name = X500p.getName("RFC1779",keyword);
        String rfc2253Name = X500p.getName("RFC2253",keyword);
        String expected1779Out = "mystring=Duke, OID.1.2.5.19=JavaSoft, OID.1.2.5=Sun Microsystems, C=US, mystring=DD";
        String expected2253Out = "mystring=Duke,1.2.5.19=#13084a617661536f6674,1.2.5=#131053756e204d6963726f73797374656d73,C=US,mystring=DD";
        assertEquals("Output order precedence problem", expected1779Out, rfc1779Name);
        assertEquals("Output order precedence problem", expected2253Out, rfc2253Name);
        try{ 
            X500p.getName("CANONICAL",keyword);
            fail("Should throw IllegalArgumentException exception here");
        } 
        catch(IllegalArgumentException e){
            //expected IllegalArgumentException here 
        } 
6
CodeRank
This code example shows how to use the following methods:
     */ 
    public void testGetIssuers() { 
        X509CRLSelector selector = new X509CRLSelector();
        X500Principal iss1 = new X500Principal("O=First Org.");
        X500Principal iss2 = new X500Principal("O=Second Org.");
        X500Principal iss3 = new X500Principal("O=Third Org.");
        assertNull("The collection should be null.", selector.getIssuers());
        selector.addIssuer(iss1);
        selector.addIssuer(iss2);
        Collection<X500Principal> result = selector.getIssuers();
        try { 
            result.add(iss3);
            fail("The returned collection should be unmodifiable.");
        } catch (UnsupportedOperationException e) {
        } 
        assertTrue("The collection should contain the specified DN.", result
                .contains(iss2));
    } 
 
    /** 
6
CodeRank
This code example shows how to use the following methods:
                + "83530302e583530305072696e636970616cf90dff3c88b877c703000078707572" 
                + "00025b42acf317f8060854e002000078700000006a30683117301506035504031" 
                + "30e7777772e676f6f676c652e636f6d31133011060355040a130a476f6f676c65" 
                + "20496e63311630140603550407130d4d6f756e7461696e2056696577311330110" 
                + "603550408130a43616c69666f726e6961310b300906035504061302555378"; 
        X500Principal actual = new X500Principal("C=US, "
                                                 + "ST=California, " 
                                                 + "L=Mountain View, " 
                                                 + "O=Google Inc, " 
                                                 + "CN=www.google.com"); 
        new SerializationTester<X500Principal>(actual, expected).test();
    } 
 
    /** 
     * ASN1-encoded trusted certificate #946059622 for 
     * Entrust.net. This certificate uses the T61String (aka 
     * TeletexString or TELETEXSTRING) encoding for one 
     * organizationalUnitNames: 
     * 
     * "www.entrust.net/CPS_2048 incorp. by ref. (limits liab.)" 
7
CodeRank
This code example shows how to use the following methods:getName, toString
 
    static void printName(String heading, String input, X500Principal p) {
        System.out.println(heading);
        System.out.println(" input:\t\t" + input);
        System.out.println();
        System.out.println(" toString:\t" + p.toString());
        System.out.println();
        System.out.println(" getName:\t" + p.getName());
        System.out.println();
        System.out.println(" getName 1779:\t" + p.getName("rfc1779"));
        System.out.println();
        System.out.println(" getName 2253:\t" + p.getName("rfc2253"));
        System.out.println();
        System.out.println(" getName canon:\t" + p.getName("canonical"));
        System.out.println();
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getEncoded
    private static X509Name convertName( 
        X500Principal    name)
    { 
        try 
        { 
            return new X509Principal(name.getEncoded());
        } 
        catch (IOException e)
        { 
            throw new IllegalArgumentException("can't convert name");
        } 
    } 
     
    /** 
     * create a PKCS10 certfication request using the BC provider. 
     */ 
    public PKCS10CertificationRequest( 
        String              signatureAlgorithm,
        X500Principal       subject,
        PublicKey           key,
6
CodeRank
This code example shows how to use the following methods:getName
        m.put("BAR", "1.2.3");
        p = new X500Principal("BAR=user", m);
 
        // override builtin keywords 
        m = Collections.singletonMap("CN", "1.2.3");
        p = new X500Principal("CN=user", m);
        if (!p.getName().startsWith("1.2.3")) {
            throw new Exception("mapping did not override builtin keyword");
        } 
 
        // override builtin OIDs 
        m = Collections.singletonMap("FOO", "2.5.4.3");
        p = new X500Principal("FOO=sean", m);
        if (!p.getName().startsWith("CN")) {
            throw new Exception("mapping did not override builtin OID");
        } 
    } 
} 
6
CodeRank

Related Java 8 X500Principal Questions & Answers:

See Code Examples for Java 8 X500Principal Methods: