use of com.salesforce.androidsdk.rest.RestClient.ClientInfo in project SalesforceMobileSDK-Android by forcedotcom.
the class ClientManager method peekRestClient.
public RestClient peekRestClient(Account acc) {
if (acc == null) {
AccountInfoNotFoundException e = new AccountInfoNotFoundException("No user account found");
SalesforceSDKLogger.i(TAG, "No user account found", e);
throw e;
}
if (SalesforceSDKManager.getInstance().isLoggingOut()) {
AccountInfoNotFoundException e = new AccountInfoNotFoundException("User is logging out");
SalesforceSDKLogger.i(TAG, "User is logging out", e);
throw e;
}
final String encryptionKey = SalesforceSDKManager.getEncryptionKey();
final String authToken = SalesforceSDKManager.decrypt(accountManager.getUserData(acc, AccountManager.KEY_AUTHTOKEN), encryptionKey);
final String refreshToken = SalesforceSDKManager.decrypt(accountManager.getPassword(acc), encryptionKey);
final String loginServer = SalesforceSDKManager.decrypt(accountManager.getUserData(acc, AuthenticatorService.KEY_LOGIN_URL), encryptionKey);
final String idUrl = SalesforceSDKManager.decrypt(accountManager.getUserData(acc, AuthenticatorService.KEY_ID_URL), encryptionKey);
final String instanceServer = SalesforceSDKManager.decrypt(accountManager.getUserData(acc, AuthenticatorService.KEY_INSTANCE_URL), encryptionKey);
final String orgId = SalesforceSDKManager.decrypt(accountManager.getUserData(acc, AuthenticatorService.KEY_ORG_ID), encryptionKey);
final String userId = SalesforceSDKManager.decrypt(accountManager.getUserData(acc, AuthenticatorService.KEY_USER_ID), encryptionKey);
final String username = SalesforceSDKManager.decrypt(accountManager.getUserData(acc, AuthenticatorService.KEY_USERNAME), encryptionKey);
final String accountName = accountManager.getUserData(acc, AccountManager.KEY_ACCOUNT_NAME);
final String lastName = SalesforceSDKManager.decrypt(accountManager.getUserData(acc, AuthenticatorService.KEY_LAST_NAME), encryptionKey);
final String email = SalesforceSDKManager.decrypt(accountManager.getUserData(acc, AuthenticatorService.KEY_EMAIL), encryptionKey);
final String encFirstName = accountManager.getUserData(acc, AuthenticatorService.KEY_FIRST_NAME);
String firstName = null;
if (encFirstName != null) {
firstName = SalesforceSDKManager.decrypt(encFirstName, encryptionKey);
}
final String encDisplayName = accountManager.getUserData(acc, AuthenticatorService.KEY_DISPLAY_NAME);
String displayName = null;
if (encDisplayName != null) {
displayName = SalesforceSDKManager.decrypt(encDisplayName, encryptionKey);
}
final String encPhotoUrl = accountManager.getUserData(acc, AuthenticatorService.KEY_PHOTO_URL);
String photoUrl = null;
if (encPhotoUrl != null) {
photoUrl = SalesforceSDKManager.decrypt(encPhotoUrl, encryptionKey);
}
final String encThumbnailUrl = accountManager.getUserData(acc, AuthenticatorService.KEY_THUMBNAIL_URL);
String thumbnailUrl = null;
if (encThumbnailUrl != null) {
thumbnailUrl = SalesforceSDKManager.decrypt(encThumbnailUrl, encryptionKey);
}
final String encLightningDomain = accountManager.getUserData(acc, AuthenticatorService.KEY_LIGHTNING_DOMAIN);
String lightningDomain = null;
if (encLightningDomain != null) {
lightningDomain = SalesforceSDKManager.decrypt(encLightningDomain, encryptionKey);
}
final String encLightningSid = accountManager.getUserData(acc, AuthenticatorService.KEY_LIGHTNING_SID);
String lightningSid = null;
if (encLightningSid != null) {
lightningSid = SalesforceSDKManager.decrypt(encLightningSid, encryptionKey);
}
final String encVFDomain = accountManager.getUserData(acc, AuthenticatorService.KEY_VF_DOMAIN);
String vfDomain = null;
if (encVFDomain != null) {
vfDomain = SalesforceSDKManager.decrypt(encVFDomain, encryptionKey);
}
final String encVFSid = accountManager.getUserData(acc, AuthenticatorService.KEY_VF_SID);
String vfSid = null;
if (encVFSid != null) {
vfSid = SalesforceSDKManager.decrypt(encVFSid, encryptionKey);
}
final String encContentDomain = accountManager.getUserData(acc, AuthenticatorService.KEY_CONTENT_DOMAIN);
String contentDomain = null;
if (encContentDomain != null) {
contentDomain = SalesforceSDKManager.decrypt(encContentDomain, encryptionKey);
}
final String encContentSid = accountManager.getUserData(acc, AuthenticatorService.KEY_CONTENT_SID);
String contentSid = null;
if (encContentSid != null) {
contentSid = SalesforceSDKManager.decrypt(encContentSid, encryptionKey);
}
final String encCSRFToken = accountManager.getUserData(acc, AuthenticatorService.KEY_CSRF_TOKEN);
String csrfToken = null;
if (encCSRFToken != null) {
csrfToken = SalesforceSDKManager.decrypt(encCSRFToken, encryptionKey);
}
final List<String> additionalOauthKeys = SalesforceSDKManager.getInstance().getAdditionalOauthKeys();
Map<String, String> values = null;
if (additionalOauthKeys != null && !additionalOauthKeys.isEmpty()) {
values = new HashMap<>();
for (final String key : additionalOauthKeys) {
final String encValue = accountManager.getUserData(acc, key);
if (encValue != null) {
final String value = SalesforceSDKManager.decrypt(encValue, encryptionKey);
values.put(key, value);
}
}
}
final String encCommunityId = accountManager.getUserData(acc, AuthenticatorService.KEY_COMMUNITY_ID);
String communityId = null;
if (encCommunityId != null) {
communityId = SalesforceSDKManager.decrypt(encCommunityId, encryptionKey);
}
final String encCommunityUrl = accountManager.getUserData(acc, AuthenticatorService.KEY_COMMUNITY_URL);
String communityUrl = null;
if (encCommunityUrl != null) {
communityUrl = SalesforceSDKManager.decrypt(encCommunityUrl, encryptionKey);
}
if (authToken == null) {
throw new AccountInfoNotFoundException(AccountManager.KEY_AUTHTOKEN);
}
if (instanceServer == null) {
throw new AccountInfoNotFoundException(AuthenticatorService.KEY_INSTANCE_URL);
}
if (userId == null) {
throw new AccountInfoNotFoundException(AuthenticatorService.KEY_USER_ID);
}
if (orgId == null) {
throw new AccountInfoNotFoundException(AuthenticatorService.KEY_ORG_ID);
}
try {
final AccMgrAuthTokenProvider authTokenProvider = new AccMgrAuthTokenProvider(this, instanceServer, authToken, refreshToken);
final ClientInfo clientInfo = new ClientInfo(new URI(instanceServer), new URI(loginServer), new URI(idUrl), accountName, username, userId, orgId, communityId, communityUrl, firstName, lastName, displayName, email, photoUrl, thumbnailUrl, values, lightningDomain, lightningSid, vfDomain, vfSid, contentDomain, contentSid, csrfToken);
return new RestClient(clientInfo, authToken, HttpAccess.DEFAULT, authTokenProvider);
} catch (URISyntaxException e) {
SalesforceSDKLogger.w(TAG, "Invalid server URL", e);
throw new AccountInfoNotFoundException("invalid server url", e);
}
}
use of com.salesforce.androidsdk.rest.RestClient.ClientInfo in project SalesforceMobileSDK-Android by forcedotcom.
the class PushService method getRestClient.
private RestClient getRestClient(UserAccount account) {
final ClientManager cm = SalesforceSDKManager.getInstance().getClientManager();
RestClient client = null;
/*
* The reason we can't directly call 'peekRestClient()' here is because
* ClientManager does not hand out a rest client when a logout is in
* progress. Hence, we build a rest client here manually, with the
* available data in the 'account' object.
*/
if (cm != null) {
try {
final AccMgrAuthTokenProvider authTokenProvider = new AccMgrAuthTokenProvider(cm, account.getInstanceServer(), account.getAuthToken(), account.getRefreshToken());
final ClientInfo clientInfo = new ClientInfo(new URI(account.getInstanceServer()), new URI(account.getLoginServer()), new URI(account.getIdUrl()), account.getAccountName(), account.getUsername(), account.getUserId(), account.getOrgId(), account.getCommunityId(), account.getCommunityUrl(), account.getFirstName(), account.getLastName(), account.getDisplayName(), account.getEmail(), account.getPhotoUrl(), account.getThumbnailUrl(), account.getAdditionalOauthValues(), account.getLightningDomain(), account.getLightningSid(), account.getVFDomain(), account.getVFSid(), account.getContentDomain(), account.getContentSid(), account.getCSRFToken());
client = new RestClient(clientInfo, account.getAuthToken(), HttpAccess.DEFAULT, authTokenProvider);
} catch (Exception e) {
SalesforceSDKLogger.e(TAG, "Failed to get rest client", e);
}
}
return client;
}
use of com.salesforce.androidsdk.rest.RestClient.ClientInfo in project SalesforceMobileSDK-Android by forcedotcom.
the class RestClientTest method setUp.
@Before
public void setUp() throws Exception {
TestCredentials.init(InstrumentationRegistry.getInstrumentation().getContext());
httpAccess = new HttpAccess(null, "dummy-agent");
TokenEndpointResponse refreshResponse = OAuth2.refreshAuthToken(httpAccess, new URI(TestCredentials.LOGIN_URL), TestCredentials.CLIENT_ID, TestCredentials.REFRESH_TOKEN, null);
authToken = refreshResponse.authToken;
instanceUrl = refreshResponse.instanceUrl;
testOauthKeys = new ArrayList<>();
testOauthKeys.add(TEST_CUSTOM_KEY);
testOauthValues = new HashMap<>();
testOauthValues.put(TEST_CUSTOM_KEY, TEST_CUSTOM_VALUE);
SalesforceSDKManager.getInstance().setAdditionalOauthKeys(testOauthKeys);
clientInfo = new ClientInfo(new URI(TestCredentials.INSTANCE_URL), new URI(TestCredentials.LOGIN_URL), new URI(TestCredentials.IDENTITY_URL), TestCredentials.ACCOUNT_NAME, TestCredentials.USERNAME, TestCredentials.USER_ID, TestCredentials.ORG_ID, null, null, TEST_FIRST_NAME, TEST_LAST_NAME, TEST_DISPLAY_NAME, TEST_EMAIL, TestCredentials.PHOTO_URL, TEST_THUMBNAIL_URL, testOauthValues, null, null, null, null, null, null, null);
restClient = new RestClient(clientInfo, authToken, httpAccess, null);
}
use of com.salesforce.androidsdk.rest.RestClient.ClientInfo in project SalesforceMobileSDK-Android by forcedotcom.
the class RestClientTest method testClientInfoResolveUrlForCommunityUrl.
@Test
public void testClientInfoResolveUrlForCommunityUrl() throws Exception {
final ClientInfo info = new ClientInfo(new URI(TestCredentials.INSTANCE_URL), new URI(TestCredentials.LOGIN_URL), new URI(TestCredentials.IDENTITY_URL), TestCredentials.ACCOUNT_NAME, TestCredentials.USERNAME, TestCredentials.USER_ID, TestCredentials.ORG_ID, null, TestCredentials.COMMUNITY_URL, null, null, null, null, null, null, testOauthValues, null, null, null, null, null, null, null);
Assert.assertEquals("Wrong url", TestCredentials.COMMUNITY_URL + "/a/b/", info.resolveUrl("a/b/").toString());
Assert.assertEquals("Wrong url", TestCredentials.COMMUNITY_URL + "/a/b/", info.resolveUrl("/a/b/").toString());
}
use of com.salesforce.androidsdk.rest.RestClient.ClientInfo in project SalesforceMobileSDK-Android by forcedotcom.
the class RestClientTest method testGetInstanceUrlForCommunity.
@Test
public void testGetInstanceUrlForCommunity() throws Exception {
final ClientInfo info = new ClientInfo(new URI(TestCredentials.INSTANCE_URL), new URI(TestCredentials.LOGIN_URL), new URI(TestCredentials.IDENTITY_URL), TestCredentials.ACCOUNT_NAME, TestCredentials.USERNAME, TestCredentials.USER_ID, TestCredentials.ORG_ID, null, TestCredentials.COMMUNITY_URL, null, null, null, null, null, null, testOauthValues, null, null, null, null, null, null, null);
Assert.assertEquals("Wrong url", TestCredentials.COMMUNITY_URL, info.getInstanceUrlAsString());
}
Aggregations