javaspring-bootauthenticationspring-securitycas

Modify Cas overlay 7.1.3 to add custom RestController


I am new to CAS codebase.

Would really appreciate some pointers?

Initialized cas overlay project from https://apereo.github.io/cas/development/installation/WAR-Overlay-Initializr.html

I am trying to add my own own class with annotation @SpringBootApplication

https://github.com/apereo/cas-overlay-template/tree/master/src/main so that it scans my packages for bean initialization and Controller class so that i can override functions of cas overlay.

https://github.com/apereo/cas-overlay-template/tree/master/src/main

I modified main entry class here https://github.com/apereo/cas-overlay-template/blob/master/gradle/springboot.gradle#L81

I can see this in the logs

2025-01-18 08:48:11,371 DEBUG [org.springframework.boot.devtools.restart.Restarter] - <Starting application com.test.AuthenticationApplication with URLs [file:/Users/Desktop/AE/ae_authentication-service/src/main/resources/, file:/Users/Desktop/AE/ae_authentication-service/build/classes/java/main/, file:/Users/Desktop/AE/ae_authentication-service/build/resources/main/]>

but why is it not scanning other packages.

Am i missing something


Solution

  • The problem is that in CAS version 7, authors (AFAIK quietly) decided to disable Spring's automatic scanning/discovery of annotated components, probably for performance reasons. Instead, CAS relies on Spring's Component Indexer now. Even though it looks like all its components are still being created in Java via @Bean methods, so there should be no components scanning or indexing necessary for CAS own components anyway.

    Source: CAS 7.0.0, how to scan self created beans, and manage by spring

    So, the solution is either to create your component (whether it is RestController or anything else) as CAS does it, i.e. in your own Java Spring configuration class (which is documented at Extending CAS Configuration).

    Or, try to put the name of your component class into the META-INF/spring.components file in your project, which you might want to automate by using the Spring indexer tools discussed in the SO page linked above. The current format of one line in that file seems to be something like org.example.YourComponentClass=org.springframework.stereotype.Component (value after the = sign might generally differ).