Ejemplo n.º 1
0
 /** The factory for signature methods. */
 public static OAuthSignatureMethod newMethod(String name,
                                              OAuthAccessor accessor)
 {
     try
     {
         Type methodClass = NAME_TO_CLASS[name];
         if (methodClass != null)
         {
             OAuthSignatureMethod method = (OAuthSignatureMethod)Activator.CreateInstance(methodClass);
             method.initialize(name, accessor);
             return(method);
         }
         OAuthProblemException problem = new OAuthProblemException("signature_method_rejected");
         List <string>         todo    = new List <string>();
         foreach (var item in NAME_TO_CLASS.Keys)
         {
             todo.Add(item);
         }
         String acceptable = OAuth.percentEncode(todo);
         if (acceptable.Length > 0)
         {
             problem.setParameter("oauth_acceptable_signature_methods",
                                  acceptable);
         }
         throw problem;
     }
     catch (Exception e)
     {
         throw new OAuthException(e);
     }
 }
Ejemplo n.º 2
0
 /**
  * Check whether the message has a valid signature.
  * @throws URISyntaxException 
  *
  * @throws OAuthProblemException
  *             the signature is invalid
  */
 public void validate(OAuthMessage message)
 {
     message.requireParameters(new[] { "oauth_signature" });
     String signature = message.getSignature();
     String baseString = getBaseString(message);
     if (!isValid(signature, baseString))
     {
         OAuthProblemException problem = new OAuthProblemException(
             "signature_invalid");
         problem.setParameter("oauth_signature", signature);
         problem.setParameter("oauth_signature_base_string", baseString);
         problem.setParameter("oauth_signature_method", message
                                                            .getSignatureMethod());
         throw problem;
     }
 }
Ejemplo n.º 3
0
        /**
         * Check whether the message has a valid signature.
         * @throws URISyntaxException
         *
         * @throws OAuthProblemException
         *             the signature is invalid
         */
        public void validate(OAuthMessage message)
        {
            message.requireParameters(new[] { "oauth_signature" });
            String signature  = message.getSignature();
            String baseString = getBaseString(message);

            if (!isValid(signature, baseString))
            {
                OAuthProblemException problem = new OAuthProblemException(
                    "signature_invalid");
                problem.setParameter("oauth_signature", signature);
                problem.setParameter("oauth_signature_base_string", baseString);
                problem.setParameter("oauth_signature_method", message
                                     .getSignatureMethod());
                throw problem;
            }
        }
Ejemplo n.º 4
0
 /** The factory for signature methods. */
 public static OAuthSignatureMethod newMethod(String name,
                                              OAuthAccessor accessor)
 {
     try
     {
         Type methodClass = NAME_TO_CLASS[name];
         if (methodClass != null)
         {
             OAuthSignatureMethod method = (OAuthSignatureMethod)Activator.CreateInstance(methodClass);
             method.initialize(name, accessor);
             return method;
         }
         OAuthProblemException problem = new OAuthProblemException("signature_method_rejected");
         List<string> todo = new List<string>();
         foreach (var item in NAME_TO_CLASS.Keys)
         {
             todo.Add(item);
         }
         String acceptable = OAuth.percentEncode(todo);
         if (acceptable.Length > 0)
         {
             problem.setParameter("oauth_acceptable_signature_methods",
                                  acceptable);
         }
         throw problem;
     }
     catch (Exception e)
     {
         throw new OAuthException(e);
     }
 }