Override the ChannelProcessingFilter with Spring Security 3.0.5 does not work

后端 未结 3 927
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-06 03:17

The default behavior of the Channel Processors is to do a sendRedirect (which is redirect temporary with 302 code). I need to change this behavior so that a permanent (301) redi

3条回答
  •  感动是毒
    2021-02-06 03:40

    I found another way to achieve the same thing with much less code and complexity. You can simply use a BeanPostProcessor to get the SecureChannelProcessor and InsecureChannelProcessor and then set your own entry point on them. That way, you can still use the defaults on everything else.

    The BeanPostProcessor:

    @Component
    public class ChannelProcessorsPostProcessor implements BeanPostProcessor {
    
        @Override
        public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
    
            if (bean instanceof SecureChannelProcessor) ((SecureChannelProcessor)bean).setEntryPoint(new MyEntryRetryPoint("https://", 443));
            else if (bean instanceof InsecureChannelProcessor) ((InsecureChannelProcessor)bean).setEntryPoint(new MyEntryRetryPoint("http://", 80));
    
            return bean;
        }
    
        @Override
        public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
    
            return bean;
        }
    }
    

提交回复
热议问题