Search in sources :

Example 1 with BaseController

use of com.microsoft.identity.common.internal.controllers.BaseController in project microsoft-authentication-library-common-for-android by AzureAD.

the class LoadAccountCommand method execute.

@Override
public List<ICacheRecord> execute() throws Exception {
    final String methodName = ":execute";
    List<ICacheRecord> result = new ArrayList<>();
    for (int ii = 0; ii < getControllers().size(); ii++) {
        final BaseController controller = getControllers().get(ii);
        com.microsoft.identity.common.internal.logging.Logger.verbose(TAG + methodName, "Executing with controller: " + controller.getClass().getSimpleName());
        result.addAll(controller.getAccounts(getParameters()));
    }
    return result;
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) BaseController(com.microsoft.identity.common.internal.controllers.BaseController) ArrayList(java.util.ArrayList)

Example 2 with BaseController

use of com.microsoft.identity.common.internal.controllers.BaseController in project microsoft-authentication-library-common-for-android by AzureAD.

the class RemoveAccountCommand method execute.

@Override
public Boolean execute() throws Exception {
    final String methodName = ":execute";
    boolean result = false;
    for (int ii = 0; ii < getControllers().size(); ii++) {
        final BaseController controller = getControllers().get(ii);
        com.microsoft.identity.common.internal.logging.Logger.verbose(TAG + methodName, "Executing with controller: " + controller.getClass().getSimpleName());
        result = controller.removeAccount((RemoveAccountCommandParameters) getParameters());
    }
    return result;
}
Also used : BaseController(com.microsoft.identity.common.internal.controllers.BaseController) RemoveAccountCommandParameters(com.microsoft.identity.common.internal.commands.parameters.RemoveAccountCommandParameters)

Example 3 with BaseController

use of com.microsoft.identity.common.internal.controllers.BaseController in project microsoft-authentication-library-common-for-android by AzureAD.

the class DeviceCodeFlowCommand method execute.

@Override
public AcquireTokenResult execute() throws Exception {
    final String methodName = ":execute";
    Logger.verbose(TAG + methodName, "Device Code Flow command initiating...");
    // Get the controller used to execute the command
    final BaseController controller = getDefaultController();
    // Fetch the parameters
    final DeviceCodeFlowCommandParameters commandParameters = (DeviceCodeFlowCommandParameters) getParameters();
    // Call deviceCodeFlowAuthRequest to get authorization result (Part 1 of DCF)
    @SuppressWarnings(WarningType.rawtype_warning) final AuthorizationResult authorizationResult = controller.deviceCodeFlowAuthRequest(commandParameters);
    // Fetch the authorization response
    final MicrosoftStsAuthorizationResponse authorizationResponse = (MicrosoftStsAuthorizationResponse) authorizationResult.getAuthorizationResponse();
    final Date expiredDate = new Date();
    try {
        long expiredInInMilliseconds = TimeUnit.SECONDS.toMillis(Long.parseLong(authorizationResponse.getExpiresIn()));
        expiredDate.setTime(expiredDate.getTime() + expiredInInMilliseconds);
    } catch (final NumberFormatException e) {
        // Shouldn't happen, but if it does, we don't want to fail the request because of this.
        Logger.error(TAG + methodName, "Failed to parse authorizationResponse.getExpiresIn()", e);
    }
    // Communicate with user app and provide authentication information
    @SuppressWarnings(WarningType.rawtype_warning) final DeviceCodeFlowCommandCallback deviceCodeFlowCommandCallback = (DeviceCodeFlowCommandCallback) getCallback();
    deviceCodeFlowCommandCallback.onUserCodeReceived(authorizationResponse.getVerificationUri(), authorizationResponse.getUserCode(), authorizationResponse.getMessage(), expiredDate);
    // Call acquireDeviceCodeFlowToken to get token result (Part 2 of DCF)
    final AcquireTokenResult tokenResult = controller.acquireDeviceCodeFlowToken(authorizationResult, commandParameters);
    Logger.verbose(TAG + methodName, "Device Code Flow command exiting with token...");
    return tokenResult;
}
Also used : AcquireTokenResult(com.microsoft.identity.common.internal.result.AcquireTokenResult) MicrosoftStsAuthorizationResponse(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationResponse) BaseController(com.microsoft.identity.common.internal.controllers.BaseController) DeviceCodeFlowCommandParameters(com.microsoft.identity.common.internal.commands.parameters.DeviceCodeFlowCommandParameters) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) Date(java.util.Date)

Example 4 with BaseController

use of com.microsoft.identity.common.internal.controllers.BaseController 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)

Example 5 with BaseController

use of com.microsoft.identity.common.internal.controllers.BaseController in project microsoft-authentication-library-common-for-android by AzureAD.

the class GetCurrentAccountCommand method execute.

@Override
public List<ICacheRecord> execute() throws Exception {
    final String methodName = ":execute";
    List<ICacheRecord> result = new ArrayList<>();
    for (int ii = 0; ii < getControllers().size(); ii++) {
        final BaseController controller = getControllers().get(ii);
        com.microsoft.identity.common.internal.logging.Logger.verbose(TAG + methodName, "Executing with controller: " + controller.getClass().getSimpleName());
        result.addAll(controller.getCurrentAccount(getParameters()));
    }
    return result;
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) BaseController(com.microsoft.identity.common.internal.controllers.BaseController) ArrayList(java.util.ArrayList)

Aggregations

BaseController (com.microsoft.identity.common.internal.controllers.BaseController)7 ClientException (com.microsoft.identity.common.exception.ClientException)2 UiRequiredException (com.microsoft.identity.common.exception.UiRequiredException)2 ICacheRecord (com.microsoft.identity.common.internal.cache.ICacheRecord)2 AcquireTokenResult (com.microsoft.identity.common.internal.result.AcquireTokenResult)2 ArrayList (java.util.ArrayList)2 DeviceCodeFlowCommandParameters (com.microsoft.identity.common.internal.commands.parameters.DeviceCodeFlowCommandParameters)1 GenerateShrCommandParameters (com.microsoft.identity.common.internal.commands.parameters.GenerateShrCommandParameters)1 RemoveAccountCommandParameters (com.microsoft.identity.common.internal.commands.parameters.RemoveAccountCommandParameters)1 SilentTokenCommandParameters (com.microsoft.identity.common.internal.commands.parameters.SilentTokenCommandParameters)1 MicrosoftStsAuthorizationResponse (com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationResponse)1 AuthorizationResult (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)1 GenerateShrResult (com.microsoft.identity.common.internal.result.GenerateShrResult)1 Date (java.util.Date)1