This is a short and sweet tutorial on how to deploy CAS via the WAR Overlay method.
This tutorial specifically requires and focuses on:
5.0.x
Overlays are a strategy to combat repetitive code and/or resources. Rather than downloading the CAS codebase and building it from source, overlays allow you to download a pre-built vanilla CAS web application server provided by the project itself, override/insert specific behavior into it and then merge it all back together to produce the final (web application) artifact. You can find a lot more about how overlays work here.
The concept of the WAR Overlay is NOT a CAS invention. It’s specifically an Apache Maven eature and of course there are techniques and plugins available to apply the same concept to Gradle-based builds as well.You are free to choose between Maven or Gradle. For this tutorial I opted into the Maven WAR overlay.
Once you have forked and cloned the repository locally, you’re ready to begin.
master
branch of the repository applies to CAS 5.0.x
deployments. That may not necessarily remain true when you start your own deployment. So examine the branches and make sure you checkout
the one matching your intended CAS version.
Similar to Grey’s, a Maven WAR overlay is composed of several facets the most important of which is the pom.xml
file. This is a build descriptor file whose job is to teach Apache Maven how to obtain, build, configure (and in certain cases deploy) artifacts.
The pom.xml
is composed of several sections. The ones you need to worry about are the following.
<properties>
<cas.version>5.0.4</cas.version>
<springboot.version>1.4.2.RELEASE</springboot.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
This is the bit that describes build settings, and specifically here, what versions of CAS, Spring Boot and Java are required for the deployment. You are in practice mostly concerned with the <cas.version>
setting and as new (maintenance) releases come out, it would be sufficient to simply update that version and re-run the build.
This might be a good time to review the CAS project’s Release Policy as well as Maintenance Policy.
The next piece describes the dependencies of the overlay build. These are the set of components almost always provided by the CAS project that will be packaged up and put into the final web application artifact. At a minimum, you need to have the cas-server-webapp
module available because that is the web application into which you intend to inject your settings and customizations, if any. Also, note that the module declarations are typically configured to download the CAS version instructed by the property ${cas.version}
.
Here is an example:
<dependencies>
<dependency>
<groupId>org.apereo.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
<version>${cas.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
</dependencies>
Including a CAS module/dependency in the pom.xml
simply advertises to CAS your intention of turning on a new feature or a variation of a current behavior. Do NOT include something in your build just because it looks and sounds cool. Remember that the point of an overlay is to only keep track of things you actually need and care about, and no more.
There are many other pieces in the pom.xml
, such as repositories, profiles, plugins, etc that I skipped. For everything else, there is MasterCard…and of course the official Apache Maven guides. Enjoy!
Now that you have a basic understanding of the build descriptor, it’s time to actually run the build. An Apache Maven build is often executed by passing specific goals/commands to Apache Maven itself, aka mvn
. So for instance in the the terminal and once inside the project directory you could execute things like:
cd cas-overlay-template
mvn clean
…which may be a problem if you don’t have already have Apache Maven downloaded and installed. While you can do that separate install, the WAR Overlay project provides you with an embedded Apache Maven instance whose job is to first determine whether you have Maven installed and if not, download and configure one for you based on the project’s needs. So you can replace that command above with:
cd cas-overlay-template
mvnw clean
…which may be a problem because, how are you supposed to know what commands/goals can be passed to the build? You can study them for sure, but the project provides you with a shell script that wraps itself around the Maven wrapper and provides an easy facade for you to remember commands and their use. This is the build.sh
file, which you can run as such:
cd cas-overlay-template
./build.sh help
Usage: build.sh [copy|clean|package|run|debug|bootrun]
What do these commands do?
Type | Description |
---|---|
copy |
Copies the configuration from the local etc/cas/config directory to /etc/cas/config . See this guide to learn more. |
clean |
Deletes any previously-built and leftover artifacts from the target directory. |
package |
Runs clean and copy . Then packages the CAS web application artifact and run through the overlay to inject local customizations. The outcome is a target/cas.war file which is ready to be deployed. |
run |
Invokes package and then deploys and runs the CAS web application via its own embedded server container. |
debug |
Same thing as run , except that you can remote-debug the CAS web application over port 5000 . |
bootrun |
Same thing as run , except the deployment is managed by the Spring Boot Maven plugin. This command has very specialized and limited use cases. |
README
file to keep to date.
As an example, here’s what I see if I were to run the package
command:
./build.sh package
Creating configuration directory under /etc/cas
Copying configuration files from etc/cas to /etc/cas/config
etc/cas/config/application.yml -> /etc/cas/config/application.yml
etc/cas/config/cas.properties -> /etc/cas/config/cas.properties
etc/cas/config/log4j2.xml -> /etc/cas/config/log4j2.xml
[INFO] Scanning for projects...
[INFO]
[INFO] Using the MultiThreadedBuilder implementation with a thread count of 5
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building cas-overlay 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ cas-overlay ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ cas-overlay ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /cas-overlay-template/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ cas-overlay ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ cas-overlay ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /cas-overlay-template/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ cas-overlay ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ cas-overlay ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.6:war (default-war) @ cas-overlay ---
[INFO] Packaging webapp
[INFO] Assembling webapp [cas-overlay] in [/cas-overlay-template/target/cas]
[info] Copying manifest...
[INFO] Processing war project
[INFO] Processing overlay [ id org.apereo.cas:cas-server-webapp]
[INFO] Webapp assembled in [786 msecs]
[INFO] Building war: /cas-overlay-template/target/cas.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.504 s (Wall Clock)
[INFO] Finished at: 2017-03-23T14:57:11+04:30
[INFO] Final Memory: 12M/441M
[INFO] ------------------------------------------------------------------------
You can see that the build attempts to download, clean, compile and package all artifacts, and finally it produces a /cas-overlay-template/target/cas.war
which you can then use for actual deployments.
build.sh
file. Things like -U
or -X
might be useful to have handy.
I am going to skip over the configuration of /etc/cas/config
and all that it deals with. If you need the reference, you may always use this guide to study various aspects of CAS configuration.
Suffice it to say that, quite simply, CAS deployment expects the main configuration file to be found under /etc/cas/config/cas.properties
. This is a key-value store that is able to dictate and alter behavior of the running CAS software.
As an example, you might encouter something like:
cas.server.name=https://cas.example.org:8443
cas.server.prefix=https://cas.example.org:8443/cas
logging.config=file:/etc/cas/config/log4j2.xml
…which at a minimum, identifies the CAS server’s url and prefix and instructs the running server to locate the logging configuration at file:/etc/cas/config/log4j2.xml
. The overlay by default ships with a log4j2.xml
that you can use to customize logging locations, levels, etc. Note that the presence of all that is contained inside /etc/cas/config/
is optional. CAS will continue to fall back onto defaults if the directory and the files within are not found.
It is VERY IMPORTANT that you contain and commit the entire overlay directory (save the obvious exclusions such as the target
directory) into some sort of source control system, such as git
. Treat your deployment just like any other project with tags, releases and functional baselines.
If I cd
into the target/cas
directory, I can see an exploded version of the cas.war
file. This is the directory that contains the results of the overlay process. Since I have not actually customized and overlaid anything yet, all configuration files simply match their default and are packaged as such. So as an example, let’s change something.
Then I’ll leave everything in that file alone, except the line I want to change.
...
screen.welcome.instructions=Speak Friend and you shall enter.
...
Then I’ll package things up as usual.
./build.sh package
...
[INFO] --- maven-war-plugin:2.6:war (default-war) @ cas-overlay ---
[INFO] Packaging webapp
[INFO] Assembling webapp [cas-overlay] in [/cas-overlay-template/target/cas]
[info] Copying manifest...
[INFO] Processing war project
[INFO] Processing overlay [ id org.apereo.cas:cas-server-webapp]
[INFO] Webapp assembled in [1005 msecs]
[INFO] Building war: /cas-overlay-template/target/cas.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
...
If I look at target/cas/WEB-INF/classes/messages.properties
after the build, I should see that the overlay process has picked and overlaid onto the default my version of the file.
You have a number of options when it comes to deploying the final cas.war
file. This post should help.
I hope this brief tutorial was of some assistance to you. It’s important that you start off simple and make changes one step at a time. Once you have a functional environment, you can gradually and slowly add customizations to move files around.
Monday-Friday
9am-6pm, Central European Time
7am-1pm, U.S. Eastern Time
Monday-Friday
9am-6pm, Central European Time