package fr.coding.tools;

import android.webkit.HttpAuthHandler;
import android.webkit.WebView;
import java.util.List;
import fr.coding.tools.model.HostAuth;
import fr.coding.tools.model.SslByPass;

/**
 * Created by Matthieu on 03/10/2015.
 */
public class AutoAuthSslWebView extends SslWebView {

    public CallbackResult<HostAuth, HostAuth> AuthAsked;

    protected List<HostAuth> allowedHosts;
    public void setAllowedHosts(List<HostAuth> hosts) {
        allowedHosts = hosts;
    }

    public List<HostAuth> getAllowedHosts() {
        return allowedHosts;
    }

    @Override
    public void onReceivedHttpAuthRequest(WebView webView, HttpAuthHandler handler, String host, String realm) {
        if (allowedHosts != null) {
            for (HostAuth ha :
                    allowedHosts) {
                if (host.equals(ha.Host)) {
                    handler.proceed(ha.Login, ha.Password);
                    return;
                }
            }
        }
        if (AuthAsked != null) {
            HostAuth hostAuth = new HostAuth();
            hostAuth.Host = host;
            HostAuth ret = AuthAsked.onCallback(hostAuth);
            if (ret != null) {
                handler.proceed(ret.Login, ret.Password);
                return;
            }
        }
        super.onReceivedHttpAuthRequest(webView, handler, host, realm);
    }
}

@@ -88,16 +88,40 @@
 WebView;
+%0A%0Aimport java.util.Date;
 %0Aimport 
@@ -588,24 +588,61 @@
 sts;%0A    %7D%0A%0A
+    public long AutoTestedDate = 0;%0A%0A
     @Overrid
@@ -767,16 +767,17 @@
      if 
+(
 (allowed
@@ -782,32 +782,84 @@
 edHosts != null)
+&&(AutoTestedDate %3C (new Date().getTime()-(15000))))
  %7B%0A            f
@@ -952,24 +952,83 @@
 ha.Host)) %7B%0A
+                    AutoTestedDate = new Date().getTime();%0A
             

Correct cycling bug when password is updated server side