KeplerServiceConnectionInfo
Represents a class object that contains Kepler service connection information.
using Relativity.Services.ServiceProxy;
using System;
using System.Net;
using System.Security;
namespace Relativity.DataExchange.Service
{
public class KeplerServiceConnectionInfo : IServiceConnectionInfo
{
private readonly NetworkCredential originalCredentials;
private SecureString currentPassword;
public Credentials Credentials { get; set; }
public NetworkCredential NetworkCredential => originalCredentials;
public Uri WebServiceBaseUrl { get; }
public KeplerServiceConnectionInfo(Uri webApiServiceUrl, NetworkCredential credential)
{
webApiServiceUrl.ThrowIfNull("webApiServiceUrl");
credential.ThrowIfNull("credential");
if (!webApiServiceUrl.IsAbsoluteUri)
throw new ArgumentException("The passed url is a relative url, while this function needs an absolute url to work correctly", "webApiServiceUrl");
WebServiceBaseUrl = new Uri(webApiServiceUrl.GetLeftPart(UriPartial.Authority));
originalCredentials = credential;
currentPassword = credential.SecurePassword;
Credentials = ConvertCredentials(credential);
}
public void UpdateCredentials(NetworkCredential credential)
{
if (credential == null)
throw new ArgumentNullException("credential");
originalCredentials.SecurePassword = credential.SecurePassword;
RefreshCredentials();
}
public bool RefreshCredentials()
{
if (<RefreshCredentials>g__IsPasswordEqual|13_0(originalCredentials, currentPassword))
return false;
Credentials = ConvertCredentials(originalCredentials);
currentPassword = originalCredentials.SecurePassword;
return true;
}
private static Credentials ConvertCredentials(NetworkCredential credential)
{
if (string.Compare(credential.UserName, "XxX_BearerTokenCredentials_XxX", StringComparison.OrdinalIgnoreCase) == 0) {
if (string.IsNullOrEmpty(credential.Password))
throw new ArgumentException("Bearer token should not be null or empty.");
return new BearerTokenCredentials(credential.Password);
}
return new UsernamePasswordCredentials(credential.UserName, credential.Password);
}
}
}