Exemple #1
0
 /// <exception cref="Javax.Security.Sasl.SaslException"/>
 public virtual byte[] EvaluateResponse(byte[] response)
 {
     if (completed)
     {
         throw new InvalidOperationException("PLAIN authentication has completed");
     }
     if (response == null)
     {
         throw new ArgumentException("Received null response");
     }
     try
     {
         string payload;
         try
         {
             payload = Runtime.GetStringForBytes(response, "UTF-8");
         }
         catch (Exception e)
         {
             throw new ArgumentException("Received corrupt response", e);
         }
         // [ authz, authn, password ]
         string[] parts = payload.Split("\u0000", 3);
         if (parts.Length != 3)
         {
             throw new ArgumentException("Received corrupt response");
         }
         if (parts[0].IsEmpty())
         {
             // authz = authn
             parts[0] = parts[1];
         }
         NameCallback nc = new NameCallback("SASL PLAIN");
         nc.SetName(parts[1]);
         PasswordCallback pc = new PasswordCallback("SASL PLAIN", false);
         pc.SetPassword(parts[2].ToCharArray());
         AuthorizeCallback ac = new AuthorizeCallback(parts[1], parts[0]);
         cbh.Handle(new Javax.Security.Auth.Callback.Callback[] { nc, pc, ac });
         if (ac.IsAuthorized())
         {
             authz = ac.GetAuthorizedID();
         }
     }
     catch (Exception e)
     {
         throw new SaslException("PLAIN auth failed: " + e.Message);
     }
     finally
     {
         completed = true;
     }
     return(null);
 }
Exemple #2
0
        private ResponseTextMessage Build(Update update)
        {
            if (UpdateType.Message.CompareTo(update.Type) == 0)
            {
                return(CommandHandler.Handle(context, update.Message));
            }

            if (update.Type == UpdateType.CallbackQuery)
            {
                return(CallbackHandler.Handle(context, update.CallbackQuery));
            }

            return(null);
        }