簡體   English   中英

適用於Android的MicroStrategy Mobile通過外部登錄頁面進行自定義

[英]MicroStrategy Mobile for Android Customize with external login page

非常感謝。 我真的是Android / Java開發的新手,我正在嘗試使用MicroStrategy Mobile for Android SDK解決此問題。 打開移動應用程序時,我們需要它進入外部登錄站點,而不是顯示默認登錄屏幕或直接登錄MicroStrategy演示服務器(默認配置)。 不幸的是,MicroStrategy在Android SDK上沒有提供足夠的文檔,我已經多次要求提供文檔,但沒有成功。 我找到了處理登錄的Activity類,並擴展了該類以瀏覽URL。 由於我在Java和Android開發中的局限性,這可能(很可能)是錯誤的。 我們的自定義身份驗證流程由Tomcat中的外部Java Webapp處理,該Web Java捕獲令牌和符號,驗證符號,解析令牌上的數據並調用不同的任務來創建用戶,分配組,隨機字母數字密碼並為用戶在飛行中。 因此,主要來說,我們轉到外部網站,並通過鏈接在該網站上發布帶有令牌的Webapp並登錄base64。 該功能已經可以用於Web訪問和移動訪問。

LoginActivity.class

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.microstrategy.android.ui.activity;

import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.microstrategy.android.MstrApplication;
import com.microstrategy.android.infrastructure.MobileLoginManager;
import com.microstrategy.android.infrastructure.SessionManager;
import com.microstrategy.android.infrastructure.SessionManager.GetSessionInfoCallback;
import com.microstrategy.android.model.config.MobileConfig;
import com.microstrategy.android.model.config.MobileProjectSettings;
import com.microstrategy.android.model.config.MobileServerSettings;
import com.microstrategy.android.network.CredentialsHelper;
import com.microstrategy.android.ui.Utils;
import com.microstrategy.android.ui.activity.MSTRNonStartupBaseActivity;
import com.microstrategy.android.ui.fragment.MobileLoginFragment;
import com.microstrategy.android.ui.view.ProgressWheel;
import com.microstrategy.android.utils.MSTRFeature;
import com.microstrategy.android.websdk.R.id;
import com.microstrategy.android.websdk.R.layout;
import com.microstrategy.android.websdk.R.string;
import java.util.HashMap;
import java.util.Map;

public class LoginActivity extends MSTRNonStartupBaseActivity {
    private static final String LOG_TAG = "LoginActivity";
    public static final String KEY_SERVER_INDEX = "com.microstrategy.android.webapp.serverIndex";
    public static final String KEY_PROJECT_INDEX = "com.microstrategy.android.webapp.projectIndex";

    public LoginActivity() {
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(layout.login_view);
        if(Utils.hasKitKat()) {
            this.getWindow().addFlags(67108864);
        } else {
            this.getWindow().addFlags(1024);
        }

        if(!MstrApplication.getInstance().isTablet()) {
            this.setRequestedOrientation(1);
        }

        if(savedInstanceState == null) {
            final int serverIndex = this.getIntent().getExtras().getInt("com.microstrategy.android.webapp.serverIndex");
            final int projectIndex = this.getIntent().getExtras().getInt("com.microstrategy.android.webapp.projectIndex");
            MobileProjectSettings projectSettings = this.getMobileConfig().getProject(serverIndex, projectIndex);
            if(projectSettings == null) {
                this.finish();
                return;
            }

            int credentialStatus = CredentialsHelper.checkProjectAndParentServerValidity(projectSettings);
            MobileLoginManager manager = MobileLoginManager.sharedLoginManager();
            MobileLoginFragment fragment = null;
            if(CredentialsHelper.isOnlyProjectChangePasswordError(credentialStatus)) {
                fragment = manager.newLoginFragment(1, new HashMap() {
                    {
                        this.put("com.microstrategy.android.webapp.serverIndex", Integer.valueOf(serverIndex));
                        this.put("com.microstrategy.android.webapp.projectIndex", Integer.valueOf(projectIndex));
                    }
                });
            } else if(projectSettings.getCredentials().getAuthMode() == 5) {
                if(!MstrApplication.getInstance().getSecurityHandler().isFeatureAvailable(MSTRFeature.UsherAuthentication)) {
                    Toast.makeText(this, string.FEATURE_NOT_AVAILABLE_MSG, 0).show();
                    this.finish();
                }

                fragment = manager.newLoginFragment(2, new HashMap() {
                    {
                        this.put("com.microstrategy.android.webapp.serverIndex", Integer.valueOf(serverIndex));
                        this.put("com.microstrategy.android.webapp.projectIndex", Integer.valueOf(projectIndex));
                    }
                });
            } else {
                if(!CredentialsHelper.isAuthenticationError(credentialStatus)) {
                    this.finish();
                    return;
                }

                fragment = manager.newLoginFragment(0, new HashMap() {
                    {
                        this.put("com.microstrategy.android.webapp.serverIndex", Integer.valueOf(serverIndex));
                        this.put("com.microstrategy.android.webapp.projectIndex", Integer.valueOf(projectIndex));
                    }
                });
            }

            this.showFragment(fragment);
        }

    }

    protected void onDestroy() {
        if(this.isFinishing()) {
            MobileLoginManager.sharedLoginManager().dismissCurrentDisplayingMobileLoginPromptView();
        }

        super.onDestroy();
    }

    public MobileConfig getMobileConfig() {
        return MstrApplication.getInstance().getConfigObject();
    }

    public void onNeedChangePassword(final int serverIndex, final int projectIndex, String errorMessage) {
        this.showFragment(MobileLoginManager.sharedLoginManager().newLoginFragment(1, new HashMap() {
            {
                this.put("com.microstrategy.android.webapp.serverIndex", Integer.valueOf(serverIndex));
                this.put("com.microstrategy.android.webapp.projectIndex", Integer.valueOf(projectIndex));
            }
        }));
    }

    private void showFragment(Fragment fragment) {
        Log.i("Authentication", "showFragment");
        this.getFragmentManager().beginTransaction().replace(id.login_fragment, fragment).commit();
    }

    public void dismissFragment(boolean validated) {
        Log.i("Authentication", "dismissFragment");
        MobileLoginManager manager = MobileLoginManager.sharedLoginManager();
        manager.setMobileLoginPromptStatus(validated?1:2);
        this.finish();
    }

    public void showProgressBar() {
        Log.i("Authentication", "showProgressBar");
        RelativeLayout disableViewContainer = (RelativeLayout)this.findViewById(id.disable_view);
        if(disableViewContainer.getVisibility() != 0) {
            disableViewContainer.setVisibility(0);
        }

        disableViewContainer.bringToFront();
        View overlayProgressbar = disableViewContainer.findViewById(id.overlay_circular_progressbar);
        if(overlayProgressbar == null) {
            disableViewContainer.removeAllViews();
            overlayProgressbar = this.getLayoutInflater().inflate(layout.overlay_circular_progressbar, disableViewContainer, false);
            disableViewContainer.setGravity(17);
            disableViewContainer.addView(overlayProgressbar);
        }

        View progressBar = overlayProgressbar.findViewById(id.progressbar_in_overlay);
        ((ProgressWheel)progressBar).spin();
    }

    public void dismissProgressBar() {
        Log.i("Authentication", "dismissProgressBar");
        this.runOnUiThread(new Runnable() {
            public void run() {
                RelativeLayout disableViewContainer = (RelativeLayout)LoginActivity.this.findViewById(id.disable_view);
                View overlayProgressbar = disableViewContainer.findViewById(id.overlay_circular_progressbar);
                if(overlayProgressbar != null) {
                    View progressBar = overlayProgressbar.findViewById(id.progressbar_in_overlay);
                    ((ProgressWheel)progressBar).stopSpinning();
                }

                if(disableViewContainer.getVisibility() == 0) {
                    disableViewContainer.setVisibility(8);
                }

            }
        });
    }

    public boolean isProgressBarSpinning() {
        RelativeLayout disableViewContainer = (RelativeLayout)this.findViewById(id.disable_view);
        if(disableViewContainer == null) {
            return false;
        } else {
            View overlayProgressbar = disableViewContainer.findViewById(id.overlay_circular_progressbar);
            if(overlayProgressbar == null) {
                return false;
            } else {
                View progressBar = overlayProgressbar.findViewById(id.progressbar_in_overlay);
                return progressBar != null && ((ProgressWheel)progressBar).isSpinning();
            }
        }
    }

    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if(intent != null) {
            Uri uri = intent.getData();
            if(uri != null && uri.getScheme().equals(this.getString(string.usher_scheme))) {
                int serverIndex = this.getIntent().getExtras().getInt("com.microstrategy.android.webapp.serverIndex");
                int projectIndex = this.getIntent().getExtras().getInt("com.microstrategy.android.webapp.projectIndex");
                MobileServerSettings mobileServerSettings = this.getMobileConfig().getMobileServer(serverIndex);
                MobileProjectSettings projectSettings = mobileServerSettings.getProject(projectIndex);
                final ProgressDialog dialog = new ProgressDialog(this);
                dialog.setTitle(this.getString(string.LOGIN));
                dialog.setMessage(this.getString(string.WAIT));
                dialog.setIndeterminate(true);
                dialog.show();
                SessionManager.getInstance().validate(projectSettings, false, new GetSessionInfoCallback() {
                    public void returnResponse(Map sessionStateInfo) {
                        if(sessionStateInfo != null && sessionStateInfo.containsKey("sessionState")) {
                            MobileLoginManager manager = MobileLoginManager.sharedLoginManager();
                            if(manager.getMobileLoginPromptStatus() == 0) {
                                manager.setMobileLoginPromptStatus(1);
                            }
                        }

                        LoginActivity.this.runOnUiThread(new Runnable() {
                            public void run() {
                                dialog.hide();
                            }
                        });
                        LoginActivity.this.finish();
                    }
                });
            }
        }

    }

    protected boolean shouldShowOfflineIndicator() {
        return false;
    }
}

CustomLoginActivity.class

   package com.microstrategy.android.custom.afip;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
import com.microstrategy.android.ui.activity.LoginActivity;

/**
 * Created by Max on 12/23/2016.
 */

public class CustomLoginActivity extends com.microstrategy.android.ui.activity.LoginActivity {
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    public CustomLoginActivity(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://authinthomo.afip.gob.ar"));
        startActivity(intent);
    }


}

AndroidManifest.xml

         </intent-filter>
</activity>
<activity android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask" android:name="com.microstrategy.android.custom.afip.CustomLoginActivity" android:theme="@style/LoginActivityTheme" android:windowSoftInputMode="adjustPan">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>

        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>

        <data android:scheme="https" android:host="authinthomo.afip.gob.ar"/>
    </intent-filter>
</activity>

我在正確的軌道上嗎? 當我安裝apk時,默認情況下,它只是按照應用程序上的配置登錄到演示服務器。 我正在使用適用於Android 10.6(最新)和Android Studio的MicroStrategy SDK。 任何意見或幫助,不勝感激。

在此先感謝,親切的問候,馬克斯

如果您尚未解決此問題。 存在一個可以在應用程序模塊的原始文件夾中創建的配置文件。 在這種情況下,您可以為自定義身份驗證過程注入Java代碼

更改清單和添加新活動的問題是MstrStartupActivity直接在com.microstrategy.android.ui.activity.LoginActivity的許多點上調用該類

MstrStartup活動非常復雜,以至於很難定位和更改所有身份驗證活動調用點。

改級

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM