From 000159226d7f63a89c8ad3550558700e8bd078b6 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Sun, 21 Jun 2015 12:09:22 -0400 Subject: [PATCH] refactor --- .../authentication/AuthenticationFlow.java | 8 --- .../AuthenticationProcessor.java | 57 +++++++++++-------- .../authentication/AuthenticatorContext.java | 4 ++ 3 files changed, 38 insertions(+), 31 deletions(-) delete mode 100755 services/src/main/java/org/keycloak/authentication/AuthenticationFlow.java diff --git a/services/src/main/java/org/keycloak/authentication/AuthenticationFlow.java b/services/src/main/java/org/keycloak/authentication/AuthenticationFlow.java deleted file mode 100755 index 3f30309f36..0000000000 --- a/services/src/main/java/org/keycloak/authentication/AuthenticationFlow.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.keycloak.authentication; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public interface AuthenticationFlow { -} diff --git a/services/src/main/java/org/keycloak/authentication/AuthenticationProcessor.java b/services/src/main/java/org/keycloak/authentication/AuthenticationProcessor.java index 509e5c58e2..904e47b860 100755 --- a/services/src/main/java/org/keycloak/authentication/AuthenticationProcessor.java +++ b/services/src/main/java/org/keycloak/authentication/AuthenticationProcessor.java @@ -325,6 +325,16 @@ public class AuthenticationProcessor { clientSession.setTimestamp(Time.currentTime()); return accessCode.getCode(); } + + @Override + public Response getChallenge() { + return challenge; + } + + @Override + public Error getError() { + return error; + } } public static class AuthException extends RuntimeException { @@ -372,15 +382,6 @@ public class AuthenticationProcessor { } } - protected boolean isProcessed(AuthenticationExecutionModel model) { - if (model.isDisabled()) return true; - ClientSessionModel.ExecutionStatus status = clientSession.getExecutionStatus().get(model.getId()); - if (status == null) return false; - return status == ClientSessionModel.ExecutionStatus.SUCCESS || status == ClientSessionModel.ExecutionStatus.SKIPPED - || status == ClientSessionModel.ExecutionStatus.ATTEMPTED - || status == ClientSessionModel.ExecutionStatus.SETUP_REQUIRED; - } - public boolean isSuccessful(AuthenticationExecutionModel model) { ClientSessionModel.ExecutionStatus status = clientSession.getExecutionStatus().get(model.getId()); if (status == null) return false; @@ -486,13 +487,9 @@ public class AuthenticationProcessor { if (authType != null) { event.detail(Details.AUTH_TYPE, authType); } - AuthenticatorFactory factory = (AuthenticatorFactory)session.getKeycloakSessionFactory().getProviderFactory(Authenticator.class, model.getAuthenticator()); - Authenticator authenticator = factory.create(); - Result context = new Result(model, authenticator); - authenticator.action(context); FlowExecution flowExecution = createFlowExecution(this.flowId); - Response challenge = flowExecution.action(execution, context); + Response challenge = flowExecution.action(execution); if (challenge != null) return challenge; if (clientSession.getAuthenticatedUser() == null) { throw new AuthException(Error.UNKNOWN_USER); @@ -585,7 +582,17 @@ public class AuthenticationProcessor { boolean alternativeSuccessful = false; Iterator executions; - public Response action(String actionExecution, Result actionResult) { + protected boolean isProcessed(AuthenticationExecutionModel model) { + if (model.isDisabled()) return true; + ClientSessionModel.ExecutionStatus status = clientSession.getExecutionStatus().get(model.getId()); + if (status == null) return false; + return status == ClientSessionModel.ExecutionStatus.SUCCESS || status == ClientSessionModel.ExecutionStatus.SKIPPED + || status == ClientSessionModel.ExecutionStatus.ATTEMPTED + || status == ClientSessionModel.ExecutionStatus.SETUP_REQUIRED; + } + + + public Response action(String actionExecution) { while (executions.hasNext()) { AuthenticationExecutionModel model = executions.next(); if (isProcessed(model)) { @@ -596,12 +603,16 @@ public class AuthenticationProcessor { if (!model.getId().equals(actionExecution)) { if (model.isAutheticatorFlow()) { FlowExecution flowExecution = createFlowExecution(model.getAuthenticator()); - return flowExecution.action(actionExecution, actionResult); + return flowExecution.action(actionExecution); } else { throw new AuthException("action is not current execution", Error.INTERNAL_ERROR); } } else { // we found the action - Response response = processResult(actionResult); + AuthenticatorFactory factory = (AuthenticatorFactory)session.getKeycloakSessionFactory().getProviderFactory(Authenticator.class, model.getAuthenticator()); + Authenticator authenticator = factory.create(); + Result result = new Result(model, authenticator); + authenticator.action(result); + Response response = processResult(result); if (response == null) return processFlow(); else return response; } @@ -674,7 +685,7 @@ public class AuthenticationProcessor { } - public Response processResult(Result result) { + public Response processResult(AuthenticatorContext result) { AuthenticationExecutionModel execution = result.getExecution(); Status status = result.getStatus(); if (status == Status.SUCCESS){ @@ -686,10 +697,10 @@ public class AuthenticationProcessor { logger.debugv("authenticator FAILED: {0}", execution.getAuthenticator()); logFailure(); clientSession.setExecutionStatus(execution.getId(), ClientSessionModel.ExecutionStatus.FAILED); - if (result.challenge != null) { + if (result.getChallenge() != null) { return sendChallenge(result, execution); } - throw new AuthException(result.error); + throw new AuthException(result.getError()); } else if (status == Status.FORCE_CHALLENGE) { clientSession.setExecutionStatus(execution.getId(), ClientSessionModel.ExecutionStatus.CHALLENGED); return sendChallenge(result, execution); @@ -705,7 +716,7 @@ public class AuthenticationProcessor { return sendChallenge(result, execution); } if (execution.isAlternative()) { - alternativeChallenge = result.challenge; + alternativeChallenge = result.getChallenge(); challengedAlternativeExecution = execution; } else { clientSession.setExecutionStatus(execution.getId(), ClientSessionModel.ExecutionStatus.SKIPPED); @@ -731,9 +742,9 @@ public class AuthenticationProcessor { } - public Response sendChallenge(Result result, AuthenticationExecutionModel execution) { + public Response sendChallenge(AuthenticatorContext result, AuthenticationExecutionModel execution) { clientSession.setNote(CURRENT_AUTHENTICATION_EXECUTION, execution.getId()); - return result.challenge; + return result.getChallenge(); } diff --git a/services/src/main/java/org/keycloak/authentication/AuthenticatorContext.java b/services/src/main/java/org/keycloak/authentication/AuthenticatorContext.java index 49e663c5e5..07a3fd1cb4 100755 --- a/services/src/main/java/org/keycloak/authentication/AuthenticatorContext.java +++ b/services/src/main/java/org/keycloak/authentication/AuthenticatorContext.java @@ -77,4 +77,8 @@ public interface AuthenticatorContext { * @return */ String generateAccessCode(); + + Response getChallenge(); + + AuthenticationProcessor.Error getError(); }