Search in sources :

Example 1 with GenerateShrCommandParameters

use of com.microsoft.identity.common.internal.commands.parameters.GenerateShrCommandParameters in project microsoft-authentication-library-common-for-android by AzureAD.

the class GenerateShrCommand method execute.

@Override
public GenerateShrResult execute() throws Exception {
    final String methodName = ":execute";
    GenerateShrResult result = null;
    final GenerateShrCommandParameters parameters = (GenerateShrCommandParameters) getParameters();
    // Iterate over our controllers, to service the request either locally or via the broker...
    // if the local (embedded) cache contains tokens for the supplied user, we will sign using
    // the embedded PoP keys. If no local user-state exists, the broker will be delegated to
    // where the same check is performed.
    BaseController controller;
    for (int ii = 0; ii < getControllers().size(); ii++) {
        controller = getControllers().get(ii);
        com.microsoft.identity.common.internal.logging.Logger.verbose(TAG + methodName, "Executing with controller: " + controller.getClass().getSimpleName());
        result = controller.generateSignedHttpRequest(parameters);
        if (null != result.getErrorCode()) {
            final String errorCode = result.getErrorCode();
            final String errorMessage = result.getErrorMessage();
            // of as thrown Exceptions
            if (NO_ACCOUNT_FOUND.equalsIgnoreCase(errorCode)) {
                if (getControllers().size() > ii + 1) {
                    // Try our next controller
                    continue;
                } else {
                    throw new UiRequiredException(errorCode, errorMessage);
                }
            } else {
                throw new ClientException(errorCode, errorMessage);
            }
        }
    }
    return result;
}
Also used : GenerateShrResult(com.microsoft.identity.common.internal.result.GenerateShrResult) BaseController(com.microsoft.identity.common.internal.controllers.BaseController) UiRequiredException(com.microsoft.identity.common.exception.UiRequiredException) ClientException(com.microsoft.identity.common.exception.ClientException) GenerateShrCommandParameters(com.microsoft.identity.common.internal.commands.parameters.GenerateShrCommandParameters)

Aggregations

ClientException (com.microsoft.identity.common.exception.ClientException)1 UiRequiredException (com.microsoft.identity.common.exception.UiRequiredException)1 GenerateShrCommandParameters (com.microsoft.identity.common.internal.commands.parameters.GenerateShrCommandParameters)1 BaseController (com.microsoft.identity.common.internal.controllers.BaseController)1 GenerateShrResult (com.microsoft.identity.common.internal.result.GenerateShrResult)1