예제 #1
0
        private void ValidateUserAccess(User user, IServiceRequest request,
                                        IAuthenticationAttributes authAttribtues,
                                        AuthorizationInfo auth)
        {
            if (user.Policy.IsDisabled)
            {
                throw new SecurityException("User account has been disabled.")
                      {
                          SecurityExceptionType = SecurityExceptionType.Unauthenticated
                      };
            }

            if (!user.Policy.IsAdministrator &&
                !authAttribtues.EscapeParentalControl &&
                !user.IsParentalScheduleAllowed())
            {
                request.AddResponseHeader("X-Application-Error-Code", "ParentalControl");

                throw new SecurityException("This user account is not allowed access at this time.")
                      {
                          SecurityExceptionType = SecurityExceptionType.ParentalControl
                      };
            }

            if (!string.IsNullOrWhiteSpace(auth.DeviceId))
            {
                if (!DeviceManager.CanAccessDevice(user.Id.ToString("N"), auth.DeviceId))
                {
                    throw new SecurityException("User is not allowed access from this device.")
                          {
                              SecurityExceptionType = SecurityExceptionType.ParentalControl
                          };
                }
            }
        }