Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
Spring Security Samples
https://github.com/spring-projects/spring-security-samples
Admin
Tokens:
18,798
Snippets:
142
Trust Score:
9.7
Update:
1 year ago
Context
Chat
Benchmark
34.43
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Running Spring Boot LDAP Application with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/ldap/README.adoc Executes the Spring Boot LDAP sample application using Gradle's `bootRun` task. This command starts the embedded server, making the application available for HTTP requests and demonstrating the LDAP bind authentication setup. ```bash ./gradlew :servlet:spring-boot:java:ldap:bootRun ``` -------------------------------- ### Starting Spring Boot SAML2 Refreshable Metadata Application (Gradle) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/refreshable-metadata/README.adoc This command executes the Gradle `bootRun` task for the `refreshable-metadata` sample application. It starts the Spring Boot application, making it accessible, typically on `http://localhost:8080/`. This is the primary way to launch the sample. ```gradle ./gradlew :servlet:spring-boot:java:saml2:refreshable-metadata:bootRun ``` -------------------------------- ### Starting Spring Boot SAML 2.0 Sample Application with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/java-configuration/saml2/login/README.adoc This command starts the Spring Boot sample application for SAML 2.0 login. It uses the Gradle wrapper to execute the `bootRun` task for the `spring-security-samples-boot-saml2login` project, making the application accessible via HTTP. ```Gradle ./gradlew :spring-security-samples-boot-saml2login:bootRun ``` -------------------------------- ### Running Authorization Server with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/restclient/README.adoc This command starts the OAuth2 Authorization Server application using Gradle's `bootRun` task. It's a prerequisite for running the main RestClient sample, providing the necessary authentication services. ```bash ./gradlew bootRun ``` -------------------------------- ### Starting Sample Application - Bash Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/cas/login/README.adoc This Gradle command executes the Spring Boot application for the CAS login sample. It specifically targets the `bootRun` task within the `servlet:spring-boot:java:cas:login` module, starting the application and making it accessible for testing. ```bash ./gradlew :servlet:spring-boot:java:cas:login:bootRun ``` -------------------------------- ### Running OAuth2 RestClient Sample with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/restclient/README.adoc This command starts the main OAuth2 RestClient sample application using Gradle's `bootRun` task. This application demonstrates making protected resource requests. ```bash ./gradlew bootRun ``` -------------------------------- ### Example Credentials for SAML 2.0 IDP Login Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/java-configuration/saml2/login/README.adoc These are example credentials to be used when prompted by the Okta SAML 2.0 Identity Provider after being redirected from the sample application. They demonstrate the format for user and password input for testing purposes. ```Text User: testuser2@spring.security.saml Password: 12345678 ``` -------------------------------- ### Running Resource Server with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/restclient/README.adoc This command starts the OAuth2 Resource Server application using Gradle's `bootRun` task. This server hosts the protected resources that the RestClient sample will attempt to access. ```bash ./gradlew bootRun ``` -------------------------------- ### Running Spring Authorization Server with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This command starts the Spring Authorization Server application using Gradle. It's a prerequisite for running the Resource Server sample with the default configuration, providing the necessary OAuth 2.0 token issuance capabilities. ```bash ./gradlew bootRun ``` -------------------------------- ### Running Stand-alone Application with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/static/README.adoc This command starts the Spring Security OAuth 2.0 Resource Server sample as a stand-alone application using Spring Boot's `bootRun` task. It allows for manual testing and exploration of the secured service. ```bash ./gradlew bootRun ``` -------------------------------- ### Running Spring Boot Application with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This snippet provides the command to run the Spring Boot application using Gradle. Executing ./gradlew bootRun compiles the project and starts the embedded web server, making the resource server accessible for testing. ```bash ./gradlew bootRun ``` -------------------------------- ### Running the Spring Boot JWT Login Application (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/README.adoc This command executes the Spring Boot application for the JWT login sample using Gradle. It starts the embedded server, making the application accessible for API interactions. This is the first step to set up the environment. ```bash ./gradlew :servlet:spring-boot:java:jwt:login:bootRun ``` -------------------------------- ### Starting Local CAS Server - Bash Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/cas/login/README.adoc This command initiates a local CAS (Central Authentication Service) server using Docker Compose. It leverages the specified `docker-compose.yml` file to provision and run the necessary services for authentication, acting as a prerequisite for the sample application. ```bash docker-compose -f docker/cas/docker-compose.yml up ``` -------------------------------- ### Resource Server Response Example Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This is an example of the successful response from the Resource Server when a request is authorized. 'subject' is dynamically replaced by the value of the `sub` field from the JWT provided by the Authorization Server. ```bash Hello, subject! ``` -------------------------------- ### Running Spring Boot Application with Gradle (Java) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/observability/README.adoc This command uses the Gradle wrapper to execute the `bootRun` task, which starts the Spring Boot application. This is the primary method to launch the sample application for testing and interaction. ```java ./gradlew :bootRun ``` -------------------------------- ### Running Spring Authorization Server with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This command starts the Spring Authorization Server application using Gradle's `bootRun` task. It is a prerequisite for running the Resource Server sample with the default configuration, providing the necessary OAuth 2.0 token issuance capabilities. ```bash ./gradlew bootRun ``` -------------------------------- ### Running Spring Boot Authorization Server (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/authorization-server/README.adoc This command starts the OAuth 2.0 Authorization Server as a standalone Spring Boot application using Gradle. Once running, the server is available for issuing requests and testing its various OAuth 2.0 functionalities. ```bash ./gradlew bootRun ``` -------------------------------- ### Running OAuth 2.0 Resource Server with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This command starts the OAuth 2.0 Resource Server application using Gradle. It can be run as a standalone service and is designed to work with an Authorization Server to secure its endpoints using OAuth 2.0 Bearer Tokens. ```bash ./gradlew bootRun ``` -------------------------------- ### Resource Server Response for /message GET Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This is the expected response from the Resource Server when an authorized GET request is successfully made to the `/message` endpoint, indicating that the protected resource content has been retrieved. ```bash secret message ``` -------------------------------- ### Running Spring Boot Resource Server (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/authorization-server/README.adoc This command starts the associated resource server application as a standalone Spring Boot application using Gradle. This server is pre-configured to work seamlessly with the authorization server sample for end-to-end testing of protected resource access. ```bash ./gradlew bootRun ``` -------------------------------- ### Running Spring Boot Application with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This command executes the Spring Boot application using the Gradle wrapper. It starts the resource server, making it ready to accept authenticated requests and validate JWTs based on the configured JWK set URI. ```bash ./gradlew bootRun ``` -------------------------------- ### Making Authenticated GET Request to Message Endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This `curl` command sends a GET request to the Resource Server's `/message` endpoint, including the access token in the `Authorization` header. This demonstrates accessing a specific secured resource that requires the `message:read` scope. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080/message ``` -------------------------------- ### Starting Spring Boot SAML 2.0 Sample Application with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/saml-extension-federation/README.adoc This command executes the Spring Boot application for the SAML 2.0 extension federation sample using Gradle. It specifically targets the `bootRun` task within the `servlet:spring-boot:java:saml2:saml-extension-federation` project, initiating the application server. ```Shell ./gradlew :servlet:spring-boot:java:saml2:saml-extension-federation:bootRun ``` -------------------------------- ### Running Spring Boot Application Stand-alone Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc Starts the Spring Security OAuth 2.0 Resource Server sample application as a stand-alone service using Spring Boot's Gradle plugin. This command allows for manual testing and exploration of the secured endpoints with various token types. ```bash ./gradlew bootRun ``` -------------------------------- ### Querying Message Endpoint with Successful Authentication (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/observability/README.adoc This HTTPie command sends a GET request to the `/message` endpoint on `localhost:8080`, providing `user` and `password` for basic authentication. It demonstrates a successful authenticated request to an endpoint that requires valid credentials. ```bash http -a user:password :8080/message ``` -------------------------------- ### Making an Authenticated GET Request to Root Endpoint (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This snippet demonstrates how to make an authenticated GET request to the root endpoint (/) of the resource server. It first exports a JWT to an environment variable TOKEN and then uses curl to send a request with the Authorization header containing the bearer token. The expected output is "Hello, subject!", where subject is extracted from the JWT. ```bash export TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdWJqZWN0IiwiZXhwIjoyMTY0MjQ1ODgwLCJhdXRob3JpdGllcyI6WyJST0xFX1VTRVIiXSwianRpIjoiMDFkOThlZWEtNjc0MC00OGRlLTk4ODAtYzM5ZjgyMGZiNzVlIiwiY2xpZW50X2lkIjoibm9zY29wZXMiLCJzY29wZSI6WyJub25lIl19.VOzgGLOUuQ_R2Ur1Ke41VaobddhKgUZgto7Y3AGxst7SuxLQ4LgWwdSSDRx-jRvypjsCgYPbjAYLhn9nCbfwtCitkymUKUNKdebvVAI0y8YvliWTL5S-GiJD9dN8SSsXUla9A4xB_9Mt5JAlRpQotQSCLojVSKQmjhMpQWmYAlKVjnlImoRwQFPI4w3Ijn4G4EMTKWUYRfrD0-WNT9ZYWBeza6QgV6sraP7ToRB3eQLy2p04cU40X-RHLeYCsMBfxsMMh89CJff-9tn7VDKi1hAGc_Lp9yS9ZaItJuFJTjf8S_vsjVB1nBhvdS_6IED_m_fOU52KiGSO2qL6shxHvg curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` -------------------------------- ### Running Resource Server with Gradle (Default) Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This command starts the Resource Server application using Gradle's `bootRun` task. When run with default settings, it expects an external Authorization Server (like the Spring Authorization Server sample) to be running to verify OAuth 2.0 Bearer Tokens. ```bash ./gradlew bootRun ``` -------------------------------- ### Running Standalone Application with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/opaque/README.adoc This command starts the Spring Security OAuth 2.0 Resource Server sample as a standalone application using Spring Boot's 'bootRun' task via Gradle. It makes the service available for external requests. ```bash ./gradlew bootRun ``` -------------------------------- ### Making Authenticated GET Request to Root Endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This `curl` command sends a GET request to the Resource Server's root endpoint (`localhost:8080`), including the previously exported access token in the `Authorization` header as a Bearer token. This demonstrates accessing a secured resource. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` -------------------------------- ### Testing LDAP Bind Authentication with cURL Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/ldap/README.adoc Sends an authenticated HTTP GET request to the running LDAP sample application using cURL. It uses 'user:password' credentials to demonstrate successful bind authentication against the configured LDAP server and retrieves the welcome message. ```bash curl --user user:password localhost:8080 && echo ``` -------------------------------- ### Running Spring Boot Application with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/jwe/README.adoc This command starts the Spring Security OAuth 2.0 Resource Server application as a stand-alone service using Spring Boot's `bootRun` task. It allows for manual testing and exploration of the resource server's behavior with OAuth 2.0 Bearer Tokens. ```bash ./gradlew bootRun ``` -------------------------------- ### Running Compiled Spring Data AOT Sample Native Executable Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/aot/data/README.adoc After successful native compilation, this command runs the generated native executable. The application will start, typically exposing an HTTP endpoint for interaction, allowing users to query and manipulate data. ```bash ./build/native/nativeCompile/data ``` -------------------------------- ### Running Spring Security Sample with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/data/README.adoc This command executes the Spring Security sample application using Gradle's `bootRun` task, which typically starts a Spring Boot application. It's the initial step to make the application accessible for testing and observing its security features. ```Java ./gradlew :bootRun ``` -------------------------------- ### Running Spring Boot SAML 2.0 Sample Application via Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/saml-extension-urls/README.adoc This shell command executes the Spring Boot application for the SAML 2.0 sample using Gradle. The `:servlet:spring-boot:java:saml2:saml-extension-urls:bootRun` task starts the embedded server, making the application accessible for testing SAML 2.0 login and logout flows. ```Shell ./gradlew :servlet:spring-boot:java:saml2:saml-extension-urls:bootRun ``` -------------------------------- ### Running Spring Boot SAML 2.0 Login Sample with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/saml2/login/README.adoc This command executes the Spring Boot application for the SAML 2.0 login sample using Gradle. It starts the embedded server, making the application accessible, and is a common way to run Spring Boot projects from the command line. ```Shell ./gradlew :servlet:spring-boot:java:saml2:login:bootRun ``` -------------------------------- ### Making Authorized GET Request to /message Endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This `curl` command sends a GET request to the Resource Server's `/message` endpoint. It uses the previously obtained `Bearer` token in the `Authorization` header to access the protected resource, demonstrating access to a specific API endpoint. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080/message ``` -------------------------------- ### Making Authorized GET Request to Root Endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This `curl` command sends a GET request to the Resource Server's root endpoint (`localhost:8080`). It includes the `Authorization` header with the `Bearer` token, allowing the Resource Server to verify and authorize the request based on the provided access token. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` -------------------------------- ### Resource Server Response for Root Endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This is the expected response from the Resource Server when an authorized GET request is made to the root endpoint. `messaging-client` is the value of the `sub` (subject) claim from the JWT used for authorization. ```bash Hello, messaging-client! ``` -------------------------------- ### Running 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 This command starts the Resource Server application with the `test` Spring profile active, which enables an embedded mock Authorization Server. This configuration is useful for local development and testing without needing a separate Authorization Server instance. ```bash ./gradlew bootRun --args='--spring.profiles.active=test' ``` -------------------------------- ### Example Access Token Response Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This JSON object represents a typical response from the OAuth 2.0 token endpoint after a successful client credentials grant. It contains the `access_token` (a JWT), its `expires_in` duration, the granted `scope`, and the `token_type` (Bearer). ```json { "access_token": "eyJraWQiOiI4YWY4Zjc2Zi0zMTdkLTQxZmYtYWY5Yi1hZjg5NDg4ODM5YzciLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJtZXNzYWdpbmctY2xpZW50IiwiYXVkIjoibWVzc2FnaW5nLWNsaWVudCIsIm5iZiI6MTYyNzMzNDQ1MCwic2NvcGUiOlsibWVzc2FnZTpyZWFkIl0sImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo5MDAwIiwiZXhwIjoxNjI3MzM0NzUwLCJpYXQiOjE2MjczMzQ0NTAsImp0aSI6IjBiYjYwZjhkLWIzNjItNDk0MC05MGRmLWZhZDg4N2Q1Yzg1ZSJ9.O8dI67B_feRjOn6pJi5ctPJmUJCNpV77SC4OiWqmpa5UHvf4Ud6L6EFe9LKuPIRrEWi8rMdCdMBOPKQMXvxLoI3LMUPf7Yj973uvZN0E988MsKwhGwxyaa_Wam8wFlk8aQlN8SbW3cKdeH-nKloNMdwjfspovefX521mxouaMjmyXdIFrM5WZ15GZK69NIniACSatE-pc9TAjKYBDbC65jVt_zHEvDQbEkZulF2bjrGOZC8C3IbJWnlKgkcshrY44TtrGPyCp2gIS0TSUUsG00iSBBC8E8zPU-YdfaP8gB9_FwUwK9zfy_hU2Ykf2aU3eulpGDVLn2rCwFeK86Rw1w", "expires_in": 299, "scope": "message:read", "token_type": "Bearer" } ``` -------------------------------- ### Querying Secret Endpoint with Failed Authorization (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/observability/README.adoc This HTTPie command sends a GET request to the `/secret` endpoint using valid `user/password` credentials. It is intended to demonstrate a failed authorization scenario, where the authenticated user lacks the necessary permissions to access the specific `/secret` resource. ```bash http -a user:password :8080/secret ``` -------------------------------- ### Running Resource Server with Embedded Mock Authorization Server Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This command starts the Resource Server application using Gradle, explicitly activating the 'test' Spring profile. This profile configures the application to use an embedded mock Authorization Server, allowing standalone testing without an external Authorization Server instance. ```bash ./gradlew bootRun --args='--spring.profiles.active=test' ``` -------------------------------- ### Making cURL Request with JWT for tenantOne Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc Sends an HTTP GET request to the `/tenantOne` endpoint of the Resource Server, including the previously exported JWT in the `Authorization` header. This demonstrates how to access a JWT-secured endpoint and receive a personalized greeting. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080/tenantOne ``` -------------------------------- ### Access Token Response Example Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This JSON object represents a typical successful response from the Authorization Server's token endpoint. It contains the `access_token` (JWT), `expires_in` (token validity duration), `scope` granted, and `token_type` (Bearer). ```json { "access_token": "eyJraWQiOiI4YWY4Zjc2Zi0zMTdkLTQxZmYtYWY5Yi1hZjg5NDg4ODM5YzciLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJtZXNzYWdpbmctY2xpZW50IiwiYXVkIjoibWVzc2FnaW5nLWNsaWVudCIsIm5iZiI6MTYyNzMzNDQ1MCwic2NvcGUiOlsibWVzc2FnZTpyZWFkIl0sImlzcyI6Imh0dHA6XC9cL2xvY2FsaG9zdDo5MDAwIiwiZXhwIjoxNjI3MzM0NzUwLCJpYXQiOjE2MjczMzQ0NTAsImp0aSI6IjBiYjYwZjhkLWIzNjItNDk0MC05MGRmLWZhZDg4N2Q1Yzg1ZSJ9.O8dI67B_feRjOn6pJi5ctPJyUJCNpV77SC4OiWqmpa5UHvf4Ud6L6EFe9LKuPIRrEWi8rMdCdMBOPKQMXvxLoI3LMUPf7Yj973uvZN0E988MsKwhGwxyaa_Wam8wFlk8aQlN8SbW3cKdeH-nKloNMdwjfspovefX521mxouaMjmyXdIFrM5WZ15GZK69NIniACSatE-pc9TAjKYBDbC65jVt_zHEvDQbEkZulF2bjrGOZC8C3IbJWnlKgkcshrY44TtrGPyCp2gIS0TSUUsG00iSBBC8E8zPU-YdfaP8gB9_FwUwK9zfy_hU2Ykf2aU3eulpGDVLn2rCwFeK86Rw1w", "expires_in": 299, "scope": "message:read", "token_type": "Bearer" } ``` -------------------------------- ### Making cURL Request with Scoped JWT 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 Sends an HTTP GET request to the `/tenantOne/message` endpoint, utilizing a JWT that contains the `message:read` scope. This command demonstrates accessing a resource that requires specific scope-based authorization. ```bash curl -H "Authorization: Bearer ``` -------------------------------- ### Accessing Protected Resource with JWT Bearer Token (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/README.adoc This `curl` command sends a GET request to the root endpoint (`/`), including the previously obtained JWT in the `Authorization` header as a Bearer token. This demonstrates how to use the JWT to authenticate and access a protected resource, expecting a 'Hello, user!' response. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 && echo ``` -------------------------------- ### Accessing Root Endpoint with General JWT (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This `curl` command sends an HTTP GET request to `localhost:8080` with the previously set `TOKEN` in the `Authorization` header. It demonstrates accessing a basic protected resource. The expected response is 'Hello, subject!', where 'subject' is derived from the JWT's `sub` claim. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` -------------------------------- ### Making Authorized Request to Root Endpoint (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/static/README.adoc This `curl` command sends an HTTP GET request to the Resource Server's root endpoint (`localhost:8080`). It includes the previously exported JWT as a Bearer token in the `Authorization` header, allowing the server to verify and authorize the request. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` -------------------------------- ### Making Authenticated Request to Root Endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/opaque/README.adoc This 'curl' command sends an HTTP GET request to the Resource Server's root endpoint ('localhost:8080'), including the previously exported 'TOKEN' as an OAuth 2.0 Bearer token in the Authorization header. It expects a 'Hello, subject!' response. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` -------------------------------- ### Configuring OAuth 2.0 Client Registration in Spring Boot (YAML) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/login/README.adoc This YAML configuration defines the OAuth 2.0 client registration for a Spring Boot application, specifying details like client ID, secret, authentication method, grant type, redirect URI, and scopes. It also configures the Spring Authorization Server provider details, including authorization, token, and JWKS URIs. This setup enables the application to interact with an OAuth 2.0 or OpenID Connect provider. ```YAML spring: security: oauth2: client: registration: login-client: provider: spring 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 client-name: Spring provider: spring: authorization-uri: http://localhost:9000/oauth2/authorize token-uri: http://localhost:9000/oauth2/token jwk-set-uri: http://localhost:9000/oauth2/jwks ``` -------------------------------- ### Making an Authenticated GET Request to /message Endpoint (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This snippet illustrates how to perform an authenticated GET request to the /message endpoint. It sets a JWT with message:read scope to the TOKEN environment variable and then uses curl to access the endpoint. The expected response is "secret message", indicating successful access to the protected resource. ```bash export TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdWJqZWN0IiwiZXhwIjoyMTY0MjQ1NjQ4LCJhdXRob3JpdGllcyI6WyJST0xFX1VTRVIiXSwianRpIjoiY2I1ZGMwNDYtMDkyMi00ZGJmLWE5MzAtOGI2M2FhZTYzZjk2IiwiY2xpZW50X2lkIjoicmVhZGVyIiwic2NvcGUiOlsibWVzc2FnZTpyZWFkIl19.Pre2ksnMiOGYWQtuIgHB0i3uTnNzD0SMFM34iyQJHK5RLlSjge08s9qHdx6uv5cZ4gZm_cB1D6f4-fLx76bCblK6mVcabbR74w_eCdSBXNXuqG-HNrOYYmmx5iJtdwx5fXPmF8TyVzsq_LvRm_LN4lWNYquT4y36Tox2ZD3feYxXvHQ3XyZn9mVKnlzv-GCwkBohCR3yPow5uVmr04qh_al52VIwKMrvJBr44igr4fTZmzwRAZmQw5rZeyep0b4nsCjadNcndHtMtYKNVuG5zbDLsB7GGvilcI9TDDnUXtwthB_3iq32DAd9x8wJmJ5K8gmX6GjZFtYzKk_zEboXoQ curl -H "Authorization: Bearer $TOKEN" localhost:8080/message ``` -------------------------------- ### 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 This JSON array represents the messages retrieved when querying the application as the user 'luke'. It illustrates the effect of ACLs, showing that 'luke' can only access messages specifically addressed to him, demonstrating data isolation. ```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" } ] ``` -------------------------------- ### Running Integration Tests with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc This command executes the integration tests for the Resource Server sample using Gradle. By default, these tests interact with a mock Authorization Server instance configured via the 'test' profile, verifying token-based authorization. ```bash ./gradlew integrationTest ``` -------------------------------- ### Running Integration Tests with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/static/README.adoc This command executes the integration tests for the Spring Security OAuth 2.0 Resource Server sample using Gradle. It verifies the application's behavior with hard-coded tokens signed by a corresponding RSA private key against the configured public key. ```bash ./gradlew integrationTest ``` -------------------------------- ### Running Integration Tests with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/authorization-server/README.adoc This command executes the integration tests for the OAuth 2.0 Authorization Server sample using Gradle. The tests verify the token introspection endpoint functionality by making requests with the `client_credentials` grant type and `client_secret_basic` authentication. ```bash ./gradlew integrationTest ``` -------------------------------- ### Running Integration Tests with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/restclient/README.adoc This command executes the integration tests for the project using Gradle. It's a standard way to verify the application's functionality and interactions with external services. ```bash ./gradlew integrationTest ``` -------------------------------- ### Running Spring Data Sample with Gradle (Java) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/acl/README.adoc This command executes the Spring Data sample application using Gradle's 'bootRun' task. It initializes the application, making it accessible for querying and demonstrating the ACL-based security features. ```Java ./gradlew :bootRun ``` -------------------------------- ### Accessing Scoped Endpoint with JWT (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This `curl` command sends an HTTP GET request to `localhost:8080/message` using the `TOKEN` that includes the `message:read` scope. This demonstrates accessing a resource protected by specific OAuth2 scopes. The expected response is 'secret message'. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080/message ``` -------------------------------- ### Exporting New Access Token for Write Operations Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/hello-security/README.adoc Similar to the previous export, this command updates the `TOKEN` environment variable with the newly obtained access token that includes the `message:write` scope. This prepares the environment for subsequent write requests. ```bash export TOKEN=... ``` -------------------------------- ### Running Integration Tests with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/opaque/README.adoc This command executes the integration tests for the Spring Security OAuth 2.0 Resource Server sample using Gradle. It points to a mock Authorization Server by default, verifying token introspection and authorization. ```bash ./gradlew integrationTest ``` -------------------------------- ### Running Integration Tests with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This command executes the integration tests for the Resource Server application using Gradle. By default, these tests interact with a mock Authorization Server instance configured via the `test` profile, verifying token-based authorization. ```bash ./gradlew integrationTest ``` -------------------------------- ### Activating Spring Profiles with Gradle (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/restclient/README.adoc This command demonstrates how to activate a specific Spring profile (e.g., 'xyz') when running a Spring Boot application via Gradle. This allows for different configurations and behaviors based on the active profile. ```bash ./gradlew bootRun --args='--spring.profiles.active=xyz' ``` -------------------------------- ### Compiling Spring Data AOT Sample with Gradle Native Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/aot/data/README.adoc This command executes the Gradle `nativeCompile` task, which compiles the Spring Data AOT sample application into a native executable. This process leverages GraalVM to produce a standalone binary for improved startup time and reduced memory footprint. ```bash ./gradlew nativeCompile ``` -------------------------------- ### Running Integration Tests with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/jwe/README.adoc This command executes the integration tests for the Spring Security OAuth 2.0 Resource Server sample using Gradle. By default, these tests interact with a mock Authorization Server and use hard-coded JWE-encrypted tokens to verify resource access. ```bash ./gradlew integrationTest ``` -------------------------------- ### Exporting First Sample JWE Token for Testing Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/jwe/README.adoc This command exports a sample JWE-encrypted token to the `TOKEN` environment variable. This token can then be used in subsequent `curl` requests to authenticate against the running Resource Server, demonstrating access to the default endpoint. ```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 ``` -------------------------------- ### Making Authenticated Request to Default Endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/jwe/README.adoc This `curl` command sends an HTTP GET request to the Resource Server's default endpoint (`localhost:8080`), including the previously exported JWE token in the `Authorization` header. It demonstrates how a client can access a protected resource using a Bearer token. ```bash curl -H "Authorization: Bearer $TOKEN" localhost:8080 ``` -------------------------------- ### Exporting Second Sample JWE Token for Testing Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/jwe/README.adoc This command exports a second sample JWE-encrypted token to the `TOKEN` environment variable. This token is configured to grant access to the `/message` endpoint, demonstrating fine-grained authorization based on token scopes or attributes. ```bash export TOKEN=eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAtMjU2In0.CRBAEgvQhpB6pPQhpkTAKpsDai1FDcvkDSRig1R3OI-g18JdTe-qDhzWwP-hV3aCwFwHxQ_g8Z8OIZvhyKpQaPwBb72UeLqqhzSIkm0gEsmmjYg1vEGOrDH5_Fqlm0LnAnXTmsbOIWYIj11ZuenI2lEmMCkVwqth0RlzakdcHRXiuDTEln_trhZpE2j80X-9rS2gZy9Raa9VLir3-F3wC0GKPEL6e3x1OygC03ix9uyXS3vpTsU9zlgoYADZyaLeOF1mCG4mQhvXs7IPpPbwNsElJwKh0xSQCHvNOQShprlvd3cHiUFKYw9fXphY1O-AUYcRzHk4DjoBdkGNQMy_Kw.KtC_z674rYBtDgkN.e8QU50Iq1JHkn-1USSxpjEkbrukb4cobvlQRK40iXGAKVIuOod4bSq5fDpIAPHugqIf-_zGsvr-2OCOdzhtBikL46wU7UdZppxPWtk-X6kl33zH_XObRMaGfe-hLxt3RPxRVn7I1Hp6tGW1Rkxyf_ESq4XlcbbrkhDoIz_G_LKXJhvQ-xahW2e0AUc7RZSucns4XUeq9xX_dd7Ht-o1TmQI9WFoFc1l7oh9GtQ6GZMsghnZ1VrbIS2L7jSYiSsD2JqSv1LLtOGj_FBA0ufhqM3LloGiwflEwAryMD10oNb73WonKEycEj1rBsTIKW7SHkI-VkrQA4-8N-aLWgHwDnzyPZmyNyKpqUMvhjIE_0w6oqU4HpN7J5nfBEIAtpPZ_pDkwAdxCQ7JV3zfiUnF7ZQ3q1PnSId315si02ZN9-wRSrMHcHnboQN1Hs4xCAfGyClVyLpCzfa_fAehjt6v1DjgjbzwSjr_LdNmWTvXYBhNO8J9Vb7axksrdwksD3pYNMY8cRZxP-LO0V5Sv1_kT_Hf2yLo2iTwB8n8szzGrJ4QQLb5Znu7Sv-M2x52cnIDMiorP3LNpFk.G85FuMSm-8bGumFAStiFQA curl -H "Authorization: Bearer $TOKEN" localhost:8080/message ``` -------------------------------- ### Running Integration Tests with Gradle Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/README.adoc Executes the integration tests for the Spring Security OAuth 2.0 Resource Server sample using Gradle. These tests validate the Resource Server's behavior with a mock Authorization Server, utilizing pre-configured JWT and opaque tokens to simulate various authorization flows. ```bash ./gradlew integrationTest ``` -------------------------------- ### Exporting Access Token for Resource Server Access (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/authorization-server/README.adoc This command exports the access token obtained for the resource server into an environment variable named `TOKEN`. This allows the token to be easily included in the `Authorization` header for subsequent requests to the resource server. ```bash export TOKEN=... ``` -------------------------------- ### Setting Java Version with SDKMan! for Spring Data AOT Sample Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/aot/data/README.adoc This command demonstrates how to use SDKMan! to switch to the specific Java version (23.0.5.r17-nik) required for compiling the Spring Data AOT sample project. This ensures compatibility and successful native compilation. ```bash sdk use java 23.0.5.r17-nik ``` -------------------------------- ### Setting JWT Token for Basic Access (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/static/README.adoc This command sets an environment variable `TOKEN` with a pre-configured JWT. This token is signed with an RSA private key and contains a 'subject' claim, enabling access to the default endpoint of the Resource Server. ```bash export TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdWJqZWN0IiwiaWF0IjoxNTE2MjM5MDIyfQ.eB2c9xtg5wcCZxZ-o-sH4Mx1JGkqAZwH4_WS0UcDbj_nen0NPBj6CqOEPhr_LZDagb4mM6HoAPJywWWG8b_Ylnn5r2gWDnZib2mb0kxIuAjnvVBrpzusw4ItTVvP_srv2DrwcisKYiKqU5X_3ka7MSVvKtswdLY3RXeCJ_S2W9go ``` -------------------------------- ### Exporting Obtained JWT to Environment Variable (Bash) Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/jwt/login/README.adoc This `bash` command first makes a POST request to the `/token` endpoint to obtain a JWT, similar to the previous step. It then captures the returned token and assigns it to an environment variable named `TOKEN`, making it easily reusable for subsequent authenticated requests. ```bash export TOKEN=`curl -XPOST user:password@localhost:8080/token` ``` -------------------------------- ### Running Application After Configuration Changes Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/opaque/README.adoc This command restarts the Spring Security OAuth 2.0 Resource Server application using Gradle's 'bootRun' task, applying any changes made to the 'application.yml' for custom Authorization Server integration. A valid token from the configured Authorization Server is required for access. ```bash ./gradlew bootRun ``` -------------------------------- ### Making Authenticated Request to Message Endpoint Source: https://github.com/spring-projects/spring-security-samples/blob/main/servlet/spring-boot/java/oauth2/resource-server/opaque/README.adoc This snippet first sets a new opaque bearer token and then uses 'curl' to make an authenticated HTTP GET request to the '/message' endpoint of the Resource Server. This endpoint typically requires a specific scope (e.g., 'message:read') for the token to be authorized. ```bash export TOKEN=b43d1500-c405-4dc9-b9c9-6cfd966c34c9 curl -H "Authorization: Bearer $TOKEN" localhost:8080/message ``` -------------------------------- ### Exporting JWT for tenantOne Authorization 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` with a sample JWT for `tenantOne`, demonstrating a typical token structure. This token is then used in subsequent `curl` commands to authorize access to the Resource Server's JWT-secured endpoints. ```bash export TOKEN=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJzdWJqZWN0IiwiZXhwIjo0NjgzODA1MTI4fQ.ULEPdHG-MK5GlrTQMhgqcyug2brTIZaJIrahUeq9zaiwUSdW83fJ7W1IDd2Z3n4a25JY2uhEcoV95lMfccHR6y_2DLrNvfta22SumY9PEDF2pido54LXG6edIGgarnUbJdR4rpRe_5oRGVa8gDx8FnuZsNv6StSZHAzw5OsuevSTJ1UbJm4UfX3wiahFOQ2OI6G-r5TB2rQNdiPHuNyzG5yznUqRIZ7-GCoMqHMaC-1epKxiX8gYXRROuUYTtcMNa86wh7OVDmvwVmFioRcR58UWBRoO1XQexTtOQq_t8KYsrPZhb9gkyW8x2bAQF-d0J0EJY8JslaH6n4RBaZISww ``` -------------------------------- ### Exporting Access Token to Environment Variable Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This command sets an environment variable `TOKEN` with the obtained access token. This allows subsequent `curl` commands to easily reference the token for authorization headers without manually copying the long token string. ```bash export TOKEN=... ``` -------------------------------- ### Exporting Access Token to Environment Variable (Write Scope) Source: https://github.com/spring-projects/spring-security-samples/blob/main/reactive/webflux/java/oauth2/resource-server/README.adoc This command updates the `TOKEN` environment variable with the newly obtained access token that includes the `message:write` scope. This ensures subsequent requests use the token with appropriate permissions for write operations. ```bash export TOKEN=... ```