Exemple #1
0
        public static void Main(string[] args)
        {
            IDependencyContainer dependencyContainer = new DependencyContainer();
            IHttpHandler         handler             = new ControllerRouter(dependencyContainer);
            IHttpHandler         resourceHandler     = new ResourceRouter();

            dependencyContainer.RegisterDependency <IHashService, HashService>();

            Server server = new Server(80, handler, resourceHandler);

            MvcEngine.Run(server);
        }
Exemple #2
0
        public static void Main()
        {
            int port = 55000;

            var controllerRouter = new ControllerRouter();

            var resourceRouter = new ResourceRouter();

            var webServer = new WebServer(port, controllerRouter, resourceRouter);

            var dbContext = new KittenWebDbContext();

            MvcEngine.Run(webServer, dbContext);
        }
Exemple #3
0
        public static void Start(IMvcApplication application)
        {
            IDependencyContainer container = new DependencyContainer();

            application.ConfigureServices(container);

            IHandleable controllerRouter = new ControllerRouter(container);
            IHandleable resourceRouter   = new ResourceRouter();

            application.Configure();

            Server server = new Server(HostingPort, controllerRouter, resourceRouter);

            MvcEngine.Run(server);
        }
Exemple #4
0
        public static async Task Start <TStartup>(MvcContext mvcContext) where TStartup : IMvcApplication, new()
        {
            TStartup mvcApplication = new TStartup();

            mvcApplication.Configure();

            DependencyContainer container = new DependencyContainer();

            mvcApplication.ConfigureServices(container);

            ControllerRouter controllerRouter = new ControllerRouter(mvcContext, container);
            ResourceRouter   resourceRouter   = new ResourceRouter();

            Server server = new Server(Port, controllerRouter, resourceRouter);

            await server.Run();
        }
Exemple #5
0
        public static void Start(IMvcApplication application)
        {
            var container = new ServiceCollection();

            application.ConfigureServices(container);

            var controllerRouter = new ControllerRouter(container);
            var resourceRouter   = new ResourceRouter();
            var customRouter     = new CustomRouter();

            var router = new HttpHandlerContext(controllerRouter, resourceRouter, customRouter);

            application.Configure();

            var server = new WebServer.WebServer(HOSTING_PORT, router);

            server.Run();
        }
        public static void Start(IMvcApplication application)
        {
            IDependencyContainer container = new DependencyContainer();

            application.ConfigureServices(container);

            IMvcRouter      controllerRouter = new ControllerRouter(container);
            IResourceRouter resourceRouter   = new ResourceRouter();
            ICustomRouter   customRouter     = new CustomRouter();

            IHttpRequestHandler httpRequestHandlingContext
                = new HttpRequestHandlingContext(controllerRouter, resourceRouter, customRouter);

            application.Configure();

            Server server = new Server(HostingPort, httpRequestHandlingContext);

            server.Run();
        }
Exemple #7
0
 /// <summary>
 /// Remove a resource router object.
 /// </summary>
 public void RemoveResourceRouter(ResourceRouter router)
 {
     Runtime.ValidateRefCounted(this);
     ResourceCache_RemoveResourceRouter(handle, (object)router == null ? IntPtr.Zero : router.Handle);
 }
Exemple #8
0
 /// <summary>
 /// Add a resource router object. By default there is none, so the routing process is skipped.
 /// </summary>
 public void AddResourceRouter(ResourceRouter router, bool addAsFirst = false)
 {
     Runtime.ValidateRefCounted(this);
     ResourceCache_AddResourceRouter(handle, (object)router == null ? IntPtr.Zero : router.Handle, addAsFirst);
 }
Exemple #9
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            string ticket = filterContext.RequestContext.HttpContext.Request.QueryString.Get("ticket");

            HttpCookie casCookie = HttpContext.Current.Request.Cookies.Get("CASTicket");

            string userDataString = (casCookie != null) ? casCookie.Value : null;

            string[] userData = !String.IsNullOrEmpty(userDataString) ? userDataString.Split(new String[] { ":" }, StringSplitOptions.None) : null;

            string loginRedirectUrl = String.Format("{0}login?service={1}", ModuleConfiguration.DefaultCasUrl, ModuleConfiguration.DefaultCasAuthorizedUrl);

            string serviceValidationUrl = String.Format("{0}serviceValidate?ticket={1}&service={2}", ModuleConfiguration.DefaultCasUrl, ticket, ModuleConfiguration.DefaultCasAuthorizedUrl);

            ILogger logger = Provider.Logger();
            ITracer tracer = Provider.Tracer();

            if ((String.IsNullOrEmpty(ticket)) && (userData == null))//((String.IsNullOrEmpty(ticket)) && (!filterContext.HttpContext.User.Identity.IsAuthenticated))
            {
                filterContext.HttpContext.Response.StatusCode = 401;
                filterContext.HttpContext.Response.Redirect(loginRedirectUrl, true);
                return;
            }
            else if ((!String.IsNullOrEmpty(ticket)) && (userData == null)) //((!String.IsNullOrEmpty(ticket)) && (!filterContext.HttpContext.User.Identity.IsAuthenticated))
            {
                //System.Net.ServicePointManager.ServerCertificateValidationCallback = (s, c, ch, p) => { return true; };

                //using (Stream stream = new WebClient().OpenRead(serviceValidationUrl))
                //{
                //    using (StreamReader reader = new StreamReader(stream))
                //    {
                //        result = reader.ReadToEnd();
                //    }
                //}

                bool enableTracing = Facade.Global.Should("EnableCASTracing");

                string traceSource = "CASTraceSource";

                ResourceRouter router = new ResourceRouter(enableTracing, traceSource);

                object responseData = router.Get(serviceValidationUrl, new ResourceIntegrator.Authentication()
                {
                    Type = AuthenticationType.Custom
                }, new Dictionary <string, string>()
                {
                });

                string result = responseData != null?responseData.ToString() : null;

                if (!String.IsNullOrEmpty(result))
                {
                    tracer.Trace(new object[] { serviceValidationUrl, result }, null);

                    try
                    {
                        ServiceResponse response = XmlUtility.XmlDeserialize(result, typeof(ServiceResponse), new Type[] { typeof(ServiceResponseAuthenticationSuccess) }, "UTF-8") as ServiceResponse;

                        if (response.SuccessItems != null && response.SuccessItems.Length > 0)
                        {
                            CasUserInfo user = new CasUserInfo()
                            {
                                UserId   = response.SuccessItems[0].Attributes.UserId,
                                UserName = response.SuccessItems[0].User,
                                Email    = response.SuccessItems[0].Attributes.Email,
                                NickName = response.SuccessItems[0].Attributes.NickName,
                                Phone    = response.SuccessItems[0].Attributes.Phone,
                                UserType = response.SuccessItems[0].Attributes.UserType
                            };//String.IsNullOrEmpty(response.SuccessItems[0].Attributes) ? null : JsonUtility.JsonDeserialize(System.Text.Encoding.UTF8.GetBytes(response.SuccessItems[0].Attributes), typeof(CasUserInfo), new Type[] { typeof(CasUserInfo) }, "root") as CasUserInfo;

                            if (user == null)
                            {
                                filterContext.HttpContext.Response.StatusCode = 404;
                                return;
                            }

                            string webApiUrl = String.Format("{0}api/Account/Cas/Auth/", ModuleConfiguration.DefaultAccountServiceUrl);

                            byte[] userBytes = JsonUtility.JsonSerialize(user, new Type[] { typeof(CasUserInfo) }, "root");
                            string userJson  = System.Text.Encoding.UTF8.GetString(userBytes);

                            object tokenResult = router.Post(webApiUrl, userJson, new ResourceIntegrator.Authentication()
                            {
                                Type = AuthenticationType.Custom
                            }, new Dictionary <string, string>()
                            {
                                { "Content-Type", "application/json;charset=utf-8" }, { "Accept", "application/json" }
                            });

                            BearerToken bearerToken = tokenResult == null ? null : JsonUtility.JsonDeserialize(System.Text.Encoding.UTF8.GetBytes(tokenResult.ToString()), typeof(BearerToken), new Type[] { typeof(BearerToken) }, "root") as BearerToken;

                            if (bearerToken == null)
                            {
                                filterContext.HttpContext.Response.StatusCode = 404;
                                return;
                            }

                            if (bearerToken != null)
                            {
                                ClaimsIdentity identity = new ClaimsIdentity(new List <Claim>()
                                {
                                    new Claim(ClaimTypes.Name, response.SuccessItems[0].User),
                                    new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity"),
                                    new Claim("AspNet.Identity.SecurityStamp", ticket)
                                }, "Cookies");

                                GenericPrincipal principal = new GenericPrincipal(identity, null);

                                HttpContext.Current.User = principal;

                                HttpContext.Current.Response.Cookies.Add(new HttpCookie("CASTicket", String.Format("{0}:{1}", principal.Identity.Name, ticket)));

                                HttpContext.Current.Response.Cookies.Add(new HttpCookie("CASAccountToken", String.Format("{0} {1}", bearerToken.TokenType, bearerToken.AccessToken)));

                                filterContext.HttpContext.Response.StatusCode = 200;
                            }
                        }

                        if (response.FailureItems != null && response.FailureItems.Length > 0)
                        {
                            foreach (var item in response.FailureItems)
                            {
                                logger.LogSystemError(item.Code, item.Value);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Provider.ExceptionHandler().HandleException(ex);
                    }
                }
            }
            else if ((userData != null) && (userData.Length > 1))
            {
                ClaimsIdentity identity = new ClaimsIdentity(new List <Claim>()
                {
                    new Claim(ClaimTypes.Name, userData[0]),
                    new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity"),
                    new Claim("AspNet.Identity.SecurityStamp", userData[1])
                }, "Cookies");

                GenericPrincipal principal = new GenericPrincipal(identity, null);
                HttpContext.Current.User = principal;
                filterContext.HttpContext.Response.StatusCode = 200;
            }

            //base.OnAuthorization(filterContext);
        }