Beispiel #1
0
        public Models.SaveResponse Log([FromBody] Models.MessageLogModel request)
        {
            var repo = new DataLib.Repository();
            var app  = repo.GetApplication(request.Application_Id);

            if (app == null)
            {
                return new Models.SaveResponse()
                       {
                           Success = false
                       }
            }
            ;

            var log = new DataLib.Models.MessageModel()
            {
                Logger         = request.Logger,
                Level          = request.Level,
                Application_Id = request.Application_Id,
                Message        = request.Message
            };

            repo.InsertMessageLog(log);
            return(new Models.SaveResponse()
            {
                Success = true
            });
        }
    }
Beispiel #2
0
        public void LoginTest()
        {
            // Create application in case it doesn't exist
            var app = InsertApplication();

            DataLib.Repository repo = new DataLib.Repository();
            Assert.IsTrue(repo.CheckAuthentication(app.Application_Id, app.Secret));
        }
Beispiel #3
0
        public void TokenAuthenticationTest()
        {
            // Create application in case it doesn't exist
            var app = InsertApplication();

            DataLib.Repository repo = new DataLib.Repository();
            var token = repo.GenerateToken(app.Application_Id);

            Assert.IsTrue(repo.CheckTokenAuthentication(token.Token));
        }
Beispiel #4
0
        public DataLib.Models.ApplicationModel Register([FromBody] Models.RegisterRequest request)
        {
            var repo = new DataLib.Repository();
            var app  = new DataLib.Models.ApplicationModel()
            {
                Display_Name   = request.Display_Name,
                Application_Id = Guid.NewGuid().ToString().Replace("-", ""),
            };

            app.Secret = app.Application_Id.Substring(0, 25);
            repo.InsertApplication(app);

            return(app);
        }
Beispiel #5
0
        /// <summary>
        /// Protected overriden method for authorizing user
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="actionContext"></param>
        /// <returns></returns>
        protected override bool OnAuthorizeUser(string username, string password, HttpActionContext actionContext)
        {
            var repo = new DataLib.Repository();

            if (repo.CheckAuthentication(username, password))
            {
                var basicAuthenticationIdentity = Thread.CurrentPrincipal.Identity as BasicAuthenticationIdentity;
                if (basicAuthenticationIdentity != null)
                {
                    basicAuthenticationIdentity.ApplicationId = username;
                }
                return(true);
            }
            return(false);
        }
Beispiel #6
0
        public DataLib.Models.ApplicationModel InsertApplication()
        {
            DataLib.Repository repo = new DataLib.Repository();
            var model = new DataLib.Models.ApplicationModel()
            {
                Application_Id = Guid.NewGuid().ToString().Replace("-", ""),
                Display_Name   = "UnitTest",
                Secret         = "test"
            };

            repo.InsertApplication(model);
            var app = repo.GetApplication(model.Application_Id);

            return(app);
        }
        public void LogMessageTest()
        {
            var appTest = new ApplicationTest();
            var app     = appTest.InsertApplication();

            DataLib.Repository repo = new DataLib.Repository();
            var log = new MessageModel()
            {
                Application_Id = app.Application_Id,
                Logger         = "UnitTest",
                Message        = "Unit Tested.",
                Level          = "Test"
            };

            repo.InsertMessageLog(log);
        }
Beispiel #8
0
 public Models.AuthResponse Auth()
 {
     if (System.Threading.Thread.CurrentPrincipal != null &&
         System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated)
     {
         var basicAuthenticationIdentity = System.Threading.Thread.CurrentPrincipal.Identity as BasicAuthenticationIdentity;
         if (basicAuthenticationIdentity != null)
         {
             var repo  = new DataLib.Repository();
             var appId = basicAuthenticationIdentity.ApplicationId;
             var token = repo.GenerateToken(appId);
             return(new Models.AuthResponse()
             {
                 Access_Token = token.Token
             });
         }
     }
     return(null);
 }
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            var repo      = new DataLib.Repository();
            var authToken = this.FetchAuthHeader(filterContext);

            if (authToken == null)
            {
                filterContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
            }
            else if (!repo.CheckTokenAuthentication(authToken))
            {
                var responseMessage = new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    ReasonPhrase = "Invalid Request"
                };
                filterContext.Response = responseMessage;
            }
            base.OnActionExecuting(filterContext);
        }