Search in sources :

Example 1 with CustomCallbackBean

use of org.springframework.beans.factory.support.security.support.CustomCallbackBean in project spring-framework by spring-projects.

the class CallbacksSecurityTests method testSecuritySanity.

@Test
public void testSecuritySanity() throws Exception {
    AccessControlContext acc = provider.getAccessControlContext();
    try {
        acc.checkPermission(new PropertyPermission("*", "read"));
        fail("Acc should not have any permissions");
    } catch (SecurityException se) {
    // expected
    }
    final CustomCallbackBean bean = new CustomCallbackBean();
    final Method method = bean.getClass().getMethod("destroy");
    method.setAccessible(true);
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() throws Exception {
                method.invoke(bean);
                return null;
            }
        }, acc);
        fail("expected security exception");
    } catch (Exception ex) {
    }
    final Class<ConstructorBean> cl = ConstructorBean.class;
    try {
        AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

            @Override
            public Object run() throws Exception {
                return cl.newInstance();
            }
        }, acc);
        fail("expected security exception");
    } catch (Exception ex) {
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) PropertyPermission(java.util.PropertyPermission) Method(java.lang.reflect.Method) CustomCallbackBean(org.springframework.beans.factory.support.security.support.CustomCallbackBean) BeanCreationException(org.springframework.beans.factory.BeanCreationException) BeansException(org.springframework.beans.BeansException) ConstructorBean(org.springframework.beans.factory.support.security.support.ConstructorBean) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)1 AccessControlContext (java.security.AccessControlContext)1 PropertyPermission (java.util.PropertyPermission)1 Test (org.junit.Test)1 BeansException (org.springframework.beans.BeansException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 ConstructorBean (org.springframework.beans.factory.support.security.support.ConstructorBean)1 CustomCallbackBean (org.springframework.beans.factory.support.security.support.CustomCallbackBean)1