2023-02-09 23:31:22 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) Cloud Software Group, Inc.
|
2017-09-13 18:14:07 +02:00
|
|
|
*
|
2013-06-24 13:41:48 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
2017-09-13 18:14:07 +02:00
|
|
|
*
|
2013-06-24 13:41:48 +02:00
|
|
|
* 1) Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2017-09-13 18:14:07 +02:00
|
|
|
*
|
2013-06-24 13:41:48 +02:00
|
|
|
* 2) Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
2017-09-13 18:14:07 +02:00
|
|
|
*
|
2013-06-24 13:41:48 +02:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-04-04 21:59:47 +02:00
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
using System.Net;
|
2023-07-10 13:58:41 +02:00
|
|
|
using System.Net.Security;
|
2017-09-13 18:14:07 +02:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
namespace XenAPI
|
|
|
|
{
|
|
|
|
public partial class Session : XenObject<Session>
|
|
|
|
{
|
|
|
|
public const int STANDARD_TIMEOUT = 24 * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
/// <summary>
|
2017-09-13 18:14:07 +02:00
|
|
|
/// This string is used as the HTTP UserAgent for each request.
|
2013-06-24 13:41:48 +02:00
|
|
|
/// </summary>
|
|
|
|
public static string UserAgent = string.Format("XenAPI/{0}", Helper.APIVersionString(API_Version.LATEST));
|
|
|
|
|
|
|
|
/// <summary>
|
2017-09-13 18:14:07 +02:00
|
|
|
/// If null, no proxy is used, otherwise this proxy is used for each request.
|
2013-06-24 13:41:48 +02:00
|
|
|
/// </summary>
|
|
|
|
public static IWebProxy Proxy = null;
|
|
|
|
|
2020-01-30 01:02:24 +01:00
|
|
|
public API_Version APIVersion = API_Version.UNKNOWN;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
public object Tag;
|
|
|
|
|
|
|
|
private List<Role> roles = new List<Role>();
|
|
|
|
|
2017-09-13 18:14:07 +02:00
|
|
|
#region Constructors
|
|
|
|
|
2023-07-10 13:58:41 +02:00
|
|
|
[Obsolete("Use Session(string url) { Timeout = ... }; instead.")]
|
2013-06-24 13:41:48 +02:00
|
|
|
public Session(int timeout, string url)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
JsonRpcClient = new JsonRpcClient(url)
|
|
|
|
{
|
|
|
|
Timeout = timeout,
|
|
|
|
KeepAlive = true,
|
|
|
|
UserAgent = UserAgent,
|
|
|
|
WebProxy = Proxy,
|
|
|
|
JsonRpcVersion = JsonRpcVersion.v2,
|
|
|
|
AllowAutoRedirect = true
|
|
|
|
};
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
2017-12-01 18:15:49 +01:00
|
|
|
public Session(string url)
|
|
|
|
{
|
2023-07-10 13:58:41 +02:00
|
|
|
JsonRpcClient = new JsonRpcClient(url)
|
|
|
|
{
|
|
|
|
Timeout = STANDARD_TIMEOUT,
|
|
|
|
KeepAlive = true,
|
|
|
|
UserAgent = UserAgent,
|
|
|
|
WebProxy = Proxy,
|
|
|
|
JsonRpcVersion = JsonRpcVersion.v2,
|
|
|
|
AllowAutoRedirect = true
|
|
|
|
};
|
2017-12-01 18:15:49 +01:00
|
|
|
}
|
|
|
|
|
2023-07-10 13:58:41 +02:00
|
|
|
[Obsolete("Use Session(string host, int port) { Timeout = ... }; instead.")]
|
2013-06-24 13:41:48 +02:00
|
|
|
public Session(int timeout, string host, int port)
|
2017-12-01 18:15:49 +01:00
|
|
|
: this(timeout, GetUrl(host, port))
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-01 18:15:49 +01:00
|
|
|
public Session(string host, int port)
|
2023-07-10 13:58:41 +02:00
|
|
|
: this(GetUrl(host, port))
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-13 18:14:07 +02:00
|
|
|
public Session(string url, string opaqueRef)
|
|
|
|
: this(url)
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
2018-01-22 16:18:30 +01:00
|
|
|
opaque_ref = opaqueRef;
|
2019-03-08 10:57:16 +01:00
|
|
|
SetupSessionDetails();
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Create a new Session instance, using the given instance and timeout. The connection details and Xen-API session handle will be
|
|
|
|
/// copied from the given instance, but a new connection will be created. Use this if you want a duplicate connection to a host,
|
|
|
|
/// for example when you need to cancel an operation that is blocking the primary connection.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="session"></param>
|
|
|
|
/// <param name="timeout"></param>
|
2023-07-10 13:58:41 +02:00
|
|
|
[Obsolete("Use Session(Session session) { Timeout = ... }; instead.")]
|
2013-06-24 13:41:48 +02:00
|
|
|
public Session(Session session, int timeout)
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
opaque_ref = session.opaque_ref;
|
2013-06-24 13:41:48 +02:00
|
|
|
APIVersion = session.APIVersion;
|
2019-03-23 19:50:13 +01:00
|
|
|
|
|
|
|
//in the following do not copy over the ConnectionGroupName
|
|
|
|
|
|
|
|
if (session.JsonRpcClient != null &&
|
|
|
|
(APIVersion == API_Version.API_2_6 || APIVersion >= API_Version.API_2_8))
|
|
|
|
{
|
|
|
|
JsonRpcClient = new JsonRpcClient(session.Url)
|
|
|
|
{
|
|
|
|
JsonRpcVersion = session.JsonRpcClient.JsonRpcVersion,
|
2023-07-10 13:58:41 +02:00
|
|
|
UserAgent = session.JsonRpcClient.UserAgent,
|
2019-03-23 19:50:13 +01:00
|
|
|
KeepAlive = session.JsonRpcClient.KeepAlive,
|
2023-07-10 13:58:41 +02:00
|
|
|
WebProxy = session.JsonRpcClient.WebProxy,
|
|
|
|
Timeout = timeout,
|
|
|
|
ProtocolVersion = session.JsonRpcClient.ProtocolVersion,
|
|
|
|
Expect100Continue = session.JsonRpcClient.Expect100Continue,
|
|
|
|
AllowAutoRedirect = session.JsonRpcClient.AllowAutoRedirect,
|
|
|
|
PreAuthenticate = session.JsonRpcClient.PreAuthenticate,
|
|
|
|
Cookies = session.JsonRpcClient.Cookies,
|
|
|
|
ServerCertificateValidationCallback = session.JsonRpcClient.ServerCertificateValidationCallback
|
|
|
|
};
|
|
|
|
}
|
|
|
|
CopyADFromSession(session);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Create a new Session instance, using the given instance. The connection details
|
|
|
|
/// and Xen-API session handle will be copied from the given instance, but a new
|
|
|
|
/// connection will be created. Use this if you want a duplicate connection to a host,
|
|
|
|
/// for example when you need to cancel an operation that is blocking the primary connection.
|
|
|
|
/// </summary>
|
|
|
|
public Session(Session session)
|
|
|
|
{
|
|
|
|
opaque_ref = session.opaque_ref;
|
|
|
|
APIVersion = session.APIVersion;
|
|
|
|
|
|
|
|
//in the following do not copy over the ConnectionGroupName
|
|
|
|
|
|
|
|
if (session.JsonRpcClient != null &&
|
|
|
|
(APIVersion == API_Version.API_2_6 || APIVersion >= API_Version.API_2_8))
|
|
|
|
{
|
|
|
|
JsonRpcClient = new JsonRpcClient(session.Url)
|
|
|
|
{
|
|
|
|
JsonRpcVersion = session.JsonRpcClient.JsonRpcVersion,
|
2019-03-23 19:50:13 +01:00
|
|
|
UserAgent = session.JsonRpcClient.UserAgent,
|
2023-07-10 13:58:41 +02:00
|
|
|
KeepAlive = session.JsonRpcClient.KeepAlive,
|
2019-03-23 19:50:13 +01:00
|
|
|
WebProxy = session.JsonRpcClient.WebProxy,
|
2023-07-10 13:58:41 +02:00
|
|
|
Timeout = session.JsonRpcClient.Timeout,
|
2019-03-23 19:50:13 +01:00
|
|
|
ProtocolVersion = session.JsonRpcClient.ProtocolVersion,
|
|
|
|
Expect100Continue = session.JsonRpcClient.Expect100Continue,
|
|
|
|
AllowAutoRedirect = session.JsonRpcClient.AllowAutoRedirect,
|
|
|
|
PreAuthenticate = session.JsonRpcClient.PreAuthenticate,
|
2023-07-10 13:58:41 +02:00
|
|
|
Cookies = session.JsonRpcClient.Cookies,
|
|
|
|
ServerCertificateValidationCallback = session.JsonRpcClient.ServerCertificateValidationCallback
|
2019-03-23 19:50:13 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
CopyADFromSession(session);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
2017-09-13 18:14:07 +02:00
|
|
|
#endregion
|
|
|
|
|
2023-07-10 13:58:41 +02:00
|
|
|
private static string GetUrl(string hostname, int port)
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
2023-07-10 13:58:41 +02:00
|
|
|
return string.Format("{0}://{1}:{2}", port == 8080 || port == 80 ? "http" : "https", hostname, port);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
2019-03-08 10:57:16 +01:00
|
|
|
private void SetupSessionDetails()
|
|
|
|
{
|
|
|
|
SetAPIVersion();
|
|
|
|
SetADDetails();
|
|
|
|
SetRbacPermissions();
|
|
|
|
}
|
|
|
|
|
2023-07-10 13:58:41 +02:00
|
|
|
private void SetAPIVersion()
|
|
|
|
{
|
|
|
|
Dictionary<XenRef<Pool>, Pool> pools = Pool.get_all_records(this);
|
|
|
|
|
|
|
|
if (pools.Values.Count > 0)
|
|
|
|
{
|
|
|
|
var pool = pools.Values.First();
|
|
|
|
Host host = Host.get_record(this, pool.master);
|
|
|
|
APIVersion = Helper.GetAPIVersion(host.API_version_major, host.API_version_minor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-23 19:50:13 +01:00
|
|
|
private void CopyADFromSession(Session session)
|
|
|
|
{
|
2020-01-30 01:02:24 +01:00
|
|
|
IsLocalSuperuser = session.IsLocalSuperuser;
|
|
|
|
SessionSubject = session.SessionSubject;
|
|
|
|
UserSid = session.UserSid;
|
2019-03-23 19:50:13 +01:00
|
|
|
roles = session.Roles;
|
2020-01-30 01:02:24 +01:00
|
|
|
Permissions = session.Permissions;
|
2019-03-23 19:50:13 +01:00
|
|
|
}
|
|
|
|
|
2018-01-22 16:18:30 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Applies only to API 1.6 (george) and above.
|
|
|
|
/// </summary>
|
2013-06-24 13:41:48 +02:00
|
|
|
private void SetADDetails()
|
|
|
|
{
|
2018-01-22 16:18:30 +01:00
|
|
|
if (APIVersion < API_Version.API_1_6)
|
2020-01-30 01:02:24 +01:00
|
|
|
{
|
|
|
|
IsLocalSuperuser = true;
|
2018-01-22 16:18:30 +01:00
|
|
|
return;
|
2020-01-30 01:02:24 +01:00
|
|
|
}
|
2018-01-22 16:18:30 +01:00
|
|
|
|
2020-01-30 01:02:24 +01:00
|
|
|
IsLocalSuperuser = get_is_local_superuser();
|
2013-06-24 13:41:48 +02:00
|
|
|
if (IsLocalSuperuser)
|
|
|
|
return;
|
|
|
|
|
2020-01-30 01:02:24 +01:00
|
|
|
SessionSubject = get_subject(this, opaque_ref);
|
|
|
|
UserSid = get_auth_user_sid();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
// Cache the details of this user to avoid making server calls later
|
|
|
|
// For example, some users get access to the pool through a group subject and will not be in the main cache
|
2020-01-30 01:02:24 +01:00
|
|
|
UserDetails.UpdateDetails(UserSid, this);
|
2018-01-22 16:18:30 +01:00
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
2018-01-22 16:18:30 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Applies only to API 1.7 (midnight-ride) and above.
|
|
|
|
/// Older versions have no RBAC, only AD.
|
|
|
|
/// </summary>
|
|
|
|
private void SetRbacPermissions()
|
|
|
|
{
|
|
|
|
if (APIVersion < API_Version.API_1_7)
|
2013-06-24 13:41:48 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// allRoles will contain every role on the server, permissions contains the subset of those that are available to this session.
|
2020-01-30 01:02:24 +01:00
|
|
|
Permissions = Session.get_rbac_permissions(this, opaque_ref);
|
2017-09-13 18:14:07 +02:00
|
|
|
Dictionary<XenRef<Role>, Role> allRoles = Role.get_all_records(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
// every Role object is either a single api call (a permission) or has subroles and contains permissions through its descendants.
|
|
|
|
// We take out the parent Roles (VM-Admin etc.) into the Session.Roles field
|
2020-01-30 01:02:24 +01:00
|
|
|
foreach (string s in Permissions)
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
foreach (XenRef<Role> xr in allRoles.Keys)
|
|
|
|
{
|
|
|
|
Role r = allRoles[xr];
|
|
|
|
if (r.subroles.Count > 0 && r.name_label == s)
|
|
|
|
{
|
|
|
|
r.opaque_ref = xr.opaque_ref;
|
|
|
|
roles.Add(r);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void UpdateFrom(Session update)
|
|
|
|
{
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string SaveChanges(Session session, string _serverOpaqueRef, Session serverObject)
|
|
|
|
{
|
|
|
|
throw new Exception("The method or operation is not implemented.");
|
|
|
|
}
|
|
|
|
|
2023-07-10 13:58:41 +02:00
|
|
|
#region Properties
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Retrieves the current users details from the UserDetails map. These values are only updated when a new session is created.
|
|
|
|
/// </summary>
|
|
|
|
public virtual UserDetails CurrentUserDetails => UserSid == null ? null : UserDetails.Sid_To_UserDetails[UserSid];
|
|
|
|
|
2017-09-13 18:14:07 +02:00
|
|
|
public JsonRpcClient JsonRpcClient { get; private set; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
2023-07-10 13:58:41 +02:00
|
|
|
public string Url => JsonRpcClient.Url;
|
2017-09-13 18:14:07 +02:00
|
|
|
|
|
|
|
public string ConnectionGroupName
|
|
|
|
{
|
2023-07-10 13:58:41 +02:00
|
|
|
get => JsonRpcClient?.ConnectionGroupName;
|
|
|
|
set => JsonRpcClient.ConnectionGroupName = value;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
2023-07-10 13:58:41 +02:00
|
|
|
public int Timeout
|
2018-04-07 01:31:17 +02:00
|
|
|
{
|
2023-07-10 13:58:41 +02:00
|
|
|
get => JsonRpcClient?.Timeout ?? STANDARD_TIMEOUT;
|
|
|
|
set => JsonRpcClient.Timeout = value;
|
|
|
|
}
|
2018-04-12 16:25:19 +02:00
|
|
|
|
2023-07-10 13:58:41 +02:00
|
|
|
public RemoteCertificateValidationCallback ServerCertificateValidationCallback
|
|
|
|
{
|
|
|
|
get => JsonRpcClient?.ServerCertificateValidationCallback;
|
|
|
|
set => JsonRpcClient.ServerCertificateValidationCallback = value;
|
2018-04-07 01:31:17 +02:00
|
|
|
}
|
|
|
|
|
2023-07-10 13:58:41 +02:00
|
|
|
public ICredentials Credentials => JsonRpcClient?.WebProxy?.Credentials;
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Always true before API version 1.6.
|
2020-01-30 01:02:24 +01:00
|
|
|
/// Filled in after successful session_login_with_password for 1.6 or newer connections
|
2013-06-24 13:41:48 +02:00
|
|
|
/// </summary>
|
2020-01-30 01:02:24 +01:00
|
|
|
public virtual bool IsLocalSuperuser { get; private set; }
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The OpaqueRef for the Subject under whose authority the current user is logged in;
|
|
|
|
/// may correspond to either a group or a user.
|
|
|
|
/// Null if IsLocalSuperuser is true.
|
|
|
|
/// </summary>
|
2020-01-30 01:02:24 +01:00
|
|
|
[JsonConverter(typeof(XenRefConverter<Subject>))]
|
|
|
|
public XenRef<Subject> SessionSubject { get; private set; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The Active Directory SID of the currently logged-in user.
|
|
|
|
/// Null if IsLocalSuperuser is true.
|
|
|
|
/// </summary>
|
2020-01-30 01:02:24 +01:00
|
|
|
public string UserSid { get; private set; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// All permissions associated with the session at the time of log in. This is the list xapi uses until the session is logged out;
|
2017-09-13 18:14:07 +02:00
|
|
|
/// even if the permitted roles change on the server side, they don't apply until the next session.
|
2013-06-24 13:41:48 +02:00
|
|
|
/// </summary>
|
2020-01-30 01:02:24 +01:00
|
|
|
public string[] Permissions { get; private set; }
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
/// <summary>
|
2017-09-13 18:14:07 +02:00
|
|
|
/// All roles associated with the session at the time of log in. Do not rely on roles for determining what a user can do,
|
2013-06-24 13:41:48 +02:00
|
|
|
/// instead use Permissions. This list should only be used for UI purposes.
|
|
|
|
/// </summary>
|
2017-09-13 18:14:07 +02:00
|
|
|
[JsonConverter(typeof(XenRefListConverter<Role>))]
|
2023-07-10 13:58:41 +02:00
|
|
|
public List<Role> Roles => roles;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
public static Session get_record(Session session, string _session)
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
2023-07-10 13:58:41 +02:00
|
|
|
Session newSession = new Session(session.Url) { opaque_ref = _session };
|
|
|
|
newSession.SetAPIVersion();
|
|
|
|
return newSession;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void login_with_password(string username, string password)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
opaque_ref = JsonRpcClient.session_login_with_password(username, password);
|
2019-03-08 10:57:16 +01:00
|
|
|
SetupSessionDetails();
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void login_with_password(string username, string password, string version)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
opaque_ref = JsonRpcClient.session_login_with_password(username, password, version);
|
2017-09-13 18:14:07 +02:00
|
|
|
|
2019-03-08 10:57:16 +01:00
|
|
|
SetupSessionDetails();
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
catch (Failure exn)
|
|
|
|
{
|
|
|
|
if (exn.ErrorDescription[0] == Failure.MESSAGE_PARAMETER_COUNT_MISMATCH)
|
|
|
|
{
|
|
|
|
// Call the 1.1 version instead.
|
|
|
|
login_with_password(username, password);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-13 18:14:07 +02:00
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
public void login_with_password(string username, string password, string version, string originator)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
opaque_ref = JsonRpcClient.session_login_with_password(username, password, version, originator);
|
2017-09-13 18:14:07 +02:00
|
|
|
|
2019-03-08 10:57:16 +01:00
|
|
|
SetupSessionDetails();
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
catch (Failure exn)
|
|
|
|
{
|
|
|
|
if (exn.ErrorDescription[0] == Failure.MESSAGE_PARAMETER_COUNT_MISMATCH)
|
|
|
|
{
|
|
|
|
// Call the pre-2.0 version instead.
|
|
|
|
login_with_password(username, password, version);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void login_with_password(string username, string password, API_Version version)
|
|
|
|
{
|
|
|
|
login_with_password(username, password, Helper.APIVersionString(version));
|
|
|
|
}
|
2017-09-13 18:14:07 +02:00
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
public void slave_local_login_with_password(string username, string password)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
opaque_ref = JsonRpcClient.session_slave_local_login_with_password(username, password);
|
2013-06-24 13:41:48 +02:00
|
|
|
//assume the latest API
|
|
|
|
APIVersion = API_Version.LATEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void logout()
|
|
|
|
{
|
|
|
|
logout(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Log out of the given session2, using this session for the connection.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="session2">The session to log out</param>
|
|
|
|
public void logout(Session session2)
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
logout(session2.opaque_ref);
|
2018-01-22 16:18:30 +01:00
|
|
|
session2.opaque_ref = null;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Log out of the session with the given reference, using this session for the connection.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="_self">The session to log out</param>
|
|
|
|
public void logout(string _self)
|
|
|
|
{
|
2017-09-13 18:14:07 +02:00
|
|
|
if (_self == null)
|
|
|
|
return;
|
|
|
|
|
2023-02-09 23:31:22 +01:00
|
|
|
JsonRpcClient.session_logout(_self);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
2017-09-13 18:14:07 +02:00
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
public void local_logout()
|
|
|
|
{
|
|
|
|
local_logout(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void local_logout(Session session2)
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
local_logout(session2.opaque_ref);
|
2018-01-22 16:18:30 +01:00
|
|
|
session2.opaque_ref = null;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
2018-02-23 17:06:32 +01:00
|
|
|
public void local_logout(string opaqueRef)
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
if (opaqueRef == null)
|
2017-09-13 18:14:07 +02:00
|
|
|
return;
|
|
|
|
|
2023-02-09 23:31:22 +01:00
|
|
|
JsonRpcClient.session_local_logout(opaqueRef);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void change_password(string oldPassword, string newPassword)
|
|
|
|
{
|
|
|
|
change_password(this, oldPassword, newPassword);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Change the password on the given session2, using this session for the connection.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="session2">The session to change</param>
|
2017-09-13 18:14:07 +02:00
|
|
|
/// <param name="oldPassword"></param>
|
|
|
|
/// <param name="newPassword"></param>
|
2013-06-24 13:41:48 +02:00
|
|
|
public void change_password(Session session2, string oldPassword, string newPassword)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
JsonRpcClient.session_change_password(session2.opaque_ref, oldPassword, newPassword);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public string get_this_host()
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
return get_this_host(this, opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string get_this_host(Session session, string _self)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_this_host(session.opaque_ref, _self ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public string get_this_user()
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
return get_this_user(this, opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string get_this_user(Session session, string _self)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_this_user(session.opaque_ref, _self ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool get_is_local_superuser()
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
return get_is_local_superuser(this, opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool get_is_local_superuser(Session session, string _self)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_is_local_superuser(session.opaque_ref, _self ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string[] get_rbac_permissions(Session session, string _self)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_rbac_permissions(session.opaque_ref, _self ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public DateTime get_last_active()
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
return get_last_active(this, opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static DateTime get_last_active(Session session, string _self)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_last_active(session.opaque_ref, _self ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool get_pool()
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
return get_pool(this, opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool get_pool(Session session, string _self)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_pool(session.opaque_ref, _self ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public XenRef<Subject> get_subject()
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
return get_subject(this, opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static XenRef<Subject> get_subject(Session session, string _self)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_subject(session.opaque_ref, _self ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public string get_auth_user_sid()
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
return get_auth_user_sid(this, opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static string get_auth_user_sid(Session session, string _self)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_auth_user_sid(session.opaque_ref, _self ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#region AD SID enumeration and bootout
|
|
|
|
|
|
|
|
public string[] get_all_subject_identifiers()
|
|
|
|
{
|
|
|
|
return get_all_subject_identifiers(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string[] get_all_subject_identifiers(Session session)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_all_subject_identifiers(session.opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public XenRef<Task> async_get_all_subject_identifiers()
|
|
|
|
{
|
|
|
|
return async_get_all_subject_identifiers(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static XenRef<Task> async_get_all_subject_identifiers(Session session)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.async_session_get_all_subject_identifiers(session.opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public string logout_subject_identifier(string subject_identifier)
|
|
|
|
{
|
|
|
|
return logout_subject_identifier(this, subject_identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static string logout_subject_identifier(Session session, string subject_identifier)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
session.JsonRpcClient.session_logout_subject_identifier(session.opaque_ref, subject_identifier);
|
|
|
|
return string.Empty;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public XenRef<Task> async_logout_subject_identifier(string subject_identifier)
|
|
|
|
{
|
|
|
|
return async_logout_subject_identifier(this, subject_identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static XenRef<Task> async_logout_subject_identifier(Session session, string subject_identifier)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.async_session_logout_subject_identifier(session.opaque_ref, subject_identifier);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region other_config stuff
|
|
|
|
|
|
|
|
public Dictionary<string, string> get_other_config()
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
return get_other_config(this, opaque_ref);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Dictionary<string, string> get_other_config(Session session, string _self)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
return session.JsonRpcClient.session_get_other_config(session.opaque_ref, _self ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void set_other_config(Dictionary<string, string> _other_config)
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
set_other_config(this, opaque_ref, _other_config);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void set_other_config(Session session, string _self, Dictionary<string, string> _other_config)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
session.JsonRpcClient.session_set_other_config(session.opaque_ref, _self ?? "", _other_config);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void add_to_other_config(string _key, string _value)
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
add_to_other_config(this, opaque_ref, _key, _value);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void add_to_other_config(Session session, string _self, string _key, string _value)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
session.JsonRpcClient.session_add_to_other_config(session.opaque_ref, _self ?? "", _key ?? "", _value ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void remove_from_other_config(string _key)
|
|
|
|
{
|
2018-02-23 17:06:32 +01:00
|
|
|
remove_from_other_config(this, opaque_ref, _key);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void remove_from_other_config(Session session, string _self, string _key)
|
|
|
|
{
|
2023-02-09 23:31:22 +01:00
|
|
|
session.JsonRpcClient.session_remove_from_other_config(session.opaque_ref, _self ?? "", _key ?? "");
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|