Code example for IdentityScope

Methods: addIdentity

0
    /** 
     * verify that only one identity with given name or public key can be added 
     * i.e. KeyManagementException is thrown 
     */ 
    public void testAddIdentity() throws Exception { 
//        SystemScope ss = new SystemScope("SystemScope"); 
        java.security.PublicKey kkk = new PublicKeyStub("kkk", "fff", null);        
        java.security.Identity aaa = new IdentityScopeStub("aaa");
        aaa.setPublicKey(kkk);
        ss.addIdentity(aaa);
         
        java.security.Identity bbb = new IdentityScopeStub("aaa");
        try { 
            ss.addIdentity(bbb);
            fail("KeyManagementException should be thrown for already used name");
        } catch (KeyManagementException ok) {}
         
        java.security.Identity ccc = new IdentityScopeStub("ccc");
        ccc.setPublicKey(kkk);
        try { 
            ss.addIdentity(ccc);
            fail("KeyManagementException should be thrown for already used key");