Package org.keycloak.email
Class ActionTokenEmail
java.lang.Object
org.keycloak.email.ActionTokenEmail
Helper for sending an "execute actions" email to a user, so callers (e.g.
InviteUserStepProvider) do not have to reimplement the individual steps:
- resolving the target client (explicit
clientIdor the realm system client); - validating the optional redirect URI against the resolved client;
- building the action-token URL and serialising the token;
- invoking
EmailTemplateProvider.sendExecuteActions(String, long).
resolveParams(org.keycloak.models.KeycloakSession, org.keycloak.models.RealmModel, org.keycloak.models.UserModel, java.lang.String, java.lang.String, java.lang.Integer) returns a ActionTokenEmail.Result (either ActionTokenEmail.Params or
an ActionTokenEmail.Ineligibility reason) and send(org.keycloak.models.KeycloakSession, org.keycloak.models.RealmModel, org.keycloak.models.UserModel, org.keycloak.email.ActionTokenEmail.Params, java.util.List<java.lang.String>, jakarta.ws.rs.core.UriInfo) throws EmailException, so callers can
map outcomes onto HTTP status codes or onto silent skips in background executors.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumOutcomes ofresolveParams(org.keycloak.models.KeycloakSession, org.keycloak.models.RealmModel, org.keycloak.models.UserModel, java.lang.String, java.lang.String, java.lang.Integer)that indicate a user is ineligible for an action-token email.static final classResolved parameters for a singleexecute-actionsemail.static final classResult ofresolveParams(org.keycloak.models.KeycloakSession, org.keycloak.models.RealmModel, org.keycloak.models.UserModel, java.lang.String, java.lang.String, java.lang.Integer): either successfully resolvedActionTokenEmail.Paramsor a structuredActionTokenEmail.Ineligibilityreason. -
Method Summary
Modifier and TypeMethodDescriptionstatic ActionTokenEmail.ResultresolveParams(KeycloakSession session, RealmModel realm, UserModel user, String clientId, String redirectUri, Integer overrideLifespanSeconds) Resolves the parameters needed to send an action-token email touser.static voidsend(KeycloakSession session, RealmModel realm, UserModel user, ActionTokenEmail.Params params, List<String> actions, jakarta.ws.rs.core.UriInfo uriInfo) Builds the action-token URL using the active HTTP request's base URI and sends the email.static voidsend(KeycloakSession session, RealmModel realm, UserModel user, ActionTokenEmail.Params params, List<String> actions, URI baseUri) Builds the action-token URL usingbaseUriand sends the email.
-
Method Details
-
resolveParams
public static ActionTokenEmail.Result resolveParams(KeycloakSession session, RealmModel realm, UserModel user, String clientId, String redirectUri, Integer overrideLifespanSeconds) Resolves the parameters needed to send an action-token email touser. Returns a structuredActionTokenEmail.Resultso callers can differentiate between- successful resolution →
ActionTokenEmail.Params; - user/client/redirect ineligibility →
ActionTokenEmail.Ineligibility; - caller-supplied invalid configuration (e.g.
redirectUriwithout aclientId) →IllegalArgumentException.
- Parameters:
session- the Keycloak sessionrealm- the realm the user belongs touser- the recipientclientId- explicit client id, ornullfor the realm system clientredirectUri- optional post-action redirect URI; requiresclientIdwhen suppliedoverrideLifespanSeconds- explicit lifespan override;nullfalls back toRealmModel.getActionTokenGeneratedByAdminLifespan()- Throws:
IllegalArgumentException- whenredirectUriis supplied withoutclientId
- successful resolution →
-
send
public static void send(KeycloakSession session, RealmModel realm, UserModel user, ActionTokenEmail.Params params, List<String> actions, jakarta.ws.rs.core.UriInfo uriInfo) throws EmailException Builds the action-token URL using the active HTTP request's base URI and sends the email. Equivalent tosend(KeycloakSession, RealmModel, UserModel, Params, List, URI)withuriInfo.getBaseUri().- Throws:
EmailException
-
send
public static void send(KeycloakSession session, RealmModel realm, UserModel user, ActionTokenEmail.Params params, List<String> actions, URI baseUri) throws EmailException Builds the action-token URL usingbaseUriand sends the email.Use this overload from contexts that do not have an active HTTP request (e.g. workflow executors) and therefore cannot supply a
UriInfo.- Throws:
EmailException
-