6767import com .nextcloud .operations .PostMethod ;
6868import com .nextcloud .utils .extensions .BundleExtensionsKt ;
6969import com .nextcloud .utils .mdm .MDMConfig ;
70- import com .owncloud .android .BuildConfig ;
7170import com .owncloud .android .MainApp ;
7271import com .owncloud .android .R ;
7372import com .owncloud .android .databinding .AccountSetupBinding ;
107106import com .owncloud .android .utils .WebViewUtil ;
108107import com .owncloud .android .utils .theme .ViewThemeUtils ;
109108
109+ import org .jetbrains .annotations .NotNull ;
110+
110111import java .io .InputStream ;
111112import java .net .URLDecoder ;
112113import java .util .ArrayList ;
@@ -351,7 +352,6 @@ private void showEnforcedServers() {
351352 showAuthStatus ();
352353 accountSetupBinding .hostUrlFrame .setVisibility (View .GONE );
353354 accountSetupBinding .hostUrlInputHelperText .setVisibility (View .GONE );
354- accountSetupBinding .scanQr .setVisibility (View .GONE );
355355 accountSetupBinding .serversSpinner .setVisibility (View .VISIBLE );
356356
357357 ArrayAdapter <String > adapter = new ArrayAdapter <>(this , R .layout .enforced_servers_spinner );
@@ -639,6 +639,13 @@ private void parseAndLoginFromWebView(String dataString) {
639639 String prefix = getString (R .string .login_data_own_scheme ) + PROTOCOL_SUFFIX + "login/" ;
640640 LoginUrlInfo loginUrlInfo = parseLoginDataUrl (prefix , dataString );
641641
642+ if (!checkAllowedServers (loginUrlInfo .getServer ())) {
643+ mServerStatusIcon = R .drawable .ic_alert ;
644+ mServerStatusText = getString (R .string .server_not_allowed );
645+ showServerStatus ();
646+ return ;
647+ }
648+
642649 if (accountSetupBinding != null ) {
643650 accountSetupBinding .hostUrlInput .setText ("" );
644651 }
@@ -649,10 +656,38 @@ private void parseAndLoginFromWebView(String dataString) {
649656 mServerStatusIcon = R .drawable .ic_alert ;
650657 mServerStatusText = getString (R .string .qr_could_not_be_read );
651658 showServerStatus ();
659+ return ;
652660 }
653661 checkOcServer ();
654662 }
655663
664+ private boolean checkAllowedServers (@ NotNull String server ) {
665+ String webviewLogin = getString (R .string .webview_login_url );
666+
667+ if (!webviewLogin .isEmpty ()) {
668+ if (webviewLogin .startsWith (server )) {
669+ return true ;
670+ }
671+ }
672+
673+ String enforcedServerList = getString (R .string .enforce_servers );
674+
675+ if (!enforcedServerList .isEmpty ()) {
676+ ArrayList <EnforcedServer > enforcedServers = new Gson ().fromJson (enforcedServerList ,
677+ new TypeToken <ArrayList <EnforcedServer >>() {
678+ }
679+ .getType ());
680+
681+ for (EnforcedServer enforcedServer : enforcedServers ) {
682+ if (enforcedServer .getUrl ().startsWith (server )) {
683+ return true ;
684+ }
685+ }
686+ }
687+
688+ return false ;
689+ }
690+
656691 /**
657692 * parses a URI string and returns a login data object with the information from the URI string.
658693 *
0 commit comments