Creating a User

Below is the example of using the SetMbSec operation to create a new repository user. The request contains the name and basic parameters of the created user. 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>NewAdmin</id>
  <n>NewAdmin</n>
  <vis>true</vis>
  <type>User</type>
<sid>
  <sid />
  </sid>
<data>
  <desc />
  <isNT>false</isNT>
  <tag />
<user>
  <mustChangePasswordAtNextLogon>true</mustChangePasswordAtNextLogon>
  <lockedState>NotLocked</lockedState>
  <maxLogonSessions>3</maxLogonSessions>
<credentials>
  <pass>NewAdmin</pass>
  </credentials>
  </user>
  </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>
  </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>
  </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" : "NewAdmin",
"n" : "NewAdmin",
"vis" : "true",
"type" : "User",
"sid" :
{
"sid" : ""
},
"data" :
{
"desc" : "",
"isNT" : "false",
"tag" : "",
"user" :
{
"mustChangePasswordAtNextLogon" : "true",
"lockedState" : "NotLocked",
"maxLogonSessions" : "3",
"credentials" :
{
"pass" : "NewAdmin"
}
}
}
}
]
}
},
"credsCache" :
{
"its" :
{
"it" :
[
{
"realm" : "$SYSTEM",
"admin" : "true",
"creds" :
{
"user" :
{
"id" : "sa"
},
"pass" : "Qwerty1"
}
}
]
}
}
},
"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"
}
}
]
}
},
"bisearchEnable" : "Disable"
}
}
}
}
public static SetMbSecResult CreateUser(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 for database connection
                // 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,
                            n = userName,
                            vis = true,
                            type = MbSubjectType.User,
                            sid = new SubjectSid() {sid = string.Empty},
                            data = new MbSubjectData()
                            {
                                desc = String.Empty,
                                isNT = false,
                                user = new MbUserData()
                                {
                                    mustChangePasswordAtNextLogon = true,
                                    maxLogonSessions = 3,
                                    lockedState = MbUserLockedState.NotLocked,
                                    credentials = new UserCreds() {pass = userName}
                                },
                                tag = String.Empty
                            }
                        }
                    }
                }
            },
            //Parameters of user list update after operation execution
            metaGet = new GetMbSecArg()
            {
                pattern = new MbSecMdPattern()
                {
                    users = ListOperation.Get
                }
            }
        },
        //Repository moniker
        tMbSec = new MbId() { id = mb }
    };
    //Create a user
    var result = somClient.SetMbSec(setMbSec);
    return result;

See also:

SetMbSec: Operation