예제 #1
0
        private void InitializeTokenManager()
        {
            ICertificateDetails fedCertificateDetails = new FedCertificateDetails();

            Cache.AddOrUpdate(fedCertificateDetails, "ICertificateDetails", 20000);
            TokenManagerFactory.GetTokenManager();
        }
예제 #2
0
        public void TokenManagerFactory_GetCertificateTokenManager()
        {
            var fedCertificateDetails = new FedCertificateDetails();

            Cache.AddOrUpdate(fedCertificateDetails, "ICertificateDetails", 20000);
            var tokenManager = TokenManagerFactory.GetTokenManager();

            Assert.IsNotNull(tokenManager);
        }
예제 #3
0
        public string GetReportsData(Guid id, ModuleType moduleType, RelatedToType type)
        {
            string reportData;

            // Get the sign-in key from the URL. This is a hash which uniquely identifies a user's
            // authentication context and can be used for impersonation.
            var tokenString = HttpContext.Current.Request.QueryString["wsSignInKey"];

            if (string.IsNullOrWhiteSpace(tokenString))
            {
                _log.Error("SSRS Report Data: SSRS Service Request made without security key.");
                throw new Exception("SSRS Service Request made without security key.");
            }
            try
            {
                // Use the given token string to authenticate the current user.
                Thread.CurrentPrincipal =
                    new JwtTokenValidator(TokenManagerFactory.GetTokenManager()).GetClaimsPrincipalFromToken(tokenString);
            }
            catch (Exception ex)
            {
                _log.Error("SSRS Report Data: Could not authenticate user : {0}", ex);
                throw;
            }

            // Check to make sure the user is authenticated.
            if (Thread.CurrentPrincipal == null ||
                Thread.CurrentPrincipal.Identity == null ||
                !Thread.CurrentPrincipal.Identity.IsAuthenticated)
            {
                _log.Error("SSRS Report Data: User is not authenticated.");
                throw new Exception("User is not authenticated.");
            }
            try
            {
                // Resolve the Report service. Note: We can't use constructor injection here since
                // the user may not be authenticated until this method executes. If the service is
                // instantiated before authentication, the system will throw an exception.
                using (var iocService = DependencyContainer.Resolve <IReportService>())
                {
                    var reportService = iocService.Instance;

                    // Retrieve report data.
                    var reportsData = reportService.GenerateReportsData(id, type, moduleType);

                    var reportsDocument = new XmlDocument();
                    var nav             = reportsDocument.CreateNavigator();
                    using (var writer = nav.AppendChild())
                    {
                        var ser = new XmlSerializer(reportsData.GetType());
                        ser.Serialize(writer, reportsData);
                    }

                    var detailDocument       = new XmlDocument();
                    var detailElementQuery   = detailDocument.CreateElement("Query");
                    var detailElementXmlData = detailDocument.CreateElement("XmlData");
                    detailElementQuery.AppendChild(detailElementXmlData);

                    detailDocument.AppendChild(detailElementQuery);

                    if (reportsDocument.DocumentElement != null)
                    {
                        detailElementXmlData.AppendChild(
                            detailDocument.ImportNode(
                                reportsDocument.DocumentElement, true));
                    }

                    reportData = detailDocument.InnerXml;
                }
            }
            catch (Exception ex)
            {
                _log.Error("SSRS Service Request Failure: {0}", ex);
                throw;
            }
            return(reportData);
        }
예제 #4
0
        public MemoryStream RenderReport(Report report, AttachmentType attachmentType, string headerText)
        {
            Warning[] warnings;
            string[]  streamIds;
            string    mimeType;
            string    encoding;
            string    extension;
            var       relatedType = report.IsSupplement ? "SupplementalReport" : "InitialReport";
            // Setup the report viewer object and get the array of bytes
            var viewer = new ReportViewer();

            viewer.ProcessingMode = ProcessingMode.Remote;


            var reportServerUri = String.Format("http://{0}/ReportServer",
                                                ConfigurationManager.AppSettings["ReportServer"]);
            var reportPath = String.Format("/{0}",
                                           ConfigurationManager.AppSettings["ReportRootPath"]);

            viewer.ServerReport.ReportPath      = reportPath;
            viewer.ServerReport.ReportServerUrl = new Uri(reportServerUri);

            int validity;
            var result = Int32.TryParse(ConfigurationManager.AppSettings["SSRSTokenTimeout"], out validity);

            if (!result)
            {
                validity = 5;
            }

            var claimsIdentityObj = Infrastructure.Caching.Cache.Get <ClaimsIdentity>(report.Id.ToString());
            var svcQuery          = String.Format("{0}",
                                                  ConfigurationManager.AppSettings["SSRSServiceHost"]) +
                                    "api/ssrsreports/getreportsdata/"
                                    + report.Id.ToString()
                                    + "/" + report.ModuleType.ToString()
                                    + "/" + relatedType + "?wsSignInKey=" + new JwtTokenGenerator(TokenManagerFactory.GetTokenManager()).GenerateJwtToken(claimsIdentityObj, validity);

            var reportParameters = new List <ReportParameter>
            {
                new ReportParameter("svcQuery", svcQuery),
                new ReportParameter("isDraft", (report.WorkflowInstance.ReportState != ReportState.Complete).ToString()),
                new ReportParameter("imageDataSource", ConfigurationManager.ConnectionStrings["InformRMSMedia"].ConnectionString),
                new ReportParameter("headerText", headerText)
            };

            _log.Debug("SSRS URI: {0}", reportServerUri);
            reportParameters.ForEach(p =>
            {
                foreach (var value in p.Values)
                {
                    _log.Debug("SSRS Parameter {0} = {1}", p.Name, value);
                }
            });

            viewer.ServerReport.SetParameters(reportParameters);
            var bytes = viewer.ServerReport.Render(attachmentType.ToString(), null, out mimeType, out encoding, out extension, out streamIds, out warnings);

            if (bytes != null)
            {
                MemoryStream = new MemoryStream(bytes);
                // Set the position to the beginning of the stream.
                MemoryStream.Seek(0, SeekOrigin.Begin);
                return(MemoryStream);
            }
            return(null);
        }
예제 #5
0
        private void RenderReportViewer(Guid id, RelatedToType relatedType, ModuleType moduleType)
        {
            _log.Debug("Rendering [{0}] [{1}] Viewer...", relatedType.GetDescription(), moduleType.GetDescription());
            try
            {
                var  isDraft = false;
                var  reportNumber = string.Empty;
                var  templateQueryService = DependencyContainer.Resolve <ITemplateQueryService>();
                Guid agencyId, templateId;

                if (relatedType != RelatedToType.Summary)
                {
                    using (var iocService = DependencyContainer.Resolve <IReportQueryService>())
                    {
                        //get workflow status detail
                        _reportQueryService = iocService.Instance;
                        var reportsInfo = _reportQueryService.GetReportInfo(id);
                        isDraft    = reportsInfo.State != ReportState.Complete;
                        agencyId   = reportsInfo.Agency.AgencyId;
                        templateId = reportsInfo.TemplateId;
                        if (!reportsInfo.WorkflowRights.CanView && !UserHasAccessRights(reportsInfo.Agency.AgencyId, moduleType))
                        {
                            ReportViewer1.Visible  = false;
                            AccessDisabled.Visible = true;
                            Response.Redirect("~/#/error");
                            return;
                        }
                        reportNumber = reportsInfo.Number;
                    }
                }
                else
                {
                    //get reportnumber for selected summary record
                    using (var iocSummaryService = DependencyContainer.Resolve <ISummaryQueryService>())
                    {
                        //get workflow status detail
                        _summaryQueryService = iocSummaryService.Instance;
                        var summaryInfo = _summaryQueryService.GetSummaryInfo(id);
                        agencyId   = summaryInfo.Agency.AgencyId;
                        templateId = templateQueryService.Instance.GetDefaultTemplate(summaryInfo.Agency.AgencyId, moduleType).Id;

                        if (!UserHasAccessRights(summaryInfo.Agency.AgencyId, moduleType))
                        {
                            ReportViewer1.Visible  = false;
                            AccessDisabled.Visible = true;
                            Response.Redirect("~/#/error");
                            return;
                        }
                        reportNumber = summaryInfo.Number;
                    }
                }

                AccessDisabled.Visible = false;

                var reportServerUri = String.Format("http://{0}/ReportServer",
                                                    ConfigurationManager.AppSettings["ReportServer"]);
                var reportPath = String.Format("/{0}",
                                               ConfigurationManager.AppSettings["ReportRootPath"]);
                ReportViewer1.ServerReport.ReportPath      = reportPath;
                ReportViewer1.ServerReport.ReportServerUrl = new Uri(reportServerUri);
                ReportViewer1.ShowParameterPrompts         = false;
                ReportViewer1.ShowFindControls             = false;
                ReportViewer1.ShowExportControls           = true;
                ReportViewer1.ShowToolBar = true;

                int validity;
                var result = Int32.TryParse(ConfigurationManager.AppSettings["SSRSTokenTimeout"], out validity);
                if (!result)
                {
                    validity = 5;
                }

                var headerText = templateQueryService.Instance.GetTemplateHeaderText(moduleType, reportNumber, agencyId, templateId);

                var svcQuery = String.Format("{0}",
                                             ConfigurationManager.AppSettings["SSRSServiceHost"]) +
                               "api/ssrsreports/getreportsdata/"
                               + id.ToString()
                               + "/" + moduleType.ToString()
                               + "/" + relatedType.ToString() + "?wsSignInKey=" + new JwtTokenGenerator(TokenManagerFactory.GetTokenManager()).GenerateJwtToken(System.Web.HttpContext.Current.User.Identity as ClaimsIdentity, validity);
                var reportParameters = new List <ReportParameter>
                {
                    new ReportParameter("svcQuery", svcQuery),
                    new ReportParameter("isDraft", isDraft.ToString()),
                    new ReportParameter("imageDataSource", ConfigurationManager.ConnectionStrings["InformRMSMediaSSRS"].ConnectionString),
                    new ReportParameter("headerText", headerText)
                };

                _log.Debug("SSRS URI: {0}", reportServerUri);
                reportParameters.ForEach(p =>
                {
                    foreach (var value in p.Values)
                    {
                        _log.Debug("SSRS Parameter {0} = {1}", p.Name, value);
                    }
                });

                ReportViewer1.ServerReport.SetParameters(reportParameters);
                ReportViewer1.ServerReport.Refresh();
            }
            catch (Exception ex)
            {
                _log.Error("Failure to render SSRS Report {0}", ex);
            }
        }
예제 #6
0
        public void TokenManagerFactory_GetSymmetricKeyTokenManager()
        {
            var tokenManager = TokenManagerFactory.GetTokenManager();

            Assert.IsNotNull(tokenManager);
        }