how to customize a filter used in CAS?

49 views
Skip to first unread message

Yan Zhou

unread,
Oct 17, 2022, 10:19:50 AM10/17/22
to CAS Community
Hi there, 

I am using CAS 6.4.x.

CasFiltersConfiguration  defines filters,  I wish to provide my own RegisteredServiceResponseHeadersEnforcementFilter (using a different name).

How would I do that without copying the entire CasFiltersConfiguration   or  RegisteredServiceResponseHeadersEnforcementFilter  and just change a couple lines?

I understand this is a Sprint boot question, but I think some may have a quick answer for me. Thanks a lot!

Yan


    @ConditionalOnProperty(prefix = "cas.http-web-request.header", name = "enabled", havingValue = "true", matchIfMissing = true)
    @RefreshScope
    @Bean
    public FilterRegistrationBean responseHeadersSecurityFilter() {
        val header = casProperties.getHttpWebRequest().getHeader();
        val initParams = new HashMap<String, String>();

 ...............

                val bean = new FilterRegistrationBean<RegisteredServiceResponseHeadersEnforcementFilter>();
        bean.setFilter(new RegisteredServiceResponseHeadersEnforcementFilter(servicesManager.getObject(),
            argumentExtractor.getObject(), authenticationRequestServiceSelectionStrategies.getObject(),
            registeredServiceAccessStrategyEnforcer.getObject()));

 ...............

        return bean;
    }


Ray Bon

unread,
Oct 17, 2022, 11:53:40 AM10/17/22
to cas-...@apereo.org
Yan,

Copy RegisteredServiceResponseHeadersEnforcementFilter into your project and modify it. The build will replace the cas version with yours.
You may need to add some compile dependencies to build.gradle.

Ray

On Mon, 2022-10-17 at 07:19 -0700, Yan Zhou wrote:
Notice: This message was sent from outside the University of Victoria email system. Please be cautious with links and sensitive information.

Yan Zhou

unread,
Oct 17, 2022, 12:23:15 PM10/17/22
to CAS Community, Ray Bon
That is what I have been doing, this means a duplication of the entire class with only change to one-line.  When we upgrade to next CAS release, we would have to find such customization and duplicating it.

I thought there maybe a better way. OK!

Yan

Dmitriy Kopylenko

unread,
Oct 17, 2022, 12:57:26 PM10/17/22
to cas-...@apereo.org
One other way to accomplish this is to disable CAS filer by setting  `cas.http-web-request.header` property to false, and then to enable your version of this bean in your own configuration class by making sure it’s recognized by Spring by advertising it in META-INF/spring.factories file in your overlay. 

D. 

--
- Website: https://apereo.github.io/cas
- Gitter Chatroom: https://gitter.im/apereo/cas
- List Guidelines: https://goo.gl/1VRrw7
- Contributions: https://goo.gl/mh7qDG
---
You received this message because you are subscribed to the Google Groups "CAS Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cas-user+u...@apereo.org.
To view this discussion on the web visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/15600683-1f15-4302-991e-ce00b258d470n%40apereo.org.
Reply all
Reply to author
Forward
0 new messages