Development GuideAuthentication

Authentication

Essencium supports three authentication methods:

  1. Local user database (username / password login) — always active
  2. External LDAP directory (username / password login) — optional
  3. External OAuth 2 provider (OpenID Connect flow) — optional

For an explanation of how each method works internally, see Security.

Configure LDAP

To enable LDAP login, activate the ldap Spring profile and configure the following variables in application-ldap.yaml:

Environment VariableExampleDescription
APP_AUTH_LDAP_ENABLEDtrueEnables LDAP login
APP_AUTH_LDAP_ALLOW_SIGNUPtrueAutomatically creates a user account on the first successful login
APP_AUTH_LDAP_URLldap://ldap.admin.frachtwerk.de:389/dc=user,dc=frachtwerk,dc=deLDAP URL including base path
APP_AUTH_LDAP_USER_SEARCH_BASEou=usersSub-path in which all users must be located
APP_AUTH_LDAP_USER_SEARCH_FILTER(mail={0})Filter used to look up users
APP_AUTH_LDAP_MANAGER_DNuid=service.fwfin,ou=services,ou=users,dc=user,dc=frachtwerk,dc=deBindDN account used to connect to the LDAP server
APP_AUTH_LDAP_MANAGER_PASSWORDsecretPassword for the BindDN account
APP_AUTH_LDAP_USER_FIRSTNAME_ATTRgivenNameLDAP attribute containing the user’s first name
APP_AUTH_LDAP_USER_LASTNAME_ATTRsnLDAP attribute containing the user’s last name
APP_AUTH_LDAP_USER_UPDATE_ROLEtrueAssigns application roles automatically on each login based on the first matching role mapping
APP_AUTH_LDAP_USER_ROLE_ATTRmemberOfLDAP attribute containing group membership
APP_AUTH_LDAP_ROLES_0_SRCcn=freelancer,ou=groups,dc=user,dc=frachtwerk,dc=deLDAP group for role mapping 0
APP_AUTH_LDAP_ROLES_0_DSTFREELANCERApplication role for role mapping 0
APP_AUTH_LDAP_ROLES_1_SRCcn=admin-fwfin,ou=groups,dc=user,dc=frachtwerk,dc=deLDAP group for role mapping 1
APP_AUTH_LDAP_ROLES_1_DSTADMINApplication role for role mapping 1

Configure OAuth 2

  1. Activate the OAuth 2 login by setting app.auth.oauth.enabled to true.

  2. (Optional) Set app.auth.oauth.allow-signup to true to automatically create a new user account on the first successful login via an external provider.

  3. Configure your OAuth provider using the spring.security.oauth2.client.* properties.

Here is an example configuration for application-oauth.yaml after activating the OAuth-Profile in application.yaml:

spring:
  security:
    oauth2:
      client:
        registration:
          fwoidc:
            client-id: frachtwerk-essencium-demo
            client-name: Frachtwerk Essencium App
            client-secret: sshhh
            scope: openid
            redirect-uri: http://localhost:8098/login/oauth2/code/fwoidc
            provider: fwoidc
            client-authentication-method: basic
            authorization-grant-type: authorization_code
 
        provider:
          fwoidc:
            authorization-uri: https://login.example.org/auth/realms/essencium/protocol/openid-connect/auth
            token-uri: https://login.example.org/auth/realms/essencium/protocol/openid-connect/token
            user-info-uri: https://login.example.org/auth/realms/essencium/protocol/openid-connect/userinfo
            jwk-set-uri: https://login.example.org/auth/realms/essencium/protocol/openid-connect/certs
            user-name-attribute: email
            user-info-authentication-method: header

Logging In

Username & password (local or LDAP)

Send a POST request to /auth/token with a JSON body:

{ "username": "your_user@example.com", "password": "your_password" }

On success, the response contains a JWT token:

{ "token": "<TOKEN_HERE>" }

OAuth 2

Given a configured provider named fwoidc:

  1. Open http://localhost:8098/oauth2/authorization/fwoidc in your browser — this redirects to the external authorization server.
  2. After successful login, you are redirected back to /?token=<TOKEN_HERE>. Copy the token from the URL query parameter.

Making Authenticated Requests

Include the JWT token in every API request (all routes under /v1/** require authentication) using either:

  • The Authorization header: Authorization: Bearer <TOKEN_HERE>
  • A query parameter: ?t=<TOKEN_HERE>

To get a new access token using your refresh token, call POST /auth/renew. This endpoint requires both:

  • The refreshToken cookie (set automatically after login)
  • The Authorization: Bearer <ACCESS_TOKEN> header (the current, possibly expired access token)

Invalidating a User’s Sessions

To immediately invalidate all active tokens for a user (for example, after a suspected account compromise), call:

POST /v1/users/{id}/terminate

This endpoint requires the USER_UPDATE right. It deletes all stored session tokens for that user, immediately invalidating all active access and refresh tokens. For details on how this mechanism works, see Security.