Search code examples
microstrategy

How to create a user using microstrategy SDK in java (External Security Module)


My goal is to create user using microstrategy SDK and assign filters and groups to the user.

  1. I have a java class CreateUser & SSOESM from SDK. Do I have to create a plugin of the create user class and deploy it in microstrategy intelligence server.

    public class CreateUser {
        public static WebIServerSession sessionInfo;
        public static final String loginName = "NewUser";
        public static final String password= "";
        public static final String fullName= "New User";
        public static final String description="New User Created Programattically";
    
        /*  The following information is required to login and manipulate the User management API */
        /* iServerName is the IServer we are connecting to */
        public static final String iServerName = "localhost";
        /* projectName is the project name we are connecting to */
        public static final String projectName = "";
        /* loginName is the user name we use to login the project */
        public static final String adminLoginName = "administrator";
        /* loginPasswd is the password we use to login the project */
        public static final String adminLoginPasswd = "";
    
        public static void main(String[] args) {
            sessionInfo = getServerSession(iServerName, projectName, adminLoginName, adminLoginPasswd);
    
            UserBean user = null;
            try {
                //Instantiate a new user
                user = (UserBean)BeanFactory.getInstance().newBean("UserBean");
                user.setSessionInfo(sessionInfo);
                user.InitAsNew();
    
                //Fetch properties for the user
                WebUser ua = (WebUser) user.getUserEntityObject();
                WebStandardLoginInfo loginInfo = ua.getStandardLoginInfo();
    
                //Set basic user information
                ua.setLoginName(loginName);
                ua.setFullName(fullName);
                user.getObjectInfo().setDescription(description);
                loginInfo.setPassword(password);
    
                //Set other properties
                Calendar cal = Calendar.getInstance();
                cal.set(2012, 11, 21);
                Date d = cal.getTime();
    
                loginInfo.setPasswordExpirationDate(d);  //Password expires on November 21, 2012
                loginInfo.setPasswordExpirationFrequency(90); //90 days to expire
                loginInfo.setPasswordExpiresAutomatically(true); //If set to false, password never expires
                loginInfo.setStandardAuthAllowed(true); //The user can log in using standard auth
    
                user.save();
            } catch (WebBeanException ex) {
                System.out.println("Error creating a user: " + ex.getMessage());
            }
        }
    
        public static WebIServerSession getServerSession(String serverName, String Project, String loginName, String password) {
            WebIServerSession sessionInfo = null;
            try {
                WebObjectsFactory woFact = WebObjectsFactory.getInstance();
                sessionInfo = woFact.getIServerSession();
    
                sessionInfo.setServerName(serverName);
                sessionInfo.setProjectName(Project);
                sessionInfo.setLogin(loginName);
                sessionInfo.setPassword(password);
                sessionInfo.setApplicationType(EnumDSSXMLApplicationType.DssXmlApplicationCustomApp);
                //Create a new session
                sessionInfo.getSessionID();
            } catch (WebObjectsException ex) {
                System.out.println("Error creating a sesion");
            }
    
            return sessionInfo;
        }
    }
    

My goal is when a user try to logon the user should be created on the fly using the sdk classes.


Solution

  • I have to create a plugin and configure the plugin to use the java class you have created as an ESM.

    https://lw.microstrategy.com/msdz/MSDZ_World2015/docs/projects/WebSDK/output/HTML5/Content/topics/esm/specifying_the_custom_esm_to_use.htm

    With that said its important to understand that the actions you are performing are very expensive. They may degrade the user experience if you are attempting to provide a fast SSO experience. Depending on the implementation you have it may be better to create a custom task, which can be fired when the user authenticates with the third party application. This task can perform all the actions you are describing, and then return a session state. Which can be used in any subsequent connections to MicroStrategy Web.