Exemplo n.º 1
0
        /// <summary>
        /// Attempts to add the given hostmask, if it doesn't already exist.
        /// </summary>
        /// 
        /// <param name="hostmask">The hostmask to add.</param>
        /// <param name="level">The level to add: either <code>ADMIN</code> or <code>PUBLIC</code>. </param>
        /// <param name="request">Our incoming <see cref="Request"/> object, which we use for creating our response.</param>
        /// 
        /// <remarks>
        /// At present we only add <see cref="HostMatchType.Start"/> type users, and if a proper level is not specified, it is assumed that the user wants
        /// a <see cref="AccessLevel.Public"/>. There is also currently no way to add a <see cref="AccessLevel.Root"/> user, which is by design.
        /// </remarks>
        private void AddUser(string hostmask, string level, Request request)
        {
            if (AuthenticationManager.KnowsHost(hostmask))
            {
                SendResponse(String.Format("The hostmask {0} already has an entry.", hostmask), request);
            }
            else
            {
                var host = new KnownHost
                {
                    AccessLevel = GetAccessLevelByName(level),
                    HostMask = hostmask,
                    HostMatchType = HostMatchType.Start,
                };

                AuthenticationManager.RememberHost(host);
                ModuleManagementContainer.HandleResponse(request.CreateResponse(ResponseType.Private, String.Format("Learned host {0}", TranslateHostToString(host))));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// A pretty-printer for a <see cref="KnownHost"/>. 
 /// </summary>
 /// 
 /// <param name="host">A <see cref="KnownHost"/> to pretty-print.</param>
 /// 
 /// <returns>A pretty-printed <see cref="KnownHost"/> entry. Oh so pretty, oh so pretty.</returns>
 /// 
 /// <remarks>
 /// This may eventually become the ToString method on <see cref="KnownHost"/>, but for now this module is the only one that cares.
 /// </remarks>
 private static string TranslateHostToString(KnownHost host)
 {
     return String.Format("[{0}: level {1}, type {2}, [metadata: {3}]]",
                          host.HostMask, host.AccessLevel, host.HostMatchType, host.MetaData.Implode(", ",
                                                                                                     x => String.Format("[{0} - {1}]", x.Tag, x.Value)));
 }
Exemplo n.º 3
0
        /// <summary>
        /// A private utility method, ensures that the user has the flags that are required to access this resource.
        /// </summary>
        /// 
        /// <param name="host">A <see cref="host"/> to check for required flags.</param>
        /// 
        /// <returns>True if the user has all the required flags, else false.</returns>
        private bool RequiredFlagsSet(KnownHost host)
        {
            // Make sure that we've even got anything to check...
            if (null != host && null != host.AccessFlags)
            {
                // Make sure that all the required flags are present on the principal.
                return _requiredFlags.All(x => host.AccessFlags.Any(y => y.Flag.Equals(x, StringComparison.CurrentCultureIgnoreCase)));
            }

            return false;
        }
Exemplo n.º 4
0
        public long CreateHostEntry(string hostMask, AccessLevel accessLevel)
        {
            var authenticationManager = GetBean<IrcAuthenticationModule>("IrcAuthenticationModule");
            var host = authenticationManager.FindHostByHostmaskMatch(hostMask);

            // TODO [Kog 04/16/2012] : This should probably throw an exception.

            // If we've seen this host before, short circuit and return the ID on file.
            if (null != host)
            {
                return host.Id;
            }

            host = new KnownHost
            {
                AccessLevel = accessLevel,
                HostMask = hostMask,
                HostMatchType = HostMatchType.Start,
            };

            // If we've never seen the host, create a new one and return that id.
            authenticationManager.RememberHost(host);
            return host.Id;
        }
Exemplo n.º 5
0
 public void Delete(KnownHost host)
 {
     HibernateTemplate.Delete(host);
 }
Exemplo n.º 6
0
 public void SaveOrUpdate(KnownHost host)
 {
     HibernateTemplate.SaveOrUpdate(host);
 }