Search in sources :

Example 21 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class X500PrincipalTest method test_equals.

/**
     * javax.security.auth.x500.X500Principal#equals(Object o)
     */
public void test_equals() {
    String name1 = "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US";
    String name2 = "cn=duke,ou=javasoft,o=sun microsystems,c=us";
    String name3 = "CN=Alex Astapchuk, OU=SSG, O=Intel ZAO, C=RU";
    X500Principal xpr1 = new X500Principal(name1);
    X500Principal xpr2 = new X500Principal(name2);
    X500Principal xpr3 = new X500Principal(name3);
    try {
        assertTrue("False returned", xpr1.equals(xpr2));
        assertFalse("True returned", xpr1.equals(xpr3));
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
}
Also used : X500Principal(javax.security.auth.x500.X500Principal)

Example 22 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class X500PrincipalTest method test_getName_Format.

/**
     * javax.security.auth.x500.X500Principal#getName(String format)
     */
public void test_getName_Format() {
    String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US";
    String expectedName = "cn=duke,ou=javasoft,o=sun microsystems,c=us";
    X500Principal xpr = new X500Principal(name);
    try {
        String resName = xpr.getName(X500Principal.CANONICAL);
        assertEquals(expectedName, resName);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
    expectedName = "CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US";
    try {
        String resName = xpr.getName(X500Principal.RFC1779);
        assertEquals(expectedName, resName);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
    try {
        String resName = xpr.getName(X500Principal.RFC2253);
        assertEquals(name, resName);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
    try {
        String resName = xpr.getName(null);
        fail("IllegalArgumentException  wasn't thrown");
    } catch (IllegalArgumentException iae) {
    }
    try {
        String resName = xpr.getName("RFC2254");
        fail("IllegalArgumentException  wasn't thrown");
    } catch (IllegalArgumentException iae) {
    }
}
Also used : X500Principal(javax.security.auth.x500.X500Principal)

Example 23 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class X500PrincipalTest method test_getEncoded.

/**
     * javax.security.auth.x500.X500Principal#getEncoded()
     */
public void test_getEncoded() {
    byte[] ba = getByteArray(TestUtils.getX509Certificate_v1());
    X500Principal xpr = new X500Principal(ba);
    try {
        byte[] res = xpr.getEncoded();
        assertNotNull(res);
        assertEquals(ba.length, res.length);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
}
Also used : X500Principal(javax.security.auth.x500.X500Principal)

Example 24 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class X500PrincipalTest method test_getName.

/**
     * javax.security.auth.x500.X500Principal#getName()
     */
public void test_getName() {
    String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US";
    X500Principal xpr = new X500Principal(name);
    try {
        String resName = xpr.getName();
        assertEquals(name, resName);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
}
Also used : X500Principal(javax.security.auth.x500.X500Principal)

Example 25 with X500Principal

use of javax.security.auth.x500.X500Principal in project robovm by robovm.

the class X500PrincipalTest method test_X500Principal_01.

/**
     * javax.security.auth.x500.X500Principal#X500Principal(String name)
     */
public void test_X500Principal_01() {
    String name = "CN=Duke,OU=JavaSoft,O=Sun Microsystems,C=US";
    try {
        X500Principal xpr = new X500Principal(name);
        assertNotNull("Null object returned", xpr);
        String resName = xpr.getName();
        assertEquals(name, resName);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
    try {
        X500Principal xpr = new X500Principal((String) null);
        fail("NullPointerException wasn't thrown");
    } catch (NullPointerException npe) {
    } catch (Exception e) {
        fail(e + " was thrown instead of NullPointerException");
    }
    try {
        X500Principal xpr = new X500Principal("X500PrincipalName");
        fail("IllegalArgumentException wasn't thrown");
    } catch (IllegalArgumentException npe) {
    } catch (Exception e) {
        fail(e + " was thrown instead of IllegalArgumentException");
    }
}
Also used : X500Principal(javax.security.auth.x500.X500Principal)

Aggregations

X500Principal (javax.security.auth.x500.X500Principal)246 X509Certificate (java.security.cert.X509Certificate)68 IOException (java.io.IOException)52 ArrayList (java.util.ArrayList)39 List (java.util.List)25 Principal (java.security.Principal)21 PublicKey (java.security.PublicKey)21 TrustAnchor (java.security.cert.TrustAnchor)21 Certificate (java.security.cert.Certificate)20 X509CertSelector (java.security.cert.X509CertSelector)16 HashMap (java.util.HashMap)16 BigInteger (java.math.BigInteger)15 KeyPair (java.security.KeyPair)15 HashSet (java.util.HashSet)14 Test (org.junit.Test)14 KeyPairGenerator (java.security.KeyPairGenerator)13 CertPathValidatorException (java.security.cert.CertPathValidatorException)13 CertificateException (java.security.cert.CertificateException)13 GeneralSecurityException (java.security.GeneralSecurityException)12 CertificateParsingException (java.security.cert.CertificateParsingException)12