Unverified Commit a20b42d6 authored by Hal Deadman's avatar Hal Deadman Committed by GitHub

Merge pull request #2 from apereo/master

merge updates
parents c1af16d0 52de5229
......@@ -2,6 +2,8 @@
......@@ -9,6 +11,11 @@ target/
\ No newline at end of file
CAS Overlay Template
Generic CAS WAR overlay to exercise the latest versions of CAS. This overlay could be freely used as a starting template for local CAS war overlays. The CAS services management overlay is available [here](https://github.com/apereo/cas-services-management-overlay).
Generic CAS WAR overlay to exercise the latest versions of CAS. This overlay could be freely used as a starting template for local CAS war overlays.
# Versions
# Requirements
- CAS `6.0.x`
- JDK `11`
* JDK 1.8+
# Overview
# Configuration
You may invoke build commands using the `build.sh` script to work with your chosen overlay using:
The `etc` directory contains the configuration files and directories that need to be copied to `/etc/cas/config`.
# Build
./build.sh [command]
To see what commands are available to the build script, run:
......@@ -25,18 +22,38 @@ To see what commands are available to the build script, run:
./build.sh help
To package the final web application, run:
# Configuration
./build.sh package
- The `etc` directory contains the configuration files and directories that need to be copied to `/etc/cas/config`.
- The specifics of the build are controlled using the `gradle.properties` file.
## Adding Modules
CAS modules may be specified under the `dependencies` block of the [Gradle build script](build.gradle):
dependencies {
compile "org.apereo.cas:cas-server-some-module:${project.casVersion}"
To update `SNAPSHOT` versions run:
Study material:
- https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html
- https://docs.gradle.org/current/userguide/dependency_management.html
## Clear Gradle Cache
If you need to, on Linux/Unix systems, you can delete all the existing artifacts (artifacts and metadata) Gradle has downloaded using:
./build.sh package -U
# Only do this when absolutely necessary!
rm -rf $HOME/.gradle/caches/
Same strategy applies to Windows too, provided you switch `$HOME` to its equivalent in the above command.
# Deployment
- Create a keystore file `thekeystore` under `/etc/cas`. Use the password `changeit` for both the keystore and the key/certificate entries.
......@@ -44,7 +61,6 @@ To update `SNAPSHOT` versions run:
On a successful deployment via the following methods, CAS will be available at:
* `http://cas.server.name:8080/cas`
* `https://cas.server.name:8443/cas`
## Executable WAR
......@@ -55,46 +71,6 @@ Run the CAS web application as an executable WAR.
./build.sh run
## Spring Boot
Run the CAS web application as an executable WAR via Spring Boot. This is most useful during development and testing.
./build.sh bootrun
### Warning!
Be careful with this method of deployment. `bootRun` is not designed to work with already executable WAR artifacts such that CAS server web application. YMMV. Today, uses of this mode ONLY work when there is **NO OTHER** dependency added to the build script and the `cas-server-webapp` is the only present module. See [this issue](https://github.com/apereo/cas/issues/2334) and [this issue](https://github.com/spring-projects/spring-boot/issues/8320) for more info.
## Spring Boot App Server Selection
There is an app.server property in the `pom.xml` that can be used to select a spring boot application server.
It defaults to `-tomcat` but `-jetty` and `-undertow` are supported.
It can also be set to an empty value (nothing) if you want to deploy CAS to an external application server of your choice.
## Windows Build
If you are building on windows, try `build.cmd` instead of `build.sh`. Arguments are similar but for usage, run:
build.cmd help
## External
Deploy resultant `target/cas.war` to a servlet container of choice.
## Command Line Shell
Invokes the CAS Command Line Shell. For a list of commands either use no arguments or use `-h`. To enter the interactive shell use `-sh`.
./build.sh cli
\ No newline at end of file
Deploy the binary web application file `cas.war` after a successful build to a servlet container of choice.
\ No newline at end of file
@echo off
@set JAVA_ARGS=-Xms500m -Xmx1g
@set CAS_DIR=\etc\cas
@set CONFIG_DIR=\etc\cas\config
@rem Call this script with DNAME and CERT_SUBJ_ALT_NAMES already set to override
@if "%DNAME%" == "" set DNAME=CN=cas.example.org,OU=Example,OU=Org,C=US
@rem List other host names or ip addresses you want in your certificate, may help with host name verification,
@rem if client apps make https connection for ticket validation and compare name in cert (include sub. alt. names)
@rem to name used to access CAS
@if "%CERT_SUBJ_ALT_NAMES%" == "" set CERT_SUBJ_ALT_NAMES=dns:example.org,dns:localhost,dns:%COMPUTERNAME%,ip:
@rem Check for mvn in path, use it if found, otherwise use maven wrapper
@set MAVEN_CMD=mvn
@where /q mvn
@if %ERRORLEVEL% neq 0 set MAVEN_CMD=.\mvnw.bat
@if "%1" == "" call:help
@if "%1" == "copy" call:copy
@if "%1" == "clean" call:clean %2 %3 %4
@if "%1" == "package" call:package %2 %3 %4
@if "%1" == "bootrun" call:bootrun %2 %3 %4
@if "%1" == "debug" call:debug %2 %3 %4
@if "%1" == "run" call:run %2 %3 %4
@if "%1" == "runalone" call:runalone %2 %3 %4
@if "%1" == "help" call:help
@if "%1" == "gencert" call:gencert
@if "%1" == "cli" call:runcli %2 %3 %4
@rem function section starts here
@echo "Creating configuration directory under %CONFIG_DIR%"
if not exist %CONFIG_DIR% mkdir %CONFIG_DIR%
@echo "Copying configuration files from etc/cas to /etc/cas"
xcopy /S /Y etc\cas\* \etc\cas
@echo "Usage: build.bat [copy|clean|package|run|debug|bootrun|gencert|cli] [optional extra args for maven or cli]"
@echo "To get started on a clean system, run "build.bat copy" and "build.bat gencert", then "build.bat run"
@echo "Note that using the copy or gencert arguments will create and/or overwrite the %CAS_DIR% which is outside this project"
call %MAVEN_CMD% clean %1 %2 %3
call %MAVEN_CMD% clean package -T 5 %1 %2 %3
call %MAVEN_CMD% clean package spring-boot:run -T 5 %1 %2 %3
call:package %1 %2 %3 & java %JAVA_ARGS% -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar target/cas.war
call:package %1 %2 %3 & java %JAVA_ARGS% -jar target/cas.war
call:package %1 %2 %3 & target/cas.war
where /q keytool
@echo Java keytool.exe not found in path.
exit /b 1
) else (
if not exist %CAS_DIR% mkdir %CAS_DIR%
@echo on
@echo Generating self-signed SSL cert for %DNAME% in %CAS_DIR%\thekeystore
keytool -genkeypair -alias cas -keyalg RSA -keypass changeit -storepass changeit -keystore %CAS_DIR%\thekeystore -dname %DNAME% -ext SAN=%CERT_SUBJ_ALT_NAMES%
@echo Exporting cert for use in trust store (used by cas clients)
keytool -exportcert -alias cas -storepass changeit -keystore %CAS_DIR%\thekeystore -file %CAS_DIR%\cas.cer
for /f %%i in ('call %MAVEN_CMD% -q --non-recursive "-Dexec.executable=cmd" "-Dexec.args=/C echo ${cas.version}" "org.codehaus.mojo:exec-maven-plugin:1.3.1:exec"') do set CAS_VERSION=%%i
@set DOWNLOAD_DIR=target
@set COMMAND_FILE=cas-server-support-shell-%CAS_VERSION%.jar
@if not exist %DOWNLOAD_DIR% mkdir %DOWNLOAD_DIR%
@if not exist %DOWNLOAD_DIR%\%COMMAND_FILE% (
@call mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:get -DgroupId=org.apereo.cas -DartifactId=cas-server-support-shell -Dversion=%CAS_VERSION% -Dpackaging=jar -DartifactItem.outputDirectory=%DOWNLOAD_DIR% -DartifactItem.destFileName=%COMMAND_FILE% -DremoteRepositories=central::default::http://repo1.maven.apache.org/maven2,snapshots::::https://oss.sonatype.org/content/repositories/snapshots -Dtransitive=false
@call mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy -Dmdep.useBaseVersion=true -Dartifact=org.apereo.cas:cas-server-support-shell:%CAS_VERSION%:jar -DoutputDirectory=%DOWNLOAD_DIR%
@call java %JAVA_ARGS% -jar %DOWNLOAD_DIR%\%COMMAND_FILE% %1 %2 %3
\ No newline at end of file
buildscript {
repositories {
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}"
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://build.shibboleth.net/nexus/content/repositories/releases/' }
apply from: "https://dl.bintray.com/scalding/generic/waroverlay.gradle"
apply plugin: "war"
apply plugin: "org.springframework.boot"
apply plugin: "eclipse"
apply plugin: "idea"
def currentBranch = "master"
def currentVersion = "$System.env.casVersion"
if (!currentVersion.contains("RC")) {
def matcher = currentVersion =~ /(\d+\.\d+\.).+/
if (matcher.find()) {
currentBranch = matcher.group(1) + "x"
logger.info "Using CAS branch [${currentBranch}] to handle overrides"
apply from: "https://raw.githubusercontent.com/apereo/cas/${currentBranch}/gradle/overrides.gradle"
eclipse {
classpath {
downloadSources = true
downloadJavadoc = true
idea {
module {
downloadJavadoc = true
downloadSources = true
war {
includeWarJars = true
entryCompression = ZipEntryCompression.STORED
springBoot {
mainClassName = "org.apereo.cas.web.CasWebApplication"
bootWar {
if (project.hasProperty('executable')) {
archiveName 'cas.war'
baseName 'cas'
excludeDevtools = false
bootRun {
sourceResources sourceSets.main
classpath = sourceSets.main.runtimeClasspath
dependencies {
if (project.hasProperty("external")) {
compile "org.apereo.cas:cas-server-webapp${project.appServer}:${project.casVersion}@war"
} else {
compile "org.apereo.cas:cas-server-webapp:${project.casVersion}@war"
// Other dependencies may be listed here...
task explodeWar(type: Copy, group: "build", description: "Explodes the cas.war") {
dependsOn build
from zipTree("build/libs/cas.war")
into "${buildDir}/cas"
task run(group: "build", description: "Run the CAS web application in embedded container mode") {
dependsOn build
doLast {
def args = "-Xmx2048M -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y"
def casRunArgs = Arrays.asList(args.split(" "))
javaexec {
main = "-jar";
jvmArgs = casRunArgs
args = ["build/libs/cas.war"]
logger.info "Started ${commandLine}"
task debug(group: "build", description: "Debug the CAS web application in embedded mode on port 5000") {
dependsOn build
doLast {
def casDebugArgs = Arrays.asList("-Xmx2048M".split(" "))
javaexec {
main = "-jar";
jvmArgs = casDebugArgs
args = ["build/libs/cas.war"]
logger.info "Started ${commandLine}"
task wrapper(type: Wrapper, description: "Update the Gradle wrapper") {
gradleVersion = "${project.gradleVersion}"
task casVersion(group: "build", description: "Display the current CAS version") {
doFirst {
println "${project.casVersion}"
task showConfiguration(group: "build", description: "Show configurations for each dependency, etc") {
doLast() {
def cfg = project.hasProperty("configuration") ? project.property("configuration") : "compile"
configurations.getByName(cfg).each { println it }
task allDependenciesInsight(type: DependencyInsightReportTask, description: "Produce insight information for all dependencies") {}
task allDependencies(type: DependencyReportTask, description: "Display a graph of all project dependencies") {}
\ No newline at end of file
function copy() {
echo -e "Creating configuration directory under /etc/cas"
mkdir -p /etc/cas/config
echo -e "Copying configuration files from etc/cas to /etc/cas"
cp -rfv etc/cas/* /etc/cas
cp -rfv ./etc/cas/* /etc/cas
function help() {
echo "Usage: build.sh [copy|clean|package|run|debug|bootrun|gencert]"
echo " copy: Copy config from ./etc/cas/config to /etc/cas/config"
echo " clean: Clean Maven build directory"
echo " package: Clean and build CAS war, also call copy"
echo " run: Build and run cas.war via spring boot (java -jar target/cas.war)"
echo " runalone: Build and run cas.war on its own (target/cas.war)"
echo " debug: Run CAS.war and listen for Java debugger on port 5000"
echo " bootrun: Run with maven spring boot plugin, doesn't work with multiple dependencies"
echo " gencert: Create keystore with SSL certificate in location where CAS looks by default"
echo " cli: Run the CAS command line shell and pass commands"
echo "******************************************************************"
tput setaf 2
echo "Apereo CAS ${casVersion}"
echo "Enterprise Single SignOn for all earthlings and beyond"
tput sgr 0
echo "- https://github.com/apereo/cas"
echo "- https://apereo.github.io/cas"
echo "******************************************************************"
echo -e "Usage: build.sh [copy|clean|package|run|dependencies|update|debug|tomcat|gencert]\n"
echo -e "\tclean: \t\tClean Maven build directory"
echo -e "\tcli: \t\tRun the CAS command line shell and pass commands"
echo -e "\tcopy: \t\tCopy config from the project's local etc/cas/config directory to the root /etc/cas/config"
echo -e "\tdebug: \t\tRun cas.war and listen for Java debugger on port 5000"
echo -e "\tdependencies: \tGet a report of all dependencies configured in the build"
echo -e "\tgencert: \tCreate keystore with SSL certificate in location where CAS looks by default"
echo -e "\tgetview: \tAsk for a view name to be included in the overlay for customizations"
echo -e "\tlistviews: \tList all CAS views that ship with the web application and can be customized in the overlay"
echo -e "\tpackage: \tClean and build CAS war"
echo -e "\trun: \t\tBuild and run cas.war via Java as an executable war"
echo -e "\trunalone: \tBuild and run cas.war on its own as a standalone executable"
echo -e "\ttomcat: \tDeploy the CAS web application to an external Apache Tomcat server"
echo -e "\tupdate: \tPackage the CAS overlay by force-updating dependencies and SNAPSHOT versions"
function clean() {
./mvnw clean "$@"
./gradlew clean "$@"
function package() {
./mvnw clean package -T 5 "$@"
./gradlew clean build "$@"
function update() {
./gradlew clean build --refresh-dependencies "$@"
function dependencies() {
./gradlew allDependencies
function bootrun() {
./mvnw clean package spring-boot:run -T 5 "$@"
function tomcat() {
./gradlew clean build -Pexternal=true "$@"
if [ ! -f apache-tomcat.zip ]; then
wget -O apache-tomcat.zip "http://www-eu.apache.org/dist/tomcat/tomcat-${tomcatVersion}/v${tomcatFullVersion}/bin/apache-tomcat-${tomcatFullVersion}.zip"
rm -Rf ./apache-tomcat
unzip -o apache-tomcat.zip >/dev/null
mv apache-tomcat-${tomcatFullVersion} apache-tomcat
export CATALINA_HOME=./apache-tomcat/
chmod +x ./apache-tomcat/bin/*.sh
echo "Attempting to shutdown Apache Tomcat..."
./apache-tomcat/bin/shutdown.sh 2>/dev/null
cp build/libs/cas.war ../apache-tomcat/webapps/
tail -F ../apache-tomcat/logs/catalina.out
function debug() {
package && java -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar target/cas.war
package && java -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar $casWar
function run() {
package && java -jar target/cas.war
package && java -XX:TieredStopAtLevel=1 -Xverify:none -jar $casWar
function runalone() {
package && chmod +x target/cas.war && target/cas.war
./gradlew clean build -Pexecutable=true "$@"
chmod +x $casWar
function listviews() {
find $explodedDir -type f -name "*.html" | xargs -n 1 basename | sort | more
function explodeApp() {
./gradlew explodeWar
echo "Exploded the CAS web application file."
function getview() {
echo "Searching for view name $@..."
results=`find $explodedDir -type f -name "*.html" | grep -i "$@"`
count=`wc -w <<< "$results"`
if [ "$count" -eq 0 ];then
echo "No views could be found matching $@"
exit 1
echo -e "Found view(s): \n$results"
if [ "$count" -eq 1 ];then
overlayfile=`echo "${results/$fromFile/$toFile}"`
overlaypath=`dirname "${overlayfile}"`
# echo "Overlay file is $overlayfile to be created at $overlaypath"
mkdir -p $overlaypath
cp $results $overlaypath
echo "Created view at $overlayfile"
ls $overlayfile
echo "More than one view file is found. Narrow down the search query..."
function gencert() {
......@@ -65,74 +147,87 @@ function gencert() {
function cli() {
rm -f *.log
CAS_VERSION=$(./gradlew casVersion --quiet)
CAS_VERSION=$(./mvnw -q -Dexec.executable="echo" -Dexec.args='${cas.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec 2>/dev/null)
# echo "CAS version: $CAS_VERSION"
echo "CAS version: $CAS_VERSION"
# echo "JAR name: $JAR_FILE_NAME"
echo "JAR name: $JAR_FILE_NAME"
# echo "JAR path: $JAR_PATH"
echo "JAR path: $JAR_PATH"
# echo "Local JAR file path: $JAR_FILE_LOCAL";
echo "Local JAR file path: $JAR_FILE_LOCAL";
if [ -f "$JAR_FILE_LOCAL" ]; then
# echo "Using JAR file locally at $JAR_FILE_LOCAL"
echo "Using JAR file locally at $JAR_FILE_LOCAL"
java -jar $JAR_FILE_LOCAL "$@"
exit 0;
if [ ! -f "$COMMAND_FILE" ]; then
mkdir -p $DOWNLOAD_DIR
./mvnw org.apache.maven.plugins:maven-dependency-plugin:3.0.2:get -DgroupId=org.apereo.cas -DartifactId=cas-server-support-shell -Dversion=$CAS_VERSION -Dpackaging=jar -DartifactItem.outputDirectory=$DOWNLOAD_DIR -DremoteRepositories=central::default::http://repo1.maven.apache.org/maven2,snapshots::::https://oss.sonatype.org/content/repositories/snapshots -Dtransitive=false
./mvnw org.apache.maven.plugins:maven-dependency-plugin:3.0.2:copy -Dmdep.useBaseVersion=true -Dartifact=org.apereo.cas:cas-server-support-shell:$CAS_VERSION:jar -DoutputDirectory=$DOWNLOAD_DIR
wget "https://repo1.maven.org/maven2/${JAR_PATH}" -P ./target
echo "Running $COMMAND_FILE"
java -jar $COMMAND_FILE "$@"
exit 0;
if [ $# -eq 0 ]; then
echo -e "No commands provided. Defaulting to [run]\n"
exit 0
if [ -z "$command" ]; then
echo "No commands provided. Defaulting to [run]"
shift 1
case "$1" in
case "$command" in
clean "$@"
package "$@"
bootrun "$@"
debug "$@"
run "$@"
runalone "$@"
gencert "$@"
cli "$@"
update "$@"
update "$@"
runalone "$@"
listviews "$@"
getview "$@"
\ No newline at end of file
description: CAS Configuration
\ No newline at end of file
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
# cas.serviceRegistry.config.location: classpath:/services
......@@ -92,7 +92,7 @@
<AsyncLogger name="org.openid4java" level="warn" />
<AsyncLogger name="org.ldaptive" level="warn" />
<AsyncLogger name="com.hazelcast" level="warn" />
<AsyncLogger name="org.jasig.spring" level="warn" />
<AsyncLogger name="org.apereo.spring" level="warn" />
<!-- Log perf stats only to perfStats.log -->
<AsyncLogger name="perfStatsLogger" level="info" additivity="false" includeLocation="true">
# Versions
#!/usr/bin/env sh