From 7d0b4616836541cb7cb225ab66c7adb45c6a3e10 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Mon, 29 May 2017 18:14:02 +0200 Subject: [PATCH] KEYCLOAK-4975 Use authenticationSession binding name in ScriptBasedAuthenticator We now use authenticationSession instead of clientSession to reflect the renaming of ClientSessionModel to AuthenticationSessionModel. Note that this is a breaking change which needs to be mentioned in the upgrade notes! --- .../authenticators/browser/ScriptBasedAuthenticator.java | 4 ++-- .../browser/ScriptBasedAuthenticatorFactory.java | 2 +- .../src/main/resources/scripts/authenticator-template.js | 2 +- .../base/src/test/resources/scripts/client-session-test.js | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/browser/ScriptBasedAuthenticator.java b/services/src/main/java/org/keycloak/authentication/authenticators/browser/ScriptBasedAuthenticator.java index af639744b7..c3d1de4f49 100644 --- a/services/src/main/java/org/keycloak/authentication/authenticators/browser/ScriptBasedAuthenticator.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/browser/ScriptBasedAuthenticator.java @@ -47,7 +47,7 @@ import java.util.Map; *
  • {@code realm} the {@link RealmModel}
  • *
  • {@code user} the current {@link UserModel}
  • *
  • {@code session} the active {@link KeycloakSession}
  • - *
  • {@code clientSession} the current {@link org.keycloak.sessions.AuthenticationSessionModel}
  • + *
  • {@code authenticationSession} the current {@link org.keycloak.sessions.AuthenticationSessionModel}
  • *
  • {@code httpRequest} the current {@link org.jboss.resteasy.spi.HttpRequest}
  • *
  • {@code LOG} a {@link org.jboss.logging.Logger} scoped to {@link ScriptBasedAuthenticator}/li> * @@ -160,7 +160,7 @@ public class ScriptBasedAuthenticator implements Authenticator { bindings.put("user", context.getUser()); bindings.put("session", context.getSession()); bindings.put("httpRequest", context.getHttpRequest()); - bindings.put("clientSession", context.getAuthenticationSession()); + bindings.put("authenticationSession", context.getAuthenticationSession()); bindings.put("LOG", LOGGER); }); } diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/browser/ScriptBasedAuthenticatorFactory.java b/services/src/main/java/org/keycloak/authentication/authenticators/browser/ScriptBasedAuthenticatorFactory.java index 4a1003c8d4..f5fabe25bb 100644 --- a/services/src/main/java/org/keycloak/authentication/authenticators/browser/ScriptBasedAuthenticatorFactory.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/browser/ScriptBasedAuthenticatorFactory.java @@ -146,7 +146,7 @@ public class ScriptBasedAuthenticatorFactory implements AuthenticatorFactory, En } script.setDefaultValue(scriptTemplate); script.setHelpText("The script used to authenticate. Scripts must at least define a function with the name 'authenticate(context)' that accepts a context (AuthenticationFlowContext) parameter.\n" + - "This authenticator exposes the following additional variables: 'script', 'realm', 'user', 'session', 'httpRequest', 'LOG'"); + "This authenticator exposes the following additional variables: 'script', 'realm', 'user', 'session', 'authenticationSession', 'httpRequest', 'LOG'"); return asList(name, description, script); } diff --git a/services/src/main/resources/scripts/authenticator-template.js b/services/src/main/resources/scripts/authenticator-template.js index f18dfdf0e3..514337d533 100644 --- a/services/src/main/resources/scripts/authenticator-template.js +++ b/services/src/main/resources/scripts/authenticator-template.js @@ -15,7 +15,7 @@ AuthenticationFlowError = Java.type("org.keycloak.authentication.AuthenticationF * session - current KeycloakSession {@see org.keycloak.models.KeycloakSession} * httpRequest - current HttpRequest {@see org.jboss.resteasy.spi.HttpRequest} * script - current script {@see org.keycloak.models.ScriptModel} - * clientSession - current client session {@see org.keycloak.models.ClientSessionModel} + * authenticationSession - current client session {@see org.keycloak.sessions.AuthenticationSessionModel} * LOG - current logger {@see org.jboss.logging.Logger} * * You one can extract current http request headers via: diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/scripts/client-session-test.js b/testsuite/integration-arquillian/tests/base/src/test/resources/scripts/client-session-test.js index 0fd70d518c..766eda1238 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/resources/scripts/client-session-test.js +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/scripts/client-session-test.js @@ -2,17 +2,17 @@ AuthenticationFlowError = Java.type("org.keycloak.authentication.AuthenticationF function authenticate(context) { - if (clientSession.getRealm().getName() != "${realm}") { + if (authenticationSession.getRealm().getName() != "${realm}") { context.failure(AuthenticationFlowError.INVALID_CLIENT_SESSION); return; } - if (clientSession.getClient().getClientId() != "${clientId}") { + if (authenticationSession.getClient().getClientId() != "${clientId}") { context.failure(AuthenticationFlowError.UNKNOWN_CLIENT); return; } - if (clientSession.getProtocol() != "${authMethod}") { + if (authenticationSession.getProtocol() != "${authMethod}") { context.failure(AuthenticationFlowError.INVALID_CLIENT_SESSION); return; }