示例#1
0
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();

            #region IoC
            var container = new UnityContainer();
            container.RegisterType <IOpmVerificator, OpmVerificator>(new HierarchicalLifetimeManager());


            string idmUrl           = System.Configuration.ConfigurationManager.AppSettings["IdmUrl"];
            IIdentityManagement idm = new IdentityManagement(idmUrl);
            container.RegisterInstance(idm);

            string eanEicCheckerUrl = System.Configuration.ConfigurationManager.AppSettings["EanEicCheckerUrl"];
            IEanEicCheckerHttpClient eanEicCheckerHttpClient = new EanEicCheckerHttpClient(eanEicCheckerUrl);
            container.RegisterInstance(eanEicCheckerHttpClient);


            IOpmRepository opmInMemoryRepository = new OpmInMemoryRepository();
            OpmRepoFiller.Fill(opmInMemoryRepository);
            container.RegisterInstance(opmInMemoryRepository);

            config.DependencyResolver = new UnityResolver(container);
            #endregion IoC
        }
示例#2
0
        public void BasicImTest()
        {
            IdentityManagement im = new IdentityManagement("https://am-proxytest.bohemiaenergy.cz/opensso/identity/");

            string       token    = im.Login("t5734", "Lcii9lvy");
            const string badToken = "AAABB123123123DFSDFsdfsdf123123dsfsdf123SDFSDF4.*AAJTSQACMDE.*";

            bool userValid = im.ValidateUser(badToken);

            Assert.IsFalse(userValid);

            IUser user = im.GetUserInfo(badToken);

            Assert.IsNull(user);

            userValid = im.ValidateUser(token);
            Assert.IsTrue(userValid);

            IUser user2 = im.GetUserInfo(token);

            Assert.NotNull(user2);
            Assert.AreEqual(user2.Id, "t5734");
        }
示例#3
0
        public void BasicImTest()
        {
            IdentityManagement im = new IdentityManagement(_idmUrl);

            string       token    = im.Login("t5734", "Lcii9lvy");
            const string badToken = "AAABB123123123DFSDFsdfsdf123123dsfsdf123SDFSDF4.*AAJTSQACMDE.*";

            bool userValid = im.ValidateUser(badToken);

            Assert.IsFalse(userValid);

            string username = im.GetUsername(badToken);

            Assert.IsNull(username);

            userValid = im.ValidateUser(token);
            Assert.IsTrue(userValid);

            string username2 = im.GetUsername(token);

            Assert.NotNull(username2);
            Assert.AreEqual(username2, "t5734");
        }
示例#4
0
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();

            bool recreateDatabase = Boolean.Parse(System.Configuration.ConfigurationManager.AppSettings["RecreateDatabase"]);

            _log.Info("DB settings:" + DbRepositoryUtil.GetDbInfo());

            if (recreateDatabase)
            {
                _log.Info("DB recreate started.");
                DbRepositoryUtil.RecreateDatabase();
                //TODO SP: move sample data to AppData
                String pathToSampleData = HttpContext.Current.Server.MapPath("~/Persistence/OpmRepoSampleData.csv");
                DbRepositoryUtil.FillSampleOpm(pathToSampleData);
                _log.Info("DB recreate finished.");
            }

            #region IoC

            _log.Info("Initializing dependencies.");
            var container = new UnityContainer();
            container.RegisterType <IOpmVerificator, OpmVerificator>(new HierarchicalLifetimeManager());

            string idmUrl           = System.Configuration.ConfigurationManager.AppSettings["IdmUrl"];
            IIdentityManagement idm = new IdentityManagement(idmUrl);
            container.RegisterInstance(idm);
            _log.Info("IDM found on " + idmUrl + ".");

            string eanEicCheckerUrl = System.Configuration.ConfigurationManager.AppSettings["EanEicCheckerUrl"];
            IEanEicCheckerHttpClient eanEicCheckerHttpClient = new EanEicCheckerHttpClient(eanEicCheckerUrl);
            container.RegisterInstance(eanEicCheckerHttpClient);
            _log.Info("EAN/EIC checker found on " + eanEicCheckerUrl + ".");

            IOpmRepository opmRepository = new OpmDbRepository();
            container.RegisterInstance(opmRepository);

            IUserAccessRepository userAccessRepository = new UserAccessDbRepository();

            int maxUserLimit = int.Parse(System.Configuration.ConfigurationManager.AppSettings["MaxUserLimit"]);
            int userLimitTimeWindownInSeconds    = int.Parse(System.Configuration.ConfigurationManager.AppSettings["UserLimitTimeWindownInSeconds"]);
            IUserAccessService userAccessService = new UserAccessService(userAccessRepository, new TimeSpan(0, 0, 0, userLimitTimeWindownInSeconds), maxUserLimit);
            container.RegisterInstance(userAccessService);
            _log.Info("User access limitation initialized with user limit [" + maxUserLimit + "], time window for access limitation [" + userLimitTimeWindownInSeconds + " s].");

            config.DependencyResolver = new UnityResolver(container);
            _log.Info("Init finished successfully.");

            #endregion IoC
        }
示例#5
0
 public void SetUp()
 {
     httpClient         = new OpmVerificationHttpClient(@"http://192.168.88.190:9876/");
     identityManagement = new IdentityManagement(@"https://am-proxytest.bohemiaenergy.cz/opensso/identity/");
 }