io.particle.android.sdk.persistance.SensitiveDataStorage Java Examples

The following examples show how to use io.particle.android.sdk.persistance.SensitiveDataStorage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParticleAccessToken.java    From particle-android with Apache License 2.0 6 votes vote down vote up
@Nullable
public static synchronized ParticleAccessToken fromSavedSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    String accessToken = sensitiveDataStorage.getToken();
    String refreshToken = sensitiveDataStorage.getRefreshToken();
    Date expirationDate = sensitiveDataStorage.getTokenExpirationDate();

    // are either of the fields "falsey" or has the expr date passed?
    if (!Py.truthy(accessToken) || !Py.truthy(expirationDate) || expirationDate.before(new Date())) {
        return null;
    }

    ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
            new Handler(Looper.getMainLooper()));
    token.scheduleExpiration();
    return token;
}
 
Example #2
Source File: ParticleAccessToken.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
@Nullable
public static synchronized ParticleAccessToken fromSavedSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    String accessToken = sensitiveDataStorage.getToken();
    String refreshToken = sensitiveDataStorage.getRefreshToken();
    Date expirationDate = sensitiveDataStorage.getTokenExpirationDate();

    // are either of the fields "falsey" or has the expr date passed?
    if (!Py.truthy(accessToken) || !Py.truthy(expirationDate) || expirationDate.before(new Date())) {
        return null;
    }

    ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
            new Handler(Looper.getMainLooper()));
    token.scheduleExpiration();
    return token;
}
 
Example #3
Source File: NextActivitySelector.java    From particle-android with Apache License 2.0 5 votes vote down vote up
private NextActivitySelector(ParticleCloud cloud,
                             SensitiveDataStorage credStorage,
                             SetupCompleteIntentBuilder setupCompleteIntentBuilder) {
    Preconditions.checkNotNull(setupCompleteIntentBuilder, "SetupCompleteIntentBuilder instance is null");

    this.cloud = cloud;
    this.credStorage = credStorage;
    this.setupCompleteIntentBuilder = setupCompleteIntentBuilder;
}
 
Example #4
Source File: NextActivitySelector.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private NextActivitySelector(ParticleCloud cloud,
                             SensitiveDataStorage credStorage,
                             SetupCompleteIntentBuilder setupCompleteIntentBuilder) {
    Preconditions.checkNotNull(setupCompleteIntentBuilder, "SetupCompleteIntentBuilder instance is null");

    this.cloud = cloud;
    this.credStorage = credStorage;
    this.setupCompleteIntentBuilder = setupCompleteIntentBuilder;
}
 
Example #5
Source File: NextActivitySelector.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
public static Intent getNextActivityIntent(Context ctx,
                                           ParticleCloud particleCloud,
                                           SensitiveDataStorage credStorage,
                                           SetupResult setupResult) {
    NextActivitySelector selector = new NextActivitySelector(particleCloud, credStorage,
            ParticleDeviceSetupLibrary.getInstance().getSetupCompleteIntentBuilder());

    return selector.buildIntentForNextActivity(ctx, setupResult);
}
 
Example #6
Source File: ParticleUser.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Try to initialize a ParticleUser class with stored credentials
 *
 * @return ParticleUser instance if successfully retrieved session, else null
 */
public static synchronized ParticleUser fromSavedSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    String user = sensitiveDataStorage.getUser();
    String password = sensitiveDataStorage.getPassword();

    if (truthy(user) && truthy(password)) {
        return new ParticleUser(user, password);
    } else {
        return null;
    }
}
 
Example #7
Source File: ParticleUser.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize ParticleUser class with new credentials and store session in keychain
 */
public static synchronized ParticleUser fromNewCredentials(String user, String password) {
    Preconditions.checkArgument(truthy(user), "Username cannot be empty or null");
    Preconditions.checkArgument(truthy(password), "Password cannot be empty or null");

    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.saveUser(user);
    sensitiveDataStorage.savePassword(password);

    return new ParticleUser(user, password);
}
 
Example #8
Source File: ParticleAccessToken.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Remove access token session data from keychain
 */
public static synchronized void removeSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.resetToken();
    sensitiveDataStorage.resetRefreshToken();
    sensitiveDataStorage.resetTokenExpirationDate();
}
 
Example #9
Source File: ParticleAccessToken.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
public static synchronized ParticleAccessToken fromTokenData(Date expirationDate, String accessToken,
                                                             @Nullable String refreshToken) {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.saveToken(accessToken);
    sensitiveDataStorage.saveRefreshToken(refreshToken);
    sensitiveDataStorage.saveTokenExpirationDate(expirationDate);

    ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
            new Handler(Looper.getMainLooper()));
    token.scheduleExpiration();
    return token;
}
 
Example #10
Source File: SDKGlobals.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
public static synchronized void init(Context ctx) {
    ctx = ctx.getApplicationContext();
    if (isInitialized) {
        return;
    }

    sensitiveDataStorage = new SensitiveDataStorage(ctx);
    appDataStorage = new AppDataStorage(ctx);

    isInitialized = true;
}
 
Example #11
Source File: ParticleUser.java    From particle-android with Apache License 2.0 5 votes vote down vote up
/**
 * Try to initialize a ParticleUser class with stored credentials
 *
 * @return ParticleUser instance if successfully retrieved session, else null
 */
public static synchronized ParticleUser fromSavedSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    String user = sensitiveDataStorage.getUser();
    String password = sensitiveDataStorage.getPassword();

    if (truthy(user) && truthy(password)) {
        return new ParticleUser(user, password);
    } else {
        return null;
    }
}
 
Example #12
Source File: ParticleUser.java    From particle-android with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize ParticleUser class with new credentials and store session in keychain
 */
public static synchronized ParticleUser fromNewCredentials(String user, String password) {
    Preconditions.checkArgument(truthy(user), "Username cannot be empty or null");
    Preconditions.checkArgument(truthy(password), "Password cannot be empty or null");

    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.saveUser(user);
    sensitiveDataStorage.savePassword(password);

    return new ParticleUser(user, password);
}
 
Example #13
Source File: ParticleAccessToken.java    From particle-android with Apache License 2.0 5 votes vote down vote up
/**
 * Remove access token session data from keychain
 */
public static synchronized void removeSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.resetToken();
    sensitiveDataStorage.resetRefreshToken();
    sensitiveDataStorage.resetTokenExpirationDate();
}
 
Example #14
Source File: ParticleAccessToken.java    From particle-android with Apache License 2.0 5 votes vote down vote up
public static synchronized ParticleAccessToken fromTokenData(Date expirationDate, String accessToken,
                                                             @Nullable String refreshToken) {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.saveToken(accessToken);
    sensitiveDataStorage.saveRefreshToken(refreshToken);
    sensitiveDataStorage.saveTokenExpirationDate(expirationDate);

    ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
            new Handler(Looper.getMainLooper()));
    token.scheduleExpiration();
    return token;
}
 
Example #15
Source File: NextActivitySelector.java    From particle-android with Apache License 2.0 5 votes vote down vote up
public static Intent getNextActivityIntent(Context ctx,
                                           ParticleCloud particleCloud,
                                           SensitiveDataStorage credStorage,
                                           SetupResult setupResult) {
    NextActivitySelector selector = new NextActivitySelector(particleCloud, credStorage,
            ParticleDeviceSetupLibrary.getInstance().getSetupCompleteIntentBuilder());

    return selector.buildIntentForNextActivity(ctx, setupResult);
}
 
Example #16
Source File: SDKGlobals.java    From spark-sdk-android with Apache License 2.0 4 votes vote down vote up
public static SensitiveDataStorage getSensitiveDataStorage() {
    return sensitiveDataStorage;
}
 
Example #17
Source File: ParticleUser.java    From particle-android with Apache License 2.0 4 votes vote down vote up
public static void removeSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.resetPassword();
    sensitiveDataStorage.resetUser();
}
 
Example #18
Source File: ParticleUser.java    From spark-sdk-android with Apache License 2.0 4 votes vote down vote up
public static void removeSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.resetPassword();
    sensitiveDataStorage.resetUser();
}