Skip to content
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
21 changes: 19 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SPDX-License-Identifier: MIT

# wsfed-caep

Java 25 port of the server-side WS-Federation relying party. Group `com.iyasec`, artifact `wsfed-caep`, packages under `com.iyasec.wsfed`. License MIT (`LICENSE`). A pull request merged into `main` publishes the library (`library/` only; the demo never) to Maven Central after the test workflow succeeds on that commit. A direct push does not. `publish.yml` runs `mvn -Prelease -f library/pom.xml deploy` in the Maven container: the `release` profile adds the sources and javadoc jars, a GPG signature on every file, and the Central publishing plugin, which uploads, publishes and waits until the release is live. Maven Central has no trusted publishing, so the job uses four repository secrets: `CENTRAL_TOKEN_USERNAME` and `CENTRAL_TOKEN_PASSWORD` (a Central Portal user token) and `GPG_PRIVATE_KEY` and `GPG_PASSPHRASE` (the release signing key, whose public half is on a public key server). A release happens when the library's files changed since the last release's tag: `publish.yml` takes one patch above the highest published version, publishes it, and creates the matching tag and GitHub Release. A change to tests, the demo, or the docs releases nothing. To choose a version or start a new minor, raise `VERSION`; the version is stamped in CI and is not committed, so the manifests can trail what is published. `-Dcentral.skipPublishing=true` builds and signs everything and uploads nothing. When this tree is published, `develop` and `main` are the same commit.
Java port of the server-side WS-Federation relying party. Bytecode is 17. The runtime image is `eclipse-temurin:25-jre` and the test image is `maven:3.9-eclipse-temurin-26`. Group `com.iyasec`, artifact `wsfed-caep`, packages under `com.iyasec.wsfed`. License MIT (`LICENSE`). A pull request merged into `main` publishes the library (`library/` only; the demo never) to Maven Central after the test workflow succeeds on that commit. A direct push does not. `publish.yml` runs `mvn -Prelease -f library/pom.xml deploy` in the Maven container: the `release` profile adds the sources and javadoc jars, a GPG signature on every file, and the Central publishing plugin, which uploads, publishes and waits until the release is live. Maven Central has no trusted publishing, so the job uses four repository secrets: `CENTRAL_TOKEN_USERNAME` and `CENTRAL_TOKEN_PASSWORD` (a Central Portal user token) and `GPG_PRIVATE_KEY` and `GPG_PASSPHRASE` (the release signing key, whose public half is on a public key server). A release happens when the library's files changed since the last release's tag: `publish.yml` takes one patch above the highest published version, publishes it, and creates the matching tag and GitHub Release. A change to tests, the demo, or the docs releases nothing. To choose a version or start a new minor, raise `VERSION`; the version is stamped in CI and is not committed, so the manifests can trail what is published. `-Dcentral.skipPublishing=true` builds and signs everything and uploads nothing. The embedded PEP depends on `com.iyasec:iya-pep`, which is not on Maven Central yet, so this work stays on `develop` until that artifact's first release. A merge to `main` publishes this library.

## Usage

Expand All @@ -17,6 +17,23 @@ The party accepts SAML 2.0 assertions with bearer confirmation `urn:oasis:names:

Omitted or `true` means on. The resolved configuration leaves `signals` null in that case. `false` is stored as `Boolean.FALSE`, does not start the receiver, and does not require transmitter metadata. The relying party never starts the receiver itself; `SignalsReceiver` is separate. Sign-in does not change when signals are off, because WS-Federation does not send OAuth scopes. A non-boolean raises a config error: `signals must be true or false`. The shipped demo omits the key.

`ssf.clientCertificate` and `ssf.clientKey` are the receiver's own TLS client identity (PEM, `file:` or `env:`, both or neither). `Resolved.ssfTlsClient()` answers that pair, else the relying party's certificate and `privateKey`, else null. The demo refuses to start the receiver when there is none. `ssf.addSubjects` defaults to true. Anything but a boolean refuses to start the receiver, with the message `ssf.addSubjects must be true or false`. `track` adds the session and then POSTs `add_subject_endpoint` `{stream_id, subject, verified: true}`. `untrack` and an event-ended session remove the subject only when no other session for that person remains. The subject is `iss_sub` (the transmitter's issuer and the session's person, which stays `nameidentifier`) else `email`. The call is inline, once, and never fails sign-in. When the embedded PEP wants events, `start` also adds the application once, `{format: opaque, id: application}`, and never removes it, so a stream that names subjects still delivers `pep-policies-changed`.

## Embedded PEP

iya-sts#1206. There is no feature flag. `library/pom.xml` depends on `com.iyasec:iya-pep:0.1.0`. The `test` and `build` stages of the Dockerfile clone `https://github.com/rcbj/iya-pep-java.git` branch `develop` and `mvn -B -DskipTests install` it before this library. One attempt: if that branch is not pushed, the build stops. Bytecode is 17. The runtime image is `eclipse-temurin:25-jre`. The test image is `maven:3.9-eclipse-temurin-26`. This stays on `develop` until `iya-pep` is on Maven Central.

`com.iyasec.wsfed.pep.EmbeddedPep` builds `com.iyasec.pep.Pep` from the `pep` object. `RelyingParty.create` and `fromFile` do that after metadata is read, then `pep.start()`.

- `pdpUrl` defaults to the identity provider's entityID, the realm issuer with `/realm/<id>` included. `application` defaults to `realm`. `signals` is the library's (`null` or `true` is on; `Boolean.FALSE` is off). `tlsCa` is `idpCa` when that value contains a PEM certificate. A missing `mode` is `local`. An unknown member is refused.
- `assertionKey` is resolved like `privateKey` (`file:` stripped, a relative path from the configuration's directory) and left as a path. The PEM is not stored in the section.
- A PEP assertion key equal to `privateKey` is refused, and `SignalsReceiver` refuses a TLS client key equal to the PEP key. Both compare JWK thumbprints (`SigningKey.jwkThumbprint`, `SigningKey.pemThumbprint`). An empty thumbprint is not a match.
- When the PEP wants events (`Mode.LOCAL`, or `permitCacheMs` greater than 0), the receiver adds `Pep.POLICIES_CHANGED_EVENT` (`urn:iya:sts:secevent:event-type:pep-policies-changed`), calls `pep.onPolicyEvent` after SET verification, and reports the stream with `setEventStream`: `requested` or `excluded` at start and after a good poll, `down` after a failed poll and on `stop`. A reused stream that lacks the event is PATCHed; a refusal is logged and the receiver still starts.
- `decide` and `decideSession` build the subject with `EmbeddedPep.subjectOf`. The id is the `name` claim (`http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name`), else the NameID. iya-sts puts the username in both. `nameidentifier` is the opaque sub and is never the id. Properties are attributes keyed by FriendlyName, else the Name's last segment (`[A-Za-z0-9_$@:-]`, 1 to 64, no dot), then `acr`, `amr` (always an array) and `auth_time`. `decideSession` denies a session past `SessionNotOnOrAfter` (`the identity provider's session has ended`) or one the receiver no longer tracks (`no signed-in session`). No `pep` section is Unavailable, `no pep section is configured`. `decide` does not throw. `Decision.httpStatus()` is 200 only for a Permit and 403 for a Deny and an Unavailable.
- The demo answers `GET /attribute-protected` (`read` / `attribute-protected` / `attr1`) and `/orders/{id}` (`read` on GET, `write` otherwise, type `order`) with that status. No sign-in is 401, asked before the PEP. `GET /live-status` includes the PEP status under `pep`. `GET /pep-status` is that status as JSON.

`docs/remote-pep.md` is the user guide.

## Errors

`Caught.error` records a caught exception through `java.lang.System.Logger`, including the stack, and the method then throws the `WsFedError` it already threw. The caught exception is the cause. `Caught.warn` is the same record when the method recovers and does not throw: a later signing key, a poll retry, a false verification, sign-out cleanup, or a handler that must still acknowledge the Security Event Token. A `catch (WsFedError)` that only throws that error again is not logged a second time.
Expand All @@ -31,7 +48,7 @@ docker build --target test .

The `test` stage runs `mvn -B test` in `maven:3.9-eclipse-temurin-26`. GitHub Actions uses that command. Do not run Maven on the host. The demo stage packages with `-DskipTests` in its own Maven image.

JUnit 5 covers the stub IdP (a signed SAML assertion the library accepts), replay, metadata, the self-signed certificate, the SSF poll receiver, the demo handler, and the trust chain (`TrustChainTest`: the install script's code and `scripts/trust_chain.py` write the four-certificate chain to `idpCa`'s path, the handshake fallback keeps every block, the library trusts the provider and a reissued leaf through that file, and refuses a forged leaf followed by the real CA certificates and the right chain under the wrong host name). The test stage installs python3 and openssl for it. The stub tests do not start iya-sts. `python3 scripts/live_iya_sts.py` does, unless `IYA_STS_URL` names one that is already running. It signs the demo in and checks two Shared Signals events on `GET /live-status`. iya-sts main sets the assertion SessionIndex to the assertion id, so a session-revoked subject that names the sign-on session matches nobody. The demo ends its one session from that handler. The nightly workflow, cron `51 6 * * *` plus workflow_dispatch, runs the unit image and that script. It never binds port 3000, 8081 or 18481-18495; its defaults are 18553 (iya-sts) and 18653 (the demo). It builds the demo the way a user does: install script first (writing the chain), then the image build, then the run with only `rp.key`, `rp.crt` and `idp-metadata.xml` mounted. No CA mount, no `idpCa` rewrite. Secrets go to docker as `-e NAME`; no log line carries a sign-in URL. `scripts/configure_iya_sts.py` is the same registration script as the Python tree; its plan is exercised there. Configure is host Python and does not import this library.
JUnit 5 covers the stub IdP (a signed SAML assertion the library accepts), replay, metadata, the self-signed certificate, the SSF poll receiver, the demo handler, and the trust chain (`TrustChainTest`: the install script's code and `scripts/trust_chain.py` write the four-certificate chain to `idpCa`'s path, the handshake fallback keeps every block, the library trusts the provider and a reissued leaf through that file, and refuses a forged leaf followed by the real CA certificates and the right chain under the wrong host name). The test stage installs python3 and openssl for it. The stub tests do not start iya-sts. `python3 scripts/live_iya_sts.py` does, unless `IYA_STS_URL` names one that is already running. It signs the demo in and checks two Shared Signals events on `GET /live-status`. iya-sts main sets the assertion SessionIndex to the assertion id, so a session-revoked subject that names the sign-on session matches nobody. The demo ends its one session from that handler. The nightly workflow, cron `51 6 * * *` plus workflow_dispatch, runs the unit image and that script. It never binds port 3000, 8081 or 18481-18495; its defaults are 18553 (iya-sts) and 18653 (the demo). It builds the demo the way a user does: install script first (writing the chain and, when signals are on, the realm-issued Shared Signals client certificate), then the image build, then the run with `rp.key`, `rp.crt` and `idp-metadata.xml` mounted file by file, plus `ssf-client.key` and `ssf-client.crt` when those files exist, and `pep-key.pem` when `--pep` (or `LIVE_PEP=1`) was set. The image's `demo/generated` is checked to hold only `idp-ca.pem`. No CA mount, no `idpCa` rewrite. `--pep` runs central, then the same image with `WSFED_CONFIG=demo/wsfed.pep-local.json`. Secrets go to docker as `-e NAME`; no log line carries a sign-in URL. `scripts/configure_iya_sts.py` is this tree's install script. It is not shared with the Python tree. Configure is host Python and does not import this library.

## Layout

Expand Down
20 changes: 18 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
# The demo image below does not run it.
FROM maven:3.9-eclipse-temurin-26 AS test
# TrustChainTest runs the install script's trust-chain code: python3, and the
# openssl CLI it reads certificate names with.
RUN apt-get update && apt-get install -y --no-install-recommends python3 openssl && rm -rf /var/lib/apt/lists/*
# openssl CLI it reads certificate names with. git fetches iya-pep, which is
# not on Maven Central yet.
RUN apt-get update && apt-get install -y --no-install-recommends python3 openssl git ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /src
# Both modules: library/ (the published library) and demo/ (the demo, HttpDemoTest,
# and TrustChainTest, which runs scripts/ against demo/wsfed.json).
Expand All @@ -16,14 +17,29 @@ COPY demo/pom.xml demo/pom.xml
COPY demo/src demo/src
COPY scripts ./scripts
COPY demo/wsfed.json demo/wsfed.json
# iya-pep is installed from commit d2bbf5ee73a93ec3b2aeb01219fc093fbb41c645 before this library's tests.
RUN git init /tmp/iya-pep-java \
&& git -C /tmp/iya-pep-java remote add origin https://github.com/rcbj/iya-pep-java.git \
&& git -C /tmp/iya-pep-java fetch --depth 1 origin d2bbf5ee73a93ec3b2aeb01219fc093fbb41c645 \
&& git -C /tmp/iya-pep-java checkout --detach FETCH_HEAD \
&& mvn -B -DskipTests -f /tmp/iya-pep-java/pom.xml install \
&& rm -rf /tmp/iya-pep-java
RUN mvn -B test

FROM maven:3.9-eclipse-temurin-26 AS build
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY pom.xml .
COPY library library
COPY demo/pom.xml demo/pom.xml
COPY demo/src demo/src
# The same install as the test stage: the demo package resolves com.iyasec:iya-pep.
RUN git init /tmp/iya-pep-java \
&& git -C /tmp/iya-pep-java remote add origin https://github.com/rcbj/iya-pep-java.git \
&& git -C /tmp/iya-pep-java fetch --depth 1 origin d2bbf5ee73a93ec3b2aeb01219fc093fbb41c645 \
&& git -C /tmp/iya-pep-java checkout --detach FETCH_HEAD \
&& mvn -B -DskipTests -f /tmp/iya-pep-java/pom.xml install \
&& rm -rf /tmp/iya-pep-java
# The demo module copies its runtime dependencies, the library among them, to demo/target/dependency.
RUN mvn -B -DskipTests package
FROM eclipse-temurin:25-jre
Expand Down
Loading