Search in sources :

Example 6 with Identity

use of java.security.Identity in project robovm by robovm.

the class IdentityTest method testAddCertificate1.

/**
     * verify addCertificate(Certificate certificate) adds a certificate for this identity.
     * If the identity has a public key, the public key in the certificate must be the same
     *
     */
public void testAddCertificate1() throws Exception {
    Identity i = new IdentityStub("iii");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", new byte[] { 1, 2, 3, 4, 5 });
    i.setPublicKey(pk1);
    // try with the same key
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    i.addCertificate(c1);
    assertSame(c1, i.certificates()[0]);
    // try Certificate with different key
    try {
        i.addCertificate(new CertificateStub("ccc", null, null, new PublicKeyStub("k2", "fff", new byte[] { 6, 7, 8, 9, 0 })));
        fail("KeyManagementException should be thrown");
    } catch (KeyManagementException ok) {
    }
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) CertificateStub(org.apache.harmony.security.tests.support.CertificateStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException)

Example 7 with Identity

use of java.security.Identity in project robovm by robovm.

the class IdentityTest method testSetPublicKey4.

//
//  Commented out since there will no be fix for the test failure
//    /**
//     *
//     * verify Identity.setPublicKey() throws KeyManagementException if key is already used
//     *
//     */
//    public void testSetPublicKey3() throws Exception {
//        Identity i1 = new IdentityStub("testSetPublicKey3_1", IdentityScope.getSystemScope());
//        Identity i2 = new IdentityStub("testSetPublicKey3_2", IdentityScope.getSystemScope());
//        PublicKey pk = new PublicKeyStub("kkk", "fff", new byte[]{1,2,3,4,5});
//        i1.setPublicKey(pk);
//        try {
//            i2.setPublicKey(pk);
//            fail("KeyManagementException should be thrown - key already used");
//        } catch (KeyManagementException ok) {};
//    }
/**
     *
     * verify Identity.setPublicKey()  removes old key and all identity's certificates
     *
     */
public void testSetPublicKey4() throws Exception {
    Identity i = new IdentityStub("testSetPublicKey4");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "Identity.testSetPublicKey4", null);
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    CertificateStub c2 = new CertificateStub("zzz", null, null, pk1);
    i.addCertificate(c1);
    i.addCertificate(c2);
    assertEquals(2, i.certificates().length);
    assertSame(pk1, i.getPublicKey());
    PublicKeyStub pk2 = new PublicKeyStub("zzz", "Identity.testSetPublicKey4", null);
    i.setPublicKey(pk2);
    assertSame(pk2, i.getPublicKey());
    assertEquals(0, i.certificates().length);
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) CertificateStub(org.apache.harmony.security.tests.support.CertificateStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity)

Example 8 with Identity

use of java.security.Identity in project robovm by robovm.

the class IdentityTest method testSetPublicKey2.

/**
     *
     * verify Identity.setPublicKey() throws KeyManagementException if key is invalid
     *
     */
public void testSetPublicKey2() throws Exception {
    Identity i2 = new IdentityStub("testSetPublicKey2_2", IdentityScope.getSystemScope());
    new PublicKeyStub("kkk", "testSetPublicKey2", new byte[] { 1, 2, 3, 4, 5 });
    try {
        i2.setPublicKey(null);
    //fail("KeyManagementException should be thrown - key is null");
    } catch (KeyManagementException ok) {
    }
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException)

Example 9 with Identity

use of java.security.Identity in project robovm by robovm.

the class IdentityTest method testEquals.

public void testEquals() throws Exception {
    IdentityStub i1 = new IdentityStub("testEquals");
    Object[] value = { null, Boolean.FALSE, new Object(), Boolean.FALSE, i1, Boolean.TRUE, new IdentityStub(i1.getName()), Boolean.TRUE };
    for (int k = 0; k < value.length; k += 2) {
        assertEquals(value[k + 1], new Boolean(i1.equals(value[k])));
        if (Boolean.TRUE.equals(value[k + 1]))
            assertEquals(i1.hashCode(), value[k].hashCode());
    }
    // check other cases
    Identity i2 = new IdentityStub("testEquals", IdentityScope.getSystemScope());
    assertEquals(i1.identityEquals(i2), i1.equals(i2));
    Identity i3 = new IdentityStub("testEquals3");
    assertEquals(i1.identityEquals(i3), i1.equals(i3));
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) Identity(java.security.Identity)

Example 10 with Identity

use of java.security.Identity in project robovm by robovm.

the class IdentityTest method testIdentityEquals.

/**
     * verify Identity.identityEquals(Identity) return true, only if names and public keys are equal
     */
public void testIdentityEquals() throws Exception {
    String name = "nnn";
    PublicKey pk = new PublicKeyStub("aaa", "fff", new byte[] { 1, 2, 3, 4, 5 });
    IdentityStub i = new IdentityStub(name);
    i.setPublicKey(pk);
    Object[] value = { //new Object(), Boolean.FALSE,
    new IdentityStub("111"), Boolean.FALSE, new IdentityStub(name), Boolean.FALSE, new IdentityStub(name, IdentityScope.getSystemScope()), Boolean.FALSE, i, Boolean.TRUE, new IdentityStub(name, pk), Boolean.TRUE };
    for (int k = 0; k < value.length; k += 2) {
        assertEquals(value[k + 1], new Boolean(i.identityEquals((Identity) value[k])));
        if (Boolean.TRUE.equals(value[k + 1]))
            assertEquals(i.hashCode(), value[k].hashCode());
    }
    Identity i2 = IdentityScope.getSystemScope().getIdentity(name);
    i2.setPublicKey(pk);
    assertTrue(i.identityEquals(i2));
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) PublicKey(java.security.PublicKey) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity)

Aggregations

Identity (java.security.Identity)23 IdentityStub (org.apache.harmony.security.tests.support.IdentityStub)13 IdentitySubclass (org.apache.harmony.security.tests.java.security.Identity2Test.IdentitySubclass)8 PublicKeyStub (org.apache.harmony.security.tests.support.PublicKeyStub)7 KeyManagementException (java.security.KeyManagementException)5 CertificateStub (org.apache.harmony.security.tests.support.CertificateStub)4 PublicKey (java.security.PublicKey)3 IdentityScope (java.security.IdentityScope)2 FileInputStream (java.io.FileInputStream)1 Principal (java.security.Principal)1 Group (java.security.acl.Group)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Vector (java.util.Vector)1 Subject (javax.security.auth.Subject)1 IdentityScopeSubclass (org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass)1 Test (org.junit.Test)1 Column (org.teiid.metadata.Column)1 MetadataFactory (org.teiid.metadata.MetadataFactory)1