Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Ant build to Maven and add GitHub Actions CI #18

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI
on: [push, pull_request]
jobs:
build:
name: Build and Test (${{ matrix.os }} / OpenJDK ${{ matrix.jdk }})
strategy:
fail-fast: true
matrix:
jdk: ['8']
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.jdk }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.jdk }}
distribution: 'temurin'
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Maven Build
run: mvn clean package -DskipTests
- name: Test
run: mvn verify
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
build/
.*
target/
!.gitignore
1 change: 0 additions & 1 deletion VERSION.txt

This file was deleted.

12 changes: 0 additions & 12 deletions build.properties.xml

This file was deleted.

36 changes: 0 additions & 36 deletions build.xml

This file was deleted.

6 changes: 0 additions & 6 deletions collection.xconf

This file was deleted.

6 changes: 0 additions & 6 deletions expath-pkg.xml.tmpl

This file was deleted.

9 changes: 0 additions & 9 deletions index.html

This file was deleted.

108 changes: 108 additions & 0 deletions pom.xml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not happy with this PR, and tend to disapprove.

First, this is a rather big change that replaces build system "ant" with build system "maven", without explaining what this change improves. "I need a better build system" is a bit vague.

I understand your goal of "add a full set of Integration Tests where we test against a Mock IDP provider", but what does maven provide that could not be done by ant? Can you sketch the mock testing procedures?

Second, I strongly dislike all those dependencies that maven pulls into the build process. I'd like to simplify the code rather than complexing it.

Third, pulling arbitrary maven artefacts into security relevant code builds, is that a good idea?

I'm open for discussion, but I don't see good reasons to apply this PR.

Copy link
Member Author

@adamretter adamretter Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"I need a better build system" is a bit vague.

Fair point!

I understand your goal of "add a full set of Integration Tests where we test against a Mock IDP provider", but what does maven provide that could not be done by ant?

I need a better build system that manages the build lifecycle so that I can:

  1. Start up the Mock IDP Provider
  2. Execute my Integration Tests
  3. Shutdown my Mock IDP Provider
  4. Collate my test results and report success of failure.

Whilst the above may be possible to achieve with Ant, it would require writing hundreds if not thousands of lines of Ant code which is completely bespoke to this project. Instead, by using Maven I can use their standard build lifecycle and existing plugins that we already use in other eXist-db projects to achieve this easily without having to write a large amount of one-off Ant code.

Second, I strongly dislike all those dependencies that maven pulls into the build process

The plugins are only part of the build process itself, they are not part of the build artefact. Ant also uses a load of 3rd party libraries to carry out its builds process. So there is little difference between Maven and Ant from that perspective!

Third, pulling arbitrary maven artefacts into security relevant code builds, is that a good idea?

I think you may have misunderstood how Maven works in practice. If you take a look at the pom.xml in this PR you will see that there is NO <dependencies> section, and therefore there are NO Maven artefacts pulled into the built artefact.

I'm open for discussion, but I don't see good reasons to apply this PR.

I will send a follow-up PR shortly with full integration test suite where this code is tested against an IDP. I think that should be evidence enough that this is required ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maven is really a step forward.... (Yeap I was an ant fan)

Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.exist-db</groupId>
<artifactId>exist-apps-parent</artifactId>
<version>1.12.0</version>
<relativePath/>
</parent>

<groupId>org.exist-db.apps</groupId>
<artifactId>existdb-saml-xquery</artifactId>
<version>1.7.0-SNAPSHOT</version>


<name>eXist-db SAML XQuery</name>
<description>SAML v2.0 Implementation in XQuery</description>
<url>https://github.com/eXist-db/existdb-saml</url>

<scm>
<url>https://github.com/eXist-db/existdb-saml.git</url>
<connection>scm:git:https://github.com/eXist-db/existdb-saml.git</connection>
<developerConnection>scm:git:https://github.com/eXist-db/existdb-saml.git</developerConnection>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- used in the EXPath Package Descriptor -->
<package-name>http://exist-db.org/apps/exsaml</package-name>

<exist.version>6.0.1</exist.version>

<exist.saml.username>exsaml</exist.saml.username>
<exist.saml.library.path>/db/system/repo/${project.artifactId}-${project.version}</exist.saml.library.path>

</properties>

<build>
<resources>
<resource>
<directory>src/main/xar-resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/xar-resources-filtered</directory>
<filtering>true</filtering>
</resource>
</resources>

<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
</testResource>
<testResource>
<directory>src/test/resources-filtered</directory>
<filtering>true</filtering>
</testResource>
</testResources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>

<plugin>
<groupId>ro.kuberam.maven.plugins</groupId>
<artifactId>kuberam-expath-plugin</artifactId>
<executions>
<execution>
<id>create-xar</id>
<phase>package</phase>
<goals>
<goal>make-xar</goal>
</goals>
<configuration>
<descriptor>xar-assembly.xml</descriptor>
<finalName>${package-final-name}</finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<configuration>
<useAgent>true</useAgent>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<mavenExecutorId>forked-path </mavenExecutorId>
<!-- avoid a bug with GPG plugin hanging http://jira.codehaus.org/browse/MGPG-9 -->
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>

</project>
6 changes: 0 additions & 6 deletions post-install.xql

This file was deleted.

13 changes: 0 additions & 13 deletions repo.xml.tmpl

This file was deleted.

1 change: 0 additions & 1 deletion saml-request-ids/KEEPME

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
xquery version "3.1";

import module namespace exsaml="http://exist-db.org/xquery/exsaml" at "/db/apps/existdb-saml/content/exsaml.xqm";
import module namespace exsaml = "http://exist-db.org/xquery/exsaml" at "${exist.saml.library.path}/modules/exsaml.xqm";
import module namespace functx = "http://www.functx.com";

declare function local:clean-reqids() {
let $reqid-col := "/db/apps/existdb-saml/saml-request-ids"
let $reqid-col := "${exist.saml.library.path}/saml-request-ids"
let $reqids := for $reqid in collection($reqid-col)/reqid
let $duration := xs:dateTime(current-dateTime()) - xs:dateTime($reqid)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ declare %private variable $exsaml:fake-user := data($exsaml:config/fake-idp/@u
declare %private variable $exsaml:fake-group := data($exsaml:config/fake-idp/@group);

(: SAML specific constants and non-configurable vars :)
declare %private variable $exsaml:saml-coll-reqid := "/db/apps/existdb-saml/saml-request-ids";
declare %private variable $exsaml:saml-coll-reqid := "${exist.saml.library.path}/saml-request-ids";
declare %private variable $exsaml:saml-version := "2.0";
declare %private variable $exsaml:status-success := "urn:oasis:names:tc:SAML:2.0:status:Success";
(: debugging only to simulate failure in fake-idp :)
Expand Down Expand Up @@ -100,7 +100,7 @@ declare function exsaml:build-authnreq-redir-url($relaystate as xs:string) {
let $zip := compression:deflate($bin, true())
(: let $log := exsaml:log("debug", "build-authnreq-redir-url; zip: " || $zip):)
(: urlencode base64 request data :)
let $urlenc := xmldb:encode($zip)
let $urlenc := xmldb:encode($zip cast as xs:string)

let $log := exsaml:log("debug", "build-authnreq-redir-url; urlenc: " || $urlenc)

Expand All @@ -122,15 +122,15 @@ declare %private function exsaml:build-saml-authnreq() {
return $req
};

declare %private function exsaml:store-authnreqid-as-exsol-user($id as xs:string, $instant as xs:string) {
declare %private function exsaml:store-authnreqid-as-exsol-user($id as xs:string, $instant as xs:dateTime) {
let $create-collection :=
if (
not(xmldb:collection-available($exsaml:saml-coll-reqid))
)
then (
let $log := exsaml:log("info", "collection " || $exsaml:saml-coll-reqid || " does not exist, attempting to create it")
return
xmldb:create-collection("/db/apps/existdb-saml", "saml-request-ids")
xmldb:create-collection(fn:replace($exsaml:saml-coll-reqid, "(.*)/[^/]+", "$1"), fn:replace($exsaml:saml-coll-reqid, ".*/([^/]+)", "$1"))
)
else ()
return
Expand All @@ -139,7 +139,7 @@ declare %private function exsaml:store-authnreqid-as-exsol-user($id as xs:string
};

(: store issued request ids in a collection, :)
declare %private function exsaml:store-authnreqid($id as xs:string, $instant as xs:string) {
declare %private function exsaml:store-authnreqid($id as xs:string, $instant as xs:dateTime) {
let $log := exsaml:log("info", "storing SAML request id: " || $id || ", date: " || $instant)
return
system:as-user(
Expand Down Expand Up @@ -228,7 +228,7 @@ declare function exsaml:process-saml-response-post() {
else ""

let $pass := exsaml:create-user-password($auth/@nameid)
let $log-in := xmldb:login("/db/apps", $auth/@nameid, $pass, true())
let $log-in := xmldb:login("/db", $auth/@nameid, $pass, true())
let $log := util:log("info", "login result: " || $log-in || ", " || fn:serialize(sm:id()))

(: put SAML token into browser session :)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
xquery version "3.1";

import module namespace scheduler="http://exist-db.org/xquery/scheduler" at "java:org.exist.xquery.modules.scheduler.SchedulerModule";


declare namespace sc="http://exist-db.org/xquery/scheduler";
import module namespace scheduler = "http://exist-db.org/xquery/scheduler";

declare variable $local:job-name := "clean-up-sso-reqids";
declare variable $local:cron := "0 0 11 * * ? *";

declare function local:start-job() {
scheduler:schedule-xquery-cron-job("/db/apps/existdb-saml/content/clean-reqids.xql", $local:cron, $local:job-name)
scheduler:schedule-xquery-cron-job("${exist.saml.library.path}/clean-reqids.xql", $local:cron, $local:job-name)
};

declare function local:show-job() {
let $jobs := scheduler:get-scheduled-jobs()
return
$jobs//sc:job[@name=$local:job-name]
$jobs//scheduler:job[@name=$local:job-name]
};

declare function local:stop-job() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<!-- @username: username of privileged user -->
<!-- @username: username of privileged user -->
<!-- @pass: plaintext password, WILL GO AWAY -->
<exsaml-creds username="exsaml" group="exsaml" pass="my other password"/>
<exsaml-creds username="${exist.saml.username}" group="${exist.saml.username}" pass="${exist.saml.username}"/>

<!-- settings for dynamic user creation -->
<!-- Since we are using a third party for authentication (SAML IDP), there
Expand Down
22 changes: 22 additions & 0 deletions src/main/xar-resources/post-install.xq
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
xquery version "3.1";

import module namespace sm = "http://exist-db.org/xquery/securitymanager";
import module namespace xmldb = "http://exist-db.org/xquery/xmldb";

(: the target collection into which the app is deployed :)
declare variable $target external;

declare variable $saml-user-name := "${exist.saml.username}";
declare variable $saml-request-ids-collection-name := "saml-request-ids";
declare variable $saml-request-ids-collection-path := $target || "/" || $saml-request-ids-collection-name;
declare variable $saml-request-ids-collection-uri := xs:anyURI($saml-request-ids-collection-path);

let $_ :=
if (fn:not(xmldb:collection-available($saml-request-ids-collection-path)))
then
xmldb:create-collection($target, $saml-request-ids-collection-name)
else()
return
let $_ := sm:chmod($saml-request-ids-collection-uri, "rwxr-x---")
return
sm:chown($saml-request-ids-collection-uri, $saml-user-name || ":" || $saml-user-name)
11 changes: 11 additions & 0 deletions src/main/xar-resources/pre-install.xq
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
xquery version "3.1";

import module namespace sm = "http://exist-db.org/xquery/securitymanager";

declare variable $saml-user-name := "${exist.saml.username}";

(: Create the default 'exsaml' user account :)
if (fn:not(sm:user-exists($saml-user-name)))
then
sm:create-account($saml-user-name, $saml-user-name, (), "existdb-saml", "existdb-saml-xquery SAML Authentication Account")
else()
Loading