1 package com
.owncloud
.android
.ui
.dialog
;
3 import android
.annotation
.SuppressLint
;
4 import android
.app
.AlertDialog
;
5 import android
.app
.Dialog
;
6 import android
.os
.Bundle
;
7 import android
.os
.Handler
;
8 import android
.support
.v4
.app
.DialogFragment
;
9 import android
.webkit
.CookieManager
;
10 import android
.webkit
.WebSettings
;
11 import android
.webkit
.WebView
;
13 import com
.owncloud
.android
.Log_OC
;
14 import com
.owncloud
.android
.authentication
.AuthenticatorActivity
;
15 import com
.owncloud
.android
.authentication
.SsoWebViewClient
;
16 import com
.owncloud
.android
.authentication
.SsoWebViewClient
.SsoWebViewClientListener
;
18 import eu
.alefzero
.webdav
.WebdavClient
;
21 * Dialog to show the WebView for SAML Authentication
23 * @author Maria Asensio
25 public class SamlWebViewDialog
extends DialogFragment
26 implements SsoWebViewClientListener
{
28 public final String SAML_DIALOG_TAG
= "SamlWebViewDialog";
30 private final static String TAG
= SamlWebViewDialog
.class.getSimpleName();
32 private WebView mSsoWebView
;
33 private SsoWebViewClient mWebViewClient
;
35 private static String mUrl
;
36 private static String mTargetUrl
;
38 private static Handler mHandler
;
42 * Public factory method to get dialog instances.
45 * @param Url Url to open at WebView
46 * @param targetURL mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mCurrentAuthTokenType)
47 * @return New dialog instance, ready to show.
49 public static SamlWebViewDialog
newInstance(Handler handler
,String url
, String targetUrl
) {
50 SamlWebViewDialog fragment
= new SamlWebViewDialog();
53 mTargetUrl
= targetUrl
;
59 public void onSaveInstanceState(Bundle outState
) {
60 super.onSaveInstanceState(outState
);
62 // Save the state of the WebView
63 mSsoWebView
.saveState(outState
);
68 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
69 Log_OC
.d(TAG
, "On Create Dialog");
72 initWebView(savedInstanceState
);
73 setRetainInstance(true
);
75 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getActivity());
77 Dialog dialog
= builder
.setView(mSsoWebView
).create();
83 @SuppressLint("SetJavaScriptEnabled")
84 private void initWebView(Bundle savedInstanceState
) {
85 CookieManager cookieManager
= CookieManager
.getInstance();
86 cookieManager
.setAcceptCookie(true
);
87 //cookieManager.removeSessionCookie();
89 mWebViewClient
= new SsoWebViewClient(mHandler
, this);
90 mWebViewClient
.setTargetUrl(mTargetUrl
);
91 if (savedInstanceState
== null
) {
93 Log_OC
.d(TAG
, "Saved Instance State NULL");
94 mSsoWebView
= new WebView(getActivity()) {
96 public boolean onCheckIsTextEditor() {
101 mSsoWebView
.setWebViewClient(mWebViewClient
);
102 mSsoWebView
.setFocusable(true
);
103 mSsoWebView
.setFocusableInTouchMode(true
);
104 mSsoWebView
.setClickable(true
);
106 WebSettings webSettings
= mSsoWebView
.getSettings();
107 webSettings
.setJavaScriptEnabled(true
);
108 webSettings
.setBuiltInZoomControls(true
);
109 webSettings
.setLoadWithOverviewMode(false
);
110 webSettings
.setSavePassword(false
);
111 webSettings
.setUserAgentString(WebdavClient
.USER_AGENT
);
113 mSsoWebView
.loadUrl(mUrl
);
116 Log_OC
.d(TAG
, "Saved Instance State NOT NULL");
118 mSsoWebView
.restoreState(savedInstanceState
);
124 public void onDestroyView() {
125 Dialog dialog
= getDialog();
126 Log_OC
.d(TAG
, "On Destroy");
127 // Work around bug: http://code.google.com/p/android/issues/detail?id=17423
128 if ((dialog
!= null
) && getRetainInstance())
129 getDialog().setOnDismissListener(null
);
131 super.onDestroyView();
136 public void onSsoFinished(String sessionCookie
) {
137 //Toast.makeText(this, "got cookies: " + sessionCookie, Toast.LENGTH_LONG).show();
139 if (sessionCookie
!= null
&& sessionCookie
.length() > 0) {
140 Log_OC
.d(TAG
, "Successful SSO - time to save the account");
141 ((AuthenticatorActivity
) getActivity()).onSamlDialogSuccess(sessionCookie
);
146 Log_OC
.d(TAG
, "SSO failed");