Skip to content

Latest commit

 

History

History

security

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

EHRbase security documentation

This page describes how to set up different security mechanisms in EHRbase and also provides some basic information on how to configure your external security servers.

Table of contents

Introduction

The EHRbase Spring-Boot application can be configured to use different security mechanisms. They are used to allow access to all resources only to authenticated users to protect stored data from unauthenticated access.

A basic role system also defines permissions on different resources, e.g. the additional admin endpoints are only accessible by users with the role admin configured.

By default EHRbase is started without security enabled (NONE) which will be reported by a message during boot.

To enable authentication start the EHRbase application with environment variable AUTH_TYPE set to the appropriate value or set the necessary data at one of the .yml files inside {projectRoot}/application/src/main/resources/.

Supported security mechanisms

  • None
  • Basic auth
  • Oauth2

Basic Auth

The basic auth mechanism uses a predefined set of users and roles that will be configured during start of EHRbase by setting the data inside the environment variables or inside the .yml file as follows:

ENV .yml Value to set Default
SECURITY_AUTHTYPE security.authType BASIC NONE
SECURITY_AUTHUSER security.authUser your username ehrbase-user
SECURITY_AUTHPASSWORD security.authPassword Your password SuperSecretPassword
SECURITY_AUTHADMINUSER security.authAdminUser Your admin username ehrbase-admin
SECURITY_AUTHADMINPASSWORD security.authAdminPassword Your admin password EvenMoreSecretPassword

To access a resource from a client generate the Base64 encoded string of {username}:{password} and add it in the Authorization header with Basic {Base64 encoded string}.

OAuth2

OAuth2 uses an external authentication server realm to authenticate a user and provide additional information about the role of each user.

To start EHRbase with OAuth2 support and configure the external server use one of the following configuration methods:

ENV .yml Value to set Default
SECURITY_AUTHTYPE security.authType OAUTH NONE
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUERURI spring.security.oauth2.resourceserver.jwt.issuer-uri Your realm base url https://localhost:8081/auth/realms/ehrbase

The realm, client and all other settings must be done inside the corresponding authentication server. A basic example on how to do this with Keycloak from JBoss can be found in the appendix of this page.

The clients must be implemented / configured to use the external authentication server as well. There are multiple libraries for many frameworks available that can be used for this.

An example on how to use Postman with OAuth2 and Keycloak is available in the appendix of this page as well.

Appendix

Keycloak with EHRbase

Keycloak is an OpenID Connect capable identity and access management server that has been tested with EHRbase. To get more information about this open source project go to https://www.keycloak.org/

In our examples we assume that you configured the Keycloak server at https://localhost:8081 and a realm named ehrbase. Change the example data as needed by your configuration.

Setup for EHRbase

Step 1: Open the Keycloak interface and create a new Realm named ehrbase

Image with add realm button in keycloak

Step 2: Enter the realm name

Image of add realm dialog

Step 3: Switch to Clients and hit the create button

Image of client section with create button

Step 4: Enter the client identifier

Image of client create dialog

In this example we are creating a client for postman. You can add multiple clients for each application that you want to add and share identification information with.

Step 5: Set basic client data

Image of new created client dialog tab

Ensure that you set Access Type to public and add a Valid Redirect URL entry for each EHRbase host you want to secure with the client. We have only one thus we set it to https://localhost:8080/*

Step 6: Navigate to Mappers and create new mapper

Image of create new mapper button

Mappers are used to map the role information into the JWT that is used on the server to identify the user

Step 7: Enter name for new Mapper

Image of new created mapper dialog tab

The name is only used inside Keycloak to identify this mapper. You can use a name as you want. Ensure that the other values match the settings in the screenshot.

Step 8: Navigate to Roles and add a new role

Image of add role button

Step 9: Enter the name for user and admin roles

Image of add new role dialog

Do not use capital letters in role names since some clients are case-sensitive with the role name

Step 10: Navigate to users and create users as required

Image of create user button

Step 11: Enter user name

Image of create new user dialog

Step 12: Set credentials for the new user

Image of credentials dialog

Ensure the password is entered twice and Temporary is set to Off.

After hitting Set Password an alert will open. Confirm the setting of the password.

Step 13: Assign roles for the user

Image of role mappings for user

You can assign multiple roles to each user as you need. Each time you assign or remove a role from a user the settings will be saved immediately.

Conclusion

You can add mutliple users for EHRbase as you need. For development purposes it is also imaginable that you only add a user with an user and an admin role. For production environments it is strictly recommended to use secure passwords and separate users for each role.

Postman for Keycloak (OpenID Connect)

To use the EHRbase with the API develeopment tool Post you can use this instruction.

We assume that you set up the Keycloak as in the appendix for this howto.

Step 1: Open Authorization tab of Collection/Folder/Request

Image of Postman Collection Authorization tab

Step 2: Enter data of your Keycloak server

Image of Postman Oauth2 dialog

You can set a different name of the token to identify it later in Postman.

To get the URLs for Auth URL and Access Token URL you can open the following URL on your system with the running Keycloak server: {https://localhost:8081}/auth/realms/{ehrbase}/.well-known/openid-configuration. Adopt the name for your realm and the hostname:port as you configured it on your system.

Step 3: Hit Request Token and enter user credentials

Image of Keycloak login screen

Step 4: Hit Use Token

Image of succeeded token getting dialog

Step 5: Save and use the credentials