From 33e402e7be066f7af205ca6778f75dc48577e9e2 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Fri, 7 Aug 2015 19:00:07 -0400 Subject: [PATCH] binding custom flows --- .../META-INF/jpa-changelog-1.5.0.xml | 9 + .../idm/RealmRepresentation.java | 27 +++ .../theme/base/admin/resources/js/app.js | 15 ++ .../admin/resources/js/controllers/realm.js | 13 +- .../authentication-flow-bindings.html | 49 +++++ .../templates/kc-tabs-authentication.html | 1 + .../migration/migrators/MigrateTo1_5_0.java | 5 +- .../java/org/keycloak/models/RealmModel.java | 9 + .../keycloak/models/entities/RealmEntity.java | 27 +++ .../utils/DefaultAuthenticationFlows.java | 4 + .../models/utils/ModelToRepresentation.java | 3 + .../models/utils/RepresentationToModel.java | 26 ++- .../models/file/adapter/RealmAdapter.java | 40 ++++ .../keycloak/models/cache/RealmAdapter.java | 39 ++++ .../models/cache/entities/CachedRealm.java | 20 ++ .../org/keycloak/models/jpa/RealmAdapter.java | 39 ++++ .../models/jpa/entities/RealmEntity.java | 35 +++ .../mongo/keycloak/adapters/RealmAdapter.java | 43 ++++ .../keycloak/protocol/saml/SamlService.java | 2 +- .../authentication/Authenticator.java | 35 ++- .../authentication/AuthenticatorFactory.java | 6 + .../ConfigurableAuthenticatorFactory.java | 10 + .../oidc/endpoints/AuthorizationEndpoint.java | 2 +- .../oidc/endpoints/TokenEndpoint.java | 2 +- .../resources/IdentityBrokerService.java | 2 +- .../resources/LoginActionsService.java | 39 ++-- .../testsuite/forms/CustomFlowTest.java | 208 ++++++++++++++++++ .../forms/CustomRegistrationFlowTest.java | 125 +++++++++++ .../forms/PassThroughAuthenticator.java | 125 +++++++++++ .../forms/PassThroughRegistration.java | 144 ++++++++++++ ...ycloak.authentication.AuthenticatorFactory | 2 + 31 files changed, 1074 insertions(+), 32 deletions(-) create mode 100755 forms/common-themes/src/main/resources/theme/base/admin/resources/partials/authentication-flow-bindings.html create mode 100755 testsuite/integration/src/test/java/org/keycloak/testsuite/forms/CustomFlowTest.java create mode 100755 testsuite/integration/src/test/java/org/keycloak/testsuite/forms/CustomRegistrationFlowTest.java create mode 100755 testsuite/integration/src/test/java/org/keycloak/testsuite/forms/PassThroughAuthenticator.java create mode 100755 testsuite/integration/src/test/java/org/keycloak/testsuite/forms/PassThroughRegistration.java create mode 100755 testsuite/integration/src/test/resources/META-INF/services/org.keycloak.authentication.AuthenticatorFactory diff --git a/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.5.0.xml b/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.5.0.xml index 4866834caa..c80f25c6a8 100755 --- a/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.5.0.xml +++ b/connections/jpa-liquibase/src/main/resources/META-INF/jpa-changelog-1.5.0.xml @@ -43,6 +43,15 @@ + + + + + + + + + diff --git a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java index d93a0d693d..43aeb613a3 100755 --- a/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java +++ b/core/src/main/java/org/keycloak/representations/idm/RealmRepresentation.java @@ -87,6 +87,9 @@ public class RealmRepresentation { protected List authenticationFlows; protected List authenticatorConfig; protected List requiredActions; + protected String browserFlow; + protected String registrationFlow; + protected String directGrantFlow; @Deprecated protected Boolean social; @@ -708,4 +711,28 @@ public class RealmRepresentation { public void setOtpPolicyPeriod(Integer otpPolicyPeriod) { this.otpPolicyPeriod = otpPolicyPeriod; } + + public String getBrowserFlow() { + return browserFlow; + } + + public void setBrowserFlow(String browserFlow) { + this.browserFlow = browserFlow; + } + + public String getRegistrationFlow() { + return registrationFlow; + } + + public void setRegistrationFlow(String registrationFlow) { + this.registrationFlow = registrationFlow; + } + + public String getDirectGrantFlow() { + return directGrantFlow; + } + + public void setDirectGrantFlow(String directGrantFlow) { + this.directGrantFlow = directGrantFlow; + } } diff --git a/forms/common-themes/src/main/resources/theme/base/admin/resources/js/app.js b/forms/common-themes/src/main/resources/theme/base/admin/resources/js/app.js index 878f13da57..19a3562ccb 100755 --- a/forms/common-themes/src/main/resources/theme/base/admin/resources/js/app.js +++ b/forms/common-themes/src/main/resources/theme/base/admin/resources/js/app.js @@ -1087,6 +1087,21 @@ module.config([ '$routeProvider', function($routeProvider) { }, controller : 'AuthenticationFlowsCtrl' }) + .when('/realms/:realm/authentication/flow-bindings', { + templateUrl : resourceUrl + '/partials/authentication-flow-bindings.html', + resolve : { + realm : function(RealmLoader) { + return RealmLoader(); + }, + flows : function(AuthenticationFlowsLoader) { + return AuthenticationFlowsLoader(); + }, + serverInfo : function(ServerInfo) { + return ServerInfo.delay; + } + }, + controller : 'RealmFlowBindingCtrl' + }) .when('/realms/:realm/authentication/flows/:flow', { templateUrl : resourceUrl + '/partials/authentication-flows.html', resolve : { diff --git a/forms/common-themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js b/forms/common-themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js index 0ed6fa4667..9aeb0e8a73 100755 --- a/forms/common-themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js +++ b/forms/common-themes/src/main/resources/theme/base/admin/resources/js/controllers/realm.js @@ -376,6 +376,7 @@ module.controller('RealmOtpPolicyCtrl', function($scope, Current, Realm, realm, genericRealmUpdate($scope, Current, Realm, realm, serverInfo, $http, $location, Dialog, Notifications, "/realms/" + realm.realm + "/authentication/otp-policy"); }); + module.controller('RealmThemeCtrl', function($scope, Current, Realm, realm, serverInfo, $http, $location, Dialog, Notifications) { genericRealmUpdate($scope, Current, Realm, realm, serverInfo, $http, $location, Dialog, Notifications, "/realms/" + realm.realm + "/theme-settings"); @@ -1620,6 +1621,13 @@ module.controller('IdentityProviderMapperCreateCtrl', function($scope, realm, id }); +module.controller('RealmFlowBindingCtrl', function($scope, flows, Current, Realm, realm, serverInfo, $http, $location, Dialog, Notifications) { + $scope.flows = flows; + + genericRealmUpdate($scope, Current, Realm, realm, serverInfo, $http, $location, Dialog, Notifications, "/realms/" + realm.realm + "/authentication/flow-bindings"); +}); + + module.controller('CreateFlowCtrl', function($scope, realm, AuthenticationFlows, Notifications, $location) { @@ -1770,8 +1778,9 @@ module.controller('AuthenticationFlowsCtrl', function($scope, $route, realm, flo }; $scope.removeFlow = function() { - AuthenticationFlows.remove({realm: realm, flow: flow.id}, function() { - $route.reload(); + console.log('Remove flow:' + $scope.flow.alias); + AuthenticationFlows.remove({realm: realm.realm, flow: $scope.flow.id}, function() { + $location.url("/realms/" + realm.realm + '/authentication/flows'); Notifications.success("Flow removed"); }) diff --git a/forms/common-themes/src/main/resources/theme/base/admin/resources/partials/authentication-flow-bindings.html b/forms/common-themes/src/main/resources/theme/base/admin/resources/partials/authentication-flow-bindings.html new file mode 100755 index 0000000000..050c5f17fa --- /dev/null +++ b/forms/common-themes/src/main/resources/theme/base/admin/resources/partials/authentication-flow-bindings.html @@ -0,0 +1,49 @@ +
+

Authentication

+ + + +
+
+ +
+
+ +
+
+ Select the flow you want to use for browser authentication. +
+
+ +
+
+ +
+
+ Select the flow you want to use for registration. +
+
+ +
+
+ +
+
+ Select the flow you want to use for direct grant authentication. +
+ +
+
+ + +
+
+
+ +
+ + + \ No newline at end of file diff --git a/forms/common-themes/src/main/resources/theme/base/admin/resources/templates/kc-tabs-authentication.html b/forms/common-themes/src/main/resources/theme/base/admin/resources/templates/kc-tabs-authentication.html index 214a9ad084..0fcd65a440 100755 --- a/forms/common-themes/src/main/resources/theme/base/admin/resources/templates/kc-tabs-authentication.html +++ b/forms/common-themes/src/main/resources/theme/base/admin/resources/templates/kc-tabs-authentication.html @@ -1,5 +1,6 @@