The following is an example of a function that logs the user in using the supplied connection and login parameters.
Sample function parameters:
Name |
Description |
|
Agent server URL. See the Connection URL section. |
|
User name. We will be login in as a system administrator of the host server (Hardware Node). You will need to know the password of your Hardware Node administrator account. |
|
We are not going to use this parameter in this example. For more information on its usage, see Parallels Agent XML Programmer's Reference Guide. |
|
Realm ID. Realm is a database containing user authentication information. Agent supports various types of authentication databases, including operating system user registries and LDAP-compliant directories, such as AD/ADAM on Windows and OpenLDAP on Linux. In our example, we will be using the user registry of the Hardware Node, which is called System Realm in Agent terminology. The globally unique ID that Agent uses for the System Realm is |
The function authenticates the specified user and, if the supplied credentials are valid, creates a session for the user and returns the session ID. All subsequent Agent requests must include the session ID in order to be recognized by Agent.
Sample function:
/// <summary>
/// Sample function Login.
/// Authenticates the user using the specified credentials and
/// creates a new session.
/// </summary>
/// <param name="url">Agent server URL.</param>
/// <param name="name">User name.</param>
/// <param name="domain">Domain.</param>
/// <param name="realm">Realm ID.</param>
/// <param name="password">Password</param>
/// <returns>New session ID.</returns>
///
public string Login(string url, string name, string domain, string realm, string password)
{
try {
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
// Login information object.
login1 loginInfo = new login1();
/* The sessionmBinding class provides the login and
* session management functionality.
*/
sessionmBinding sessionm = new VZA.sessionmBinding();
/* Instantiate the System.Text.Encoding class that will
* be used to convert strings to byte arrays.
*/
System.Text.Encoding ascii = System.Text.Encoding.ASCII;
// Populate the connection and the login parameters.
sessionm.Url = url;
loginInfo.name = ascii.GetBytes(name);
if (domain.Length != 0) {
loginInfo.domain = ascii.GetBytes(domain);
}
if (realm.Length != 0) {
loginInfo.realm = realm;
}
loginInfo.password = ascii.GetBytes(password);
// Log the specified user in.
return sessionm.login(loginInfo).session_id;
}
catch (Exception e) {
return "Exception: " + e.Message;
}
}