Java 正在验证已签名的请求:签名\u无效

Java 正在验证已签名的请求:签名\u无效,java,servlets,oauth,opensocial,Java,Servlets,Oauth,Opensocial,我正在尝试使用该页面上的示例Java代码验证。我想应该是这样的,但是我仍然得到一个签名错误 主要验证代码: // NOTE: req = HttpServletRequest // check for hyves if (!"hyves.nl".equals(req.getParameter("oauth_consumer_key"))) { throw new RuntimeException("Only hyves supported"); } // update hyve

我正在尝试使用该页面上的示例Java代码验证。我想应该是这样的,但是我仍然得到一个签名错误

主要验证代码:

 // NOTE: req = HttpServletRequest

 // check for hyves
 if (!"hyves.nl".equals(req.getParameter("oauth_consumer_key"))) {
  throw new RuntimeException("Only hyves supported");
 }

 // update hyves' certificate
 getHyvesCert(req.getParameter("xoauth_signature_publickey"));

 // construct message object
 OAuthMessage oaMessage = new OAuthMessage(req.getMethod(), getRequestUrl(req), getParameters(req));

 // validate message
 // (will throw exception if invalid)
 new SimpleOAuthValidator().validateMessage(oaMessage, new OAuthAccessor(OAUTH_CONSUMER_HYVES));
OAUTH\u CONSUMER\u HYVES

 private static final OAuthServiceProvider OAUTH_THIS = new OAuthServiceProvider(null, null, null);
 private static final OAuthConsumer OAUTH_CONSUMER_HYVES = new OAuthConsumer(null, "hyves.nl", null, OAUTH_THIS);
getHyvesCert

 public void getHyvesCert(String name) {

  synchronized(certLoadLock) {

  // in reality this is code that downloads the certificate
  // with the specified name, but this is the result
  hyvesCert = "---BEGIN CERTIFICATE---- etc...";

  OAUTH_CONSUMER_HYVES.setProperty(RSA_SHA1.X509_CERTIFICATE, hyvesCert);

  }   

 }

方法
getRequestUrl
getParameters
是。

我发现了问题
getRequestUrl()
返回了错误的URL,因为Tomcat位于nginx代理之后。因此,虽然发件人会使用URL“http://example.com/bla要签署请求,服务器正在使用http://example.com:8080/bla“验证它。

与问题无关,您是否意识到将
OAuthServiceProvider
OAuthConsumer
声明为servlet常量意味着它们将在所有请求之间共享?换句话说:这绝对不是线程安全的。您希望根据每个请求创建它们,正如示例中所示。初始化完成后,它们不是只读对象吗?在请求之间对它们的唯一更改可能是证书的更新(实际上大约每年更新一次),并且执行该操作的代码是同步的。