public async Task <CertificateContent> Get(string certificateId, IAuthHeaders authHeaders)
        {
            var channel = new Channel("data.certificate-manager.api.cloud.yandex.net", 443, new SslCredentials());
            var client  = new CertificateContentService.CertificateContentServiceClient(channel);
            var request = new GetCertificateContentRequest
            {
                CertificateId = certificateId
            };
            var response = await client.GetAsync(request, authHeaders.ToMetadata());

            return(new CertificateContent(
                       id: response.CertificateId,
                       chain: response.CertificateChain.ToArray(),
                       privateKey: response.PrivateKey
                       ));
        }
Beispiel #2
0
        public BaseController()
        {
            try
            {
                //
                // process authentication if a provider is configured
                //
                //
                string authNProviderName = ConfigurationManager.AppSettings["AuthenticationProvider"];

                if (!string.IsNullOrEmpty(authNProviderName))
                {
                    Type authNProviderType = Type.GetType(authNProviderName);
                    if (authNProviderType == null)
                    {
                        SendError(401, "Unable to load authentication provider.");
                    }

                    // only send 408 error when the request is ajax and authenticated user is unknown
                    if (System.Web.HttpContext.Current.Request.Headers["X-Requested-With"] == "XMLHttpRequest" &&
                        SessionState.Get(System.Web.HttpContext.Current.Session.SessionID, AUTH_USER) == null)
                    {
                        SendError(408, "Session timed out.");
                        return;
                    }

                    IAuthentication authNProvider = (IAuthentication)Activator.CreateInstance(authNProviderType);
                    _authenticatedUser = authNProvider.Authenticate(System.Web.HttpContext.Current.Session);

                    SessionState.Set(System.Web.HttpContext.Current.Session.SessionID, AUTH_USER, _authenticatedUser);

                    if (System.Web.HttpContext.Current.Response.IsRequestBeingRedirected)
                    {
                        return;
                    }

                    if (string.IsNullOrEmpty(_authenticatedUser))
                    {
                        SendError(401, "Authentication failed.");
                    }

                    //
                    // process authorization if a provider is configured
                    //
                    string authZProviderName = ConfigurationManager.AppSettings["AuthorizationProvider"];

                    if (!string.IsNullOrEmpty(authZProviderName))
                    {
                        Type authZProviderType = Type.GetType(authZProviderName);

                        if (authZProviderType == null)
                        {
                            SendError(401, "Unable to load authorization provider.");
                        }

                        IAuthorization authZProvider = (IAuthorization)Activator.CreateInstance(authZProviderType);
                        bool           authorized    = authZProvider.Authorize(System.Web.HttpContext.Current.Session, "adapterAdmins", _authenticatedUser);

                        if (!authorized)
                        {
                            SendError(401, "User [" + _authenticatedUser + "] not authorized.");
                        }
                    }

                    //
                    // get authorization headers if a provider is configured
                    //
                    try
                    {
                        string headersProviderName = ConfigurationManager.AppSettings["AuthHeadersProvider"];

                        if (!string.IsNullOrEmpty(headersProviderName))
                        {
                            Type headersProviderType = Type.GetType(headersProviderName);

                            if (headersProviderType == null)
                            {
                                SendError(401, "Unable to load auth header provider.");
                            }

                            IAuthHeaders headersProvider = (IAuthHeaders)Activator.CreateInstance(headersProviderType);
                            _authHeaders = headersProvider.Get(_authenticatedUser);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.Error("Error getting authorization headers: " + e);
                        throw e;
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error("Authentication error: " + e.Message + ": " + e.StackTrace.ToString());
                SendError(401, e.ToString());
            }
        }