Search in sources :

Example 16 with Advisor

use of org.springframework.aop.Advisor in project spring-integration by spring-projects.

the class SecuredChannelsParserTests method testAdminRequiredForSend.

@Test
public void testAdminRequiredForSend() {
    String beanName = "adminRequiredForSend";
    messageChannel.setBeanName(beanName);
    MessageChannel proxy = (MessageChannel) applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, beanName);
    assertTrue("Channel was not proxied", AopUtils.isAopProxy(proxy));
    Advisor[] advisors = ((Advised) proxy).getAdvisors();
    assertEquals("Wrong number of interceptors", 1, advisors.length);
    ChannelSecurityInterceptor interceptor = (ChannelSecurityInterceptor) advisors[0].getAdvice();
    ChannelAccessPolicy policy = this.retrievePolicyForPatternString(beanName, interceptor);
    assertNotNull("Pattern '" + beanName + "' is not included in mappings", policy);
    Collection<ConfigAttribute> sendDefinition = policy.getConfigAttributesForSend();
    Collection<ConfigAttribute> receiveDefinition = policy.getConfigAttributesForReceive();
    assertTrue("ROLE_ADMIN not found as send attribute", this.getRolesFromDefintion(sendDefinition).contains("ROLE_ADMIN"));
    assertTrue("Policy applies to receive", receiveDefinition.size() == 0);
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ChannelAccessPolicy(org.springframework.integration.security.channel.ChannelAccessPolicy) Advised(org.springframework.aop.framework.Advised) ConfigAttribute(org.springframework.security.access.ConfigAttribute) Advisor(org.springframework.aop.Advisor) ChannelSecurityInterceptor(org.springframework.integration.security.channel.ChannelSecurityInterceptor) Test(org.junit.Test)

Example 17 with Advisor

use of org.springframework.aop.Advisor in project spring-integration by spring-projects.

the class SecuredChannelsParserTests method testAdminOrUserRequiredForSend.

@Test
public void testAdminOrUserRequiredForSend() {
    String beanName = "adminOrUserRequiredForSend";
    messageChannel.setBeanName(beanName);
    MessageChannel proxy = (MessageChannel) applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, beanName);
    assertTrue("Channel was not proxied", AopUtils.isAopProxy(proxy));
    Advisor[] advisors = ((Advised) proxy).getAdvisors();
    assertEquals("Wrong number of interceptors", 1, advisors.length);
    ChannelSecurityInterceptor interceptor = (ChannelSecurityInterceptor) advisors[0].getAdvice();
    ChannelAccessPolicy policy = this.retrievePolicyForPatternString(beanName, interceptor);
    assertNotNull("Pattern '" + beanName + "' is not included in mappings", policy);
    Collection<ConfigAttribute> sendDefinition = policy.getConfigAttributesForSend();
    Collection<ConfigAttribute> receiveDefinition = policy.getConfigAttributesForReceive();
    Collection<String> sendRoles = this.getRolesFromDefintion(sendDefinition);
    assertTrue("ROLE_ADMIN not found as send attribute", sendRoles.contains("ROLE_ADMIN"));
    assertTrue("ROLE_USER not found as send attribute", sendRoles.contains("ROLE_USER"));
    assertTrue("Policy applies to receive", receiveDefinition.size() == 0);
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ChannelAccessPolicy(org.springframework.integration.security.channel.ChannelAccessPolicy) Advised(org.springframework.aop.framework.Advised) ConfigAttribute(org.springframework.security.access.ConfigAttribute) Advisor(org.springframework.aop.Advisor) ChannelSecurityInterceptor(org.springframework.integration.security.channel.ChannelSecurityInterceptor) Test(org.junit.Test)

Example 18 with Advisor

use of org.springframework.aop.Advisor in project spring-data-commons by spring-projects.

the class TransactionRepositoryFactoryBeanSupportUnitTests method disablesDefaultTransactionsIfConfigured.

// DATACMNS-656
@Test
public void disablesDefaultTransactionsIfConfigured() {
    SampleTransactionalRepositoryFactoryBean factoryBean = new SampleTransactionalRepositoryFactoryBean();
    factoryBean.setEnableDefaultTransactions(false);
    factoryBean.setBeanFactory(new DefaultListableBeanFactory());
    factoryBean.afterPropertiesSet();
    CrudRepository<Object, Long> repository = factoryBean.getObject();
    Advisor[] advisors = ((Advised) repository).getAdvisors();
    boolean found = false;
    for (Advisor advisor : advisors) {
        if (advisor.getAdvice() instanceof TransactionInterceptor) {
            found = true;
            TransactionInterceptor interceptor = (TransactionInterceptor) advisor.getAdvice();
            assertThat(getField(interceptor.getTransactionAttributeSource(), "enableDefaultTransactions")).isEqualTo(false);
            break;
        }
    }
    assertThat(found).isTrue();
}
Also used : TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) Advised(org.springframework.aop.framework.Advised) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Advisor(org.springframework.aop.Advisor) Test(org.junit.Test)

Example 19 with Advisor

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

the class GlobalMethodSecurityBeanDefinitionParserTests method targetShouldAllowProtectedMethodInvocationWithCorrectRole.

@Test
public void targetShouldAllowProtectedMethodInvocationWithCorrectRole() {
    loadContext();
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("user", "password");
    SecurityContextHolder.getContext().setAuthentication(token);
    this.target.someUserMethod1();
    // SEC-1213. Check the order
    Advisor[] advisors = ((Advised) this.target).getAdvisors();
    assertThat(advisors).hasSize(1);
    assertThat(((MethodSecurityMetadataSourceAdvisor) advisors[0]).getOrder()).isEqualTo(1001);
}
Also used : MethodSecurityMetadataSourceAdvisor(org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor) Advised(org.springframework.aop.framework.Advised) Advisor(org.springframework.aop.Advisor) MethodSecurityMetadataSourceAdvisor(org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.jupiter.api.Test)

Example 20 with Advisor

use of org.springframework.aop.Advisor in project spring-framework by spring-projects.

the class PerThisAspect method twoAdvicesOnOneAspect.

@Test
void twoAdvicesOnOneAspect() {
    TestBean target = new TestBean();
    TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect();
    List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect, "someBean"));
    assertThat(advisors.size()).as("Two advice methods found").isEqualTo(2);
    ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
    itb.setName("");
    assertThat(itb.getAge()).isEqualTo(0);
    int newAge = 32;
    itb.setAge(newAge);
    assertThat(itb.getAge()).isEqualTo(1);
}
Also used : ITestBean(org.springframework.beans.testfixture.beans.ITestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) Advisor(org.springframework.aop.Advisor) TwoAdviceAspect(test.aop.TwoAdviceAspect) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.jupiter.api.Test)

Aggregations

Advisor (org.springframework.aop.Advisor)70 Test (org.junit.jupiter.api.Test)33 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)25 Advised (org.springframework.aop.framework.Advised)21 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)19 Test (org.junit.Test)16 TestBean (org.springframework.beans.testfixture.beans.TestBean)16 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)14 AspectJPointcutAdvisor (org.springframework.aop.aspectj.AspectJPointcutAdvisor)11 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)11 ArrayList (java.util.ArrayList)10 JoinPoint (org.aspectj.lang.JoinPoint)8 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)8 Method (java.lang.reflect.Method)7 SyntheticInstantiationAdvisor (org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor)7 StaticMethodMatcherPointcutAdvisor (org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor)7 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)7 LockMixinAdvisor (test.mixin.LockMixinAdvisor)7 Advice (org.aopalliance.aop.Advice)6 CountingBeforeAdvice (org.springframework.aop.testfixture.advice.CountingBeforeAdvice)6