Skip to content

Commit

Permalink
Get callerSessionDataKey for success request
Browse files Browse the repository at this point in the history
  • Loading branch information
janakamarasena committed Oct 24, 2023
1 parent 67f1aea commit 7bb0b7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private AuthServiceResponse processCommonAuthResponse(AuthServiceRequestWrapper
AuthServiceResponse authServiceResponse = new AuthServiceResponse();

if (isAuthFlowSuccessful(request)) {
handleSuccessAuthResponse(request, authServiceResponse);
handleSuccessAuthResponse(request, response, authServiceResponse);
} else if (isAuthFlowFailed(request, response)) {
handleFailedAuthResponse(request, response, authServiceResponse);
} else if (isAuthFlowIncomplete(request)) {
Expand Down Expand Up @@ -124,9 +124,10 @@ private void handleIntermediateAuthResponse(AuthServiceRequestWrapper request, A
authServiceResponse.setData(responseData);
}

private void handleSuccessAuthResponse(AuthServiceRequestWrapper request, AuthServiceResponse authServiceResponse) {
private void handleSuccessAuthResponse(AuthServiceRequestWrapper request, AuthServiceResponseWrapper response,
AuthServiceResponse authServiceResponse) throws AuthServiceException {

authServiceResponse.setSessionDataKey(request.getSessionDataKey());
authServiceResponse.setSessionDataKey(getFlowCompletionSessionDataKey(request, response));
authServiceResponse.setFlowStatus(AuthServiceConstants.FlowStatus.SUCCESS_COMPLETED);
}

Expand Down Expand Up @@ -272,8 +273,19 @@ private boolean isSentToRetryPageOnMissingContext(AuthServiceRequestWrapper requ
Boolean.TRUE.equals(request.getAttribute(FrameworkConstants.IS_SENT_TO_RETRY))) {
Map<String, String> queryParams = AuthServiceUtils.extractQueryParams(response.getRedirectURL());
return StringUtils.equals(queryParams.get(FrameworkConstants.STATUS_PARAM),
FrameworkConstants.ERROR_STATUS_AUTH_CONTEXT_NULL);
FrameworkConstants.ERROR_STATUS_AUTH_CONTEXT_NULL);
}
return false;
}

private String getFlowCompletionSessionDataKey(AuthServiceRequestWrapper request,
AuthServiceResponseWrapper response) throws AuthServiceException {

String completionSessionDataKey = (String) request.getAttribute(FrameworkConstants.SESSION_DATA_KEY);
if (StringUtils.isBlank(completionSessionDataKey)) {
completionSessionDataKey = response.getSessionDataKey();
}

return completionSessionDataKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.wso2.carbon.identity.application.authentication.framework.exception.auth.service.AuthServiceException;
import org.wso2.carbon.identity.application.authentication.framework.model.CommonAuthResponseWrapper;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;
import org.wso2.carbon.identity.application.authentication.framework.util.auth.service.AuthServiceConstants;
import org.wso2.carbon.identity.application.authentication.framework.util.auth.service.AuthServiceUtils;

Expand Down Expand Up @@ -65,6 +66,18 @@ public boolean isErrorResponse() throws AuthServiceException {
return Boolean.parseBoolean(queryParams.get(AuthServiceConstants.AUTH_FAILURE_PARAM));
}

/**
* Get the sessionDataKey related to the authentication flow.
*
* @return String of sessionDataKey.
* @throws AuthServiceException
*/
public String getSessionDataKey() throws AuthServiceException {

Map<String, String> queryParams = AuthServiceUtils.extractQueryParams(getRedirectURL());
return queryParams.get(FrameworkConstants.SESSION_DATA_KEY);
}

@Override
public String getRedirectURL() {

Expand Down

0 comments on commit 7bb0b7f

Please sign in to comment.