Code example for ProxyFactory

Methods: getProxy, addAdvice

0
 
 
	private static MessageChannel getSecuredChannel(String role) throws Exception { 
		QueueChannel channel = new QueueChannel(); 
		channel.setBeanName("securedChannel"); 
		ProxyFactory proxyFactory = new ProxyFactory(channel); 
		proxyFactory.addAdvice(createInterceptor(role)); 
		return (MessageChannel) proxyFactory.getProxy(); 
	} 
 
	private static ChannelSecurityInterceptor createInterceptor(String role) throws Exception { 
		ChannelSecurityMetadataSource securityMetadataSource = new ChannelSecurityMetadataSource(); 
		securityMetadataSource.addPatternMapping(Pattern.compile("secured.*"), new DefaultChannelAccessPolicy(role, null)); 
		ChannelSecurityInterceptor interceptor = new ChannelSecurityInterceptor(securityMetadataSource); 
		@SuppressWarnings("rawtypes") 
		AffirmativeBased accessDecisionManager = new AffirmativeBased(Collections.<AccessDecisionVoter>singletonList(new RoleVoter())); 
		accessDecisionManager.afterPropertiesSet(); 
		interceptor.setAccessDecisionManager(accessDecisionManager); 
		interceptor.setAuthenticationManager(new MockAuthenticationManager(true)); 
		interceptor.afterPropertiesSet();