### Start the Sample Boot Application Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/java-configuration/saml2/login/README.adoc Run the Spring Boot application using Gradle. This starts the sample service provider on localhost:8080. ```bash ./gradlew :spring-security-samples-boot-saml2login:bootRun ``` -------------------------------- ### Start Local CAS Server with Docker Compose Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/cas/login/README.adoc Run from the project root to start the local CAS server using Docker. Requires Docker installed or a running CAS server. ```bash docker-compose -f docker/cas/docker-compose.yml up ``` -------------------------------- ### Run the LDAP sample application Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/ldap/README.adoc Starts the Spring Boot application with Gradle. Run this first before making requests. ```bash ./gradlew :servlet:spring-boot:java:ldap:bootRun ``` -------------------------------- ### Response from /message GET Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc The response from the /message GET request. ```bash secret message ``` -------------------------------- ### Example JWT Response Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/README.adoc Example response from the /token endpoint, a JWT token string. ```bash eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJzZWxmIiwic3ViIjoidXNlciIsImV4cCI6MTYwNDA0MzA1MSwiaWF0IjoxNjA0MDA3MDUxfQ.yDF_JgSwl5sk21CF7AE1AYbYzRd5YYqe3MIgSWpgN0t2UqsjaaEDhmmICKizt-_0iZy8nkEpNnvgqv5bOHDhs7AXlYS1pg8dgPKuyfkhyVIKa3DhuGyb7tFjwJxHpr128BXf1Dbq-p7Njy46tbKsZhP5zGTjdXlqlAhR4Bl5Fxaxr7D0gdTVBVTlUp9DCy6l-pTBpsvHxShkjXJ0GHVpIZdB-c2e_K9PfTW5MDPcHekG9djnWPSEy-fRvKzTsyVFhdy-X3NXQWWkjFv9bNarV-bhxMlzqhujuaeXJGEqUZlkhBxTsqFr1N7XVcmhs3ECdjEyun2fUSge4BoC7budsQ ``` -------------------------------- ### Run Authorization Server with ./gradlew bootRun Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Starts the pre-configured Authorization Server sample as a stand-alone application. Navigate to 'servlet/spring-boot/java/oauth2/authorization-server' first. ```bash ./gradlew bootRun ``` -------------------------------- ### Run the JWT Login Sample Application Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/README.adoc Starts the Spring Boot application using Gradle. Run this first to use the sample. ```bash ./gradlew :servlet:spring-boot:java:jwt:login:bootRun ``` -------------------------------- ### Query /message with HTTPie for successful authentication Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/observability/README.adoc Sends a GET request to /message with user/password credentials. This should return a successful response. ```bash http -a user:password :8080/message` ``` -------------------------------- ### Run Sample Application with Gradle bootRun Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/cas/login/README.adoc Run from the project root to start the sample application. Alternatively, run the CasLoginApplication class from your IDE. ```bash ./gradlew :servlet:spring-boot:java:cas:login:bootRun ``` -------------------------------- ### Run Resource Server with mock Authorization Server Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Starts the Resource Server with an embedded mock Authorization Server using the 'test' profile. ```bash ./gradlew bootRun --args='--spring.profiles.active=test' ``` -------------------------------- ### Run the sample Boot application with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/refreshable-metadata/README.adoc Starts the Spring Boot application using the Gradle wrapper. Run from the project root. The application will be available at http://localhost:8080/. ```bash ./gradlew :servlet:spring-boot:java:saml2:refreshable-metadata:bootRun ``` -------------------------------- ### Export certificate to file Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/xml/java/contacts/src/site/resources/sslhowto.txt Exports the generated certificate to a text file for later import into the Java cacerts store. ```bash keytool -export -v -rfc -alias acegisecurity -file acegisecurity.txt -keystore keystore -storepass password ``` -------------------------------- ### Run the Spring Boot application Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/acl/README.adoc Use this command to start the sample application. After running, you can query for messages using `luke/password` and `rob/password`. ```java ./gradlew :bootRun ``` -------------------------------- ### Run the sample Boot application Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/saml-extension-federation/README.adoc Starts the Spring Boot application for the SAML extension federation sample. ```bash ./gradlew :servlet:spring-boot:java:saml2:saml-extension-federation:bootRun ``` -------------------------------- ### Request tenantTwo root endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc Sends a GET request to /tenantTwo with the opaque token. The response is 'Hello, subject for tenantTwo!'. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080/tenantTwo ``` -------------------------------- ### Request / with Bearer Token Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/README.adoc Sends a GET request to the root endpoint with the bearer token for authentication. The response should be 'Hello, user!'. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 && echo ``` -------------------------------- ### GET request to root with Bearer token Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Sends a GET request to the Resource Server root endpoint using the exported token. Responds with 'Hello, messaging-client!'. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` -------------------------------- ### GET request to /message Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Sends a GET request to the /message endpoint with the bearer token. Responds with 'secret message'. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080/message ``` -------------------------------- ### Request tenantOne root endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc Sends a GET request to /tenantOne with the JWT token. The response is 'Hello, subject for tenantOne!'. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080/tenantOne ``` -------------------------------- ### Copy certificate and keystore to required locations Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/xml/java/contacts/src/site/resources/sslhowto.txt Copies the exported certificate to the Java security directory and the keystore to the web container location. Requires configuring the web container and testing via https://localhost:8443. ```bash copy acegisecurity.txt %JAVA_HOME%\lib\security ``` ```bash copy keystore %YOUR_WEB_CONTAINER_LOCATION% ``` -------------------------------- ### Import certificate into cacerts Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/xml/java/contacts/src/site/resources/sslhowto.txt Imports the exported certificate into the Java cacerts keystore. Requires answering 'yes' to trust the certificate. The default cacerts password is 'changeit'. ```bash cd %JAVA_HOME%\lib\security ``` ```bash keytool -import -v -file acegisecurity.txt -keypass password -keystore cacerts -storepass changeit -alias acegisecurity ``` -------------------------------- ### OAuth2 token response JSON Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Example response from the token endpoint. Contains the access token, expiration time, scope, and token type. ```json { "access_token": "eyJraWQiOiI4YWY4Zjc2Zi0zMTdkLTQxZmYtYWY5Yi1hZjg5NDg4ODM5YzciLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJtZXNzYWdpbmctY2xpZW50IiwiYXVkIjoibWVzc2FnaW5nLWNsaWVudCIsIm5iZiI6MTYyNzMzNDQ1MCwic2NvcGUiOlsibWVzc2FnZTpyZWFkIl0sImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo5MDAwIiwiZXhwIjoxNjI3MzM0NzUwLCJpYXQiOjE2MjczMzQ0NTAsImp0aSI6IjBiYjYwZjhkLWIzNjItNDk0MC05MGRmLWZhZDg4N2Q1Yzg1ZSJ9.O8dI67B_feRjOn6pJi5ctPJmUJCNpV77SC4OiWqmpa5UHvf4Ud6L6EFe9LKuPIRrEWi8rMdCdMBOPKQMXvxLoI3LMUPf7Yj973uvZN0E988MsKwhGwxyaa_Wam8wFlk8aQlN8SbW3cKdeH-nKloNMdwjfspovefX521mxouaMjmyXdIFrM5WZ15GZK69NIniACSatE-pc9TAjKYBDbC65jVt_zHEvDQbEkZulF2bjrGOZC8C3IbJWnlKgkcshrY44TtrGPyCp2gIS0TSUUsG00iSBBC8E8zPU-YdfaP8gB9_FwUwK9zfy_hU2Ykf2aU3eulpGDVLn2rCwFeK86Rw1w", "expires_in": 299, "scope": "message:read", "token_type": "Bearer" } ``` -------------------------------- ### One-time token example from logs Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/authentication/mfa/formLogin+ott/README.adoc Shows the format of the one-time token printed in the logs after requesting a token. The token is a UUID and is used to complete the OTT login. ```bash ******************************************************** Use this one-time token: 1319c31d-c5e0-4123-9b1f-3ffc34aba673 ******************************************************** ``` -------------------------------- ### Generate self-signed certificate with keytool Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/xml/java/contacts/src/site/resources/sslhowto.txt Creates a self-signed certificate for CAS HTTPS. Requires answering prompts with 'localhost' for first/last name and 'yes' to confirm. The certificate is stored in a keystore with password 'password'. ```bash keytool -keystore keystore -alias acegisecurity -genkey -keyalg RSA -validity 9999 -storepass password -keypass password ``` -------------------------------- ### Example response for user rob Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/aot/data/README.adoc Shows the JSON response when querying '/' with user 'rob'. Unlike luke, rob also sees firstName and lastName fields. ```json ... { "created": "2014-07-12T04:00:00Z", "id": 102, "summary": "Is this secure?", "text": "This message is for Rob", "to": { "email": "rob@example.com", "firstName": "Rob", "id": "rob", "lastName": "Winch", "password": "password" } } ... ``` -------------------------------- ### Custom Authorization Server properties Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc Example properties for pointing to a custom Authorization Server's JWK set and introspection endpoints. Replace the URLs and credentials with your own. ```yaml tenantOne.jwk-set-uri: https://dev-123456.oktapreview.com/oauth2/default/v1/keys tenantTwo.introspection-uri: https://dev-123456.oktapreview.com/oauth2/default/v1/introspect tenantTwo.introspection-client-id: client tenantTwo.introspection-client-secret: secret ``` -------------------------------- ### Example response for user luke Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/aot/data/README.adoc Shows the JSON response when querying '/' with user 'luke'. Because domain objects are secured, only a subset of fields is returned (no firstName/lastName). ```json ... { "created": "2014-07-12T16:00:00Z", "id": 112, "summary": "Is this secure?", "text": "This message is for Luke", "to": { "email": "luke@example.com", "id": "luke", "password": "password" } } ... ``` -------------------------------- ### Introspection endpoint response (JSON) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/authorization-server/README.adoc Example response from the token introspection endpoint. Shows active=true, audience, client_id, expiration, issuer, and scope for the token. ```json { "active": true, "aud": [ "messaging-client" ], "client_id": "messaging-client", "exp": 1627334750, "iat": 1627334450, "iss": "http://localhost:9000", "jti": "0bb60f8d-b362-4940-90df-fad887d5c85e", "nbf": 1627334450, "scope": "message:read", "sub": "messaging-client", "token_type": "Bearer" } ``` -------------------------------- ### Change JWK Set URI to custom Authorization Server Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Example of changing the jwk-set-uri property to a custom Authorization Server's JWK set endpoint. ```yaml spring: security: oauth2: resourceserver: jwt: jwk-set-uri: https://dev-123456.oktapreview.com/oauth2/default/v1/keys ``` -------------------------------- ### Example JSON response for Luke's messages Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/acl/README.adoc Shows the expected JSON output when querying `/` with `luke`. The response contains only Luke's messages due to ACL security. ```json [ { "created": "2014-07-12T10:00:00Z", "id": 110, "summary": "Hello Luke", "text": "This message is for Luke", "to": "luke" }, { "created": "2014-07-12T10:00:00Z", "id": 111, "summary": "Greetings Luke", "text": "This message is for Luke", "to": "luke" }, { "created": "2014-07-12T10:00:00Z", "id": 112, "summary": "Is this secure?", "text": "This message is for Luke", "to": "luke" } ] ``` -------------------------------- ### Update message with HTTPie Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/aot/data/README.adoc Sends a PUT request to :8080/102 to change the message text. Requires copying the X-CSRF-TOKEN and Cookie: JSESSIONID headers from a previous GET request. ```bash echo -n "updated message" | http -a rob:password PUT :8080/102 "X-CSRF-TOKEN: {copied from GET request}" "Cookie: JSESSIONID={copied from GET request}" ``` -------------------------------- ### Sample credentials Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/saml-extension-urls/README.adoc Credentials to log in to the local IdP. ```text User: user1 Password: user1pass ``` -------------------------------- ### Run integration tests with ./gradlew integrationTest Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Executes the integration tests for the Resource Server sample. The tests use a mock Authorization Server via the 'test' profile and hard-coded tokens. ```bash ./gradlew integrationTest ``` -------------------------------- ### Run with elevated-security profile Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/authentication/mfa/formLogin+ott/README.adoc Launches the application with the `elevated-security` profile, which allows login with either factor and asks for OTT only on the `/profile` page. ```bash ./gradlew :bootRun --args='spring.profiles.active=elevated-security' ``` -------------------------------- ### Response from /message POST Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc The response from the /message POST request. ```bash Message was created. Content: my message ``` -------------------------------- ### Export access token Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Sets the TOKEN environment variable to the access token from the previous response. Replace '...' with the actual token value. ```bash export TOKEN=... ``` -------------------------------- ### Run with custom-pages profile Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/authentication/mfa/formLogin+ott/README.adoc Launches the application with the `custom-pages` profile, which uses custom pages for login and one-time-token. ```bash ./gradlew :bootRun --args='spring.profiles.active=custom-pages' ``` -------------------------------- ### Run the native executable Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/aot/data/README.adoc Runs the compiled native executable from the build output directory. ```bash ./build/native/nativeCompile/data ``` -------------------------------- ### Configure Okta OAuth2 Client in application.yml Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/login/README.adoc Set the OAuth2 client registration and provider properties for Okta. Replace client-id, client-secret, and the Okta preview sub-domain in the URIs with your credentials. ```yaml spring: security: oauth2: client: registration: <1> okta: <2> client-id: okta-client-id client-secret: okta-client-secret provider: <3> okta: authorization-uri: https://your-subdomain.oktapreview.com/oauth2/v1/authorize token-uri: https://your-subdomain.oktapreview.com/oauth2/v1/token user-info-uri: https://your-subdomain.oktapreview.com/oauth2/v1/userinfo user-name-attribute: sub jwk-set-uri: https://your-subdomain.oktapreview.com/oauth2/v1/keys ``` -------------------------------- ### Test Credentials for Okta IDP Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/java-configuration/saml2/login/README.adoc Use these credentials to log in to the Okta SAML 2.0 IDP after being redirected from the sample application. ```text User: testuser2@spring.security.saml Password: 12345678 ``` -------------------------------- ### Expected response for tenantTwo message Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc The response phrase returned when accessing /tenantTwo/message with a valid opaque token. ```bash secret message for tenantTwo ``` -------------------------------- ### Set token for /message endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/opaque/README.adoc Sets an environment variable with a token for the /message endpoint. ```bash export TOKEN=b43d1500-c405-4dc9-b9c9-6cfd966c34c9 ``` -------------------------------- ### Set token for root endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/opaque/README.adoc Sets an environment variable with a token for the root endpoint. ```bash export TOKEN=00ed5855-1869-47a0-b0c9-0f3ce520aee7 ``` -------------------------------- ### Configure SAML 2.0 relying party metadata URIs in application.yml Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/login/README.adoc Set the asserting party metadata URI for each registration (one and two) to point to your own IdP instead of the local Docker IdP. Replace {your-idp-metadata-endpoint} with the actual endpoint. ```java spring: security: saml2: relyingparty: registration: one: assertingparty.metadata-uri: {your-idp-metadata-endpoint} // ... two: assertingparty.metadata-uri: {your-idp-metadata-endpoint} ``` -------------------------------- ### Request OAuth2 token with message:write scope Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Obtains an access token with the 'message:write' scope for POST requests. ```bash curl -X POST messaging-client:secret@localhost:9000/oauth2/token -d "grant_type=client_credentials" -d "scope=message:write" ``` -------------------------------- ### Request and Export Token Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/README.adoc Requests a token from the /token endpoint and stores it in the TOKEN environment variable for later use. ```bash export TOKEN=`curl -XPOST user:password@localhost:8080/token` ``` -------------------------------- ### POST request to /message Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Sends a POST request to the /message endpoint with the bearer token and a message body. Responds with 'Message was created. Content: my message'. ```bash curl -H "Authorization: Bearer $TOKEN" -d "my message" localhost:8080/message ``` -------------------------------- ### Default Authorization Server properties Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc The default configuration in application.yml pointing to a mock Authorization Server. Replace these with your own endpoints. ```yaml tenantOne.jwk-set-uri: ${mockwebserver.url}/.well-known/jwks.json tenantTwo.introspection-uri: ${mockwebserver.url}/introspect tenantTwo.introspection-client-id: client tenantTwo.introspection-client-secret: secret ``` -------------------------------- ### CAS Sample Credentials Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/cas/login/README.adoc Use these credentials to log in at the local CAS server after being redirected from the sample application. ```bash User: casuser Password: Mellon ``` -------------------------------- ### POST to /token with user/password Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/README.adoc Sends a POST request to the /token endpoint with basic authentication credentials user:password. The response is a JWT. ```bash curl -XPOST user:password@localhost:8080/token ``` -------------------------------- ### Set TOKEN and request root endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Exports a JWT as TOKEN and calls the root endpoint. The response is 'Hello, subject!' where subject is the JWT's sub field. ```bash export TOKEN=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0IiwiZXhwIjo0NjgzODA1MTI4fQ.ULEPdHG-MK5GlrTQMhgqcyug2brTIZaJIrahUeq9zaiwUSdW83fJ7W1IDd2Z3n4a25JY2uhEcoV95lMfccHR6y_2DLrNvfta22SumY9PEDF2pido54LXG6edIGgarnUbJdR4rpRe_5oRGVa8gDx8FnuZsNv6StSZHAzw5OsuevSTJ1UbJm4UfX3wiahFOQ2OI6G-r5TB2rQNdiPHuNyzG5yznUqRIZ7-GCoMqHMaC-1epKxiX8gYXRROuUYTtcMNa86wh7OVDmvwVmFioRcR58UWBRoO1XQexTtOQq_t8KYsrPZhb9gkyW8x2bAQF-d0J0EJY8JslaH6n4RBaZISww ``` ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` ```bash Hello, subject! ``` -------------------------------- ### Set JWT token for tenantOne Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc Sets an environment variable TOKEN to a hard-coded JWT for tenantOne. This token is used in subsequent curl requests. ```bash export TOKEN=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0IiwiZXhwIjo0NjgzODA1MTI4fQ.ULEPdHG-MK5GlrTQMhgqcyug2brTIZaJIrahUeq9zaiwUSdW83fJ7W1IDd2Z3n4a25JY2uhEcoV95lMfccHR6y_2DLrNvfta22SumY9PEDF2pido54LXG6edIGgarnUbJdR4rpRe_5oRGVa8gDx8FnuZsNv6StSZHAzw5OsuevSTJ1UbJm4UfX3wiahFOQ2OI6G-r5TB2rQNdiPHuNyzG5yznUqRIZ7-GCoMqHMaC-1epKxiX8gYXRROuUYTtcMNa86wh7OVDmvwVmFioRcR58UWBRoO1XQexTtOQq_t8KYsrPZhb9gkyW8x2bAQF-d0J0EJY8JslaH6n4RBaZISww ``` -------------------------------- ### Configure application.yml for GitHub OAuth client Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/webclient/README.adoc Set the OAuth client registration properties in application.yml for the authorization code grant flow. Replace client-id and client-secret with your GitHub OAuth credentials. The registration ID is 'github' and the scope includes read:user and public_repo. ```yaml spring: security: oauth2: client: registration: <1> client-id: <2> client-id: replace-with-client-id client-secret: replace-with-client-secret provider: github scope: read:user,public_repo ``` -------------------------------- ### Configure application.yml for Google OAuth2 Client Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/login/README.adoc Set the OAuth2 client registration properties in application.yml to use Google as the authentication provider. Replace the client-id and client-secret values with your Google OAuth 2.0 credentials. ```yaml spring: security: oauth2: client: registration: <1> google: <2> client-id: google-client-id client-secret: google-client-secret ``` -------------------------------- ### Compile with Gradle nativeCompile Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/aot/data/README.adoc Compiles the project using the Gradle wrapper's nativeCompile task. ```bash ./gradlew nativeCompile ``` -------------------------------- ### Set opaque token and request tenantTwo message endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc Sets an opaque token and requests /tenantTwo/message. The response is 'secret message for tenantTwo'. ```bash export TOKEN=b43d1500-c405-4dc9-b9c9-6cfd966c34c9 curl -H "Authorization: Bearer $TOKEN" localhost:8080/tenantTwo/message ``` -------------------------------- ### Switch Java version with SDKMan Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/aot/data/README.adoc Use this command to select the required Java compiler version (23.0.5.r17-nik) when not using SDKMan's automatic version selection. ```bash sdk use java 23.0.5.r17-nik ``` -------------------------------- ### Response from root endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc The response from the root endpoint. 'messaging-client' is the value of the 'sub' field in the JWT. ```bash Hello, messaging-client! ``` -------------------------------- ### Configure IdP metadata URI in application.yml Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/saml-extension-urls/README.adoc Set the asserting party metadata URI to your own IdP endpoint as an alternative to using the local Docker IdP. ```java spring: security: saml2: relyingparty: registration: one: assertingparty.metadata-uri: {your-idp-metadata-endpoint} ``` -------------------------------- ### Set TOKEN and POST /message request Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc Exports a JWT with the 'message:write' scope and sends a POST request to /message with the body 'my message'. The response is 'Message was created. Content: my message'. ```bash export TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdWJqZWN0IiwiZXhwIjoyMTY0MjQzOTA0LCJhdXRob3JpdGllcyI6WyJST0xFX1VTRVIiXSwianRpIjoiZGI4ZjgwMzQtM2VlNy00NjBjLTk3NTEtMDJiMDA1OWI5NzA4IiwiY2xpZW50X2lkIjoid3JpdGVyIiwic2NvcGUiOlsibWVzc2FnZTp3cml0ZSJdfQ.USvpx_ntKXtchLmc93auJq0qSav6vLm4B7ItPzhrDH2xmogBP35eKeklwXK5GCb7ck1aKJV5SpguBlTCz0bZC1zAWKB6gyFIqedALPAran5QR-8WpGfl0wFqds7d8Jw3xmpUUBduRLab9hkeAhgoVgxevc8d6ITM7kRnHo5wT3VzvBU8DquedVXm5fbBnRPgG4_jOWJKbqYpqaR2z2TnZRWh3CqL82Orh1Ww1dJYF_fae1dTVV4tvN5iSndYcGxMoBaiw3kRRi6EyNxnXnt1pFtZqc1f6D9x4AHiri8_vpBp2vwG5OfQD5-rrleP_XlIB3rNQT7tu3fiqu4vUzQaEg ``` ```bash curl -H "Authorization: Bearer $TOKEN" -d "my message" localhost:8080/message ``` -------------------------------- ### Alternative: X.509 with one-time token login Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/authentication/mfa/x509+webauthn/README.adoc After a client certificate is accepted, generates a token and sends it to the configured destination to continue login. ```java http .x509(Customizer.withDefaults()) .oneTimeTokenLogin(Customizer.withDefaults()) ``` -------------------------------- ### Configure application.yml for GitHub OAuth Client Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/webclient/README.adoc Set the OAuth client registration properties in application.yml. Replace client-id and client-secret with your GitHub OAuth credentials. The registration ID is 'github' and the scope includes read:user and public_repo. ```yaml spring: security: oauth2: client: registration: <1> client-id: <2> client-id: replace-with-client-id client-secret: replace-with-client-secret provider: github scope: read:user,public_repo ``` -------------------------------- ### Configure X.509 and WebAuthn MFA in HttpSecurity Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/authentication/mfa/x509+webauthn/README.adoc Requires both X.509 and WebAuthn for full authorization. Redirects to `/webauthn` when WebAuthn authority is missing. ```java http .x509(Customizer.withDefaults()) .webAuthn((webauthn) -> webauthn // ... .factor((f) -> f.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/webauthn"))) ); ``` -------------------------------- ### Set JWT token and request tenantOne message endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc Sets a JWT token with the 'message:read' scope and requests /tenantOne/message. The response is 'secret message for tenantOne'. ```bash export TOKEN=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0Iiwic2NvcGUiOiJtZXNzYWdlOnJlYWQiLCJleHAiOjQ2ODM4MDUxNDF9.h-j6FKRFdnTdmAueTZCdep45e6DPwqM68ZQ8doIJ1exi9YxAlbWzOwId6Bd0L5YmCmp63gGQgsBUBLzwnZQ8kLUgUOBEC3UzSWGRqMskCY9_k9pX0iomX6IfF3N0PaYs0WPC4hO1s8wfZQ-6hKQ4KigFi13G9LMLdH58PRMK0pKEvs3gCbHJuEPw-K5ORlpdnleUTQIwINafU57cmK3KocTeknPAM_L716sCuSYGvDl6xUTXO7oPdrXhS_EhxLP6KxrpI1uD4Ea_5OWTh7S0Wx5LLDfU6wBG1DowN20d374zepOIEkR-Jnmr_QlR44vmRqS5ncrF-1R0EGcPX49U6A curl -H "Authorization: Bearer $TOKEN" localhost:8080/tenantOne/message ``` -------------------------------- ### Expected response for tenantOne message Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc The response phrase returned when accessing /tenantOne/message with a JWT that has the 'message:read' scope. ```bash secret message for tenantOne ``` -------------------------------- ### Request the root endpoint with LDAP credentials Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/ldap/README.adoc Uses curl to authenticate with user 'user' and password 'password' against localhost:8080. The expected response is 'Hello, user!'. ```bash curl --user user:password localhost:8080 && echo ``` ```bash Hello, user! ``` -------------------------------- ### Configure GitHub OAuth2 client in application.yml Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/login/README.adoc Set the GitHub OAuth2 client registration properties in application.yml. Replace the client-id and client-secret values with your GitHub OAuth application credentials. The registration ID 'github' is used in the default redirect URI template {baseUrl}/login/oauth2/code/{registrationId}. ```yaml spring: security: oauth2: client: registration: <1> github: <2> client-id: github-client-id client-secret: github-client-secret ``` -------------------------------- ### Configure JWK Set URI in application.yml Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Default configuration for the sample's JWK set endpoint. Change the jwk-set-uri property to point to your Authorization Server's JWK set endpoint. ```yaml spring: security: oauth2: resourceserver: jwt: jwk-set-uri: http://localhost:9000/oauth2/jwks ``` -------------------------------- ### Minimal introspection configuration Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/opaque/README.adoc Configuration after changing the introspection-uri to your Authorization Server's endpoint. The client id and secret are omitted. ```yaml spring: security: oauth2: resourceserver: opaque: introspection-uri: ${mockwebserver.url}/introspect ``` -------------------------------- ### Expected Response Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/README.adoc Expected response from the root endpoint when authenticated with the bearer token. ```bash Hello, user! ``` -------------------------------- ### Expected test output for tenantTwo Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc The response phrase returned when the Resource Server verifies an opaque token for tenantTwo. The 'subject' is the value of the 'sub' field in the Introspection response. ```bash Hello, subject for tenantTwo! ``` -------------------------------- ### Set TOKEN environment variable for / endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc Exports a JWT with the 'subject' sub claim and ROLE_USER authority to the TOKEN environment variable for use with the / endpoint. ```bash export TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdWJqZWN0IiwiZXhwIjoyMTY0MjQ1ODgwLCJhdXRob3JpdGllcyI6WyJST0xFX1VTRVIiXSwianRpIjoiMDFkOThlZWEtNjc0MC00OGRlLTk4ODAtYzM5ZjgyMGZiNzVlIiwiY2xpZW50X2lkIjoibm9zY29wZXMiLCJzY29wZSI6WyJub25lIl19.VOzgGLOUuQ_R2Ur1Ke41VaobddhKgUZgto7Y3AGxst7SuxLQ4LgWwdSSDRx-jRvypjsCgYPbjAYLhn9nCbfwtCitkymUKUNKdebvVAI0y8YvliWTL5S-GiJD9dN8SSsXUla9A4xB_9Mt5JAlRpQotQSCLojVSKQmjhMpQWmYAlKVjnlImoRwQFPI4w3Ijn4G4EMTKWUYRfrD0-WNT9ZYWBeza6QgV6sraP7ToRB3eQLy2p04cU40X-RHLeYCsMBfxsMMh89CJff-9tn7VDKi1hAGc_Lp9yS9ZaItJuFJTjf8S_vsjVB1nBhvdS_6IED_m_fOU52KiGSO2qL6shxHvg ``` -------------------------------- ### Set TOKEN and request /message endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Exports a JWT with the message:read scope and calls the /message endpoint. The response is 'secret message'. ```bash export TOKEN=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0Iiwic2NvcGUiOiJtZXNzYWdlOnJlYWQiLCJleHAiOjQ2ODM4MDUxNDF9.h-j6FKRFdnTdmAueTZCdep45e6DPwqM68ZQ8doIJ1exi9YxAlbWzOwId6Bd0L5YmCmp63gGQgsBUBLzwnZQ8kLUgUOBEC3UzSWGRqMskCY9_k9pX0iomX6IfF3N0PaYs0WPC4hO1s8wfZQ-6hKQ4KigFi13G9LMLdH58PRMK0pKEvs3gCbHJuEPw-K5ORlpdnleUTQIwINafU57cmK3KocTeknPAM_L716sCuSYGvDl6xUTXO7oPdrXhS_EhxLP6KxrpI1uD4Ea_5OWTh7S0Wx5LLDfU6wBG1DowN20d374zepOIEkR-Jnmr_QlR44vmRqS5ncrF-1R0EGcPX49U6A ``` ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080/message ``` ```bash secret message ``` -------------------------------- ### Set token and request root endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/jwe/README.adoc Exports a JWE-encrypted token and sends a request to the root endpoint. The response is 'Hello, subject!'. ```bash export TOKEN=eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAtMjU2In0.IyeWtsTonaiWJdoT13B0M7gpqVxAirVGlfqFI4TOmTRcVHICs_ESezS7fa0ODS9XYdwklTtG7hH39yeeMzr2Zo1Ghh-m36fdoqQrV1Do04rUvuTjqbgyNffeZEGB6rquJ-cyAVjp_Oljy10-Bbnw7CeVGwNBSVo9UCB5j49OlNWhLxFpYARFmOlYpXj-s4Q4JiqV6EvjDAYeohAR4QQmND3qoxR-s2I6SLcIho0sSSpUlhrRiqu2uvWefHDcZJdW2WYWnxLHxhzNu3CfnLiqhhaA_YA_iWXR9FYnPDCf_4q3FgSXcgttXzomFKAx5DwnE_dXvsCvpWxslZMU1UIiLA.MHOrrza2GQ9_5PIv.zU4tfhxT6apWBC3stBwQmGlCQBltWVQe4dFIykybWWBFqxo1bf2BZ37twzoEIFXG9jSYEMH4mvBXPWSvn66t-_jnqLnKTJst2plBjhagGCAoLNWXVKeYNp67o-lKOD_JJQFqsRw4oE05VSgRr14MZeaUBFcU3A_kKxMXOu899DKfXBGJvj75H7lDyd8RUXTb-OSWWfUiJc6Y5AUy1zCZCN9yfDsCXt9heTsZANy92Oou9sMFaXkYzyums5OtkBtLFzyuNMEoNioRehTV-FTuL8tDRB1mNhHObwsBfFbR6M1jJK37pHUXGtko-yZ6NGwxyLtwGh4uU2jzE614rQzuzR8aHaHxOkUs1pBTZ8AcRt41snByOe-KU0adthHxedobFiQQBoQ05DgSU7DO6hsK0uVBDF3eG2KjH4L2lZy-WugloLHhdguUoO9F0zUx15-XZO4EVzmhy8xfH2tSXz98eKzz9Dv0DdGnrBL9cK2MM88N1zoq5u4NdlnE12HvuesB7GKdMwZx1-gTw_pzP81TzcctJWl6ETK09Uc.jk0O8qc4Fvip856stDz05Q ``` ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` -------------------------------- ### Request OAuth2 token with curl Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc Obtains an access token from the Authorization Server using client credentials. The response includes an access_token, expires_in, scope, and token_type. ```bash curl -X POST messaging-client:secret@localhost:9000/oauth2/token -d "grant_type=client_credentials" -d "scope=message:read" ``` -------------------------------- ### Configure IdP metadata endpoint in application.yml Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/refreshable-metadata/README.adoc Set the saml2.ap.metadata property to your Identity Provider's metadata endpoint. Replace {your-idp-metadata-endpoint} with the actual URL. This is an alternative to using the local Docker IdP. ```yaml saml2: ap.metadata: {your-idp-metadata-endpoint} ``` -------------------------------- ### Opaque token introspection configuration Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/opaque/README.adoc Configuration for the Resource Server to introspect opaque tokens. Replace the introspection-uri, client id, and secret with your Authorization Server's details. ```yaml spring: security: oauth2: resourceserver: opaque: introspection-uri: ${mockwebserver.url}/introspect introspection-client-id: client introspection-client-secret: secret ``` -------------------------------- ### Configure Facebook OAuth2 client in application.yml Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/login/README.adoc Sets the OAuth2 client registration for Facebook in application.yml. The base property prefix is spring.security.oauth2.client.registration, and 'facebook' is the ClientRegistration ID. Replace client-id and client-secret with your OAuth 2.0 credentials. ```yaml spring: security: oauth2: client: registration: <1> facebook: <2> client-id: facebook-client-id client-secret: facebook-client-secret ``` -------------------------------- ### Configure application.yml for Spring Authorization Server Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/login/README.adoc Set the OAuth client and provider properties in application.yml to use Spring Authorization Server as the authentication provider. Replace client-id, client-secret, and the localhost URLs with your own credentials and domain. The openid scope is required for OpenID Connect 1.0 authentication. ```yaml spring: security: oauth2: client: registration: <1> login-client: <2> provider: spring <3> client-id: login-client client-secret: openid-connect client-authentication-method: client_secret_basic authorization-grant-type: authorization_code redirect-uri: http://127.0.0.1:8080/login/oauth2/code/login-client scope: openid,profile <4> client-name: Spring provider:<5> spring: authorization-uri: http://localhost:9000/oauth2/authorize token-uri: http://localhost:9000/oauth2/token jwk-set-uri: http://localhost:9000/oauth2/jwks issuer-uri: http://localhost:9000 ``` -------------------------------- ### Expected response phrase from Resource Server Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc The Resource Server returns this phrase after verifying the JWT with the Authorization Server. The 'subject' is the value of the 'sub' field in the JWT. ```bash Hello, subject! ``` -------------------------------- ### Default JWK set URI configuration in application.yml Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/jwe/README.adoc The default configuration points to the mock Authorization Server's JWK set endpoint. Change this property to use your own Authorization Server. ```yaml spring: security: oauth2: resourceserver: jwt: jwk-set-uri: ${mockwebserver.url}/.well-known/jwks.json ``` -------------------------------- ### Introspect token with curl Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/authorization-server/README.adoc Sends a POST request to the token introspection endpoint with the exported token. The response includes active status, audience, client_id, expiration, issuer, and scope. ```bash curl -X POST messaging-client:secret@localhost:9000/oauth2/introspect -d "token=$TOKEN" ``` -------------------------------- ### SamlExtensionUrlForwardingFilter class Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/saml-extension-urls/README.adoc A forwarding filter that maps SAML Extension URLs to Spring Security URLs. It has an order of -101 to run before the FilterChainProxy. ```java @Component @Order(-101) // To run before FilterChainProxy public class SamlExtensionUrlForwardingFilter extends OncePerRequestFilter { // ... } ```