Commit 67510e19 authored by Misagh Moayyed's avatar Misagh Moayyed

Merge branch '6.0'

# Conflicts:
#	pom.xml
parents ae6af09c 40a9be81
......@@ -2,6 +2,8 @@
!/.project
.project
.settings
.history
.vscode
target/
.idea/
.DS_Store
......@@ -9,6 +11,11 @@ target/
overlays/
.gradle/
build/
log/
bin/
*.war
*.iml
*.log
tmp/
./apache-tomcat
apache-tomcat.zip
\ 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
```xml
<cas.version>5.3.x</cas.version>
```
# 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
```bash
./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
```bash
./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):
```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:
```bash
./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,47 +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.
```bash
./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/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.
```xml
<app.server>-tomcat<app.server>
```
## 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`.
```bash
./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:127.0.0.1
@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
@goto:eof
:copy
@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
@goto:eof
:help
@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"
@goto:eof
:clean
call %MAVEN_CMD% clean %1 %2 %3
exit /B %ERRORLEVEL%
@goto:eof
:package
call %MAVEN_CMD% clean package -T 5 %1 %2 %3
exit /B %ERRORLEVEL%
@goto:eof
:bootrun
call %MAVEN_CMD% clean package spring-boot:run -T 5 %1 %2 %3
exit /B %ERRORLEVEL%
@goto:eof
:debug
call:package %1 %2 %3 & java %JAVA_ARGS% -Xdebug -Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n -jar target/cas.war
@goto:eof
:run
call:package %1 %2 %3 & java %JAVA_ARGS% -jar target/cas.war
@goto:eof
:runalone
call:package %1 %2 %3 & target/cas.war
@goto:eof
:gencert
where /q keytool
if ERRORLEVEL 1 (
@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
)
@goto:eof
:runcli
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 CAS_VERSION=%CAS_VERSION: =%
@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
@goto:eof
\ No newline at end of file
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}"
}
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
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')) {
launchScript()
}
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
#!/bin/bash
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"
echo " run: Build and run cas.war via Java (i.e. java -jar target/cas.war)"
echo " runalone: Build and run cas.war on its own as a standalone executable (target/cas.war)"
echo " debug: Run CAS.war and listen for Java debugger on port 5000"
echo " bootrun: Run with maven spring boot plugin"
echo " listviews: List all CAS views that ship with the web application and can be customized in the overlay"
echo " getview: Ask for a view name to be included in the overlay for customizations"
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"
clear
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() {
shift
./mvnw clean "$@"
./gradlew clean "$@"
}
function package() {
shift
./mvnw clean package -T 5 "$@"
# copy
./gradlew clean build "$@"
}
function update() {
./gradlew clean build --refresh-dependencies "$@"
}
function dependencies() {
./gradlew allDependencies
}
function bootrun() {
shift
./mvnw clean package spring-boot:run -P bootiful -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"
fi
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/
./apache-tomcat/bin/startup.sh
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
casWar="build/libs/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
casWar="build/libs/cas.war"
package && java -XX:TieredStopAtLevel=1 -Xverify:none -jar $casWar
}
function runalone() {
shift
./mvnw clean package -P default,exec "$@"
chmod +x target/cas.war
target/cas.war
./gradlew clean build -Pexecutable=true "$@"
casWar="build/libs/cas.war"
chmod +x $casWar
$casWar
}
function listviews() {
shift
explodeapp
find $PWD/target/cas -type f -name "*.html" | xargs -n 1 basename | sort | more
explodeApp
explodedDir=build/cas
find $explodedDir -type f -name "*.html" | xargs -n 1 basename | sort | more
}
function explodeapp() {
if [ ! -d $PWD/target/cas ];then
echo "Building the CAS web application and exploding the final war file..."
./mvnw clean package war:exploded "$@"
fi
function explodeApp() {
./gradlew explodeWar
echo "Exploded the CAS web application file."
}
function getview() {
shift
explodeapp
explodeApp
echo "Searching for view name $@..."
results=`find $PWD/target/cas -type f -name "*.html" | grep -i "$@"`
echo -e "Found view(s): \n$results"
explodedDir=build/cas
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
fi
echo -e "Found view(s): \n$results"
if [ "$count" -eq 1 ];then
# echo "Found view $results to include in the overlay"
firststring="target/cas/WEB-INF/classes"
secondstring="src/main/resources"
overlayfile=`echo "${results/$firststring/$secondstring}"`
fromFile="build/cas/WEB-INF/classes"
toFile="src/main/resources"
overlayfile=`echo "${results/$fromFile/$toFile}"`
overlaypath=`dirname "${overlayfile}"`
# echo "Overlay file is $overlayfile to be created at $overlaypath"
mkdir -p $overlaypath
......@@ -92,7 +129,6 @@ function getview() {
fi
}
function gencert() {
if [[ ! -d /etc/cas ]] ; then
copy
......@@ -111,79 +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"
JAR_FILE_NAME="cas-server-support-shell-${CAS_VERSION}.jar"
# echo "JAR name: $JAR_FILE_NAME"
echo "JAR name: $JAR_FILE_NAME"
JAR_PATH="org/apereo/cas/cas-server-support-shell/${CAS_VERSION}/${JAR_FILE_NAME}"
# echo "JAR path: $JAR_PATH"
echo "JAR path: $JAR_PATH"
JAR_FILE_LOCAL="$HOME/.m2/repository/$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;
fi
DOWNLOAD_DIR=./target
DOWNLOAD_DIR=./build/libs
COMMAND_FILE="${DOWNLOAD_DIR}/${JAR_FILE_NAME}"
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
fi
echo "Running $COMMAND_FILE"
java -jar $COMMAND_FILE "$@"
exit 0;
}
if [ $# -eq 0 ]; then
echo -e "No commands provided. Defaulting to [run]\n"
run
exit 0
command=$1
if [ -z "$command" ]; then
echo "No commands provided. Defaulting to [run]"
command="run"
fi
case "$1" in
shift 1
case "$command" in
"copy")
copy
;;
"clean")
shift
clean "$@"
;;
"package")
shift
package "$@"
;;
"bootrun")
shift
bootrun "$@"
"help")
help
;;
"clean")
clean "$@"
;;
"package"|"build")
package "$@"
;;
"debug")
debug "$@"
;;
debug "$@"
;;
"run")
run "$@"
;;
run "$@"
;;
"gencert")
gencert "$@"
;;
"cli")
cli "$@"
;;