CL-HTTP Chapter 8: Authentication and Access Control


Reference Manual | Prev: Chapter 7. HTML Generation | Next: Chapter 9. Data Caching and Performance


Contents

  1. 8.1 Overview
  2. 8.2 Subnet-Based Access Control
  3. 8.3 Basic Authentication
  4. 8.4 Digest Authentication
  5. 8.5 X.509 Certificate Authentication
  6. 8.6 Managing Users and Groups
  7. 8.7 Web-Based Administration
  8. 8.8 Examples

8.1 Overview

CL-HTTP provides a comprehensive, object-oriented authentication and access control system that governs who can access which URLs and what HTTP methods they may invoke. The system is built around five core concepts:

Realms
A realm defines an authentication space governed by a single authentication scheme (basic, digest, or certificate). All users, groups, and access controls belong to exactly one realm. Because no elements are shared across realms and each realm uses a single scheme, security cannot be compromised by elements using a weaker scheme. Realms are represented by CLOS classes descended from http:realm.
Users
A user object contains a username, personal name, email address, and a password digest specific to the realm's authentication scheme. Users belong to one realm and to zero or more groups within that realm. Users are represented by classes descended from http:user.
Groups
Groups aggregate users (and other groups) into named entities that can be authorized to access specific resources. Groups support hierarchical nesting via superior and inferior relationships. Groups are represented by classes descended from http:group.
Access Controls
An access control object aggregates users and groups and specifies which HTTP methods they may invoke on a URL. Access controls are linked to URLs and govern all accesses after a client has passed any IP address restrictions. They are represented by classes descended from http:access-control.
Capabilities
A capability alist relates HTTP methods to groups and users. Each entry has the form (METHOD &rest GROUPS-AND-USERS), where METHOD is an HTTP method keyword (:GET, :HEAD, :POST, :PUT, :DELETE, :OPTIONS, :TRACE) or :DEFAULT. Groups are specified by keyword, users by string.

CL-HTTP provides two independent mechanisms for controlling access:

Both mechanisms can be combined for defense in depth. For example, digest authentication can be restricted to clients on trusted subnets, providing both identity verification and network-level filtering.

8.1.1 Authentication Schemes

The authentication scheme is determined by the realm type. CL-HTTP supports the following schemes:

Scheme KeywordRealm ClassSecurity Level
:basic basic-realm Weak — Base64 encoding only. Useful because it is universally deployed in clients, but provides no cryptographic security.
:digest digest-realm Moderate — MD5 hash. Cracked and deemed insecure since 2004. Use :digest-sha-256 instead.
:digest-sha digest-sha-realm Moderate — SHA-1 160-bit hash. NIST recommended phase-out in 2010.
:digest-sha-256 digest-sha-256-realm Strong — SHA-256. Recommended for all new digest authentication.
:digest-sha-384 digest-sha-384-realm Strong — SHA-384.
:digest-sha-512 digest-sha-512-realm Strong — SHA-512.
:certificate certificate-realm Strong — X.509 client certificates via SSL/TLS. Requires :cl-http-ssl-client feature.

The scheme-to-class mapping is maintained in http:*realm-scheme-class-alist* and can be extended via http:add-realm-scheme to register application-specific realm classes.

8.1.2 Class Hierarchy

Each authentication scheme defines a complete set of CLOS classes for its realm, users, groups, and access controls. The class hierarchy uses mixins to separate mechanism from policy:

realm
  standard-realm
    basic-realm          ; :basic scheme
    digest-realm         ; :digest (MD5) scheme
    digest-sha-realm     ; :digest-sha (SHA-1) scheme
    digest-sha-256-realm ; :digest-sha-256 scheme
    digest-sha-384-realm ; :digest-sha-384 scheme
    digest-sha-512-realm ; :digest-sha-512 scheme
    certificate-realm    ; :certificate scheme

user
  standard-user
    basic-user
    digest-user
    certificate-user

group
  standard-group
    basic-group
    digest-group
    certificate-group

access-control
  standard-access-control
    basic-access-control
    digest-access-control
    certificate-access-control
  standard-url-access-control
    basic-url-access-control
    digest-url-access-control
    certificate-url-access-control

When a realm is created, it automatically uses the correct user, group, and access control classes for its scheme. For example, a basic-realm creates basic-user, basic-group, and basic-access-control objects. The class selection is controlled by the class-allocated slots realm-user-class, realm-group-class, and realm-access-control-class.

8.2 Subnet-Based Access Control

Subnet-based access control restricts URL access based on the client's IP address. It operates independently of user authentication and is evaluated first — a client must pass subnet restrictions before any password challenge is issued.

8.2.1 Global Secure Subnets

The variable http:*secure-subnets* holds a list of trusted subnet specifications. When set, it provides a global default for all URLs that do not specify their own subnet restrictions.

;; Trust only the local class C subnet
(setq http:*secure-subnets* '("192.168.1.0"))

;; Trust multiple subnets
(setq http:*secure-subnets* '("192.168.1.0" "10.0.0.0"))

In subnet specifications, a zero component acts as a wildcard. For example, "192.168.0.0" matches any address starting with 192.168.

8.2.2 Per-URL Subnet Restrictions

The :secure-subnets keyword on http:export-url restricts read access (GET, HEAD) to clients on specified subnets:

;; Only allow access from the local network
(http:export-url #u"/cl-http/sources/server/"
                 :directory
                 :pathname "http:server;"
                 :recursive-p t
                 :secure-subnets '("192.168.1.0")
                 :keywords '(:cl-http :documentation))

For finer control over read vs. write access, use :read-subnets and :write-subnets separately:

;; Allow anyone to read, but only the local host can write
(http:export-url #u"/cl-http/users/"
                 :directory
                 :pathname "http:www;cl-http;users;"
                 :recursive-p t
                 :read-subnets nil        ; no read restriction
                 :write-subnets (list (http:local-host-ip-address))
                 :keywords '(:cl-http :documentation))

8.2.3 Restricting to the Local Host

A common pattern restricts access to the machine running the server:

;; Only accessible from localhost
(http:export-url #u"/cl-http/maintenance/configure-server.html"
                 :computed
                 :response-function #'write-configure-server-form
                 :secure-subnets (list (http:local-host-ip-address))
                 :private t
                 :proxy-revalidate t)

8.2.4 Subnet Match Predicate

The predicate http:ip-subnet-match-p tests whether a host address falls within a given subnet list. It replaces the older name ip-host-trusted-p; the meaning is unchanged. A NIL subnet list now signals an error rather than returning silently — callers must pass an explicit list of allowed subnets (or use http:*secure-subnets* as a fallback). http:trusted-host-p consults the global secure-subnets list and respects this stricter contract.

;; Permit one /24 plus the local host
(http:ip-subnet-match-p (http:client-host *client*)
                        (list "192.168.1.0/24"
                              (http:local-host-ip-address)))

8.3 Basic Authentication

Basic authentication (RFC 2617) is the simplest HTTP authentication scheme. The client sends the username and password encoded in Base64. Because Base64 is trivially reversible, basic authentication provides no cryptographic security. It is useful only because it is universally supported by web clients.

Security note: Basic authentication should be combined with subnet security or used only over SSL/TLS connections. On its own, it merely keeps honest people honest.

8.3.1 Setting Up Basic Authentication

The setup sequence is: create a realm, create groups, add users to groups, define access controls, then export URLs with authentication.

Step 1: Create a realm.

;; Create a basic authentication realm
(http:add-realm :my-realm :basic)

Step 2: Create groups within the realm. Groups must exist before users are assigned to them.

;; Create multiple groups at once
(http:add-groups :my-realm :users :administrators)

;; Or one at a time
(http:add-group :my-realm :users)

Step 3: Add users with passwords and group memberships.

(http:add-user "alice" :my-realm
               :password "alice-secret"
               :groups '(:users)
               :personal-name "Alice Johnson"
               :email-address "alice@example.com")

(http:add-user "bob" :my-realm
               :password "bob-secret"
               :groups '(:users :administrators)
               :personal-name "Bob Smith"
               :email-address "bob@example.com")

Step 4: Define access control groups (capabilities).

;; Give :administrators full access, :users read access
(http:add-access-control-group :admin-access
                               :my-realm
                               :capabilities '((:get :users)
                                               (:head :users)
                                               (:default :administrators)))

Step 5: Export URLs with authentication.

;; Any user in the realm can access this URL
(http:export-url #u"/protected/public.html"
                 :computed
                 :response-function #'write-protected-page
                 :authentication-realm :my-realm
                 :capabilities nil   ; nil = any user in the realm
                 :private t
                 :proxy-revalidate t)

;; Only users matching :admin-access capabilities
(http:export-url #u"/protected/admin.html"
                 :computed
                 :response-function #'write-admin-page
                 :authentication-realm :my-realm
                 :capabilities :admin-access
                 :private t
                 :proxy-revalidate t)

8.3.2 Inline Capabilities

Instead of pre-defining an access control group with add-access-control-group, you can pass a capability alist directly to :capabilities:

;; Inline capability alist — system-hackers do everything
(http:export-url #u"/admin/system.html"
                 :computed
                 :response-function #'write-system-page
                 :authentication-realm :system-admin
                 :capabilities '((:default :system-hackers))
                 :private t
                 :proxy-revalidate t)

8.4 Digest Authentication

Digest authentication (RFC 2069, RFC 2617) is significantly stronger than basic authentication. Instead of sending the password, the client sends a one-way hash (digest) of the username, password, realm, nonce, and request URI. The server verifies the digest against its stored password digest. Replay attacks are prevented for different URLs and different IP addresses.

Important: MD5 and SHA-1 are considered insecure. All new applications should use SHA-256 as the digest algorithm by specifying :digest-sha-256 as the realm scheme.

8.4.1 Setting Up Digest Authentication

;; Create a digest realm using SHA-256
(http:add-realm :secure-realm :digest-sha-256)

;; Create groups
(http:add-groups :secure-realm :members :elite-members)

;; Add users
(http:add-user "mike" :secure-realm
               :password "mike-secret"
               :groups '(:members)
               :personal-name "Mike Smith"
               :email-address "mike@example.com")

(http:add-user "joe" :secure-realm
               :password "joe-secret"
               :groups '(:members :elite-members)
               :personal-name "Joe Doe"
               :email-address "joe@example.com")

;; Define capabilities for elite members
(http:add-access-control-group :elite-access
                               :secure-realm
                               :capabilities '((:get :elite-members)
                                               (:head :elite-members)))

;; Export URL accessible to any realm member
(http:export-url #u"/secure/members.html"
                 :computed
                 :response-function #'write-members-page
                 :authentication-realm :secure-realm
                 :capabilities nil
                 :private t
                 :proxy-revalidate t)

;; Export URL accessible only to elite members
(http:export-url #u"/secure/elite.html"
                 :computed
                 :response-function #'write-elite-page
                 :authentication-realm :secure-realm
                 :capabilities :elite-access
                 :private t
                 :proxy-revalidate t)

8.4.2 Nonce Management

Digest authentication uses nonces (numbers used once) to prevent replay attacks. The nonce encodes a time window during which it remains valid. The variable http:*digest-authentication-nonce-life-time* controls this window in seconds. A shorter window reduces the replay attack window but causes more frequent re-authentication challenges.

Combining digest authentication with subnet security and a short nonce lifetime provides reasonable access control for sensitive resources.

8.4.3 Initial Server Setup for Digest Authentication

When first setting up a server with digest authentication, perform these one-time initializations:

  1. Seed the random number generator. Evaluate the form (http:digest-authentication-random-seed t) sixteen times manually. The time variability of manual evaluation increases randomness of the seed, making digest authentication passwords more secure.
  2. Set the Webmaster password. The built-in :server realm (digest authentication) has a Webmaster account for web-based server maintenance:
    (http:save-authentication-object
      (http:intern-user :server "Webmaster"
                        :personal-name "Common Lisp Wizard"
                        :password "your-secret-password"
                        :email-address "admin@your-host.example.com"))
    

    Security note: Never set this password over the network. The password travels in clear text during assignment. Set passwords for digest-authenticated realms only from the server console.

  3. Secure the password directory. The directory HTTP:PW; stores serialized authentication data. For maximum security, this directory should reside on the same machine as the server and be protected by file system permissions.

8.4.4 Available Digest Algorithms

The digest algorithm is selected by the realm's scheme keyword:

SchemeAlgorithmDigest SizeStatus
:digest / :md5MD5128 bitsInsecure since 2004
:digest-shaSHA-1160 bitsPhase-out recommended
:digest-sha-256SHA-256256 bitsRecommended
:digest-sha-384SHA-384384 bitsSecure
:digest-sha-512SHA-512512 bitsSecure

8.5 X.509 Certificate Authentication

Certificate authentication uses X.509 client certificates presented during SSL/TLS handshake. This is the strongest authentication method available, as it relies on public key cryptography rather than passwords. Certificate authentication requires the :cl-http-ssl-client feature to be active.

8.5.1 Defining a Certificate Realm

Certificate realms are defined with http:define-certificate-realm, which specifies the acceptable certificate authorities, key sizes, cryptographic algorithms, cipher suites, and SSL versions:

(http:define-certificate-realm :client-cert-realm
  (:key-size 2048
   :algorithms '(:rsa :dsa)
   :verify-modes '(:always))
  :verisign :thawte :digicert)

The parameters control which client certificates are acceptable:

:key-size
Minimum acceptable public key size in bits. Default is 1024; production systems should require at least 2048.
:algorithms
Acceptable public key algorithms, a list of keywords such as :rsa and :dsa.
:verify-modes
Certificate verification frequency: :always verifies on every request; :once verifies only on first connection.
:ssl-versions
Acceptable SSL/TLS protocol versions.
:cyphers
Acceptable cipher suites.

The positional arguments after the keyword parameters are keywords denoting acceptable certificate authorities (the issuers of client certificates).

8.5.2 Using Certificate Authentication

Once a certificate realm is defined, it is used with http:export-url in the same way as basic or digest realms. Users, groups, and access controls work identically — the only difference is the authentication mechanism used to verify identity.

;; Export a URL requiring client certificate authentication
(http:export-url #u"/secure/cert-protected.html"
                 :computed
                 :response-function #'write-cert-page
                 :authentication-realm :client-cert-realm
                 :capabilities nil
                 :private t
                 :proxy-revalidate t)

8.6 Managing Users and Groups

8.6.1 User Management

The primary interface for user management consists of these functions:

(http:add-user username realm &key password groups personal-name email-address)
Creates a user in the specified realm. If the user already exists, updates the supplied fields. Groups must exist in the realm before assigning users to them.
(http:intern-user realm username &key if-does-not-exist password groups personal-name email-address)
The lower-level interning function. :if-does-not-exist can be :create, :error, or :soft (returns nil). add-user calls this with :if-does-not-exist :create.
(http:unintern-user realm user)
Removes a user from a realm, including removal from all groups.
(http:set-user-password user password)
Changes a user's password. The password is stored as a digest, never in clear text.
(http:update-user user &key personal-name email-address password groups)
Updates multiple user fields at once. When groups are supplied, the user is added to new groups and removed from groups not in the new list.

8.6.2 Group Management

(http:add-group realm group)
Creates a named group within a realm. group is a keyword.
(http:add-groups realm &rest groups)
Creates multiple groups at once within a realm.
(http:intern-group realm group &key if-does-not-exist)
The lower-level interning function for groups.
(http:group-add-user group user)
Adds a user to a group.
(http:group-remove-user group user)
Removes a user from a group.

8.6.3 Access Control Management

(http:add-access-control-group name realm &key capabilities)
Creates a named access control with a capability alist within a realm. The name is a keyword used to reference this access control when exporting URLs.
(http:intern-access-control realm name &key if-does-not-exist capability-alist)
The lower-level interning function for access controls.
(http:unintern-access-control realm access-control)
Removes an access control from a realm.

8.6.4 Capability Alist Syntax

The capability alist passed to :capabilities on add-access-control-group or export-url is a list of entries, each of the form:

(METHOD &rest GROUPS-AND-USERS)

Where:

Examples:

;; :users can GET and HEAD; :admins can do everything
'((:get :users)
  (:head :users)
  (:default :admins))

;; "frank" can do everything except DELETE
'((:delete)
  (:default "frank"))

;; Any user in the realm can do everything
'((:default :any-user-in-realm))

;; :developers can GET, HEAD, and POST
'((:get :developers)
  (:head :developers)
  (:post :developers))

8.6.5 Realm Management

(http:add-realm realm-name scheme)
Creates a realm with the given name keyword and authentication scheme. A convenience wrapper around intern-realm.
(http:intern-realm realm &key if-does-not-exist scheme)
Interns a realm. scheme is one of :basic, :digest, :md5, :digest-sha, :digest-sha-256, :digest-sha-384, :digest-sha-512, or :certificate.
(http:unintern-realm realm)
Removes a realm and all its users, groups, and access controls.
(http:map-realms function)
Maps a function over all realms. The function receives two arguments: the realm name string and the realm object.

8.6.6 Persisting Authentication Data

Authentication data (realms, users, groups, access controls) can be saved to and restored from disk. Passwords are stored as digests, never in clear text. However, access to the authentication data file compromises security, so the file must be protected.

(http:save-authentication-data &key pathname if-exists)
Writes all current authentication data to a Lisp file. The default pathname is http:*authentication-data-pathname*.
(http:restore-authentication-data &key pathname if-does-not-exist clear-stale-data)
Restores authentication data from a saved file. When clear-stale-data is non-null, all existing authentication data in memory is purged before loading.

Security note: For production sites, use these functions to manage password data rather than embedding clear-text passwords in source files. The example code in this chapter uses clear-text passwords for pedagogical purposes only.

8.7 Web-Based Administration

CL-HTTP provides a web-based interface for managing authentication realms, groups, users, and access controls. The interface is exported by calling http:export-access-control-interface:

(http:export-access-control-interface
  :port 8443
  :protocol :https
  :authentication-realm :server
  :capabilities :webmasters
  :secure-subnets (list (http:local-host-ip-address)))

This exports the following administration URLs:

URLFunction
/cl-http/describe-realm? Browse and describe authentication realms
/cl-http/describe-group? Describe groups within a realm (syntax: realm|group)
/cl-http/describe-access-control? Describe access controls within a realm
/cl-http/describe-user? Describe a user's capabilities
/cl-http/edit-user? Edit a user's access capabilities
/cl-http/edit-user.html Form for editing user access control
/cl-http/create-user.html Form for creating user accounts with privileges

The administration interface should always be protected by both authentication and subnet restrictions. For maximum security, restrict access to the local host and the :server realm's Webmaster account.

8.7.1 Security Policies for Write Methods

HTTP methods such as PUT and DELETE change server state. The variable http:*accept-write-methods* controls the global security policy for these side-effecting methods. It can be set via the server configuration interface or programmatically.

Available policies:

Policy KeywordRequirements
:access-controlled URLs must restrict users via either user authentication or subnet security.
:authenticated-users URLs must restrict users via user authentication only.
:authenticated-users-on-write-subnets URLs must restrict users via both user authentication and write subnet security.
:local-host Users must be on the local host running the server.
:none No users can invoke side-effecting methods.
:remote-host Requires URLs to control access, but respects any global or URL-level controls.
:write-subnets URLs must restrict access to hosts trusted for write operations.

8.7.2 Accessing Authentication in Response Functions

After a user has been authenticated, the server instance (bound to http:*server*) contains the user object and authentication method. Response functions can access these via:

(http:server-user-object server)
Returns the authenticated user object, or nil if no authentication was performed.
(http:server-authentication-method server)
Returns the authentication method used (e.g., :basic, :digest).
(http:allow-user-access-p url-or-access-control user http-method)
Predicate that checks whether a user should have access to a URL via a given HTTP method. Respects group inheritance.

Authenticated users are recorded in the Common Log File by qualified name (e.g., "realm|username"). Service providers should strictly respect people's privacy when using user properties and logging.

8.8 Examples

This section provides complete, working examples for each authentication method. The examples use clear-text passwords for clarity; production sites should use http:save-authentication-data and http:restore-authentication-data instead.

8.8.1 Basic Authentication Example

This example sets up two realms with basic authentication, multiple users and groups, and several access-controlled URLs demonstrating different capability patterns.

(in-package :http)

;;; --- Realm Setup ---

;; Create two basic authentication realms
(add-realm :minimum-security :basic)
(add-realm :system-admin :basic)

;; Create groups before assigning users to them
(add-groups :minimum-security :users :developers)
(add-group :system-admin :system-hackers)

;;; --- User Setup ---

(add-user "ernest" :minimum-security
          :password "ernest-foo"
          :groups '(:users)
          :personal-name "Ernest Jones"
          :email-address "ernest@foo.com")

(add-user "jim" :minimum-security
          :password "jim-foo"
          :groups '(:developers :users)
          :personal-name "Jim Thompson"
          :email-address "jim@foo.com")

(add-user "frank" :minimum-security
          :password "frank-foo"
          :groups '(:developers :users)
          :personal-name "Frank Smith"
          :email-address "frank@foo.com")

(add-user "luke" :system-admin
          :password "luke-foo"
          :groups '(:system-hackers)
          :personal-name "Luke Miller"
          :email-address "luke@foo.com")

;;; --- Access Control Groups ---

;; Developers can GET, HEAD, and POST
(add-access-control-group :minimum-security-developers
                          :minimum-security
                          :capabilities '((:get :developers)
                                          (:head :developers)
                                          (:post :developers)))

;; Frank can do everything except DELETE
(add-access-control-group :minimum-security-frank-capabilities
                          :minimum-security
                          :capabilities '((:delete)
                                          (:default "frank")))

;;; --- URL Exports ---

;; Any user in :minimum-security realm can access
(export-url #u"/cl-http/authentication/minimum.html"
            :computed
            :response-function #'display-url-authentication-status
            :authentication-realm :minimum-security
            :capabilities nil
            :private t
            :proxy-revalidate t
            :language :en)

;; Only :developers group
(export-url #u"/cl-http/authentication/minimum-developers.html"
            :computed
            :response-function #'display-url-authentication-status
            :authentication-realm :minimum-security
            :capabilities :minimum-security-developers
            :private t
            :proxy-revalidate t
            :language :en)

;; Only user "frank"
(export-url #u"/cl-http/authentication/minimum-frank.html"
            :computed
            :response-function #'display-url-authentication-status
            :authentication-realm :minimum-security
            :capabilities :minimum-security-frank-capabilities
            :private t
            :proxy-revalidate t
            :language :en)

;; Inline capabilities: :system-hackers do everything
(export-url #u"/cl-http/authentication/system-hackers.html"
            :computed
            :response-function #'display-url-authentication-status
            :authentication-realm :system-admin
            :capabilities '((:default :system-hackers))
            :private t
            :proxy-revalidate t
            :language :en)

8.8.2 Digest Authentication Example (SHA-256)

This example uses the recommended SHA-256 digest authentication scheme.

(in-package :http)

;; Create a digest realm using SHA-256
(add-realm :digest-realm :digest-sha-256)

;; Create groups before user assignment
(add-groups :digest-realm :members :elite-members)

;; Add users
(add-user "mike" :digest-realm
          :password "mike-foo"
          :groups '(:members)
          :personal-name "Mike Smith"
          :email-address "mike@foo.com")

(add-user "joe" :digest-realm
          :password "joe-foo"
          :groups '(:members :elite-members)
          :personal-name "Joe Doe"
          :email-address "joe@foo.com")

;; Define capabilities for elite members
(add-access-control-group :elite-members-access
                          :digest-realm
                          :capabilities '((:get :elite-members)
                                          (:head :elite-members)))

;; Any realm member can access
(export-url #u"/cl-http/authentication/members.html"
            :computed
            :response-function #'display-url-authentication-status
            :authentication-realm :digest-realm
            :capabilities nil
            :private t
            :proxy-revalidate t
            :language :en)

;; Only elite members
(export-url #u"/cl-http/authentication/elite-members.html"
            :computed
            :response-function #'display-url-authentication-status
            :authentication-realm :digest-realm
            :capabilities :elite-members-access
            :private t
            :proxy-revalidate t
            :language :en)

8.8.3 Combined Subnet and Authentication

This example combines subnet restrictions with digest authentication for defense in depth. The log files are accessible only to the Webmaster from the local machine.

(in-package :http)

;; Export log files with both subnet and password protection
(export-url #u"/cl-http/logs/"
            :directory
            :pathname (http:log-directory)
            :recursive-p t
            :authentication-realm :server
            :capabilities :webmasters
            :secure-subnets (list (local-host-ip-address))
            :private t
            :proxy-revalidate t
            :language :en)

;; Export administration interface on HTTPS with restrictions
(export-access-control-interface
  :port 8443
  :protocol :https
  :authentication-realm :server
  :capabilities :webmasters
  :secure-subnets (list (local-host-ip-address)))

8.8.4 Certificate Authentication Example

This example sets up X.509 certificate authentication. It requires the :cl-http-ssl-client feature and a properly configured SSL server with client certificate verification enabled.

(in-package :http)

#+cl-http-ssl-client
(progn
  ;; Define a certificate realm requiring 2048-bit RSA keys
  (define-certificate-realm :cert-realm
    (:key-size 2048
     :algorithms '(:rsa)
     :verify-modes '(:always))
    :digicert :lets-encrypt)

  ;; Create groups and users within the certificate realm
  (add-groups :cert-realm :operators :viewers)

  ;; Export a URL requiring certificate authentication
  (export-url #u"/secure/cert-only.html"
              :computed
              :response-function #'write-cert-page
              :authentication-realm :cert-realm
              :capabilities '((:default :operators))
              :private t
              :proxy-revalidate t))

8.8.5 Custom Realm Class

Applications can define custom realm classes and register them with the scheme-class mapping using http:add-realm-scheme:

(in-package :http)

;; Define a custom realm class with additional slots
(defclass my-organization-realm (digest-sha-256-realm)
  ((organization :initarg :organization
                 :accessor realm-organization)
   (department :initarg :department
               :accessor realm-department))
  (:documentation "A digest realm that tracks organizational affiliation."))

;; Register the custom realm class
(add-realm-scheme :organization-digest 'my-organization-realm)

;; Now use it
(intern-realm :engineering
              :if-does-not-exist :create
              :scheme :organization-digest)

Reference Manual | Prev: Chapter 7. HTML Generation | Next: Chapter 9. Data Caching and Performance