Adding a Domain User

Below is the example of using the SetMbSec operation to add a domain user connected from server. The request contains user name (the user must be in the domain) and necessary parameters. The response contains the updated list of repository users.

SOAP request:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SetMbSec xmlns="http://www.prognoz.ru/PP.SOM.Som">
<tMbSec xmlns=" ">
  <id>S1!M</id>
  </tMbSec>
<tArg xmlns=" ">
<pattern>
  <users>Add</users>
  <credsCache>Add</credsCache>
  </pattern>
<meta>
<users>
<its>
<it>
  <k>0</k>
  <id>FS\ASBADMIN</id>
  <type>User</type>
<sid>
  <sid />
  </sid>
<data>
  <isNT>true</isNT>
  </data>
  </it>
  </its>
  </users>
<credsCache>
<its>
<it>
  <realm>$SYSTEM</realm>
  <admin>true</admin>
<creds>
<user>
  <id>sa</id>
  </user>
  <pass>Qwerty1</pass>
  </creds>
  </it>
  </its>
  </credsCache>
<currentDomainSubjectAddStates>
<its>
<it>
  <subjectType>User</subjectType>
  <state>98</state>
  </it>
  </its>
  </currentDomainSubjectAddStates>
  </meta>
<metaGet>
<pattern>
  <users>Get</users>
  </pattern>
  </metaGet>
  </tArg>
  </SetMbSec>
  </s:Body>
  </s:Envelope>

SOAP response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<SetMbSecResult xmlns="http://www.prognoz.ru/PP.SOM.Som" xmlns:q1="http://www.prognoz.ru/PP.SOM.Som" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<id xmlns=" ">
  <id>S1!M</id>
  </id>
<metaGet xmlns=" ">
<id>
  <id>S1!M</id>
  </id>
<meta>
<users>
<its>
<it>
  <k>2147483649</k>
  <id>ADMIN</id>
  <vis>1</vis>
  <type>User</type>
<sid>
  <sid>PS-1-1</sid>
  <type>User</type>
  </sid>
  </it>
<it>
  <k>532</k>
  <id>GUEST</id>
  <n>GUEST</n>
  <vis>1</vis>
  <type>User</type>
<sid>
  <sid>PS-1-532</sid>
  <type>User</type>
  </sid>
  </it>
<it>
  <k>545</k>
  <id>NEWADMIN</id>
  <n>NewAdmin</n>
  <vis>1</vis>
  <type>User</type>
<sid>
  <sid>PS-1-545</sid>
  <type>User</type>
  </sid>
  </it>
<it>
  <k>2147483646</k>
  <id>FS\ASBADMIN</id>
  <n>ASB Admin</n>
  <vis>1</vis>
  <type>User</type>
<sid>
  <sid>S-1-5-21-2210245889-1953428358-4221806923-2817</sid>
  <type>User</type>
  </sid>
  </it>
  </its>
  </users>
  <bisearchEnable>Disable</bisearchEnable>
  </meta>
  </metaGet>
  </SetMbSecResult>
  </soapenv:Body>
  </soapenv:Envelope>

JSON request:

{
"SetMbSec" :
{
"tMbSec" :
{
"id" : "S1!M"
},
"tArg" :
{
"pattern" :
{
"users" : "Add",
"credsCache" : "Add"
},
"meta" :
{
"users" :
{
"its" :
{
"it" :
[
{
"k" : "0",
"id" : "FS\ASBADMIN",
"type" : "User",
"sid" :
{
"sid" : ""
},
"data" :
{
"isNT" : "true"
}
}
]
}
},
"credsCache" :
{
"its" :
{
"it" :
[
{
"realm" : "$SYSTEM",
"admin" : "true",
"creds" :
{
"user" :
{
"id" : "sa"
},
"pass" : "Qwerty1"
}
}
]
}
},
"currentDomainSubjectAddStates" :
{
"its" :
{
"it" :
[
{
"subjectType" : "User",
"state" : "98"
}
]
}
}
},
"metaGet" :
{
"pattern" :
{
"users" : "Get"
}
}
}
}
}

JSON response:

{
"SetMbSecResult" :
{
"id" :
{
"id" : "S1!M"
},
"metaGet" :
{
"id" :
{
"id" : "S1!M"
},
"meta" :
{
"users" :
{
"its" :
{
"it" :
[
{
"k" : "2147483649",
"id" : "ADMIN",
"vis" : "1",
"type" : "User",
"sid" :
{
"sid" : "PS-1-1",
"type" : "User"
}
},
{
"k" : "532",
"id" : "GUEST",
"n" : "GUEST",
"vis" : "1",
"type" : "User",
"sid" :
{
"sid" : "PS-1-532",
"type" : "User"
}
},
{
"k" : "545",
"id" : "NEWADMIN",
"n" : "NewAdmin",
"vis" : "1",
"type" : "User",
"sid" :
{
"sid" : "PS-1-545",
"type" : "User"
}
},
{
"k" : "2147483646",
"id" : "FS\ASBADMIN",
"n" : "ASB Admin",
"vis" : "1",
"type" : "User",
"sid" :
{
"sid" : "S-1-5-21-2210245889-1953428358-4221806923-2817",
"type" : "User"
}
}
]
}
},
"bisearchEnable" : "Disable"
}
}
}
}
public static SetMbSecResult CreateDomainUser(string mb, string userName)
{
    var somClient = new SomPortTypeClient(); //Proxy object for executing operations
    //Operation execution parameters
    var setMbSec = new SetMbSec()
    {
        tArg = new SetMbSecArg()
        {
            //Operation execution pattern
            pattern = new MbSecMdPattern()
            {
                users = ListOperation.Add,
                credsCache = ListOperation.Add
            },
            meta = new MbSecMd()
            {
                //Credentials that are used to connect the database server
                //The specified user must have permissions to create users at DBMS level
                credsCache = new UserCredsCache
                {
                    its = new RealmUserCreds[]
                    {
                        new RealmUserCreds
                        {
                            realm = "$SYSTEM",
                            admin = true,
                            creds = new UserCreds
                            {
                                user = new UserId { id = "sa" },
                                pass = "Qwerty1"
                            }
                        }
                    }
                },
                users = new MbSubjects()
                {
                    its = new MbSubject[1]
                    {
                        new MbSubject()
                        {
                            k = 0,
                            id = userName,
                            type = MbSubjectType.User,
                            sid = new SubjectSid() {sid = string.Empty},
                            data = new MbSubjectData()
                            {
                                isNT = true,
                            }
                        }
                    }
                },
                currentDomainSubjectAddStates = new MbSecDomainSubjectAddStateEntries()
                {
                    its = new MbSecDomainSubjectAddStateEntry[1]
                    {
                        new MbSecDomainSubjectAddStateEntry()
                        {
                            state = 98, //MakeExternalOn + ManageDBGrantsOn + Keep
                            subjectType = MbSubjectType.User
                        }
                    }
                }
            },
            //Parameters of user list update after executing operation
            metaGet = new GetMbSecArg()
            {
                pattern = new MbSecMdPattern()
                {
                    users = ListOperation.Get
                }
            }
        },
        //Repository moniker
        tMbSec = new MbId() { id = mb }
    };
    //Create a domain user connected from server
    var result = somClient.SetMbSec(setMbSec);
    return result;

See also:

SetMbSec: Operation