Example #1
0
        private static PopCommandResult AuthenticateWithAppropriateMechanism(PopSession session,
                                                                         bool allowInsecureMechanism,
                                                                         ICredentialsByHost credentials,
                                                                         string username,
                                                                         IEnumerable<string> usingSaslMechanisms)
        {
            PopCommandResult result = null;

              foreach (var mechanism in usingSaslMechanisms) {
            if (!allowInsecureMechanism && SaslClientMechanism.IsMechanismPlainText(mechanism))
              // disallow plain text mechanism
              continue;

            if (string.Equals(mechanism, SaslMechanisms.Anonymous, StringComparison.OrdinalIgnoreCase))
              // disallow 'ANONYMOUS' mechanism
              continue;

            var authMechanism = PopAuthenticationMechanism.GetKnownOrCreate(mechanism);

            if (session.ServerCapabilities.IsCapable(authMechanism)) {
              result = session.Auth(credentials, username, authMechanism);

              if (result.Succeeded)
            break;
            }
              }

              if ((result == null || result.Failed) && allowInsecureMechanism) {
            if (session.ApopAvailable)
              result = session.Apop(credentials, username);
              }

              if ((result == null || result.Failed) && allowInsecureMechanism)
            result = session.Login(credentials, username);

              return result;
        }
Example #2
0
        private static PopCommandResult AuthenticateAsAnonymous(PopSession session,
                                                            string username,
                                                            bool canFallback)
        {
            PopCommandResult result = null;

              if (string.IsNullOrEmpty(username))
            username = "******";

              if (session.ServerCapabilities.IsCapable(PopAuthenticationMechanism.Anonymous))
            // try AUTH ANONYUMOUS
            result = session.Auth(new NetworkCredential(username, string.Empty),
                              null,
                              PopAuthenticationMechanism.Anonymous);

              if (result == null || (result.Failed && canFallback))
            // try anonymous LOGIN
            result = session.Login(new NetworkCredential("anonymous", username),
                               null);

              return result;
        }