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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations