Search in sources :

Example 1 with ITargetObject

use of org.springframework.security.ITargetObject in project spring-security by spring-projects.

the class MethodSecurityInterceptorWithAopConfigTests method securityInterceptorIsAppliedWhenUsedWithAopConfig.

@Test(expected = AuthenticationCredentialsNotFoundException.class)
public void securityInterceptorIsAppliedWhenUsedWithAopConfig() {
    setContext("<aop:config>" + "     <aop:pointcut id='targetMethods' expression='execution(* org.springframework.security.TargetObject.*(..))'/>" + "     <aop:advisor advice-ref='securityInterceptor' pointcut-ref='targetMethods' />" + "</aop:config>" + TARGET_BEAN_AND_INTERCEPTOR + AUTH_PROVIDER_XML + ACCESS_MANAGER_XML);
    ITargetObject target = (ITargetObject) appContext.getBean("target");
    // Check both against interface and class
    try {
        target.makeLowerCase("TEST");
        fail("AuthenticationCredentialsNotFoundException expected");
    } catch (AuthenticationCredentialsNotFoundException expected) {
    }
    target.makeUpperCase("test");
}
Also used : ITargetObject(org.springframework.security.ITargetObject) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) Test(org.junit.Test)

Example 2 with ITargetObject

use of org.springframework.security.ITargetObject in project spring-security by spring-projects.

the class MethodSecurityInterceptorWithAopConfigTests method securityInterceptorIsAppliedWhenUsedWithBeanNameAutoProxyCreator.

@Test(expected = AuthenticationCredentialsNotFoundException.class)
public void securityInterceptorIsAppliedWhenUsedWithBeanNameAutoProxyCreator() {
    setContext("<b:bean id='autoProxyCreator' class='org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator'>" + "   <b:property name='interceptorNames'>" + "       <b:list>" + "          <b:value>securityInterceptor</b:value>" + "       </b:list>" + "   </b:property>" + "   <b:property name='beanNames'>" + "       <b:list>" + "          <b:value>target</b:value>" + "       </b:list>" + "   </b:property>" + "   <b:property name='proxyTargetClass' value='false'/>" + "</b:bean>" + TARGET_BEAN_AND_INTERCEPTOR + AUTH_PROVIDER_XML + ACCESS_MANAGER_XML);
    ITargetObject target = (ITargetObject) appContext.getBean("target");
    try {
        target.makeLowerCase("TEST");
        fail("AuthenticationCredentialsNotFoundException expected");
    } catch (AuthenticationCredentialsNotFoundException expected) {
    }
    target.makeUpperCase("test");
}
Also used : ITargetObject(org.springframework.security.ITargetObject) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) Test(org.junit.Test)

Example 3 with ITargetObject

use of org.springframework.security.ITargetObject in project spring-security by spring-projects.

the class MethodSecurityInterceptorTests method createTarget.

private void createTarget(boolean useMock) {
    realTarget = useMock ? mock(ITargetObject.class) : new TargetObject();
    ProxyFactory pf = new ProxyFactory(realTarget);
    pf.addAdvice(interceptor);
    advisedTarget = (ITargetObject) pf.getProxy();
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) ITargetObject(org.springframework.security.ITargetObject) TargetObject(org.springframework.security.TargetObject)

Aggregations

ITargetObject (org.springframework.security.ITargetObject)3 Test (org.junit.Test)2 AuthenticationCredentialsNotFoundException (org.springframework.security.authentication.AuthenticationCredentialsNotFoundException)2 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 TargetObject (org.springframework.security.TargetObject)1