I have been working tirelessly to learn and implement auto authentication on a website I use at university. I believe that I have now successfully set up the auto authentication part of my app, however I now do not know how to display the website to them now that they are passed the login stage. I know how I would do this before the auto authentication but since I have used JSoup to auto authenticate I am just left with a Document variable holding the webpage. Is it possible to now load that Document into the WebView for the user to continue using the website as if they had just manually logged in or am I going at this problem the wrong way? I am also unable to use the .join()
method on my thread as I have not handled an error, but I am unsure where or how I should be handling this InteruptException.
Here is my code so far:
`
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import org.apache.commons.codec.binary.Base64;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
private String url;
private WebView web;
private Document doc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = (WebView) findViewById(R.id.webView);
CookieManager.getInstance().setAcceptCookie(true);
web.getSettings().setDomStorageEnabled(true);
System.out.println("About to try!!!!!!!!");
Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
String username2 = "*********";
String password2 = "*********";
String login = username2 + ":" + password2;
url = "https://hrorganiser.essex.ac.uk/";
String base64login = new String(Base64.encodeBase64(login.getBytes()));
try
{
doc = Jsoup.connect(url).header("Authorization", "Basic " + base64login).get();
System.out.println(">> Connection Successful");
}
catch (Exception e)
{
e.printStackTrace();
System.out.println(">> Connection To "+url+" Failed");
}
}
});
thread.start();
thread.join();
if (doc == null) {
System.out.println("Error Connecting...");
} else {
web.loadUrl(doc.html());
}
}
}`