Exemplo n.º 1
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            //Checks whether user information has been entered
            if (actionContext.Request.Headers.Authorization == null)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden,
                                                                              "You must give a username and a password in basic authentication");
                return;
            }

            //Encoding the user name and password from base64
            string authenticationToken        = actionContext.Request.Headers.Authorization.Parameter;
            string decodedAuthenticationToken = Encoding.UTF8.GetString(
                Convert.FromBase64String(authenticationToken));

            string[] usernamePasswordArray = decodedAuthenticationToken.Split(':');
            string   username = usernamePasswordArray[0];
            string   password = usernamePasswordArray[1];

            if (username == "admin" && password == "9999")
            {
                LoginToken <Administrator> adminToken = (LoginToken <Administrator>)FlightSystemCenter.GetInstance().Login(username, password);
                actionContext.Request.Properties["adminToken"] = adminToken;
                FlightSystemCenter          f           = FlightSystemCenter.GetInstance();
                LoggedInAdministratorFacade adminFacade = (LoggedInAdministratorFacade)f.GetFacade(adminToken);
                actionContext.Request.Properties["adminFacade"] = adminFacade;
            }
            else
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                              "You are not authorized");
            }
        }
Exemplo n.º 2
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            //Checks whether user information has been entered
            if (actionContext.Request.Headers.Authorization == null)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden,
                                                                              "You must give a username and a password in basic authentication");
                return;
            }

            //Encoding the user name and password from base64
            string authenticationToken        = actionContext.Request.Headers.Authorization.Parameter;
            string decodedAuthenticationToken = Encoding.UTF8.GetString(
                Convert.FromBase64String(authenticationToken));

            string[] usernamePasswordArray = decodedAuthenticationToken.Split(':');
            string   username = usernamePasswordArray[0];
            string   password = usernamePasswordArray[1];

            ILoginToken token;

            try
            {
                token = FlightSystemCenter.GetInstance().Login(username, password);
            }
            catch (UserNotFoundException e)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.NotFound, e.Message);
                return;
            }
            catch (WrongPasswordException e)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.NotFound, e.Message);
                return;
            }

            if (token != null && token.GetType() == typeof(LoginToken <AirlineCompany>))
            {
                LoginToken <AirlineCompany> airlineToken = (LoginToken <AirlineCompany>)token;
                actionContext.Request.Properties["airlineToken"] = token;
                FlightSystemCenter    f             = FlightSystemCenter.GetInstance();
                LoggedInAirlineFacade airlineFacade = (LoggedInAirlineFacade)f.GetFacade(airlineToken);
                actionContext.Request.Properties["airlineFacade"] = airlineFacade;
            }

            else
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized,
                                                                              "You are not authorized");
            }
        }
Exemplo n.º 3
0
 public TestCenter()
 {
     ClearDataBase();
     f                    = FlightSystemCenter.GetInstance();
     adminToken           = (LoginToken <Administrator>)f.Login(FlightConfig.ADMIN_NAME, FlightConfig.ADMIN_PASSWORD);
     adminFacade          = (LoggedInAdministratorFacade)f.GetFacade(adminToken);
     cust                 = CreateCustomerForTests();
     customerToken        = (LoginToken <Customer>)f.Login(cust.USER_NAME, cust.PASSWORD);
     customerFacade       = (LoggedInCustomerFacade)f.GetFacade(customerToken);
     airlinecompany       = CreateAirlineCompanyForTests();
     airlinecompanyToken  = (LoginToken <AirlineCompany>)f.Login(airlinecompany.USER_NAME, airlinecompany.PASSWORD);
     airlinecompanyFacade = (LoggedInAirlineFacade)f.GetFacade(airlinecompanyToken);
     anonymousFacade      = (AnonymousUserFacade)f.GetFacade(null);
 }