![JAR search and dependency download from the Maven repository](/logo.png)
co.easimart.EasimartAuthenticationManager Maven / Gradle / Ivy
package co.easimart;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import bolts.Continuation;
import bolts.Task;
/** package */ class EasimartAuthenticationManager {
private final Object lock = new Object();
private final Map callbacks = new HashMap<>();
private final EasimartCurrentUserController controller;
public EasimartAuthenticationManager(EasimartCurrentUserController controller) {
this.controller = controller;
}
public void register(final String authType, AuthenticationCallback callback) {
if (authType == null) {
throw new IllegalArgumentException("Invalid authType: " + null);
}
synchronized (lock) {
if (this.callbacks.containsKey(authType)) {
throw new IllegalStateException("Callback already registered for <" + authType + ">: "
+ this.callbacks.get(authType));
}
this.callbacks.put(authType, callback);
}
if (EasimartAnonymousUtils.AUTH_TYPE.equals(authType)) {
// There's nothing to synchronize
return;
}
// Synchronize the current user with the auth callback.
controller.getAsync(false).onSuccessTask(new Continuation>() {
@Override
public Task then(Task task) throws Exception {
EasimartUser user = task.getResult();
if (user != null) {
return user.synchronizeAuthDataAsync(authType);
}
return null;
}
});
}
public Task restoreAuthenticationAsync(String authType, final Map authData) {
final AuthenticationCallback callback;
synchronized (lock) {
callback = this.callbacks.get(authType);
}
if (callback == null) {
return Task.forResult(true);
}
return Task.call(new Callable() {
@Override
public Boolean call() throws Exception {
return callback.onRestore(authData);
}
}, EasimartExecutors.io());
}
public Task deauthenticateAsync(String authType) {
final AuthenticationCallback callback;
synchronized (lock) {
callback = this.callbacks.get(authType);
}
if (callback != null) {
return Task.call(new Callable() {
@Override
public Void call() throws Exception {
callback.onRestore(null);
return null;
}
}, EasimartExecutors.io());
}
return Task.forResult(null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy