Example #1
0
        public void SsoLogin(string samlAssertionXML, string orgName)
        {
            HttpClient httpClient = this.HttpClient;

            httpClient.DefaultRequestHeaders.Clear();
            string str = this.GZipEncodeXmlToString(samlAssertionXML);

            if (orgName.Equals("System", StringComparison.OrdinalIgnoreCase))
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", "SIGN token=\"" + str + "\"");
            }
            else
            {
                httpClient.DefaultRequestHeaders.Add("Authorization", "SIGN token=\"" + str + "\",org=\"" + orgName + "\"");
            }
            httpClient.DefaultRequestHeaders.Add("Accept", vCloudClient.SUPPORTED_SDK_VERSIONS[this.VcloudClientVersion]);
            HttpRequestHeaders defaultRequestHeaders = httpClient.DefaultRequestHeaders;
            VersionInfoType    supportedVersion      = this.GetSupportedVersions()[this._vcloudClientVersion.Value()];

            if (supportedVersion == null)
            {
                throw new VCloudException(this._vcloudClientVersion.Value() + " " + SdkUtil.GetI18nString(SdkMessage.VERSION_NOT_SUPPORTED));
            }
            Response response = RestUtil.Login(this, supportedVersion.LoginUrl, defaultRequestHeaders);

            if (!response.IsExpected(200))
            {
                response.HandleUnExpectedResponse();
            }
            SessionType resource = response.GetResource <SessionType>();

            this.setOrgName(resource.org);
            this.setUserName(resource.user);
        }
Example #2
0
 public void Login(string userName, string password)
 {
     try
     {
         HttpClient httpClient = this.HttpClient;
         httpClient.DefaultRequestHeaders.Clear();
         httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(userName.Trim() + ":" + password.Trim())));
         HttpRequestHeaders defaultRequestHeaders = httpClient.DefaultRequestHeaders;
         VersionInfoType    supportedVersion      = this.GetSupportedVersions()[this._vcloudClientVersion.Value()];
         if (supportedVersion == null)
         {
             throw new VCloudException(this._vcloudClientVersion.Value() + " " + SdkUtil.GetI18nString(SdkMessage.VERSION_NOT_SUPPORTED));
         }
         Response response = RestUtil.Login(this, supportedVersion.LoginUrl, defaultRequestHeaders);
         if (!response.IsExpected(200))
         {
             response.HandleUnExpectedResponse();
         }
         SessionType resource = response.GetResource <SessionType>();
         this.setOrgName(resource.org);
         this.setUserName(resource.user);
     }
     catch (Exception ex)
     {
         Logger.Log(TraceLevel.Critical, ex.Message);
         throw ex;
     }
 }