Hello, I'm currently upgrading a highly customized 4.X CAS version to 5.0.6
and running into a problem with cached assets on our F5 Appliance.
The problem is that many of the customized assets have the same name (ex.
cas.js) but different content, and while we can clear the F5 Ram Cache,
this does not allow us the flexibility to switch cleanly back and
forth between the two versioned deployments and we would rather add
a VersionResourceResolver to the newer version (5.0.X) of the application
so that all assets have hash codes in the file names so that the F5
appliance will cache the proper version, and the two applications will not
be getting one another's assets.
If someone has already done this and could provide some pointers I would
appreciate it. I think I'm half way there, but am not sure I'm not mixing
solutions. We have a desire to get away from our highly customized versions
and back inline with the direction of the underlying CAS software (and this
is out first step).
I've read several articles and gotten as far as encoding the urls in the
templates, but when the login page is accessed, the server returns a 404
for the javascript assets, so here is what I have in the 5.0.6 application:
*Background/Environment:*
- Software: CAS 5.0.6 built with an overlay
- Application.properties in src/main/resources
- JavaScript resources in: src/main/resources/static/js
- Thymeleaf templates in in: src/main/resources/static/templates
- Environment:
- Local: build and run locally via a fat jar.
- Everywhere else: fat jar built on Jenkins, Docker Image deployed
to K8S Cluster with an F5
*Resources I've reviewed:*
- CAS User Interface Customization
<https://apereo.github.io/cas/5.0.x/installation/User-Interface-Customization-CSSJS.html>
(No
real info)
- Spring Boot 1.4.2 Reference
<https://docs.spring.io/spring-boot/docs/1.4.2.RELEASE/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-static-content>
(Static
Content, which suggests that the ResourceUrlEncodingFilter should be
AutoConfigured and handled internally by Thymeleaf but it doesn't seem to
be, which is why I added the bean and additional syntax to the templates
below).
*Application.properties*
*spring.resources.chain.strategy.content.enabled*=*true**spring.resources.chain.strategy.content.paths*=*/***
*StaticResourceConfig.java*
@Configuration*public class *StaticResourceConfig *extends
*WebMvcConfigurerAdapter {
@Override *public void *addResourceHandlers(ResourceHandlerRegistry
registry) {
VersionResourceResolver versionResourceResolver = *new
*VersionResourceResolver()
.addVersionStrategy(*new *ContentVersionStrategy(),
*"/js/*.js"*);
registry.addResourceHandler(*"/js/**"*)
.addResourceLocations(*"classpath:/static/"*)
.setCachePeriod(60 * 60 * 24 * 365) */* one year */*
.resourceChain(*true*)
.addResolver(versionResourceResolver);
}
*/**** * Enables usage of versioned assets in thyme leaf templates.**
* **@return* **/* @Bean *public *ResourceUrlEncodingFilter
resourceUrlEncodingFilter(){
*return new *ResourceUrlEncodingFilter();
}
}
*LoginForm.html*
...
<*script **type=**"text/javascript"
**th**:src=**"${@mvcResourceUrlProvider.getForLookupPath('/js/login.js')}"
*/>
...
The the script tag above is rendered properly in the page by
the ResourceUrlEncodingFilter:
<script type="text/javascript"
src="/js/login-5082a374b0db842cb10cbe96ee10ecbc.js" />
However, the server responds with a 404 when the file is requested.
*Conculsion:*
I feel like I'm missing some component that maps
login-5082a374b0db842cb10cbe96ee10ecbc.js back to login.js when the request
is received but don't know where to go and debug to look for it.
In my Google searches, I've seen a few bugs listed with regards to the
ordering of Resolvers and the Ant Path Matching Patterns in
Spring/SpringBoot, but am just getting around to figuring out which classes
log to debug and can report back when I find anything there, but wanted to
get this email in the event anyone has some experience or advice with this.
Thanks,
-John
--
- 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/a/apereo.org/d/msgid/cas-user/2c886b2e-5b24-47e8-9ada-78dd9eb04d7c%40apereo.org.