From d2afb4892ad88b7749fb067bfca5181bd89e3c99 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Fri, 16 Oct 2015 12:51:11 +0200 Subject: [PATCH] KEYCLOAK-1975 Increase/decrease flow priority doesn't work --- .../AuthenticationManagementResource.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/admin/AuthenticationManagementResource.java b/services/src/main/java/org/keycloak/services/resources/admin/AuthenticationManagementResource.java index 1d441ece5f..063e66c272 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/AuthenticationManagementResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/AuthenticationManagementResource.java @@ -431,9 +431,16 @@ public class AuthenticationManagementResource { execution.setRequirement(AuthenticationExecutionModel.Requirement.DISABLED); execution.setAuthenticatorFlow(true); execution.setAuthenticator(provider); + execution.setPriority(getNextPriority(parentFlow)); + realm.addAuthenticatorExecution(execution); } + private int getNextPriority(AuthenticationFlowModel parentFlow) { + List executions = getSortedExecutions(parentFlow); + return executions.isEmpty() ? 0 : executions.get(executions.size() - 1).getPriority() + 1; + } + /** * Add new authentication execution to a flow * @@ -453,12 +460,13 @@ public class AuthenticationManagementResource { } String provider = data.get("provider"); - AuthenticationExecutionModel execution = new AuthenticationExecutionModel(); execution.setParentFlow(parentFlow.getId()); execution.setRequirement(AuthenticationExecutionModel.Requirement.DISABLED); execution.setAuthenticatorFlow(false); execution.setAuthenticator(provider); + execution.setPriority(getNextPriority(parentFlow)); + realm.addAuthenticatorExecution(execution); } @@ -583,13 +591,7 @@ public class AuthenticationManagementResource { if (parentFlow.isBuiltIn()) { throw new BadRequestException("It is illegal to add execution to a built in flow"); } - int priority = 0; - List executions = getSortedExecutions(parentFlow); - for (AuthenticationExecutionModel execution : executions) { - priority = execution.getPriority(); - } - if (priority > 0) priority += 10; - model.setPriority(priority); + model.setPriority(getNextPriority(parentFlow)); model = realm.addAuthenticatorExecution(model); return Response.created(uriInfo.getAbsolutePathBuilder().path(model.getId()).build()).build(); }