Skip to main content

Security

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.

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.ymlValue to setDefault
SECURITY_AUTHTYPEsecurity.authTypeBASICNONE
SECURITY_AUTHUSERsecurity.authUseryour usernameehrbase-user
SECURITY_AUTHPASSWORDsecurity.authPasswordYour passwordSuperSecretPassword
SECURITY_AUTHADMINUSERsecurity.authAdminUserYour admin usernameehrbase-admin
SECURITY_AUTHADMINPASSWORDsecurity.authAdminPasswordYour admin passwordEvenMoreSecretPassword

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.ymlValue to setDefault
SECURITY_AUTHTYPEsecurity.authTypeOAUTHNONE
SECURITY_OAUTH2USERROLEsecurity.oauth2UserRoleDesired user role nameUSER
SECURITY_OAUTH2ADMINROLEsecurity.oauth2AdminRoleDesired admin role nameADMIN
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUERURIspring.security.oauth2.resourceserver.jwt.issuer-uriYour realm base urlhttp://localhost:8081/auth/realms/ehrbase

The realm, client and all other settings must be done inside the corresponding authentication server. The user and admin role names are configurable, enabling compatibility with authentication servers which are opinionated on the names of custom OAuth roles or scopes. EHRBase will look for the admin/user role in the realm_access.roles and scope claims of the JWT provided on an authenticated request.

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.

Management

Access to the management(actuator) endpoints can be configured through the management.endpoints.web.access property (supported values: ADMIN_ONLY, PRIVATE, PUBLIC, default: ADMIN_ONLY).

In addition, write-access to all management endpoints is protected against CSRF by default. This protection can be disabled using ehrbase.security.management.endpoints.web.csrf-validation-enabled=false.

All EHRbase management configurations:

ENV.ymlDefault
MANAGEMENT_ENDPOINT_WEB_ACCESSmanagement.endpoints.web.accessADMIN_ONLY
EHRBASE_SECURITY_MANAGEMENT_ENDPOINTS_WEB_CSRFVALIDATIONENABLEDehrbase.security.management.endpoints.web.csrf-validation-enabledtrue