Esempio n. 1
0
        protected override async void HandleAuthorizationChanged(object sender, AuthorizationSession e)
        {
            base.HandleAuthorizationChanged(sender, e);

            if (AuthorizationSession != null)
            {
                CreateMenu();
            }
            else
            {
                ResetMenu();
            }
            await InvokeAsync(() => StateHasChanged()).ConfigureAwait(false);
        }
Esempio n. 2
0
        private static Task ClearAuthorizationSessionAsync(CloudTable sessionTable, AuthorizationSession session)
        {
            if (sessionTable is null)
            {
                throw new ArgumentNullException(nameof(sessionTable));
            }

            if (session is null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            return(sessionTable
                   .ExecuteAsync(TableOperation.Delete(session)));
        }
Esempio n. 3
0
        protected override async void HandleAuthorizationChanged(object sender, AuthorizationSession e)
        {
            base.HandleAuthorizationChanged(sender, e);

            if (e == null)
            {
                await SetPageBeforeLoginAsync(PageName).ConfigureAwait(false);

                NavigationManager.NavigateTo($"/{StaticLiterals.LoginPage}");
            }
            else
            {
                await InvokeAsync(() => StateHasChanged()).ConfigureAwait(false);
            }
        }
        protected override void CreateMenu()
        {
            base.CreateMenu();

            if (AuthorizationSession != null)
            {
                if (AuthorizationSession.HasRole("SysAdmin") ||
                    AuthorizationSession.HasRole("AppAdmin"))
                {
                    CreateAdminMenu();
                }
            }
            else
            {
                CreateLogonMenu();
            }
        }
Esempio n. 5
0
        private static async Task <AuthorizationSession> SetAuthorizationSessionAsync(CloudTable sessionTable, AuthorizationSession session)
        {
            if (sessionTable is null)
            {
                throw new ArgumentNullException(nameof(sessionTable));
            }

            if (session is null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            var sessionResult = await sessionTable
                                .ExecuteAsync(TableOperation.InsertOrReplace(session))
                                .ConfigureAwait(false);

            return(sessionResult.Result as AuthorizationSession);
        }
        /// <summary>
        /// Gets an OAuth authorization session.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The resource group name of the data factory.
        /// </param>
        /// <param name='dataFactoryName'>
        /// Required. A unique data factory instance name.
        /// </param>
        /// <param name='linkedServiceType'>
        /// Required. The type of OAuth linked service.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The Get authorization session operation response.
        /// </returns>
        public async Task <AuthorizationSessionGetResponse> GetAsync(string resourceGroupName, string dataFactoryName, string linkedServiceType, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (resourceGroupName != null && resourceGroupName.Length > 1000)
            {
                throw new ArgumentOutOfRangeException("resourceGroupName");
            }
            if (Regex.IsMatch(resourceGroupName, "^[-\\w\\._\\(\\)]+$") == false)
            {
                throw new ArgumentOutOfRangeException("resourceGroupName");
            }
            if (dataFactoryName == null)
            {
                throw new ArgumentNullException("dataFactoryName");
            }
            if (dataFactoryName != null && dataFactoryName.Length > 63)
            {
                throw new ArgumentOutOfRangeException("dataFactoryName");
            }
            if (Regex.IsMatch(dataFactoryName, "^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$") == false)
            {
                throw new ArgumentOutOfRangeException("dataFactoryName");
            }
            if (linkedServiceType == null)
            {
                throw new ArgumentNullException("linkedServiceType");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceGroupName", resourceGroupName);
                tracingParameters.Add("dataFactoryName", dataFactoryName);
                tracingParameters.Add("linkedServiceType", linkedServiceType);
                TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/subscriptions/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/resourcegroups/";
            url = url + Uri.EscapeDataString(resourceGroupName);
            url = url + "/providers/Microsoft.DataFactory/datafactories/";
            url = url + Uri.EscapeDataString(dataFactoryName);
            url = url + "/oauth/authorizationsession/";
            url = url + Uri.EscapeDataString(linkedServiceType);
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2015-09-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-client-request-id", Guid.NewGuid().ToString());

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    AuthorizationSessionGetResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new AuthorizationSessionGetResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            AuthorizationSession authorizationSessionInstance = new AuthorizationSession();
                            result.AuthorizationSession = authorizationSessionInstance;

                            JToken endpointValue = responseDoc["endpoint"];
                            if (endpointValue != null && endpointValue.Type != JTokenType.Null)
                            {
                                Uri endpointInstance = TypeConversion.TryParseUri(((string)endpointValue));
                                authorizationSessionInstance.Endpoint = endpointInstance;
                            }

                            JToken sessionIdValue = responseDoc["sessionId"];
                            if (sessionIdValue != null && sessionIdValue.Type != JTokenType.Null)
                            {
                                string sessionIdInstance = ((string)sessionIdValue);
                                authorizationSessionInstance.SessionId = sessionIdInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }