MicroStrategy ONE

Pass Custom Login Parameters in Android

You can customize the information sent in a login request for Android. For example, you can add customized login parameters to the request. Customized login parameters are useful for passing additional information in the login request. The CustomizedLoginParameter class is responsible for carrying customized login parameters for every login request.

APIs

Copy
package com.microstrategy.android.model.config;

import java.util.HashMap;
import java.util.Set;

public class CustomizedLoginParameter {
    private HashMap<String, String> mServerParamsMap;
    private static CustomizedLoginParameter sCustomizedLoginParameter;

    private CustomizedLoginParameter() {
        if(mServerParamsMap == null) {
            mServerParamsMap = new HashMap<String, String>();
        }
    }

    /**
     * This method provides the singleton instance of this class
     *
     * @return the singleton instance of this class
     *
     * */
    public synchronized static CustomizedLoginParameter sharedCustomizedLoginParam(){
        if(sCustomizedLoginParameter == null){
            sCustomizedLoginParameter = new CustomizedLoginParameter();
        }
        return sCustomizedLoginParameter;
    }

    /**
     * This method provides all the customized login parameter keys.
     *
     * @return a String Array which holds all the customized login parameter keys.
     * */

    public String[] getCustomizedLoginParamKeys(){
        Set<String> keySet = mServerParamsMap.keySet();
        return keySet.toArray(new String[keySet.size()]);
    }

    /**
     * Giving a specific customized login parameter key, return the value.
     *
     * @param key the String of the customized login parameter key.
     * @return value for the customized login parameter key. return null if the key doesn't exist.
     * */

    public String getCustomizedLoginParamForKey(String key) {
        return mServerParamsMap.get(key);
    }

    /**
     * Giving a specific customized login parameter key, remove this item.
     *
     * @param key the String of the customized login parameter key.
     * */
    public void removeCustomizedLoginParamForKey(String key){
        mServerParamsMap.remove(key);
    }

    /**
     * This method is used to insert one item in customized login parameter dictionary.
     *
     * @param key the String of the customized login parameter key.
     * @param value value for the customized login parameter key you want to set.
     * */
    public void setCustomizedLoginParamForKey(String value, String key){
        if(key != null && value != null && !key.isEmpty() ) {
            mServerParamsMap.put(key, value);
        }
    }

    /**
     * This method is used to clear all the customized login parameters.
     * */
    public void clearCustomizedLoginParams(){
        mServerParamsMap.clear();
    }

    /**
     * This method is used to get the size of all the customized login parameters.
     *
     * @return the count of all the customized login parameters
     * */
    public int sizeOfCustomizedLoginParams(){
        return mServerParamsMap.size();
    }

    /**
     * This method is used to get the map of all the customized login parameters.
     *
     * @return the hashMap of the customized login parameters
     * */
    public HashMap<String,String> getCustomizedLoginParams() {
        return mServerParamsMap;
    }
}

Internal Logic

All of the customized login parameters are merged with project credential parameters and added to the request body as shown below.

Copy
//Put customized server parameters
JSONObject customizedParameters = new JSONObject(CustomizedLoginParameter.sharedCustomizedLoginParam().getCustomizedLoginParams());

//Put customized project credentials parameters
MobileLoginCustomAuthenticationParameters customAuthenticationParameters = projectCredentials.getCustomAuthenticationParameters();
if (customAuthenticationParameters!=null) {
    String[] serverParamKeys = customAuthenticationParameters.getServerParamKeys();
    if (serverParamKeys != null && serverParamKeys.length > 0) {
        try {
            for (String key : serverParamKeys) {
                customizedParameters.putOpt(key, customAuthenticationParameters.getServerParamForKey(key));
            }
        }catch (JSONException ex){
            ex.printStackTrace();
        }
    }
}
if(customizedParameters.length() > 0) {
    params.put("svp", customizedParameters);
}

APIs and Usage

Download the Android SDK and use the CustomizedLoginParameter singleton instance to store customized headers and values as shown in the code snippet below.

Copy
CustomizedLoginParameter.sharedCustomizedLoginParam().setCustomizedLoginParamForKey("testValue","testKey");