BoxAuthStorage.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.epson.iprint.storage.box;
  2. import android.content.Context;
  3. import com.box.androidsdk.content.auth.BoxAuthentication;
  4. import com.box.androidsdk.content.models.BoxEntity;
  5. import com.eclipsesource.json.JsonObject;
  6. import com.eclipsesource.json.JsonValue;
  7. import com.epson.iprint.storage.StorageSecureStore;
  8. import epson.server.utils.Define;
  9. import java.util.Map;
  10. import java.util.concurrent.ConcurrentHashMap;
  11. public class BoxAuthStorage extends BoxAuthentication.AuthStorage {
  12. private static final String SECURE_STORE_KEY = "FolderViewer.BOXNET_AUTO_INFO_V4";
  13. protected void storeAuthInfoMap(Map<String, BoxAuthentication.BoxAuthenticationInfo> map, Context context) {
  14. JsonObject jsonObject = new JsonObject();
  15. for (Map.Entry next : map.entrySet()) {
  16. jsonObject.add((String) next.getKey(), (JsonValue) ((BoxAuthentication.BoxAuthenticationInfo) next.getValue()).toJsonObject());
  17. }
  18. StorageSecureStore.getSharedSecureStore().put("FolderViewer.BOXNET_AUTO_INFO_V4", new BoxEntity(jsonObject).toJson(), StorageSecureStore.EXEC_MODE.OVERWRITE_IF_EXIST);
  19. }
  20. protected void clearAuthInfoMap(Context context) {
  21. StorageSecureStore.getSharedSecureStore().revoke("FolderViewer.BOXNET_AUTO_INFO_V4");
  22. }
  23. protected void storeLastAuthenticatedUserId(String str, Context context) {
  24. StorageSecureStore sharedSecureStore = StorageSecureStore.getSharedSecureStore();
  25. if (str == null || str.isEmpty()) {
  26. sharedSecureStore.revoke(Define.BOXNET_LAST_AUTHENTICATED_USER_ID);
  27. } else {
  28. sharedSecureStore.put(Define.BOXNET_LAST_AUTHENTICATED_USER_ID, str, StorageSecureStore.EXEC_MODE.OVERWRITE_IF_EXIST);
  29. }
  30. }
  31. protected String getLastAuthentictedUserId(Context context) {
  32. return StorageSecureStore.getSharedSecureStore().fetch(Define.BOXNET_LAST_AUTHENTICATED_USER_ID);
  33. }
  34. protected ConcurrentHashMap<String, BoxAuthentication.BoxAuthenticationInfo> loadAuthInfoMap(Context context) {
  35. ConcurrentHashMap<String, BoxAuthentication.BoxAuthenticationInfo> concurrentHashMap = new ConcurrentHashMap<>();
  36. String fetch = StorageSecureStore.getSharedSecureStore().fetch("FolderViewer.BOXNET_AUTO_INFO_V4");
  37. if (fetch != null && fetch.length() > 0) {
  38. BoxEntity boxEntity = new BoxEntity();
  39. boxEntity.createFromJson(fetch);
  40. for (String next : boxEntity.getPropertiesKeySet()) {
  41. JsonValue propertyValue = boxEntity.getPropertyValue(next);
  42. BoxAuthentication.BoxAuthenticationInfo boxAuthenticationInfo = null;
  43. if (propertyValue.isString()) {
  44. boxAuthenticationInfo = new BoxAuthentication.BoxAuthenticationInfo();
  45. boxAuthenticationInfo.createFromJson(propertyValue.asString());
  46. } else if (propertyValue.isObject()) {
  47. boxAuthenticationInfo = new BoxAuthentication.BoxAuthenticationInfo();
  48. boxAuthenticationInfo.createFromJson(propertyValue.asObject());
  49. }
  50. concurrentHashMap.put(next, boxAuthenticationInfo);
  51. }
  52. }
  53. return concurrentHashMap;
  54. }
  55. public static void deleteOldData() {
  56. StorageSecureStore sharedSecureStore = StorageSecureStore.getSharedSecureStore();
  57. sharedSecureStore.revoke(Define.BOXNET_TOKEN);
  58. sharedSecureStore.revoke(Define.BOXNET_USERNAME);
  59. sharedSecureStore.revoke(Define.BOXNET_PASSOWRD);
  60. }
  61. }