/** * Extracts url server from the account * * @deprecated This method will be removed in version 1.0. * Use {@link #getBaseUrlForAccount(Context, Account)} * instead. * * @param context * @param account * @return url server or null on failure * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ @Deprecated public static String constructBasicURLForAccount(Context context, Account account) throws AccountNotFoundException { return getBaseUrlForAccount(context, account); }
/** * Method for deferred load of account attributes from AccountManager * * @param context * @throws AccountNotFoundException * @throws AuthenticatorException * @throws IOException * @throws OperationCanceledException */ public void loadCredentials(Context context) throws AuthenticatorException, IOException, OperationCanceledException { if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); } if (mSavedAccount != null) { mCredentials = AccountUtils.getCredentialsForAccount(context, mSavedAccount); } }
public String getDisplayName() { if (mDisplayName != null && mDisplayName.length() > 0) { return mDisplayName; } else if (mCredentials != null) { return mCredentials.getUsername(); } else if (mSavedAccount != null) { return AccountUtils.getUsernameForAccount(mSavedAccount); } else { return null; } }
AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; String username = AccountUtils.getUsernameForAccount(account); AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false); AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false); String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type), false);
/** * Constructor for already saved OC accounts. * * Do not use for anonymous credentials. */ public OwnCloudAccount(Account savedAccount, Context context) throws AccountNotFoundException { if (savedAccount == null) { throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null"); } if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); } mSavedAccount = savedAccount; mSavedAccountName = savedAccount.name; mCredentials = null; // load of credentials is delayed AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseUrl = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_OC_BASE_URL); if (baseUrl == null ) { throw new AccountNotFoundException(mSavedAccount, "Account not found", null); } mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount)); mDisplayName = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME); }
/** * Constructs full url to host and webdav resource basing on host version * * @param context Valid Android {@link Context}, needed to access the {@link AccountManager} * @param account A stored ownCloud {@link Account} * @return Full URL to WebDAV endpoint in the server corresponding to 'account'. * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ public static String getWebDavUrlForAccount(Context context, Account account) throws AccountNotFoundException { String webDavUrlForAccount = ""; try { OwnCloudCredentials ownCloudCredentials = getCredentialsForAccount(context, account); webDavUrlForAccount = getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_FILES_PATH_4_0 + ownCloudCredentials.getUsername(); } catch (OperationCanceledException e) { e.printStackTrace(); } catch (AuthenticatorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return webDavUrlForAccount; }
/** * Constructs full url to host and webdav resource basing on host version * * @deprecated To be removed in release 1.0. * * @param context * @param account * @return url or null on failure * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ @Deprecated public static String constructFullURLForAccount(Context context, Account account) throws AccountNotFoundException { AccountManager ama = AccountManager.get(context); String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL); String version = ama.getUserData(account, Constants.KEY_OC_VERSION); boolean supportsOAuth = (ama.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2) != null); boolean supportsSamlSso = (ama.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null); String webdavpath = getWebdavPath(supportsOAuth, supportsSamlSso); if (baseurl == null || webdavpath == null) throw new AccountNotFoundException(account, "Account not found", null); return baseurl + webdavpath; }
/** * Extracts url server from the account * @param context * @param account * @return url server or null on failure * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ public static String getBaseUrlForAccount(Context context, Account account) throws AccountNotFoundException { AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL); if (baseurl == null ) throw new AccountNotFoundException(account, "Account not found", null); return baseurl; }
/** * Constructor for non yet saved OC accounts. * * @param baseUri URI to the OC server to get access to. * @param credentials Credentials to authenticate in the server. NULL is valid for anonymous credentials. */ public OwnCloudAccount(Uri baseUri, OwnCloudCredentials credentials) { if (baseUri == null) { throw new IllegalArgumentException("Parameter 'baseUri' cannot be null"); } mSavedAccount = null; mSavedAccountName = null; mBaseUri = baseUri; mCredentials = credentials != null ? credentials : OwnCloudCredentialsFactory.getAnonymousCredentials(); String username = mCredentials.getUsername(); if (username != null) { mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username); } }
/** * Asynchronous execution of the operation * started by {@link RemoteOperation#execute(OwnCloudClient, * OnRemoteOperationListener, Handler)}, * and result posting. */ @Override public final void run() { final RemoteOperationResult resultToSend = runOperation(); if (mAccount != null && mContext != null) { // Save Client Cookies AccountUtils.saveClient(mClient, mAccount, mContext); } if (mListenerHandler != null && mListener != null) { mListenerHandler.post(() -> mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend)); } else if (mListener != null) { mListener.onRemoteOperationFinish(RemoteOperation.this, resultToSend); } } }
private void keepCookiesUpdated(Context context, OwnCloudAccount account, OwnCloudClient reusedClient) { AccountManager am = AccountManager.get(context.getApplicationContext()); if (am != null && account.getSavedAccount() != null) { String recentCookies = am.getUserData(account.getSavedAccount(), AccountUtils.Constants.KEY_COOKIES); String previousCookies = reusedClient.getCookiesString(); if (recentCookies != null && previousCookies != "" && !recentCookies.equals(previousCookies)) { AccountUtils.restoreCookies(account.getSavedAccount(), reusedClient, context); } } }
@Override public OwnCloudClient getClientFor(OwnCloudAccount account, Context context) throws AccountUtils.AccountNotFoundException, OperationCanceledException, AuthenticatorException, IOException { OwnCloudVersion ownCloudVersion = null; if (account.getSavedAccount() != null) { ownCloudVersion = AccountUtils.getServerVersionForAccount( account.getSavedAccount(), context ); } if (ownCloudVersion != null && ownCloudVersion.isSessionMonitoringSupported()) { return mSingleSessionManager.getClientFor(account, context); } else { return mSimpleFactoryManager.getClientFor(account, context); } }
public Uri getUserFilesWebDavUri() { return mCredentials instanceof OwnCloudAnonymousCredentials ? Uri.parse(mBaseUri + WEBDAV_FILES_PATH_4_0) : Uri.parse(mBaseUri + WEBDAV_FILES_PATH_4_0 + AccountUtils.getUserId( mAccount.getSavedAccount(), getContext() ) ); }
String username = AccountUtils.getUsernameForAccount(account); OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION)); String accessToken = am.blockingGetAuthToken( account, AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false); String accessToken = am.blockingGetAuthToken( account, AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false); String password = am.blockingGetAuthToken( account, AccountTypeUtils.getAuthTokenTypePass(account.type), false);
/** * Constructor for already saved OC accounts. * * Do not use for anonymous credentials. */ public OwnCloudAccount(Account savedAccount, Context context) throws AccountNotFoundException { if (savedAccount == null) { throw new IllegalArgumentException("Parameter 'savedAccount' cannot be null"); } if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); } mSavedAccount = savedAccount; mSavedAccountName = savedAccount.name; mCredentials = null; // load of credentials is delayed AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseUrl = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_OC_BASE_URL); if (baseUrl == null ) { throw new AccountNotFoundException(mSavedAccount, "Account not found", null); } mBaseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(context, mSavedAccount)); mDisplayName = ama.getUserData(mSavedAccount, AccountUtils.Constants.KEY_DISPLAY_NAME); }
public String getDisplayName() { if (mDisplayName != null && mDisplayName.length() > 0) { return mDisplayName; } else if (mCredentials != null) { return mCredentials.getUsername(); } else if (mSavedAccount != null) { return AccountUtils.getUsernameForAccount(mSavedAccount); } else { return null; } }
/** * Method for deferred load of account attributes from AccountManager * * @param context * @throws AuthenticatorException * @throws IOException * @throws OperationCanceledException */ public void loadCredentials(Context context) throws AuthenticatorException, IOException, OperationCanceledException { if (context == null) { throw new IllegalArgumentException("Parameter 'context' cannot be null"); } if (mSavedAccount != null) { mCredentials = AccountUtils.getCredentialsForAccount(context, mSavedAccount); } }
/** * Extracts url server from the account * * @param context Valid Android {@link Context}, needed to access the {@link AccountManager} * @param account A stored ownCloud {@link Account} * @return Full URL to the server corresponding to 'account', ending in the base path * common to all API endpoints. * @throws AccountNotFoundException When 'account' is unknown for the AccountManager */ public static String getBaseUrlForAccount(Context context, Account account) throws AccountNotFoundException { AccountManager ama = AccountManager.get(context.getApplicationContext()); String baseurl = ama.getUserData(account, Constants.KEY_OC_BASE_URL); if (baseurl == null) throw new AccountNotFoundException(account, "Account not found", null); return baseurl; }
/** * Constructor for non yet saved OC accounts. * * @param baseUri URI to the OC server to get access to. * @param credentials Credentials to authenticate in the server. NULL is valid for anonymous credentials. */ public OwnCloudAccount(Uri baseUri, OwnCloudCredentials credentials) { if (baseUri == null) { throw new IllegalArgumentException("Parameter 'baseUri' cannot be null"); } mSavedAccount = null; mSavedAccountName = null; mBaseUri = baseUri; mCredentials = credentials != null ? credentials : OwnCloudCredentialsFactory.getAnonymousCredentials(); String username = mCredentials.getUsername(); if (username != null) { mSavedAccountName = AccountUtils.buildAccountName(mBaseUri, username); } }
public Uri getUploadsWebDavUri() { return mCredentials instanceof OwnCloudAnonymousCredentials ? Uri.parse(mBaseUri + WEBDAV_UPLOADS_PATH_4_0) : Uri.parse(mBaseUri + WEBDAV_UPLOADS_PATH_4_0 + AccountUtils.getUserId( mAccount.getSavedAccount(), getContext() ) ); }