use of com.owncloud.android.lib.common.network.RedirectionPath in project android by owncloud.
the class AuthenticatorAsyncTask method doInBackground.
@Override
protected RemoteOperationResult doInBackground(Object... params) {
RemoteOperationResult result;
if (params != null && params.length == 2) {
String url = (String) params[0];
OwnCloudCredentials credentials = (OwnCloudCredentials) params[1];
// Client
Uri uri = Uri.parse(url);
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, mContext, true);
client.setCredentials(credentials);
// Operation - try credentials
ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(REMOTE_PATH, mContext, SUCCESS_IF_ABSENT);
result = operation.execute(client);
String targetUrlAfterPermanentRedirection = null;
if (operation.wasRedirected()) {
RedirectionPath redirectionPath = operation.getRedirectionPath();
targetUrlAfterPermanentRedirection = redirectionPath.getLastPermanentLocation();
}
// Operation - get display name
if (result.isSuccess()) {
GetRemoteUserInfoOperation remoteUserNameOperation = new GetRemoteUserInfoOperation();
if (targetUrlAfterPermanentRedirection != null) {
// we can't assume that any subpath of the domain is correctly redirected; ugly stuff
client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(AccountUtils.trimWebdavSuffix(targetUrlAfterPermanentRedirection)), mContext, true);
client.setCredentials(credentials);
}
result = remoteUserNameOperation.execute(client);
}
// let the caller knows what is real URL that should be accessed for the account
// being authenticated if the initial URL is being redirected permanently (HTTP code 301)
result.setLastPermanentLocation(targetUrlAfterPermanentRedirection);
} else {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
}
return result;
}
Aggregations