Java 类java.security.GuardedObject 实例源码

项目:In-the-Box-Fork    文件:GuardedObjectTest.java   
/** Test real guard can both allow and deny access. */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "",
        method = "GuardedObject",
        args = {java.lang.Object.class, java.security.Guard.class}
    ),
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "",
        method = "getObject",
        args = {}
    )
})
public void testGuard() {
    final String message = "test message";
    final StringBuffer objBuffer = new StringBuffer("235345 t");
    GuardedObject go = new GuardedObject(objBuffer, new Guard() {

        public void checkGuard(Object object) throws SecurityException {
            if (object == objBuffer && objBuffer.length() == 0) {
                throw new SecurityException(message);
            }
        }
    });
    assertEquals(objBuffer, go.getObject());

    objBuffer.setLength(0);
    try {
        go.getObject();
        fail("SecurityException is not thrown");
    } catch (Exception ok) {
        assertEquals(message, ok.getMessage());
    }
}
项目:cn1    文件:GuardedObjectTest.java   
public void testDisableGuard() throws Throwable {
    try {
        copySerializable(new GuardedObject(null, new MyGuard(false)));
        fail("Should not serialize if guard denies access");
    }
    catch (SecurityException ok) {}
}
项目:river-container    文件:AttributeStoreImpl.java   
/**
 Retrieve an attribute, checking security permissions if it happens
 to be a guarded object.
 @param name
 @return
 */
public Object getAttribute(String name) {
    Object attr=attributes.get(name);
    if (attr instanceof GuardedObject) {
        return ((GuardedObject) attr).getObject();
    }
    return attr;
}
项目:freeVM    文件:GuardedObjectTest.java   
public void testDisableGuard() throws Throwable {
    try {
        copySerializable(new GuardedObject(null, new MyGuard(false)));
        fail("Should not serialize if guard denies access");
    }
    catch (SecurityException ok) {}
}
项目:freeVM    文件:GuardedObjectTest.java   
public void testDisableGuard() throws Throwable {
    try {
        copySerializable(new GuardedObject(null, new MyGuard(false)));
        fail("Should not serialize if guard denies access");
    }
    catch (SecurityException ok) {}
}
项目:cn1    文件:GuardedObjectTest.java   
/**
 * @see com.intel.drl.test.SerializationTest#getData()
 */
protected Object[] getData() {
    return new Object[] { new GuardedObject(null, null),
            new GuardedObject("dsgdfg", null),
            new GuardedObject(new Integer(76547), new MyGuard(true)), };
}
项目:cn1    文件:GuardedObjectTest.java   
public void assertDeserialized(Serializable golden, Serializable test) {
    assertSame(golden.getClass(), test.getClass());
    assertEquals(((GuardedObject) golden).getObject(),
            ((GuardedObject) test).getObject());
}
项目:freeVM    文件:GuardedObjectTest.java   
/**
 * @see com.intel.drl.test.SerializationTest#getData()
 */
protected Object[] getData() {
    return new Object[] { new GuardedObject(null, null),
            new GuardedObject("dsgdfg", null),
            new GuardedObject(new Integer(76547), new MyGuard(true)), };
}
项目:freeVM    文件:GuardedObjectTest.java   
public void assertDeserialized(Serializable golden, Serializable test) {
    assertSame(golden.getClass(), test.getClass());
    assertEquals(((GuardedObject) golden).getObject(),
            ((GuardedObject) test).getObject());
}
项目:freeVM    文件:GuardedObjectTest.java   
/**
 * @see com.intel.drl.test.SerializationTest#getData()
 */
protected Object[] getData() {
    return new Object[] { new GuardedObject(null, null),
            new GuardedObject("dsgdfg", null),
            new GuardedObject(new Integer(76547), new MyGuard(true)), };
}
项目:freeVM    文件:GuardedObjectTest.java   
public void assertDeserialized(Serializable golden, Serializable test) {
    assertSame(golden.getClass(), test.getClass());
    assertEquals(((GuardedObject) golden).getObject(),
            ((GuardedObject) test).getObject());
}