Skip to content

Latest commit

 

History

History
105 lines (68 loc) · 3.49 KB

File metadata and controls

105 lines (68 loc) · 3.49 KB

service-springboot-rest: SpringBoot REST Service

Level: Beginner Technologies: SpringBoot Summary: SpringBoot REST Service Target Product: Red Hat SSO Source: https://github.com/redhat-developer/redhat-sso-quickstarts

What is it?

The service-springboot-rest quickstart demonstrates how to write a RESTful service with SpringBoot that is secured with Red Hat SSO.

There are 2 endpoints exposed by the service:

  • public - requires no authentication
  • products - can be invoked by users with the user role and returns a list of products

System Requirements

All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Maven 3.1.1 or later.

Configuration in Red Hat SSO

Prior to running the quickstart you need to create a client in Red Hat SSO and download the installation file.

The following steps shows how to create the client required for this quickstart:

  • Open the Red Hat SSO admin console
  • Select Clients from the menu
  • Click Create
  • Add the following values:
    • Client ID: You choose (for example service-springboot)
    • Client Protocol: openid-connect
  • Click Save

Once saved you need to change the Access Type to bearer-only and click save.

Finally you need to update the adapter using SpringBoot's configuration file (application.properties). If you followed the steps above it should be:

server.compression.enabled: true
server.compression.min-response-size: 1
server.connection-timeout=5000
server.port = 8081
keycloak.realm=springboot-quickstart
keycloak.auth-server-url=http://localhost:8180/auth
keycloak.ssl-required=external
keycloak.resource=service-springboot
keycloak.public-client=true
keycloak.bearer-only=true
keycloak.securityConstraints[0].securityCollections[0].name = protected resource
keycloak.securityConstraints[0].authRoles[0] = user
keycloak.securityConstraints[0].securityCollections[0].patterns[0] = /products

Build and Run the Quickstart

  1. Open a terminal and navigate to the root directory of this quickstart.

  2. The following shows the command to deploy the quickstart:

    mvn spring-boot:run
    
    

Access the Quickstart

The endpoints for the service are:

You can open the public endpoint directly in the browser to test the service. The other endpoint require invoking with a bearer token. To invoke these endpoints use one of the example quickstarts:

  • app-springboot - SpringBoot application that invokes the example service. Requires service example to be deployed.
  • app-jee-html5 - HTML5 application that invokes the example service. Requires service example to be deployed.
  • app-jee-jsp - JSP application packaged that invokes the example service. Requires service example to be deployed.

Integration test of the Quickstart

  1. Make sure you have an Red Hat SSO server running with an admin user in the master realm or use the provided docker image
  2. Be sure to set the TestHelper.keycloakBaseUrl in the createArchive method (default URL is localhost:8180/auth).
  3. Set accordingly the correct url for the keycloak.auth-server-url in the test application.properties.
  4. Run mvn test -Pspring-boot