Search in sources :

Example 6 with ChannelSecurityInterceptor

use of org.springframework.integration.security.channel.ChannelSecurityInterceptor 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 7 with ChannelSecurityInterceptor

use of org.springframework.integration.security.channel.ChannelSecurityInterceptor 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 8 with ChannelSecurityInterceptor

use of org.springframework.integration.security.channel.ChannelSecurityInterceptor in project faf-java-server by FAForever.

the class IntegrationSecurityConfig method channelSecurityInterceptor.

@Bean
public ChannelSecurityInterceptor channelSecurityInterceptor(AuthenticationManager authenticationManager) {
    ChannelSecurityInterceptor channelSecurityInterceptor = new ChannelSecurityInterceptor();
    channelSecurityInterceptor.setAuthenticationManager(authenticationManager);
    channelSecurityInterceptor.setAccessDecisionManager(new AffirmativeBased(Collections.singletonList(new RoleVoter())));
    return channelSecurityInterceptor;
}
Also used : AffirmativeBased(org.springframework.security.access.vote.AffirmativeBased) RoleVoter(org.springframework.security.access.vote.RoleVoter) ChannelSecurityInterceptor(org.springframework.integration.security.channel.ChannelSecurityInterceptor) Bean(org.springframework.context.annotation.Bean)

Example 9 with ChannelSecurityInterceptor

use of org.springframework.integration.security.channel.ChannelSecurityInterceptor in project spring-integration by spring-projects.

the class SecuredChannelsParserTests method testAdminRequiredForSendAndReceive.

@Test
public void testAdminRequiredForSendAndReceive() {
    String beanName = "adminRequiredForSendAndReceive";
    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();
    assertNotNull("Pattern does not apply to 'send'", sendDefinition);
    assertNotNull("Pattern does not apply to 'receive'", receiveDefinition);
    Collection<String> sendRoles = this.getRolesFromDefintion(sendDefinition);
    Collection<String> receiveRoles = this.getRolesFromDefintion(receiveDefinition);
    assertTrue("ROLE_ADMIN not found in send attributes", sendRoles.contains("ROLE_ADMIN"));
    assertTrue("ROLE_ADMIN not found in receive attributes", receiveRoles.contains("ROLE_ADMIN"));
}
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)

Aggregations

ChannelSecurityInterceptor (org.springframework.integration.security.channel.ChannelSecurityInterceptor)9 ChannelAccessPolicy (org.springframework.integration.security.channel.ChannelAccessPolicy)6 Test (org.junit.Test)5 Advisor (org.springframework.aop.Advisor)5 Advised (org.springframework.aop.framework.Advised)5 MessageChannel (org.springframework.messaging.MessageChannel)5 ConfigAttribute (org.springframework.security.access.ConfigAttribute)5 Bean (org.springframework.context.annotation.Bean)3 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 ChannelSecurityMetadataSource (org.springframework.integration.security.channel.ChannelSecurityMetadataSource)1 AffirmativeBased (org.springframework.security.access.vote.AffirmativeBased)1 RoleVoter (org.springframework.security.access.vote.RoleVoter)1