locked
MDS API Security : import /export user rights RRS feed

  • General discussion

  • Hello

    in order to make a full automatic installation of a MDS package within a MSI, I try to import Security privileges for a given model

    I've already exported the security principals and security privileges with XMLSerializer and now I try to import it to a new DB/MDS Model

    the user that needs the update rights on the model already exists but must be granted with Update rights on a given model programmaticaly

    I don't know how to grant him the rights...

    I've already used impersonate mode to be able to deploy the new model with a specific mds user/service and this is working good. (for this, you can see  this link)

     

     

    I tried several ways : 

    Could you help me to do this please ?

     

     private static void ImportUserRights(MDSConfiguration conf)
     {
      using (MDS_WS.c = Common.MDS_WS.CreateMdsProxy(conf.MDSServiceUrl))
      {
      SecurityPrincipals sp = GetXMLSecurityPrincipals(conf, MDS_WS.c);
      MDS_WS.c.SecurityPrincipalsUpdate(MDS_WS.intl, sp);
      }
      //Collection<ModelPrivilege> colmPrivileges = GetXMLModelPrivilege(conf, c);
      //c.SecurityPrivilegesUpdate(MDS_WS.intl, new SecurityPrivileges() { ModelPrivileges = colmPrivileges });
     }
    
     private static SecurityPrincipals GetXMLSecurityPrincipals(MDSConfiguration conf, ServiceClient c)
     {
      XmlSerializer xs = new XmlSerializer(typeof(SecurityPrincipals));
      // Create a new file stream for reading the XML file
      FileStream ReadFileStream = new FileStream(conf.SecurityFolderPath + @conf.SecurityPrincipalsFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
      // Load the object saved above by using the Deserialize function
      SecurityPrincipals principals = (SecurityPrincipals)xs.Deserialize(ReadFileStream);
    
      // Cleanup
      ReadFileStream.Close();
      return principals;
     }
    
     private static Collection<ModelPrivilege> GetXMLModelPrivilege(MDSConfiguration conf, ServiceClient c)
     {
      XmlSerializer xs = new XmlSerializer(typeof(SecurityPrivileges));
      // Create a new file stream for reading the XML file
      FileStream ReadFileStream = new FileStream(@conf.SecurityFolderPath + @conf.SecurityPrincipalsFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
      // Load the object saved above by using the Deserialize function
      SecurityPrivileges privileges = xs.Deserialize(ReadFileStream) as SecurityPrivileges;
      // Cleanup
      ReadFileStream.Close();
      Identifier modelIdentifier = MDS_WS.GetModelIdFromName(conf.MDSServiceUrl, conf.MDSModelName);
      Collection<ModelPrivilege> cmp = new Collection<ModelPrivilege>();
      foreach (ModelPrivilege mp in privileges.ModelPrivileges)
      {
    
      if (mp.ModelId == modelIdentifier)
      {
       cmp.Add(mp);
      }
      }
      return cmp;
     }
    
    Thanks and Regards,

     

     

     

     

     


    Xavier Averbouch
    Tuesday, August 24, 2010 7:43 AM