Revert "Pre expire tokens"

This reverts commit 0a417725eb.
pull/200/head
M66B 4 years ago
parent 2e85b3bc0d
commit e49321af2c

@ -306,9 +306,8 @@ public class EmailService implements AutoCloseable {
this.listener = listener; this.listener = listener;
} }
@NonNull public void connect(EntityAccount account) throws MessagingException {
public ServiceAuthenticator connect(EntityAccount account) throws MessagingException { connect(
return connect(
account.host, account.port, account.host, account.port,
account.auth_type, account.provider, account.auth_type, account.provider,
account.user, account.password, account.user, account.password,
@ -324,9 +323,8 @@ public class EmailService implements AutoCloseable {
account.certificate_alias, account.fingerprint); account.certificate_alias, account.fingerprint);
} }
@NonNull public void connect(EntityIdentity identity) throws MessagingException {
public ServiceAuthenticator connect(EntityIdentity identity) throws MessagingException { connect(
return connect(
identity.host, identity.port, identity.host, identity.port,
identity.auth_type, identity.provider, identity.auth_type, identity.provider,
identity.user, identity.password, identity.user, identity.password,
@ -342,16 +340,14 @@ public class EmailService implements AutoCloseable {
identity.certificate_alias, identity.fingerprint); identity.certificate_alias, identity.fingerprint);
} }
@NonNull public void connect(
public ServiceAuthenticator connect(
String host, int port, String host, int port,
int auth, String provider, String user, String password, int auth, String provider, String user, String password,
String certificate, String fingerprint) throws MessagingException { String certificate, String fingerprint) throws MessagingException {
return connect(host, port, auth, provider, user, password, null, certificate, fingerprint); connect(host, port, auth, provider, user, password, null, certificate, fingerprint);
} }
@NonNull private void connect(
private ServiceAuthenticator connect(
String host, int port, String host, int port,
int auth, String provider, String user, String password, int auth, String provider, String user, String password,
ServiceAuthenticator.IAuthenticated intf, ServiceAuthenticator.IAuthenticated intf,
@ -395,13 +391,11 @@ public class EmailService implements AutoCloseable {
properties.put("mail." + protocol + ".yahoo.guid", "FAIRMAIL_V1"); properties.put("mail." + protocol + ".yahoo.guid", "FAIRMAIL_V1");
connect(host, port, auth, user, authenticator, factory); connect(host, port, auth, user, authenticator, factory);
return authenticator;
} catch (AuthenticationFailedException ex) { } catch (AuthenticationFailedException ex) {
if (auth == AUTH_TYPE_GMAIL || auth == AUTH_TYPE_OAUTH) { if (auth == AUTH_TYPE_GMAIL || auth == AUTH_TYPE_OAUTH) {
try { try {
authenticator.refreshToken(true); authenticator.refreshToken(true);
connect(host, port, auth, user, authenticator, factory); connect(host, port, auth, user, authenticator, factory);
return authenticator;
} catch (Exception ex1) { } catch (Exception ex1) {
Log.e(ex1); Log.e(ex1);
throw new AuthenticationFailedException( throw new AuthenticationFailedException(

@ -84,8 +84,7 @@ public class ServiceAuthenticator extends Authenticator {
return new PasswordAuthentication(user, token); return new PasswordAuthentication(user, token);
} }
String refreshToken(boolean expire) String refreshToken(boolean expire) throws AuthenticatorException, OperationCanceledException, IOException, JSONException, MessagingException {
throws AuthenticatorException, OperationCanceledException, IOException, JSONException, MessagingException {
if (auth == AUTH_TYPE_GMAIL) { if (auth == AUTH_TYPE_GMAIL) {
GmailState authState = GmailState.jsonDeserialize(password); GmailState authState = GmailState.jsonDeserialize(password);
authState.refresh(context, user, expire); authState.refresh(context, user, expire);
@ -120,34 +119,6 @@ public class ServiceAuthenticator extends Authenticator {
return password; return password;
} }
boolean isTokenValid(int minValidity) {
Long expiration = null;
long validUntil = new Date().getTime() +
Math.round(minValidity * 60 * 1000L * 1.1f);
try {
if (auth == AUTH_TYPE_GMAIL) {
GmailState authState = GmailState.jsonDeserialize(password);
expiration = authState.getAccessTokenExpirationTime();
} else if (auth == AUTH_TYPE_OAUTH) {
AuthState authState = AuthState.jsonDeserialize(password);
expiration = authState.getAccessTokenExpirationTime();
}
} catch (JSONException ex) {
Log.e(ex);
}
if (expiration != null && expiration < validUntil) {
EntityLog.log(context, user + " token" +
" expiration=" + new Date(expiration) +
" valid until" + new Date(validUntil) +
" min valid=" + minValidity + "m");
return false;
}
return true;
}
interface IAuthenticated { interface IAuthenticated {
void onPasswordChanged(String newPassword); void onPasswordChanged(String newPassword);
} }

@ -1268,9 +1268,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
db.folder().setFolderStates(account.id, null); db.folder().setFolderStates(account.id, null);
db.account().setAccountState(account.id, "connecting"); db.account().setAccountState(account.id, "connecting");
ServiceAuthenticator authenticator;
try { try {
authenticator = iservice.connect(account); iservice.connect(account);
} catch (Throwable ex) { } catch (Throwable ex) {
// Immediately report auth errors // Immediately report auth errors
if (ex instanceof AuthenticationFailedException) { if (ex instanceof AuthenticationFailedException) {
@ -1859,9 +1858,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
"Unrecoverable", "Unrecoverable",
new Exception(state.getUnrecoverable())); new Exception(state.getUnrecoverable()));
if (!authenticator.isTokenValid(account.poll_interval))
throw new StoreClosedException(iservice.getStore(), "Token invalidation");
// Sends store NOOP // Sends store NOOP
if (EmailService.SEPARATE_STORE_CONNECTION) { if (EmailService.SEPARATE_STORE_CONNECTION) {
EntityLog.log(this, account.name + " checking store" + EntityLog.log(this, account.name + " checking store" +

Loading…
Cancel
Save