Java 类java.security.UnresolvedPermission 实例源码

项目:evosuite    文件:MSecurityManager.java   
protected boolean checkUnresolvedPermission(UnresolvedPermission perm) {
    /*
     * From documentation:
     * -------------------------------------------------------------------------------------------------------------------------- The
     * java.security.UnresolvedPermission class is used to hold Permissions that were "unresolved" when the Policy was initialized. An unresolved
     * permission is one whose actual Permission class does not yet exist at the time the Policy is initialized (see below). The policy for a Java
     * runtime (specifying which permissions are available for code from various principals) is represented by a Policy object. Whenever a Policy
     * is initialized or refreshed, Permission objects of appropriate classes are created for all permissions allowed by the Policy. Many
     * permission class types referenced by the policy configuration are ones that exist locally (i.e., ones that can be found on CLASSPATH).
     * Objects for such permissions can be instantiated during Policy initialization. For example, it is always possible to instantiate a
     * java.io.FilePermission, since the FilePermission class is found on the CLASSPATH. Other permission classes may not yet exist during Policy
     * initialization. For example, a referenced permission class may be in a JAR file that will later be loaded. For each such class, an
     * UnresolvedPermission is instantiated. Thus, an UnresolvedPermission is essentially a "placeholder" containing information about the
     * permission. Later, when code calls AccessController.checkPermission on a permission of a type that was previously unresolved, but whose
     * class has since been loaded, previously-unresolved permissions of that type are "resolved". That is, for each such UnresolvedPermission, a
     * new object of the appropriate class type is instantiated, based on the information in the UnresolvedPermission. This new object replaces
     * the UnresolvedPermission, which is removed.
     * -------------------------------------------------------------------------------------------------------------------------- In theory it
     * shouldn't really happen, unless some customized permission classes are used in the SUT. It also poses a problem: we might run a test case
     * that throws this security exception but, if we run it again, it might not throw it anymore. Just to be sure, for now we deny this
     * permission
     */
    return false;
}
项目:In-the-Box-Fork    文件:UnresolvedPermissionTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "!SerializationSelf",
    args = {}
)
public void testSerialization() throws Exception {
    UnresolvedPermission up = new UnresolvedPermission(
            "java.security.SecurityPermission", "a.b.c", "actions", null);
    assertEquals("java.security.SecurityPermission", up.getUnresolvedType());
    assertEquals("a.b.c", up.getUnresolvedName());
    assertEquals("actions", up.getUnresolvedActions());
    assertNull(up.getUnresolvedCerts());

    UnresolvedPermission deserializedUp = (UnresolvedPermission) SerializationTester
            .getDeserilizedObject(up);
    assertEquals("java.security.SecurityPermission", deserializedUp
            .getUnresolvedType());
    assertEquals("a.b.c", deserializedUp.getUnresolvedName());
    assertEquals("actions", deserializedUp.getUnresolvedActions());
    assertNull(deserializedUp.getUnresolvedCerts());
}
项目:In-the-Box-Fork    文件:UnresolvedPermissionTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "!SerializationGolden",
    args = {}
)
public void testSerialization_Compatibility() throws Exception {
    UnresolvedPermission up = new UnresolvedPermission(
            "java.security.SecurityPermission", "a.b.c", "actions", null);
    assertEquals("java.security.SecurityPermission", up.getUnresolvedType());
    assertEquals("a.b.c", up.getUnresolvedName());
    assertEquals("actions", up.getUnresolvedActions());
    assertNull(up.getUnresolvedCerts());

    SerializationTest.verifyGolden(this, up, new SerializableAssert() {
        public void assertDeserialized(Serializable orig, Serializable ser) {
            UnresolvedPermission deserializedUp = (UnresolvedPermission) ser;
            assertEquals("java.security.SecurityPermission", deserializedUp
                    .getUnresolvedType());
            assertEquals("a.b.c", deserializedUp.getUnresolvedName());
            assertEquals("actions", deserializedUp.getUnresolvedActions());
            assertNull(deserializedUp.getUnresolvedCerts());
        }
    });
}
项目:In-the-Box-Fork    文件:UnresolvedPermissionTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getActions",
    args = {}
)
public void testGetActions() {
    UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1",
            "action1", null);
    UnresolvedPermission up2 = null;

    assertEquals("", up1.getActions());
    try {
        up2.getActions();
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:In-the-Box-Fork    文件:UnresolvedPermissionTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getUnresolvedActions",
    args = {}
)
public void testGetUnresolvedActions() {
    UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1",
            "action1 @#$%^&*", null);
    UnresolvedPermission up2 = null;

    assertEquals("action1 @#$%^&*", up1.getUnresolvedActions());
    try {
        up2.getUnresolvedActions();
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:In-the-Box-Fork    文件:UnresolvedPermissionTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "toString",
    args = {}
)
public void testToString() {
    UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1",
            "action1", null);
    UnresolvedPermission up2 = new UnresolvedPermission("type1", "name1",
            "action1", null);
    UnresolvedPermission up3 = null;
    assertTrue(up1.toString().contains(""));
    assertTrue(up2.toString().contains(""));
    try {
        up3.toString();
        fail("NullPointerException expected");
    }catch (NullPointerException e) {
        // expected
    }
}
项目:ant    文件:Permissions.java   
private java.security.Permission createPermission(
        final Permissions.Permission permission) {
    try {
        // First add explicitly already resolved permissions will not be
        // resolved when added as unresolved permission.
        final Class<? extends java.security.Permission> clazz = Class.forName(
                permission.getClassName()).asSubclass(java.security.Permission.class);
        final String name = permission.getName();
        final String actions = permission.getActions();
        final Constructor<? extends java.security.Permission> ctr = clazz.getConstructor(PARAMS);
        return ctr.newInstance(new Object[] {name, actions});
    } catch (final Exception e) {
        // Let the UnresolvedPermission handle it.
        return new UnresolvedPermission(permission.getClassName(),
                permission.getName(), permission.getActions(), null);
    }
}
项目:cn1    文件:UnresolvedPermissionCollectionTest.java   
/**
 * Return array holding 3 collections: empty, single- and multi-element.
 */
protected Object[] getData() {
    Permission up1 = new UnresolvedPermission("131234", null, null, null);
    Permission up2 = new UnresolvedPermission("131234", "ui23rjh", null,
            null);
    Permission up3 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456",
            "26r ytf", new java.security.cert.Certificate[0]);
    PermissionCollection pc1 = up1.newPermissionCollection();
    PermissionCollection pc2 = up1.newPermissionCollection();
    pc2.add(up3);
    PermissionCollection pc3 = up1.newPermissionCollection();
    pc3.add(up1);
    pc3.add(up2);
    pc3.add(up3);
    return new Object[] { pc1, pc2, pc3 };
}
项目:cn1    文件:UnresolvedPermissionTest.java   
public void testSerialization() throws Exception {
    UnresolvedPermission up = new UnresolvedPermission(
            "java.security.SecurityPermission", "a.b.c", "actions", null);
    assertEquals("java.security.SecurityPermission", up.getUnresolvedType());
    assertEquals("a.b.c", up.getUnresolvedName());
    assertEquals("actions", up.getUnresolvedActions());
    assertNull(up.getUnresolvedCerts());

    UnresolvedPermission deserializedUp = (UnresolvedPermission) SerializationTester
            .getDeserilizedObject(up);
    assertEquals("java.security.SecurityPermission", deserializedUp
            .getUnresolvedType());
    assertEquals("a.b.c", deserializedUp.getUnresolvedName());
    assertEquals("actions", deserializedUp.getUnresolvedActions());
    assertNull(deserializedUp.getUnresolvedCerts());
}
项目:cn1    文件:UnresolvedPermissionTest.java   
public void testSerialization_Compatibility() throws Exception {
    UnresolvedPermission up = new UnresolvedPermission(
            "java.security.SecurityPermission", "a.b.c", "actions", null);
    assertEquals("java.security.SecurityPermission", up.getUnresolvedType());
    assertEquals("a.b.c", up.getUnresolvedName());
    assertEquals("actions", up.getUnresolvedActions());
    assertNull(up.getUnresolvedCerts());

    SerializationTest.verifyGolden(this, up, new SerializableAssert() {
        public void assertDeserialized(Serializable orig, Serializable ser) {
            UnresolvedPermission deserializedUp = (UnresolvedPermission) ser;
            assertEquals("java.security.SecurityPermission", deserializedUp
                    .getUnresolvedType());
            assertEquals("a.b.c", deserializedUp.getUnresolvedName());
            assertEquals("actions", deserializedUp.getUnresolvedActions());
            assertNull(deserializedUp.getUnresolvedCerts());
        }
    });
}
项目:cn1    文件:SerializationTest.java   
private boolean equalsUnresolvedPermission(UnresolvedPermission up1,
        UnresolvedPermission up2) {
    java.security.cert.Certificate[] certs = up1.getUnresolvedCerts();
    if (certs != null && certs.length == 0) {
        if (null == up2.getUnresolvedCerts()) {
            if (up1.getName().equals(up2.getName())) {
                String up1Name = up1.getUnresolvedName();
                String up2Name = up2.getUnresolvedName();
                if (up1Name == null ? up2Name == null : up1Name
                        .equals(up2Name)) {
                    String up1Actions = up1.getUnresolvedActions();
                    String up2Actions = up2.getUnresolvedActions();
                    return up1Actions == null ? up2Actions == null
                            : up1Actions.equals(up2Actions);
                }
            }
        }
        return false;
    }
    return up1.equals(up2);
}
项目:cn1    文件:SerializationTest.java   
public void assertDeserialized(Serializable initial,
        Serializable deserialized) {
    UnresolvedPermission initPerm = (UnresolvedPermission) initial;
    UnresolvedPermission dserPerm = (UnresolvedPermission) deserialized;
    java.security.cert.Certificate[] certs = initPerm
            .getUnresolvedCerts();
    if (certs != null && certs.length == 0) {
        Assert.assertEquals(initPerm.getUnresolvedType(), dserPerm
                .getUnresolvedType());
        Assert.assertEquals(initPerm.getUnresolvedName(), dserPerm
                .getUnresolvedName());
        Assert.assertEquals(initPerm.getUnresolvedActions(), dserPerm
                .getUnresolvedActions());
        Assert.assertNull(dserPerm.getUnresolvedCerts());
    } else {
        Assert.assertEquals(initPerm, dserPerm);
    }
}
项目:freeVM    文件:UnresolvedPermissionCollectionTest.java   
/**
 * Return array holding 3 collections: empty, single- and multi-element.
 */
protected Object[] getData() {
    Permission up1 = new UnresolvedPermission("131234", null, null, null);
    Permission up2 = new UnresolvedPermission("131234", "ui23rjh", null,
            null);
    Permission up3 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456",
            "26r ytf", new java.security.cert.Certificate[0]);
    PermissionCollection pc1 = up1.newPermissionCollection();
    PermissionCollection pc2 = up1.newPermissionCollection();
    pc2.add(up3);
    PermissionCollection pc3 = up1.newPermissionCollection();
    pc3.add(up1);
    pc3.add(up2);
    pc3.add(up3);
    return new Object[] { pc1, pc2, pc3 };
}
项目:freeVM    文件:UnresolvedPermissionCollectionTest.java   
/**
 * Return array holding 3 collections: empty, single- and multi-element.
 */
protected Object[] getData() {
    Permission up1 = new UnresolvedPermission("131234", null, null, null);
    Permission up2 = new UnresolvedPermission("131234", "ui23rjh", null,
            null);
    Permission up3 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456",
            "26r ytf", new java.security.cert.Certificate[0]);
    PermissionCollection pc1 = up1.newPermissionCollection();
    PermissionCollection pc2 = up1.newPermissionCollection();
    pc2.add(up3);
    PermissionCollection pc3 = up1.newPermissionCollection();
    pc3.add(up1);
    pc3.add(up2);
    pc3.add(up3);
    return new Object[] { pc1, pc2, pc3 };
}
项目:freeVM    文件:UnresolvedPermissionTest.java   
public void testSerialization() throws Exception {
    UnresolvedPermission up = new UnresolvedPermission(
            "java.security.SecurityPermission", "a.b.c", "actions", null);
    assertEquals("java.security.SecurityPermission", up.getUnresolvedType());
    assertEquals("a.b.c", up.getUnresolvedName());
    assertEquals("actions", up.getUnresolvedActions());
    assertNull(up.getUnresolvedCerts());

    UnresolvedPermission deserializedUp = (UnresolvedPermission) SerializationTester
            .getDeserilizedObject(up);
    assertEquals("java.security.SecurityPermission", deserializedUp
            .getUnresolvedType());
    assertEquals("a.b.c", deserializedUp.getUnresolvedName());
    assertEquals("actions", deserializedUp.getUnresolvedActions());
    assertNull(deserializedUp.getUnresolvedCerts());
}
项目:freeVM    文件:UnresolvedPermissionTest.java   
public void testSerialization_Compatibility() throws Exception {
    UnresolvedPermission up = new UnresolvedPermission(
            "java.security.SecurityPermission", "a.b.c", "actions", null);
    assertEquals("java.security.SecurityPermission", up.getUnresolvedType());
    assertEquals("a.b.c", up.getUnresolvedName());
    assertEquals("actions", up.getUnresolvedActions());
    assertNull(up.getUnresolvedCerts());

    SerializationTest.verifyGolden(this, up, new SerializableAssert() {
        public void assertDeserialized(Serializable orig, Serializable ser) {
            UnresolvedPermission deserializedUp = (UnresolvedPermission) ser;
            assertEquals("java.security.SecurityPermission", deserializedUp
                    .getUnresolvedType());
            assertEquals("a.b.c", deserializedUp.getUnresolvedName());
            assertEquals("actions", deserializedUp.getUnresolvedActions());
            assertNull(deserializedUp.getUnresolvedCerts());
        }
    });
}
项目:freeVM    文件:SerializationTest.java   
private boolean equalsUnresolvedPermission(UnresolvedPermission up1,
        UnresolvedPermission up2) {
    java.security.cert.Certificate[] certs = up1.getUnresolvedCerts();
    if (certs != null && certs.length == 0) {
        if (null == up2.getUnresolvedCerts()) {
            if (up1.getName().equals(up2.getName())) {
                String up1Name = up1.getUnresolvedName();
                String up2Name = up2.getUnresolvedName();
                if (up1Name == null ? up2Name == null : up1Name
                        .equals(up2Name)) {
                    String up1Actions = up1.getUnresolvedActions();
                    String up2Actions = up2.getUnresolvedActions();
                    return up1Actions == null ? up2Actions == null
                            : up1Actions.equals(up2Actions);
                }
            }
        }
        return false;
    }
    return up1.equals(up2);
}
项目:freeVM    文件:SerializationTest.java   
public void assertDeserialized(Serializable initial,
        Serializable deserialized) {
    UnresolvedPermission initPerm = (UnresolvedPermission) initial;
    UnresolvedPermission dserPerm = (UnresolvedPermission) deserialized;
    java.security.cert.Certificate[] certs = initPerm
            .getUnresolvedCerts();
    if (certs != null && certs.length == 0) {
        Assert.assertEquals(initPerm.getUnresolvedType(), dserPerm
                .getUnresolvedType());
        Assert.assertEquals(initPerm.getUnresolvedName(), dserPerm
                .getUnresolvedName());
        Assert.assertEquals(initPerm.getUnresolvedActions(), dserPerm
                .getUnresolvedActions());
        Assert.assertNull(dserPerm.getUnresolvedCerts());
    } else {
        Assert.assertEquals(initPerm, dserPerm);
    }
}
项目:blackadder    文件:PolicyUtilsTest.java   
public void testInstantiatePermission()
    throws Throwable
{
    String name = "abc";
    Permission expected = new SecurityPermission( name );
    //test valid input
    assertEquals( expected, PolicyUtils.instantiatePermission( SecurityPermission.class, name, null ) );
    assertEquals( expected, PolicyUtils.instantiatePermission( SecurityPermission.class, name, "4t46" ) );

    //test invalid class
    try
    {
        PolicyUtils.instantiatePermission( UnresolvedPermission.class, null, null );
        fail( "IllegalArgumentException expected on invalid class argument" );
    }
    catch( IllegalArgumentException ok )
    {
    }
}
项目:elasticsearch_my    文件:PluginSecurity.java   
/** Format permission type, name, and actions into a string */
static String formatPermission(Permission permission) {
    StringBuilder sb = new StringBuilder();

    String clazz = null;
    if (permission instanceof UnresolvedPermission) {
        clazz = ((UnresolvedPermission) permission).getUnresolvedType();
    } else {
        clazz = permission.getClass().getName();
    }
    sb.append(clazz);

    String name = null;
    if (permission instanceof UnresolvedPermission) {
        name = ((UnresolvedPermission) permission).getUnresolvedName();
    } else {
        name = permission.getName();
    }
    if (name != null && name.length() > 0) {
        sb.append(' ');
        sb.append(name);
    }

    String actions = null;
    if (permission instanceof UnresolvedPermission) {
        actions = ((UnresolvedPermission) permission).getUnresolvedActions();
    } else {
        actions = permission.getActions();
    }
    if (actions != null && actions.length() > 0) {
        sb.append(' ');
        sb.append(actions);
    }
    return sb.toString();
}
项目:Elasticsearch    文件:PluginSecurity.java   
/** Format permission type, name, and actions into a string */
static String formatPermission(Permission permission) {
    StringBuilder sb = new StringBuilder();

    String clazz = null;
    if (permission instanceof UnresolvedPermission) {
        clazz = ((UnresolvedPermission) permission).getUnresolvedType();
    } else {
        clazz = permission.getClass().getName();
    }
    sb.append(clazz);

    String name = null;
    if (permission instanceof UnresolvedPermission) {
        name = ((UnresolvedPermission) permission).getUnresolvedName();
    } else {
        name = permission.getName();
    }
    if (name != null && name.length() > 0) {
        sb.append(' ');
        sb.append(name);
    }

    String actions = null;
    if (permission instanceof UnresolvedPermission) {
        actions = ((UnresolvedPermission) permission).getUnresolvedActions();
    } else {
        actions = permission.getActions();
    }
    if (actions != null && actions.length() > 0) {
        sb.append(' ');
        sb.append(actions);
    }
    return sb.toString();
}
项目:In-the-Box-Fork    文件:PermissionsTest.java   
/**
 * Can add any type of permissions. Cannot add if collection is read-only.
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "add",
    args = {java.security.Permission.class}
)
public void testAdd() {
    Permissions ps = new Permissions();
    Permission ap = new AllPermission();
    Permission bp = new BasicPermission("jhb23jhg5") {
    };
    Permission sp0 = new SecurityPermission("abc");
    Permission sp1 = new SecurityPermission("a.b.c");
    Permission sp2 = new SecurityPermission("a.b.*");
    Permission sp3 = new SecurityPermission("a.*");
    Permission up1 = new UnresolvedPermission("131234", null, null, null);
    Permission up2 = new UnresolvedPermission("KUJKHVKJgyuygjhb", "xcv456",
        "26r ytf", new java.security.cert.Certificate[0]);
    Permission[] arr = new Permission[] {
        up1, up2, ap, bp, sp0, sp1, sp2, sp3,  };
    for (int i = 0; i < arr.length; i++) {
        ps.add(arr[i]);
    }

    //test add duplicate
    ps.add(up1);
    ps.add(sp0);

    ps.setReadOnly();
    try {
        ps.add(up1);
        fail("read-only flag is ignored");
    } catch (SecurityException ok) {
    }
}
项目:In-the-Box-Fork    文件:AccessControlExceptionTest.java   
/**
 *
 * Tests AccessControlException.getPermission()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getPermission",
    args = {}
)
public void testGetPermission() {
    Permission perm = new UnresolvedPermission("unresolvedType",
            "unresolvedName", "unresolvedActions", null);
    AccessControlException ex = new AccessControlException("001", perm);
    assertSame(ex.getPermission(), perm);
}
项目:In-the-Box-Fork    文件:UnresolvedPermissionTest.java   
/**
 * UnresolvedPermission never implies any other permission.
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "implies",
    args = {java.security.Permission.class}
)
public void testImplies() {
    UnresolvedPermission up = new UnresolvedPermission(
            "java.security.SecurityPermission", "a.b.c", null, null);
    assertFalse(up.implies(up));
    assertFalse(up.implies(new AllPermission()));
    assertFalse(up.implies(new SecurityPermission("a.b.c")));
}
项目:In-the-Box-Fork    文件:UnresolvedPermissionTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "hashCode",
    args = {}
)
public void testHashCode() {
    UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1",
            "action1", null);
    UnresolvedPermission up2 = new UnresolvedPermission("type1", "name1",
            "action1", null);
    UnresolvedPermission up3 = new UnresolvedPermission("type3", "name3",
            "action3", null);

    UnresolvedPermission up4 = null;

    assertTrue(up1.hashCode() == up2.hashCode());
    assertTrue(up1.hashCode() != up3.hashCode());
    assertTrue(up2.hashCode() != up3.hashCode());

    try {
        up4.hashCode();
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
        // expected
    }
}
项目:In-the-Box-Fork    文件:UnresolvedPermissionTest.java   
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "newPermissionCollection",
    args = {}
)
public void testNewPermissionCollection() {
    UnresolvedPermission up1 = new UnresolvedPermission("type1", "name1",
            "action1", null);
    UnresolvedPermission up2 = new UnresolvedPermission("type1", "name1",
            "action1", null);
    UnresolvedPermission up3 = null;

    PermissionCollection pc = up1.newPermissionCollection();
    assertTrue(!pc.isReadOnly());
    pc.add(up1);
    pc.add(up2);
    Enumeration<Permission> permissions = pc.elements();
    assertNotNull(permissions);

    assertTrue("Should imply", !pc.implies(up1));
    assertTrue("Should not imply", !pc.implies(up3));

    try {
        up3.newPermissionCollection();
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
        // expected
    }

}
项目:In-the-Box-Fork    文件:AllPermissionTest.java   
/** AllPermission implies any other permission */
@TestTargetNew(
    level = TestLevel.PARTIAL,
    notes = "Null parameter checking missed",
    method = "implies",
    args = {java.security.Permission.class}
)
public void testImplies()
{
    AllPermission a1 = new AllPermission();
    assertTrue(a1.implies(new AllPermission()));
    assertTrue(a1.implies(new BasicPermission("2323"){}));
    assertTrue(a1.implies(new UnresolvedPermission("2323", "", "", null)));
}
项目:cn1    文件:UnresolvedPermissionTest.java   
/**
 * @see com.intel.drl.test.SerializationTest#getData()
 */
protected Object[] getData() {
    // test with real certificates ?
    return new Object[] {
            new UnresolvedPermission("type", "name", "actions", null),
            new UnresolvedPermission("type", null, null, new Certificate[0]) };
}
项目:cn1    文件:UnresolvedPermissionTest.java   
public void testSerializationWithCertificates() throws Exception {

        // Regression for HARMONY-2762
        CertificateFactory certificateFactory = CertificateFactory
                .getInstance("X.509");
        Certificate certificate = certificateFactory
                .generateCertificate(new ByteArrayInputStream(TestUtils
                        .getEncodedX509Certificate()));

        UnresolvedPermission unresolvedPermission = new UnresolvedPermission(
                "java.security.SecurityPermission", "a.b.c", "action",
                new Certificate[] { certificate });
        SerializationTest.verifySelf(unresolvedPermission);
        SerializationTest.verifyGolden(this, unresolvedPermission);
    }
项目:cn1    文件:UnresolvedPermissionTest.java   
/** 
 * UnresolvedPermission never implies any other permission.
 */
public void testImplies()
{
    UnresolvedPermission up = new UnresolvedPermission("java.security.SecurityPermission", "a.b.c", null, null);
    assertFalse(up.implies(up));
    assertFalse(up.implies(new AllPermission()));
    assertFalse(up.implies(new SecurityPermission("a.b.c")));
}
项目:cn1    文件:PolicyUtilsTest.java   
public void testInstantiatePermission() throws Throwable {
    String name = "abc";
    Permission expected = new SecurityPermission(name);
    //test valid input
    assertEquals(expected, PolicyUtils.instantiatePermission(SecurityPermission.class, name, null));
    assertEquals(expected, PolicyUtils.instantiatePermission(SecurityPermission.class, name, "4t46"));

    //test invalid class
    try {
        PolicyUtils.instantiatePermission(UnresolvedPermission.class, null, null);
        fail("IllegalArgumentException expected on invalid class argument");
    } catch (IllegalArgumentException ok) {}        
}
项目:cn1    文件:SerializationTest.java   
/**
  * Returns <code>comparator</code> for provided serializable
  * <code>object</code>.
  * 
  * The <code>comparator</code> is searched in the following order: <br>-
  * if <code>test</code> implements SerializableAssert interface then it is
  * selected as </code>comparator</code>.<br>- if passed <code>object</code>
  * has class in its classes hierarchy that overrides <code>equals(Object)</code>
  * method then <code>DEFAULT_COMPARATOR</code> is selected.<br> - the
  * method tries to select one of known comparators basing on <code>object's</code>
  * class,for example, if passed <code>object</code> is instance of
  * java.lang.Throwable then <code>THROWABLE_COMPARATOR</code> is used.<br>-
  * otherwise RuntimeException is thrown
  * 
  * @param test -
  *            test case
  * @param object -
  *            object to be compared
  * @return object's comparator
  */
 public static SerializableAssert defineComparator(TestCase test,
         Object object) throws Exception {

     if (test instanceof SerializableAssert) {
         return (SerializableAssert) test;
     }

     Method m = object.getClass().getMethod("equals",
             new Class[] { Object.class });

     if (m.getDeclaringClass() != Object.class) {
        if (object instanceof UnresolvedPermission) {
    // object is an instance of UnresolvedPermission, use
    // UNRESOLVED_PERMISSION_COMPARATOR
    return UNRESOLVED_PERMISSION_COMPARATOR;
}
         // one of classes overrides Object.equals(Object) method
         // use default comparator
         return DEFAULT_COMPARATOR;
     }

     // TODO use generics to detect comparator
     // instead of 'instanceof' for the first element
     if (object instanceof java.lang.Throwable) {
         return THROWABLE_COMPARATOR;
     } else if (object instanceof java.security.PermissionCollection) {
         return PERMISSION_COLLECTION_COMPARATOR;
     }

     throw new RuntimeException("Failed to detect comparator");
 }
项目:appengine-java-vm-runtime    文件:AppEngineWebXml.java   
public Permissions getUserPermissions() {
  Permissions permissions = new Permissions();
  for (UserPermission permission : userPermissions) {
    permissions.add(
        new UnresolvedPermission(
            permission.getClassName(), permission.getName(), permission.getActions(), null));
  }
  permissions.setReadOnly();
  return permissions;
}
项目:freeVM    文件:UnresolvedPermissionTest.java   
/**
 * @see com.intel.drl.test.SerializationTest#getData()
 */
protected Object[] getData() {
    // test with real certificates ?
    return new Object[] {
            new UnresolvedPermission("type", "name", "actions", null),
            new UnresolvedPermission("type", null, null, new Certificate[0]) };
}
项目:freeVM    文件:UnresolvedPermissionTest.java   
public void testSerializationWithCertificates() throws Exception {

        // Regression for HARMONY-2762
        CertificateFactory certificateFactory = CertificateFactory
                .getInstance("X.509");
        Certificate certificate = certificateFactory
                .generateCertificate(new ByteArrayInputStream(TestUtils
                        .getEncodedX509Certificate()));

        UnresolvedPermission unresolvedPermission = new UnresolvedPermission(
                "java.security.SecurityPermission", "a.b.c", "action",
                new Certificate[] { certificate });
        SerializationTest.verifySelf(unresolvedPermission);
        SerializationTest.verifyGolden(this, unresolvedPermission);
    }
项目:freeVM    文件:UnresolvedPermissionTest.java   
/** 
 * UnresolvedPermission never implies any other permission.
 */
public void testImplies()
{
    UnresolvedPermission up = new UnresolvedPermission("java.security.SecurityPermission", "a.b.c", null, null);
    assertFalse(up.implies(up));
    assertFalse(up.implies(new AllPermission()));
    assertFalse(up.implies(new SecurityPermission("a.b.c")));
}
项目:freeVM    文件:PolicyUtilsTest.java   
public void testInstantiatePermission() throws Throwable {
    String name = "abc";
    Permission expected = new SecurityPermission(name);
    //test valid input
    assertEquals(expected, PolicyUtils.instantiatePermission(SecurityPermission.class, name, null));
    assertEquals(expected, PolicyUtils.instantiatePermission(SecurityPermission.class, name, "4t46"));

    //test invalid class
    try {
        PolicyUtils.instantiatePermission(UnresolvedPermission.class, null, null);
        fail("IllegalArgumentException expected on invalid class argument");
    } catch (IllegalArgumentException ok) {}        
}
项目:freeVM    文件:UnresolvedPermissionTest.java   
/**
 * @see com.intel.drl.test.SerializationTest#getData()
 */
protected Object[] getData() {
    // test with real certificates ?
    return new Object[] {
            new UnresolvedPermission("type", "name", "actions", null),
            new UnresolvedPermission("type", null, null, new Certificate[0]) };
}