3 Authentication
Ralph Schaer edited this page 2026-10-30 16:08:52 +01:00

Authentication

Authentication establishes a session identity. Authorization decides which operations that identity may perform; see Security. Both servlet and reactive transports discover Spring beans implementing WampAuthenticationProvider.

Session establishment

  1. The client sends HELLO with roles and optional authmethods, authid, and authextra.
  2. The router selects the first requested method for which a provider exists. Providers are collected in Spring order; the first provider for a given method name wins.
  3. The provider creates a CHALLENGE. The client responds with AUTHENTICATE.
  4. Successful verification establishes the session and sends WELCOME; authentication failures send ABORT.

If the client requests methods but none is supported, establishment fails with wamp.error.no_such_authmethod. If no methods are requested, the router accepts the transport principal (authmethod/authprovider are transport), or establishes an anonymous session (anonymous/static). Registering a provider alone does not require every client to use WAMP authentication. Apply transport access rules or WAMP authorization to require an identity.

Application messages before establishment, another HELLO during authentication, and an unsolicited AUTHENTICATE violate the session protocol.

The realm is available to a provider through the original HelloMessage. Core routing ignores it and does not copy it into established-session headers or SessionDetail.

Built-in providers

These implementations are available in ch.rasc.wamp2spring.auth; instantiate the ones your application needs as beans.

Method Provider Application-supplied dependency
ticket TicketWampAuthenticationProvider TicketVerifier
wampcra WampCraAuthenticationProvider WampCraAuthenticationInfoProvider returning a secret and WampAuthentication
wamp-scram WampScramAuthenticationProvider WampScramAuthenticationInfoProvider returning SCRAM credentials and identity
dynamic (or a custom name) DynamicAuthenticationProvider DynamicAuthenticationProcedure implementing the challenge and verification callbacks

Example registration using an application-defined TicketVerifier bean:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ch.rasc.wamp2spring.auth.TicketVerifier;
import ch.rasc.wamp2spring.auth.TicketWampAuthenticationProvider;
import ch.rasc.wamp2spring.auth.WampAuthenticationProvider;

@Configuration
public class WampAuthenticationConfiguration {
  @Bean
  public WampAuthenticationProvider ticketAuthentication(TicketVerifier verifier) {
    return new TicketWampAuthenticationProvider(verifier);
  }
}

Implement TicketVerifier.verify(authId, ticket, helloAuthExtra, authenticateExtra) to validate against your application's credentials. Return new WampAuthentication(authId, authRole) on success or null to reject the ticket. The optional longer WampAuthentication constructor accepts an auth-provider name and authextra.

WAMP-CRA uses a challenge and HMAC-SHA256 signature based on the supplied secret. SCRAM requires an authid and client nonce in HELLO.authextra; its credential class supports pbkdf2 and argon2id13 factories or stored-key/server-key construction. The server returns its SCRAM verifier in WELCOME.authextra. Dynamic authentication delegates to local Java callbacks; it is not an automatic outbound RPC to an authenticator service.

Custom providers

Implement these methods on a Spring bean:

String getAuthMethod();
WampAuthenticationChallenge challenge(HelloMessage helloMessage);
WampAuthentication authenticate(HelloMessage helloMessage,
    AuthenticateMessage authenticateMessage, WampAuthenticationChallenge challenge);

WampAuthenticationChallenge separates public extra from private state. Only extra is sent to the client; use state to retain verification context. Throw WampAuthenticationException with a WampError to reject establishment. A custom provider's successful authenticate must return a WampAuthentication.

Identity visible to application code

WAMP messages expose the principal, WAMP/transport IDs, peer roles, auth method, and auth provider. getAuthId() derives from the principal's name; getAuthRole() derives from its authorities, preferring a ROLE_ authority and stripping the prefix. Use Principal parameters, message metadata, or WampAuthorizer for WAMP-authenticated identities.

The built-in WampAuthentication principal implements Java Principal, not Spring Security Authentication. It is not automatically converted into a Spring Security context. Consequently WAMP auth roles alone do not satisfy the security module's hasRole/authenticated rules or @AuthenticationPrincipal; see Security.

In the current implementation, the wire WELCOME.authid is taken from HELLO.authid, while application metadata derives identity from the authenticated principal. Applications that canonicalize IDs should account for that distinction.

Source: authentication classes, WampSessionSupport.