コード例 #1
0
        public void SetRemotePassword(Guid accessToken, string password)
        {
            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            if (endPoint.AccessType == AccessType.Remote)
            {
                throw new ArgumentException("Access token is a remote token!");
            }

            this.VerifyAccess(accessToken);

            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Password is invalid", "password");
            }

            this.coreSettings.RemoteControlPassword = password;

            this.UpdateRemoteAccessPermissions(AccessPermission.Guest);
        }
コード例 #2
0
        /// <summary>
        /// Gets the remaining votes for a given access token. Returns the current value immediately
        /// and then any changes to the remaining votes, or <c>null</c> , if voting isn't supported.
        /// </summary>
        public IObservable <int?> ObserveRemainingVotes(Guid accessToken)
        {
            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            return(endPoint.EntryCountObservable.CombineLatest(
                       this.coreSettings.WhenAnyValue(x => x.MaxVoteCount),
                       this.WhenAnyValue(x => x.IsGuestSystemReallyEnabled),
                       (entryCount, maxVoteCount, enableGuestSystem) => enableGuestSystem ? maxVoteCount - entryCount : (int?)null));
        }
コード例 #3
0
        private AccessEndPoint FindEndPoint(Guid token)
        {
            this.endPointLock.EnterReadLock();

            AccessEndPoint endPoint = this.endPoints.FirstOrDefault(x => x.AccessToken == token);

            this.endPointLock.ExitReadLock();

            return(endPoint);
        }
コード例 #4
0
        /// <summary>
        /// Returns whether a vote for the given access token and entry is already registered.
        /// </summary>
        public bool IsVoteRegistered(Guid accessToken, PlaylistEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            return(endPoint.IsRegistered(entry));
        }
コード例 #5
0
        public void DowngradeLocalAccess(Guid accessToken)
        {
            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            if (this.localPassword == null)
            {
                throw new InvalidOperationException("Local password is not set");
            }

            endPoint.SetAccessPermission(AccessPermission.Guest);
        }
コード例 #6
0
        private AccessEndPoint VerifyAccessToken(Guid token)
        {
            AccessEndPoint endPoint = this.FindEndPoint(token);

            if (endPoint == null)
            {
                throw new ArgumentException("EndPoint with the gived access token was not found.");
            }

            return(endPoint);
        }
コード例 #7
0
        /// <summary>
        /// Verifies the access rights for the given access token.
        /// </summary>
        /// <param name="accessToken">The access token, whichs access rights should be verified.</param>
        /// <param name="localRestrictionCombinator">
        /// An optional restriction constraint for local access.
        /// </param>
        /// <exception cref="AccessException">
        /// The token has guest permission and is either of type remote or of type local and the
        /// restriction combinator was true.
        /// </exception>
        public void VerifyAccess(Guid accessToken, bool localRestrictionCombinator = true)
        {
            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            if (endPoint.AccessPermission.FirstAsync().Wait() == AccessPermission.Admin)
            {
                return;
            }

            if (endPoint.AccessType == AccessType.Remote || endPoint.AccessType == AccessType.Local && localRestrictionCombinator)
            {
                throw new AccessException();
            }
        }
コード例 #8
0
        public void UpgradeRemoteAccess(Guid accessToken, string password)
        {
            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            if (endPoint.AccessType == AccessType.Local)
            {
                throw new ArgumentException("Access token is a local token!");
            }

            if (password != this.coreSettings.RemoteControlPassword)
            {
                throw new WrongPasswordException("Remote password is wrong");
            }

            endPoint.SetAccessPermission(AccessPermission.Admin);
        }
コード例 #9
0
        public void UpgradeLocalAccess(Guid accessToken, string password)
        {
            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            if (endPoint.AccessType == AccessType.Remote)
            {
                throw new ArgumentException("Access token is a remote token!");
            }

            if (password != this.localPassword)
            {
                throw new WrongPasswordException("Password is wrong");
            }

            endPoint.SetAccessPermission(AccessPermission.Admin);
        }
コード例 #10
0
        /// <summary>
        /// Registers a vote for the given access token and decrements the count of the remainig votes.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// There are no votes left for the given access token, or a the same entry is registered twice.
        /// </exception>
        public void RegisterVote(Guid accessToken, PlaylistEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            this.VerifyVotingPreconditions(accessToken);

            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            if (!endPoint.RegisterEntry(entry) && !entry.IsShadowVoted)
            {
                throw new InvalidOperationException("Entry already registered");
            }
        }
コード例 #11
0
        /// <summary>
        /// Registers a new remote access token which's default reights depend on the <see
        /// cref="CoreSettings.LockRemoteControl" /> setting.
        /// </summary>
        public Guid RegisterRemoteAccessToken(Guid deviceId)
        {
            this.Log().Info("Creating remote access token");

            this.endPointLock.EnterReadLock();

            AccessEndPoint endPoint = this.endPoints.FirstOrDefault(x => x.DeviceId == deviceId);

            this.endPointLock.ExitReadLock();

            if (endPoint != null)
            {
                return(endPoint.AccessToken);
            }

            return(this.RegisterToken(AccessType.Remote, this.GetDefaultRemoteAccessPermission(), deviceId));
        }
コード例 #12
0
        /// <summary>
        /// Verifies that voting is enabled and that the vote count of the given endpoint doesn't
        /// exceed the maximum vote count.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// The exception that is thrown if one of the preconditions isn't satisfied.
        /// </exception>
        public void VerifyVotingPreconditions(Guid accessToken)
        {
            if (!this.coreSettings.EnableGuestSystem)
            {
                throw new InvalidOperationException("Voting isn't enabled.");
            }

            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            if (endPoint.AccessType == AccessType.Local)
            {
                return;
            }

            if (endPoint.EntryCount == this.coreSettings.MaxVoteCount)
            {
                throw new InvalidOperationException("No votes left");
            }
        }
コード例 #13
0
        public void SetLocalPassword(Guid accessToken, string password)
        {
            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            if (endPoint.AccessType == AccessType.Remote)
            {
                throw new ArgumentException("Access token is a remote token!");
            }

            this.VerifyAccess(accessToken);

            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException("Password is invalid", "password");
            }

            this.localPassword = password;
        }
コード例 #14
0
        /// <summary>
        /// Registers a vote for the given access token and decrements the count of the remainig votes.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// There are no votes left for the given access token, or a the same entry is registered twice.
        ///
        /// -- or--
        ///
        /// The access token isn't a guest token.
        /// </exception>
        public void RegisterShadowVote(Guid accessToken, PlaylistEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            if (!entry.IsShadowVoted)
            {
                throw new ArgumentException("Entry must be shadow voted");
            }

            this.VerifyVotingPreconditions(accessToken);

            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            if (endPoint.AccessPermission.FirstAsync().Wait() != AccessPermission.Guest)
            {
                throw new InvalidOperationException("Access token has to be a guest token.");
            }

            endPoint.RegisterEntry(entry);
        }
コード例 #15
0
        public IObservable <AccessPermission> ObserveAccessPermission(Guid accessToken)
        {
            AccessEndPoint endPoint = this.VerifyAccessToken(accessToken);

            return(endPoint.AccessPermission);
        }