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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations