Skip to content

Commit

Permalink
Add timeout for long wait
Browse files Browse the repository at this point in the history
Resolves wso2#1665
  • Loading branch information
madurangasiriwardena committed Jul 29, 2018
1 parent 0f34be2 commit d9fd348
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
import org.wso2.carbon.identity.application.mgt.ApplicationConstants;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.core.util.IdentityUtil;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -70,6 +71,7 @@
import static org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus.FAIL_COMPLETED;
import static org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus.INCOMPLETE;
import static org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus.SUCCESS_COMPLETED;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.AdaptiveAuthentication.ADAPTIVE_AUTH_LONG_WAIT_TIMEOUT;
import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils.promptOnLongWait;

public class GraphBasedSequenceHandler extends DefaultStepBasedSequenceHandler implements SequenceHandler {
Expand Down Expand Up @@ -471,12 +473,14 @@ private boolean callExternalSystem(HttpServletRequest request, HttpServletRespon
if (caller != null) {
FrameworkServiceDataHolder.getInstance().getAsyncSequenceExecutor().exec(caller, asyncReturn, context);
if (!promptOnLongWait()) {
int waitTimeout = getLongWaitTimeout();
synchronized (context) {
try {
context.wait();
context.wait(waitTimeout);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.error("Error while waiting for the external call the complete. ", e);
log.error("Thread interrupted while waiting for the external call to complete for session " +
"data key: " + context.getContextIdentifier() + ". ", e);
}
}
resumeLongWait(request, response, context);
Expand All @@ -486,6 +490,23 @@ private boolean callExternalSystem(HttpServletRequest request, HttpServletRespon
return false;
}

private int getLongWaitTimeout() {

String waitTimeoutPropValue = IdentityUtil.getProperty(ADAPTIVE_AUTH_LONG_WAIT_TIMEOUT);
int waitTimeout = 10000;
try {
if (waitTimeoutPropValue != null) {
waitTimeout = Integer.parseInt(waitTimeoutPropValue);
}
} catch (NumberFormatException e) {
//ignore. Default value will be used.
if (log.isDebugEnabled()) {
log.debug("Error while reading the wait timeout. ", e);
}
}
return waitTimeout;
}

private void handleDecisionPoint(HttpServletRequest request, HttpServletResponse response,
AuthenticationContext context, SequenceConfig sequenceConfig,
DynamicDecisionNode dynamicDecisionNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,9 @@ public static class Consent {
public static final String EXPLICIT_CONSENT_TYPE = "EXPLICIT";
public static final String INFINITE_TERMINATION = "DATE_UNTIL:INDEFINITE";
}

public static class AdaptiveAuthentication {

public static final String ADAPTIVE_AUTH_LONG_WAIT_TIMEOUT = "AdaptiveAuth.LongWaitTimeout";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,9 @@
<!--End of timeouts in milliseconds-->

<!--<PromptOnLongWait>false</PromptOnLongWait>-->

<!--Timeout in milliseconds for the waiting external calls-->
<LongWaitTimeout>10000</LongWaitTimeout>
</AdaptiveAuth>

</Server>

0 comments on commit d9fd348

Please sign in to comment.