Exemplo n.º 1
0
        /// <summary>
        /// The authorize.
        /// </summary>
        /// <param name="payload">
        /// The payload.
        /// </param>
        /// <param name="roles">
        /// The roles.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        internal static bool Authorize(AuthPayload payload, string[] roles)
        {
            if (payload != null)
            {
                CustomIdentity    identity         = payload.CustomIdentity;
                ISecurityProvider securityProvider = authorizers[identity.SecurityProviderName];
                bool isAuthorized = securityProvider.IsAuthorized(payload, roles);

                if (isAuthorized)
                {
                    string userName     = identity.Name;
                    string providerName = identity.SecurityProviderName;

                    Thread.CurrentPrincipal =
                        new CustomPrincipal(identity, roles);

                    Log.Verbose("User Id {0} is authorized", identity.UserId);

                    return(true);
                }
                else
                {
                    Log.Verbose("Anauthorized user");
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }