diff --git a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenRequestBuilder.java b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenRequestBuilder.java index 0cc016f4244..07e83bfe8a6 100755 --- a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenRequestBuilder.java +++ b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenRequestBuilder.java @@ -24,9 +24,11 @@ import org.wso2.carbon.identity.action.execution.ActionExecutionRequestBuilder; import org.wso2.carbon.identity.action.execution.exception.ActionExecutionRequestBuilderException; import org.wso2.carbon.identity.action.execution.model.ActionExecutionRequest; +import org.wso2.carbon.identity.action.execution.model.ActionExecutionRequestContext; import org.wso2.carbon.identity.action.execution.model.ActionType; import org.wso2.carbon.identity.action.execution.model.AllowedOperation; import org.wso2.carbon.identity.action.execution.model.Event; +import org.wso2.carbon.identity.action.execution.model.FlowContext; import org.wso2.carbon.identity.action.execution.model.Operation; import org.wso2.carbon.identity.action.execution.model.Organization; import org.wso2.carbon.identity.action.execution.model.Request; @@ -80,11 +82,12 @@ public ActionType getSupportedActionType() { } @Override - public ActionExecutionRequest buildActionExecutionRequest(Map eventContext) + public ActionExecutionRequest buildActionExecutionRequest(FlowContext flowContext, + ActionExecutionRequestContext actionExecutionContext) throws ActionExecutionRequestBuilderException { OAuthTokenReqMessageContext tokenMessageContext = - (OAuthTokenReqMessageContext) eventContext.get("tokenMessageContext"); + flowContext.getValue("tokenMessageContext", OAuthTokenReqMessageContext.class); Map additionalClaimsToAddToToken = getAdditionalClaimsToAddToToken(tokenMessageContext); diff --git a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenResponseProcessor.java b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenResponseProcessor.java index 1657577e7cc..bd9daf98b28 100644 --- a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenResponseProcessor.java +++ b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenResponseProcessor.java @@ -27,6 +27,7 @@ import org.wso2.carbon.identity.action.execution.ActionExecutionLogConstants; import org.wso2.carbon.identity.action.execution.ActionExecutionResponseProcessor; import org.wso2.carbon.identity.action.execution.exception.ActionExecutionResponseProcessorException; +import org.wso2.carbon.identity.action.execution.model.ActionExecutionResponseContext; import org.wso2.carbon.identity.action.execution.model.ActionExecutionStatus; import org.wso2.carbon.identity.action.execution.model.ActionInvocationErrorResponse; import org.wso2.carbon.identity.action.execution.model.ActionInvocationFailureResponse; @@ -34,9 +35,9 @@ import org.wso2.carbon.identity.action.execution.model.ActionType; import org.wso2.carbon.identity.action.execution.model.Error; import org.wso2.carbon.identity.action.execution.model.ErrorStatus; -import org.wso2.carbon.identity.action.execution.model.Event; import org.wso2.carbon.identity.action.execution.model.FailedStatus; import org.wso2.carbon.identity.action.execution.model.Failure; +import org.wso2.carbon.identity.action.execution.model.FlowContext; import org.wso2.carbon.identity.action.execution.model.PerformableOperation; import org.wso2.carbon.identity.action.execution.model.Success; import org.wso2.carbon.identity.action.execution.model.SuccessStatus; @@ -80,15 +81,16 @@ public ActionType getSupportedActionType() { } @Override - public ActionExecutionStatus processSuccessResponse(Map eventContext, Event event, - ActionInvocationSuccessResponse - actionInvocationSuccessResponse) + public ActionExecutionStatus processSuccessResponse(FlowContext flowContext, + ActionExecutionResponseContext + + responseContext) throws ActionExecutionResponseProcessorException { OAuthTokenReqMessageContext tokenMessageContext = - (OAuthTokenReqMessageContext) eventContext.get("tokenMessageContext"); - PreIssueAccessTokenEvent preIssueAccessTokenEvent = (PreIssueAccessTokenEvent) event; - List operationsToPerform = actionInvocationSuccessResponse.getOperations(); + flowContext.getValue("tokenMessageContext", OAuthTokenReqMessageContext.class); + PreIssueAccessTokenEvent preIssueAccessTokenEvent = (PreIssueAccessTokenEvent) responseContext.getActionEvent(); + List operationsToPerform = responseContext.getActionInvocationResponse().getOperations(); AccessToken requestAccessToken = preIssueAccessTokenEvent.getAccessToken(); AccessToken.Builder responseAccessTokenBuilder = preIssueAccessTokenEvent.getAccessToken().copy(); @@ -120,7 +122,7 @@ public ActionExecutionStatus processSuccessResponse(Map AccessToken responseAccessToken = responseAccessTokenBuilder.build(); updateTokenMessageContext(tokenMessageContext, responseAccessToken); - return new SuccessStatus.Builder().setResponseContext(eventContext).build(); + return new SuccessStatus.Builder().setResponseContext(flowContext.getContextData()).build(); } private void logOperationExecutionResults(ActionType actionType, @@ -164,10 +166,13 @@ private void logOperationExecutionResults(ActionType actionType, } @Override - public ActionExecutionStatus processFailureResponse(Map eventContext, Event actionEvent, - ActionInvocationFailureResponse failureResponse) throws - ActionExecutionResponseProcessorException { + public ActionExecutionStatus processFailureResponse(FlowContext flowContext, + ActionExecutionResponseContext + + responseContext) + throws ActionExecutionResponseProcessorException { + ActionInvocationFailureResponse failureResponse = responseContext.getActionInvocationResponse(); handleInvalidErrorCodes(failureResponse.getFailureReason()); return new FailedStatus(new Failure(failureResponse.getFailureReason(), failureResponse.getFailureDescription())); @@ -207,9 +212,9 @@ private boolean isServerError(String errorCode) { } @Override - public ActionExecutionStatus processErrorResponse(Map map, Event event, - ActionInvocationErrorResponse - actionInvocationErrorResponse) + public ActionExecutionStatus processErrorResponse(FlowContext flowContext, + ActionExecutionResponseContext + responseContext) throws ActionExecutionResponseProcessorException { /* @@ -220,7 +225,7 @@ public ActionExecutionStatus processErrorResponse(Map map * However, currently this value is not propagated by the endpoint to comply with OAuth specification. */ return new ErrorStatus(new Error(OAuth2ErrorCodes.SERVER_ERROR, - actionInvocationErrorResponse.getErrorDescription())); + responseContext.getActionInvocationResponse().getErrorDescription())); } private void updateTokenMessageContext(OAuthTokenReqMessageContext tokenMessageContext, diff --git a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/AbstractAuthorizationGrantHandler.java b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/AbstractAuthorizationGrantHandler.java index 0b8db898c2e..39952da4f0b 100644 --- a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/AbstractAuthorizationGrantHandler.java +++ b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/AbstractAuthorizationGrantHandler.java @@ -31,6 +31,7 @@ import org.wso2.carbon.identity.action.execution.model.ActionType; import org.wso2.carbon.identity.action.execution.model.Error; import org.wso2.carbon.identity.action.execution.model.Failure; +import org.wso2.carbon.identity.action.execution.model.FlowContext; import org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException; import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; import org.wso2.carbon.identity.base.IdentityConstants; @@ -76,13 +77,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.Date; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.function.Consumer; import static org.wso2.carbon.identity.oauth.common.OAuthConstants.OAUTH_APP; import static org.wso2.carbon.identity.oauth.common.OAuthConstants.RENEW_TOKEN_WITHOUT_REVOKING_EXISTING_ENABLE_CONFIG; @@ -614,15 +612,13 @@ private ActionExecutionStatus executePreIssueAccessTokenActions( ActionExecutionStatus executionStatus = null; if (checkExecutePreIssueAccessTokensActions(tokenReqMessageContext)) { - Map additionalProperties = new HashMap<>(); - Consumer> mapInitializer = - map -> map.put("tokenMessageContext", tokenReqMessageContext); - mapInitializer.accept(additionalProperties); + FlowContext flowContext = FlowContext.create().add("tokenMessageContext", tokenReqMessageContext); try { executionStatus = OAuthComponentServiceHolder.getInstance().getActionExecutorService() - .execute(ActionType.PRE_ISSUE_ACCESS_TOKEN, additionalProperties, - IdentityTenantUtil.getTenantDomain(IdentityTenantUtil.getLoginTenantId())); + .execute(ActionType.PRE_ISSUE_ACCESS_TOKEN, flowContext, + IdentityTenantUtil.getTenantDomain(IdentityTenantUtil.getLoginTenantId())); + if (log.isDebugEnabled()) { log.debug(String.format( "Invoked pre issue access token action for clientID: %s grant types: %s. Status: %s", diff --git a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/RefreshGrantHandler.java b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/RefreshGrantHandler.java index e5f3fb6d82c..41d5225ddd4 100644 --- a/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/RefreshGrantHandler.java +++ b/components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/token/handlers/grant/RefreshGrantHandler.java @@ -29,6 +29,7 @@ import org.wso2.carbon.identity.action.execution.model.ActionType; import org.wso2.carbon.identity.action.execution.model.Error; import org.wso2.carbon.identity.action.execution.model.Failure; +import org.wso2.carbon.identity.action.execution.model.FlowContext; import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; import org.wso2.carbon.identity.application.authentication.framework.exception.UserIdNotFoundException; import org.wso2.carbon.identity.application.authentication.framework.inbound.FrameworkClientException; @@ -77,12 +78,9 @@ import java.sql.Timestamp; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -843,14 +841,11 @@ private ActionExecutionStatus executePreIssueAccessTokenActions( setCustomizedAccessTokenAttributesToMessageContext(refreshTokenValidationDataDO, tokenReqMessageContext); - Map additionalProperties = new HashMap<>(); - Consumer> mapInitializer = - map -> map.put("tokenMessageContext", tokenReqMessageContext); - mapInitializer.accept(additionalProperties); + FlowContext flowContext = FlowContext.create().add("tokenMessageContext", tokenReqMessageContext); try { executionStatus = OAuthComponentServiceHolder.getInstance().getActionExecutorService() - .execute(ActionType.PRE_ISSUE_ACCESS_TOKEN, additionalProperties, + .execute(ActionType.PRE_ISSUE_ACCESS_TOKEN, flowContext, IdentityTenantUtil.getTenantDomain(IdentityTenantUtil.getLoginTenantId())); if (log.isDebugEnabled()) { log.debug(String.format( diff --git a/components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenRequestBuilderTest.java b/components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenRequestBuilderTest.java index fe8cf0a16cd..17a23dee77c 100644 --- a/components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenRequestBuilderTest.java +++ b/components/org.wso2.carbon.identity.oauth/src/test/java/org/wso2/carbon/identity/oauth/action/execution/PreIssueAccessTokenRequestBuilderTest.java @@ -23,12 +23,12 @@ import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.wso2.carbon.identity.action.execution.exception.ActionExecutionRequestBuilderException; import org.wso2.carbon.identity.action.execution.model.ActionExecutionRequest; import org.wso2.carbon.identity.action.execution.model.ActionType; import org.wso2.carbon.identity.action.execution.model.AllowedOperation; +import org.wso2.carbon.identity.action.execution.model.FlowContext; import org.wso2.carbon.identity.action.execution.model.Header; import org.wso2.carbon.identity.action.execution.model.Operation; import org.wso2.carbon.identity.action.execution.model.Param; @@ -146,20 +146,13 @@ public void testGetSupportedActionType() { Assert.assertEquals(actionType, ActionType.PRE_ISSUE_ACCESS_TOKEN); } - @DataProvider(name = "BuildTokenRequestMessageContext") - public Object[][] buildTokenRequestMessageContext() { - - return new Object[][]{ - {mockTokenMessageContext()}, - }; - } - - @Test(dataProvider = "BuildTokenRequestMessageContext") - public void testBuildActionExecutionRequest(Map eventContext) + @Test + public void testBuildActionExecutionRequest() throws ActionExecutionRequestBuilderException { ActionExecutionRequest actionExecutionRequest = preIssueAccessTokenRequestBuilder. - buildActionExecutionRequest(eventContext); + buildActionExecutionRequest( + FlowContext.create().add("tokenMessageContext", getMockTokenMessageContext()), null); Assert.assertNotNull(actionExecutionRequest); Assert.assertEquals(actionExecutionRequest.getActionType(), ActionType.PRE_ISSUE_ACCESS_TOKEN); assertEvent((PreIssueAccessTokenEvent) actionExecutionRequest.getEvent(), getExpectedEvent()); @@ -254,21 +247,11 @@ private void assertAllowedOperations(List actual, List mockTokenMessageContext() { - - Map eventContext = new HashMap<>(); + private OAuthTokenReqMessageContext getMockTokenMessageContext() { OAuth2AccessTokenReqDTO tokenReqDTO = mockTokenRequestDTO(); AuthenticatedUser authenticatedUser = mockAuthenticatedUser(); - OAuthTokenReqMessageContext tokenMessageContext = mockMessageContext(tokenReqDTO, authenticatedUser); - eventContext.put("tokenMessageContext", tokenMessageContext); - - return eventContext; + return mockMessageContext(tokenReqDTO, authenticatedUser); } /** diff --git a/pom.xml b/pom.xml index d8d6d26e83b..b0ac914257c 100644 --- a/pom.xml +++ b/pom.xml @@ -967,7 +967,7 @@ [1.0.1, 2.0.0) - 7.7.221 + 7.7.261 [5.25.234, 8.0.0) [2.0.0, 3.0.0)