首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MicroStrategy移动安卓版自定义外部登录页面

MicroStrategy移动安卓版自定义外部登录页面
EN

Stack Overflow用户
提问于 2016-12-27 22:24:29
回答 0查看 285关注 0票数 0

非常感谢。我对Android/Java开发是个新手,我正在尝试用Android SDK的MicroStrategy Mobile来解决这个问题。我们需要移动应用程序去一个外部登录网站时,它是打开,而不是显示默认登录屏幕或直接登录到MicroStrategy演示服务器(默认配置)。不幸的是,MicroStrategy没有提供足够的Android SDK文档,我已经多次请求文档,但都没有成功。我已经找到了处理Login的Activity类,并扩展了该类以浏览到URL。由于我在Java和Android开发方面的局限性,这可能(很可能)是错误的。我们的自定义身份验证流程由Tomcat中的外部Java Webapp处理,它捕获令牌和签名,验证签名,解析令牌上的数据,并调用创建用户的不同任务,分配组,随机字母数字密码,并为用户动态打开会话。因此,我们主要转到外部网站,通过那里的链接,我们使用令牌向webapp发送帖子,并登录base64。该功能已经在Web访问和移动访问中发挥作用。

LoginActivity.class

代码语言:javascript
复制
//
// 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

代码语言:javascript
复制
   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

代码语言:javascript
复制
         </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时,默认情况下,它只是登录到应用程序上配置的演示服务器。我使用的是MicroStrategy SDK for Android10.6(最新版本)& Android Studio。任何意见或帮助都是非常感谢的。

提前谢谢,好的问候,麦克斯

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41346926

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档