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.
{
"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"
}
}
}
}
}
{
"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 operation execution
//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, using which database connection is executed
// 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,
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 for updating users list 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: