当前位置: 首页>>代码示例>>Java>>正文


Java Identity类代码示例

本文整理汇总了Java中java.security.Identity的典型用法代码示例。如果您正苦于以下问题:Java Identity类的具体用法?Java Identity怎么用?Java Identity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Identity类属于java.security包,在下文中一共展示了Identity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addIdentity

import java.security.Identity; //导入依赖的package包/类
/**
 * @see java.security.IdentityScope#addIdentity(java.security.Identity)
 */
public synchronized void addIdentity(Identity identity) throws KeyManagementException {
    if (identity == null) {
        throw new NullPointerException("identity == null");
    }

    String name = identity.getName();
    if (names.containsKey(name)) {
        throw new KeyManagementException("name '" + name + "' is already used");
    }

    PublicKey key = identity.getPublicKey();
    if (key != null && keys.containsKey(key)) {
        throw new KeyManagementException("key '" + key + "' is already used");
    }

    names.put(name, identity);
    if (key != null) {
        keys.put(key, identity);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:SystemScope.java

示例2: test_addIdentityLjava_security_Identity

import java.security.Identity; //导入依赖的package包/类
/**
 * @tests java.security.IdentityScope#addIdentity(java.security.Identity)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "addIdentity",
    args = {java.security.Identity.class}
)
public void test_addIdentityLjava_security_Identity() throws Exception {
           IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
                   new IdentityScopeSubclass());
           Identity id = new IdentitySubclass("id1");
           id.setPublicKey(pubKey);
           sub.addIdentity(id);
           try {
               Identity id2 = new IdentitySubclass("id2");
               id2.setPublicKey(pubKey);
               sub.addIdentity(id2);
               fail("KeyManagementException should have been thrown");
           } catch (KeyManagementException e) {
               // Expected
           }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:25,代码来源:IdentityScope2Test.java

示例3: test_removeIdentityLjava_security_Identity

import java.security.Identity; //导入依赖的package包/类
/**
 * @tests java.security.IdentityScope#removeIdentity(java.security.Identity)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "removeIdentity",
    args = {java.security.Identity.class}
)
public void test_removeIdentityLjava_security_Identity() throws Exception {
           IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
                   new IdentityScopeSubclass());
           Identity id = new IdentitySubclass();
           id.setPublicKey(pubKey);
           sub.addIdentity(id);
           sub.removeIdentity(id);
           try {
               sub.removeIdentity(id);
               fail("KeyManagementException should have been thrown");
           } catch (KeyManagementException e) {
               // expected
           }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:IdentityScope2Test.java

示例4: test_identities

import java.security.Identity; //导入依赖的package包/类
/**
 * @tests java.security.IdentityScope#identities()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "identities",
    args = {}
)
public void test_identities() throws Exception {
           IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
                   new IdentityScopeSubclass());
           Identity id = new IdentitySubclass();
           id.setPublicKey(pubKey);
           sub.addIdentity(id);
           Enumeration<Identity> en = sub.identities();
           assertTrue("Wrong object contained in identities", en.nextElement()
                   .equals(id));
           assertTrue("Contains too many elements", !en.hasMoreElements());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:IdentityScope2Test.java

示例5: test_getIdentityLjava_security_PublicKey

import java.security.Identity; //导入依赖的package包/类
/**
 * @tests java.security.IdentityScope#getIdentity(java.security.PublicKey)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    method = "getIdentity",
    args = {java.security.PublicKey.class}
)
public void test_getIdentityLjava_security_PublicKey() throws Exception {
    IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
            new IdentityScopeSubclass());
    Identity id = new IdentitySubclass();
    id.setPublicKey(pubKey);
    sub.addIdentity(id);
    Identity returnedId = sub.getIdentity(pubKey);
    assertEquals("Test 1: Returned Identity not the same as the added one;",
            id, returnedId);

    assertNull("Test 2: Null value expected.",
            sub.getIdentity((PublicKey) null));

    PublicKey anotherKey = KeyPairGenerator.getInstance("DSA").genKeyPair().getPublic();
    assertNull("Test 3: Null value expected.",
            sub.getIdentity(anotherKey));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:IdentityScope2Test.java

示例6: test_getIdentityLjava_lang_String

import java.security.Identity; //导入依赖的package包/类
/**
 * @tests java.security.IdentityScope#getIdentity(java.lang.String)
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "getIdentity",
    args = {java.lang.String.class}
)
public void test_getIdentityLjava_lang_String() throws Exception {
           IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
                   new IdentityScopeSubclass());
           Identity id = new IdentitySubclass("test");
           id.setPublicKey(pubKey);
           sub.addIdentity(id);
           Identity returnedId = sub.getIdentity("test");
           assertEquals("Returned Identity not the same as the added one", id,
                   returnedId);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:20,代码来源:IdentityScope2Test.java

示例7: test_toString

import java.security.Identity; //导入依赖的package包/类
/**
 * @tests java.security.IdentityScope#toString()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "toString",
    args = {}
)
public void test_toString() throws Exception {
        IdentityScopeSubclass sub = new IdentityScopeSubclass("test",
                new IdentityScopeSubclass());
        Identity id = new IdentitySubclass();
        id.setPublicKey(pubKey);
        sub.addIdentity(id);
        assertNotNull("toString returned a null", sub.toString());
        assertTrue("Not a valid String ", sub.toString().length() > 0);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:19,代码来源:IdentityScope2Test.java

示例8: test_ConstructorLjava_lang_String

import java.security.Identity; //导入依赖的package包/类
/**
 * @tests java.security.Identity#Identity(java.lang.String)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "Identity",
    args = {java.lang.String.class}
)
public void test_ConstructorLjava_lang_String() {
    String[] str = {"test", "", null};
    IdentitySubclass is;
    for (int i = 0; i < str.length; i++) {
        try {
            is = new IdentitySubclass(str[i]);
            assertNotNull(is);
            assertTrue(is instanceof Identity);
        } catch (Exception e) {
            fail("Unexpected exception for Identity(java.lang.String) with parameter " + str[i]);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:Identity2Test.java

示例9: identityEquals

import java.security.Identity; //导入依赖的package包/类
/**
 * @tests java.security.Identity#identityEquals(java.security.Identity)
 */
@TestTargetNew(
    level = TestLevel.PARTIAL,
    notes = "Method identityEquals(java.security.Identity) is not tested",
    method = "identityEquals",
    args = {java.security.Identity.class}
)
public void test_identityEqualsLjava_security_Identity() throws Exception {
           IdentitySubclass sub = new IdentitySubclass("test", null);
           CertificateFactory cf = CertificateFactory.getInstance("X.509");
           X509Certificate cert[] = new X509Certificate[1];
           cert[0] = (X509Certificate) cf.generateCertificate(certArray);
           sub.setPublicKey(cert[0].getPublicKey());
           CertificateImpl certImpl = new CertificateImpl(cert[0]);
           sub.addCertificate(certImpl);
           IdentitySubclass sub2 = new IdentitySubclass("test", null);
           sub2.setPublicKey(cert[0].getPublicKey());
           assertEquals("the two Identity objects are not identity-equal",
                   sub2, sub);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:23,代码来源:Identity2Test.java

示例10: testEquals

import java.security.Identity; //导入依赖的package包/类
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "equals",
    args = {java.lang.Object.class}
)
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));

}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:27,代码来源:IdentityTest.java

示例11: testAddCertificate1

import java.security.Identity; //导入依赖的package包/类
/**
 * 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
 *
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "addCertificate",
    args = {java.security.Certificate.class}
)
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) {}
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:IdentityTest.java

示例12: testAddCertificate2

import java.security.Identity; //导入依赖的package包/类
/**
 * verify addCertificate(Certificate certificate) adds a certificate for this identity.
 * if the identity does not have a public key, the identity's public key is set to be that specified in the certificate.
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "addCertificate",
    args = {java.security.Certificate.class}
)
public void testAddCertificate2() throws Exception {
    Identity i = new IdentityStub("iii");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null);
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    i.addCertificate(c1);
    assertSame(c1, i.certificates()[0]);
    assertSame(pk1, i.getPublicKey());

}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:20,代码来源:IdentityTest.java

示例13: testCertificates

import java.security.Identity; //导入依赖的package包/类
/**
 * verify certificates() returns a copy of all certificates for this identity
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "certificates",
    args = {}
)
public void testCertificates() throws Exception {
    Identity i = new IdentityStub("iii");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", null);
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    CertificateStub c2 = new CertificateStub("zzz", null, null, pk1);
    i.addCertificate(c1);
    i.addCertificate(c2);
    java.security.Certificate[] s = i.certificates();
    assertEquals(2, s.length);
    assertTrue(c1.equals(s[0]) || c2.equals(s[0]));
    assertTrue(c1.equals(s[1]) || c2.equals(s[1]));
    s[0] = null;
    s[1] = null;
    // check that the copy was modified
    s = i.certificates();
    assertEquals(2, s.length);
    assertTrue(c1.equals(s[0]) || c2.equals(s[0]));
    assertTrue(c1.equals(s[1]) || c2.equals(s[1]));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:29,代码来源:IdentityTest.java

示例14: testGetScope

import java.security.Identity; //导入依赖的package包/类
/**
 * verify Identity.getScope() returns identity's scope
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getScope",
    args = {}
)
public void testGetScope() throws Exception {
   Identity i = new IdentityStub("testGetScope");
   assertNull(i.getScope());
   IdentityScope s = IdentityScope.getSystemScope();

   Identity i2 = new IdentityStub("testGetScope2", s);
   assertSame(s, i2.getScope());

}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:19,代码来源:IdentityTest.java

示例15: testSetPublicKey4

import java.security.Identity; //导入依赖的package包/类
/**
 *
 * verify Identity.setPublicKey()  removes old key and all identity's certificates
 *
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "setPublicKey",
    args = {java.security.PublicKey.class}
)
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);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:27,代码来源:IdentityTest.java


注:本文中的java.security.Identity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。