예제 #1
0
        protected override void OnApplicationStarted()
        {
            Log.Logger = new EventAdapter("JohnsonControls.P2000.WebUI");
            _sessionStore = LazyKernel.Value.Get<IBuildingSecuritySessionStore>();

            AreaRegistration.RegisterAllAreas();

            // Add Filters for CsrfPrevention
            var crsfProtection = new CsrfPreventionFilter();
            GlobalFilters.Filters.Add(crsfProtection);
            WebApi.GlobalConfiguration.Configuration.Filters.Add(crsfProtection);

            // Add Filters for AuthenticationRequiredException
            var authenticationRequiredExceptionFilter = new AuthenticationRequiredExceptionFilter(_sessionStore);
            var authenticationRequiredExceptionApiFilter = new AuthenticationRequiredExceptionApiFilter(_sessionStore);
            GlobalFilters.Filters.Add(authenticationRequiredExceptionFilter);
            WebApi.GlobalConfiguration.Configuration.Filters.Add(authenticationRequiredExceptionApiFilter);

            // Register Filters
            RegisterGlobalMvcFilters(GlobalFilters.Filters);
            RegisterGlobalWebApiFilters(WebApi.GlobalConfiguration.Configuration.Filters);

            // Register Routes
            RegisterRoutes(RouteTable.Routes);
            
            // Register Bundles
            RegisterBundles();

            // This line lets us share the ninject dependency resolver between the mvc and web api call stacks
            WebApi.GlobalConfiguration.Configuration.DependencyResolver = new WebApiResolverAdapter(DependencyResolver.Current);
            var factory = new MvcBuildingSecurityProviderFactory(LazyKernel.Value.Get<IBuildingSecuritySessionStore>());
            ValueProviderFactories.Factories.Add(factory);
            base.OnApplicationStarted();
        }
예제 #2
0
        /// <summary>
        /// Determines if the principal is logged in to the system.
        /// </summary>
        /// <param name="principal">The <see cref="IPrincipal"/> to check the logged in status for.</param>
        /// <param name="sessionStore">The session store that holds information for the logged in users.</param>
        /// <param name="sessionId">The user's current Http sessionId </param>
        /// <returns>True if the <see cref="IPrincipal"/> is logged on to the system, otherwise false.</returns>
        public static bool IsLoggedOn(this IPrincipal principal, IBuildingSecuritySessionStore sessionStore, string sessionId)
        {
            if (principal  != null && sessionStore != null && principal.Identity.IsAuthenticated)
            {
                IUser user;
                return  sessionStore.TryRetrieveUser(principal.Identity.Name, out user) &&
                       user.UserSessionId == sessionId;
            }

            return false;
        }
예제 #3
0
        public AccountControllerTest()
        {
            var principalStub = new Mock<IPrincipal>();
            var identityStub = new Mock<IIdentity>();

            identityStub.SetupGet(i => i.Name).Returns(UserName);
            principalStub.SetupGet(p => p.Identity).Returns(identityStub.Object);

            var httpContextStub = new Mock<HttpContextBase>();
            httpContextStub.SetupGet(context => context.User).Returns(principalStub.Object);
            _controllerContextStub = new Mock<ControllerContext>();
            _controllerContextStub.SetupGet(c => c.HttpContext).Returns(httpContextStub.Object);
            _controllerContextStub.SetupGet(c => c.IsChildAction).Returns(false);
            _controllerContextStub.SetupGet(c => c.RouteData).Returns((RouteData)null);

            _user = new MutableUser {Name =UserName, FullName = FullName};
            _sessionStore = new BuildingSecuritySessionStore();
            _sessionStore.AddUser(_user);
        }
예제 #4
0
        public AlarmsControllerTest()
        {
            _mockFactory = new MockRepository(MockBehavior.Loose);

            //need to mock Thread.CurrentPrincipal.Identity.Name
            var principalStub = _mockFactory.Create<IPrincipal>();
            var identityStub = _mockFactory.Create<IIdentity>();

            identityStub.SetupGet(n => n.Name).Returns(UserName);
            principalStub.SetupGet(p => p.Identity).Returns(identityStub.Object);

            var mockHttpContext = _mockFactory.Create<HttpContextBase>();
            mockHttpContext.SetupGet(x => x.User).Returns(principalStub.Object);
            _controllerContextStub = _mockFactory.Create<ControllerContext>();
            _controllerContextStub.SetupGet(x => x.HttpContext).Returns(mockHttpContext.Object);
            _controllerContextStub.SetupGet(y => y.IsChildAction).Returns(false);

            _user =new MutableUser{ Name =UserName,FullName = FullName,UserPreferences = new UserPreferences(TimeZoneInfo.Local.Id), Partitions = Enumerable.Empty<Partition>(), CanViewAlarmManager = true};
            _sessionStore = new BuildingSecuritySessionStore();
            _sessionStore.AddUser(_user);
        }
예제 #5
0
 public SessionController(IBuildingSecuritySessionStore sessionStore) : base(sessionStore)
 {}
예제 #6
0
 public HistoryController(IBuildingSecuritySessionStore sessionStore, IBuildingSecurityClient buildingSecurityClient) : base(sessionStore)
 {
     _buildingSecurityClient = buildingSecurityClient;
 }
 public AlarmDisplayOptionsController(IBuildingSecuritySessionStore sessionStore, IBuildingSecurityClient buildingSecurityClient)
     : base(sessionStore)
 {
     _buildingSecurityClient = buildingSecurityClient;
 }
예제 #8
0
 protected BaseApiController(IBuildingSecuritySessionStore sessionStore)
 {
     SessionStore = sessionStore;
 }
 public AlarmResponsesController(IBuildingSecuritySessionStore sessionStore, IBuildingSecurityClient buildingSecurityClient) : base(sessionStore)
 {
     _buildingSecurityClient = buildingSecurityClient;
 }
 public AuthenticationRequiredExceptionApiFilter(IBuildingSecuritySessionStore sessionStore)
 {
     _sessionStore = sessionStore;
 }
예제 #11
0
 public KeepUserSessionActive(IBuildingSecuritySessionStore sessionStore)
 {
     _sessionStore = sessionStore;
 }
 public ReportParametersController(IBuildingSecuritySessionStore sessionStore, IReportingClientFactory reportingClientFactory) : base(sessionStore)
 {
     _reportingClientFactory = reportingClientFactory;
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PushServices"/> with the specified values and services.
 /// </summary>
 /// <param name="currentUserName">The name of the user this registration should be associated with.</param>
 /// <param name="clientId">The id of the calling signalr client.
 /// uses to add / remove channel callbacks.</param>
 /// <param name="sessionStore"> </param>
 public PushServices(string currentUserName, string clientId, IBuildingSecuritySessionStore sessionStore)
 {
     _currentUserName = currentUserName;
     _clientId = clientId;
     _sessionStore = sessionStore;
 }
예제 #14
0
 /// <summary>
 /// Initiates a new instance of the <see cref="MvcLoggedOnAttribute"/> class.
 /// </summary>
 /// <param name="sessionStore">The <see cref="IBuildingSecuritySessionStore"/> service that contains the user's session information.</param>
 public MvcLoggedOnAttribute(IBuildingSecuritySessionStore sessionStore)
 {
     if (sessionStore == null) throw new ArgumentNullException("sessionStore");
     _sessionStore = sessionStore;
 }
예제 #15
0
 public SimulatorController(IBuildingSecuritySessionStore sessionStore, ISimulatorClient simulationClient) : base(sessionStore)
 {
      _simulationClient = simulationClient;
 }
예제 #16
0
 public AccountController GetAccountController(IBuildingSecuritySessionStore sessionStore = null, IAuthenticationServices authenticationServices = null)
 {
     return new AccountController(sessionStore ?? _sessionStore, authenticationServices ?? new Mock<IAuthenticationServices>().Object);
 }
예제 #17
0
 public AccountController(IBuildingSecuritySessionStore sessionStore, IAuthenticationServices authenticationServices)
 {
     _sessionStore = sessionStore;
     _authenticationServices = authenticationServices;
 }
예제 #18
0
 public AuthenticationServices(IBuildingSecurityClient buildingSecurityClient, IBuildingSecuritySessionStore sessionStore, IHttpSessionManager sessionManager)
 {
     _buildingSecurityClient = buildingSecurityClient;
     _sessionStore = sessionStore;
     _sessionManager = sessionManager;
 }
 public UserPreferencesController(IBuildingSecuritySessionStore sessionStore, IBuildingSecurityClient buildingSecurityClient) : base(sessionStore)
 {
     if (buildingSecurityClient == null) throw new ArgumentNullException("buildingSecurityClient");
     _buildingSecurityClient = buildingSecurityClient;
 }
 public MvcBuildingSecurityProviderFactory(IBuildingSecuritySessionStore sessionStore)
 {
     if (sessionStore == null) throw new ArgumentNullException("sessionStore");
     _sessionStore = sessionStore;
 }