Exemplo n.º 1
0
        public static void Initialize(TestContext context)
        {
            // Force load of the DLL
            var p = FirebirdSql.Data.FirebirdClient.FbCharset.Ascii;

            TestApplicationContext.TestAssembly = typeof(TestMessageParsing).Assembly;
            TestApplicationContext.Initialize(context.DeploymentDirectory);

            // Create the test harness device / application
            var securityDevService = ApplicationServiceContext.Current.GetService <IRepositoryService <SecurityDevice> >();
            var securityAppService = ApplicationServiceContext.Current.GetService <IRepositoryService <SecurityApplication> >();
            var metadataService    = ApplicationServiceContext.Current.GetService <IAssigningAuthorityRepositoryService>();

            AuthenticationContext.Current = new AuthenticationContext(AuthenticationContext.SystemPrincipal);
            // Create device
            var dev = new SecurityDevice()
            {
                DeviceSecret = "DEVICESECRET",
                Name         = "TEST_HARNESS|TEST"
            };

            dev.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
            dev = securityDevService.Insert(dev);

            var app = new SecurityApplication()
            {
                Name = "TEST_HARNESS",
                ApplicationSecret = "APPLICATIONSECRET"
            };

            app.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
            app.AddPolicy(PermissionPolicyIdentifiers.UnrestrictedClinicalData);
            app.AddPolicy(PermissionPolicyIdentifiers.ReadMetadata);
            app = securityAppService.Insert(app);
            metadataService.Insert(new Core.Model.DataTypes.AssigningAuthority("TEST", "TEST", "1.2.3.4.5.6.7")
            {
                IsUnique = true,
                AssigningApplicationKey = app.Key
            });

            // Add another application for security checks
            dev = new SecurityDevice()
            {
                DeviceSecret = "DEVICESECRET2",
                Name         = "TEST_HARNESS2|TEST"
            };
            dev.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
            dev = securityDevService.Insert(dev);

            app = new SecurityApplication()
            {
                Name = "TEST_HARNESS2",
                ApplicationSecret = "APPLICATIONSECRET2"
            };
            app.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
            app.AddPolicy(PermissionPolicyIdentifiers.UnrestrictedClinicalData);
            app.AddPolicy(PermissionPolicyIdentifiers.ReadMetadata);
            app = securityAppService.Insert(app);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create the specified authority
        /// </summary>
        public static void CreateAuthority(string nsid, string oid, string applicationName, byte[] deviceSecret)
        {
            // Create the test harness device / application
            var securityDevService = ApplicationServiceContext.Current.GetService <IRepositoryService <SecurityDevice> >();
            var securityAppService = ApplicationServiceContext.Current.GetService <IRepositoryService <SecurityApplication> >();
            var metadataService    = ApplicationServiceContext.Current.GetService <IAssigningAuthorityRepositoryService>();

            AuthenticationContext.Current = new AuthenticationContext(AuthenticationContext.SystemPrincipal);
            string pubId  = $"{applicationName}|TEST";
            var    device = securityDevService.Find(o => o.Name == pubId).FirstOrDefault();

            if (device == null)
            {
                device = new SecurityDevice()
                {
                    DeviceSecret = BitConverter.ToString(deviceSecret).Replace("-", ""),
                    Name         = $"{applicationName}|TEST"
                };
                device.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
                device = securityDevService.Insert(device);
            }

            // Application
            var app = securityAppService.Find(o => o.Name == applicationName).FirstOrDefault();

            if (app == null)
            {
                app = new SecurityApplication()
                {
                    Name = applicationName,
                    ApplicationSecret = BitConverter.ToString(deviceSecret).Replace("-", "")
                };
                app.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
                app.AddPolicy(PermissionPolicyIdentifiers.UnrestrictedClinicalData);
                app.AddPolicy(PermissionPolicyIdentifiers.ReadMetadata);
                app = securityAppService.Insert(app);
            }

            // Create AA
            var aa = metadataService.Get(nsid);

            if (aa == null)
            {
                aa = new SanteDB.Core.Model.DataTypes.AssigningAuthority(nsid, nsid, oid)
                {
                    AssigningApplicationKey = app.Key,
                    IsUnique = true
                };
                metadataService.Insert(aa);
            }
        }
Exemplo n.º 3
0
        public void Initialize()
        {
            // Force load of the DLL
            var p = FirebirdSql.Data.FirebirdClient.FbCharset.Ascii;

            TestApplicationContext.TestAssembly = typeof(TestMessageParsing).Assembly;
            TestApplicationContext.Initialize(TestContext.CurrentContext.TestDirectory);

            // Create the test harness device / application
            var securityDevService = ApplicationServiceContext.Current.GetService <IRepositoryService <SecurityDevice> >();
            var securityAppService = ApplicationServiceContext.Current.GetService <IRepositoryService <SecurityApplication> >();
            var metadataService    = ApplicationServiceContext.Current.GetService <IAssigningAuthorityRepositoryService>();

            this.m_serviceManager = ApplicationServiceContext.Current.GetService <IServiceManager>();

            AuthenticationContext.EnterSystemContext();

            // Create device
            var dev = new SecurityDevice()
            {
                DeviceSecret = "DEVICESECRET",
                Name         = "TEST_HARNESS|TEST"
            };

            dev.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
            securityDevService.Insert(dev);

            // Create device
            dev = new SecurityDevice()
            {
                DeviceSecret = "DEVICESECRET",
                Name         = "TEST_HARNESS|MASTER"
            };
            dev.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
            dev.AddPolicy("1.3.6.1.4.1.33349.3.1.5.9.2.6");
            securityDevService.Insert(dev);

            var app = new SecurityApplication()
            {
                Name = "TEST_HARNESS",
                ApplicationSecret = "APPLICATIONSECRET"
            };

            app.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
            app.AddPolicy(PermissionPolicyIdentifiers.UnrestrictedClinicalData);
            app.AddPolicy(PermissionPolicyIdentifiers.ReadMetadata);
            app = securityAppService.Insert(app);
            metadataService.Insert(new Core.Model.DataTypes.AssigningAuthority("TEST", "TEST", "1.2.3.4.5.6.7")
            {
                IsUnique = true,
                AssigningApplicationKey = app.Key
            });

            metadataService.Insert(new Core.Model.DataTypes.AssigningAuthority("SSN", "US Social Security Number", "2.16.840.1.113883.4.1")
            {
                IsUnique = false,
                Url      = "http://hl7.org/fhir/sid/us-ssn",
                AssigningApplicationKey = app.Key
            });

            // Add another application for security checks
            dev = new SecurityDevice()
            {
                DeviceSecret = "DEVICESECRET2",
                Name         = "TEST_HARNESS2|TEST"
            };

            dev.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
            securityDevService.Insert(dev);

            app = new SecurityApplication()
            {
                Name = "TEST_HARNESS2",
                ApplicationSecret = "APPLICATIONSECRET2"
            };

            app.AddPolicy(PermissionPolicyIdentifiers.LoginAsService);
            app.AddPolicy(PermissionPolicyIdentifiers.UnrestrictedClinicalData);
            app.AddPolicy(PermissionPolicyIdentifiers.ReadMetadata);
            securityAppService.Insert(app);
        }