求restEasy oauth signature_invalid解决方案

问题描述

求restEasyoauth报错。WEB.xml<?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID"version="3.0"><display-name>WebApplication</display-name><!--RESTEasy监听器--><listener><listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class></listener><!--整合Spring--><listener><listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext-*.xml</param-value></context-param><!--Spring懒加载--><filter><filter-name>OpenSessionInViewFilter</filter-name><filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping><filter-name>OpenSessionInViewFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!--OAuth认证--><servlet><servlet-name>OAuth</servlet-name><servlet-class>org.jboss.resteasy.auth.oauth.OAuthServlet</servlet-class></servlet><servlet-mapping><servlet-name>OAuth</servlet-name><url-pattern>/oauth/*</url-pattern></servlet-mapping><!--OAuth过滤器TheOAuthFilterhandlesauthenticationforprotectedresources--><filter><filter-name>OAuthFilter</filter-name><filter-class>org.jboss.resteasy.auth.oauth.OAuthFilter</filter-class></filter><filter-mapping><filter-name>OAuthFilter</filter-name><url-pattern>/api/*</url-pattern></filter-mapping><context-param><param-name>oauth.provider.provider-class</param-name><param-value>com.iovereye.webservice.oauth.OAuthDBProvider</param-value></context-param><!--增加URI访问前缀--><context-param><param-name>resteasy.servlet.mapping.prefix</param-name><param-value>/api</param-value></context-param><!--restEasy过滤规则--><servlet><servlet-name>Resteasy</servlet-name><servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class></servlet><servlet-mapping><servlet-name>Resteasy</servlet-name><url-pattern>/api/*</url-pattern></servlet-mapping></web-app>

解决方案

解决方案二:
OAuthDBPrivider.java[code=java]packagecom.iovereye.webservice.oauth;importjava.net.HttpURLConnection;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjava.util.Date;importjava.util.Properties;importjava.util.Set;importjava.util.UUID;importorg.jboss.resteasy.auth.oauth.OAuthConsumer;importorg.jboss.resteasy.auth.oauth.OAuthException;importorg.jboss.resteasy.auth.oauth.OAuthProvider;importorg.jboss.resteasy.auth.oauth.OAuthRequestToken;importorg.jboss.resteasy.auth.oauth.OAuthToken;importcom.iovereye.webservice.util.Logs;publicclassOAuthDBProviderimplementsOAuthProvider{privatestaticfinalStringDEFAULT_CONSUMER_ROLE="user";privatestaticConnectionconn;publicOAuthDBProvider(){initConnection();}privatestaticsynchronizedvoidinitConnection(){if(conn!=null){return;}Propertiesprops=newProperties();try{props.load(OAuthDBProvider.class.getResourceAsStream("/jdbc.properties"));}catch(Exceptionex){thrownewRuntimeException("db.propertiesresourceisnotavailable");}Stringdriver=props.getProperty("jdbc.driverClassName");Stringurl=props.getProperty("jdbc.url");Stringuser=props.getProperty("jdbc.username");Stringpassword=props.getProperty("jdbc.password");initConnection(driver,url,user,password);}privatestaticvoidinitConnection(Stringdriver,Stringurl,Stringuser,Stringpassword){try{Class.forName(driver);conn=DriverManager.getConnection(url,user,password);}catch(Exceptionex){thrownewRuntimeException("InmemoryOAuthDBcannotbecreated"+ex.getMessage());}//try{//////consumers//update("CREATETABLEconsumers(idINTEGERAUTO_INCREMENTPRIMARYKEY,c_keyVARCHAR(150)"//+",secretVARCHAR(256),display_nameVARCHAR(256),connect_uriVARCHAR(256),"//+"scopesVARCHAR(256),permissionsVARCHAR(256),unique(c_key))");//////requesttokens//update("CREATETABLErequest_tokens(idINTEGERAUTO_INCREMENTPRIMARYKEY,consumer_keyVARCHAR(150)"//+",tokenVARCHAR(256),secretVARCHAR(256),callbackVARCHAR(256),scopesVARCHAR(256)"//+",permissionsVARCHAR(256),verifierVARCHAR(256),foreignkey(consumer_key)referencesconsumers(c_key))");//////accesstokens//update("CREATETABLEaccess_tokens(idINTEGERAUTO_INCREMENTPRIMARYKEY,consumer_keyVARCHAR(150)"//+",tokenVARCHAR(256),secretVARCHAR(256),scopesVARCHAR(256),"//+"permissionsVARCHAR(256),foreignkey(consumer_key)referencesconsumers(c_key))");//////custompermissionstorolesmap//update("CREATETABLEpermissions(idINTEGERAUTO_INCREMENTPRIMARYKEY,permissionVARCHAR(256)"//+",roleVARCHAR(256))");//////addpermissionstovaluesmap//registerCustomPermissionsAndRoles();////}catch(SQLExceptionex){////thrownewRuntimeException("OAuthDBtablescannotbecreated:"//+ex.getMessage());////}}privatestaticsynchronizedvoidupdate(Stringexpression)throwsSQLException{Statementst=conn.createStatement();//statementsinti=st.executeUpdate(expression);//runthequeryif(i==-1){System.out.println("dberror:"+expression);}st.close();}privatestaticvoidregisterCustomPermissionsAndRoles(){try{//for3-legOAuthdemosinvolvingtheenduseranda3rdparty//printerserviceupdate("INSERTINTOpermissions(permission,role)"+"VALUES('"+"printResources"+"','"+"PrinterService"+"'"+")");//forOAuthpushmessagingdemosupdate("INSERTINTOpermissions(permission,role)"+"VALUES('"+"sendMessages"+"','"+"MessagingService"+"'"+")");}catch(SQLExceptionex){thrownewRuntimeException("Permissionscannotbemappedtoroles");}}/***注册应用*/publicOAuthConsumerregisterConsumer(StringconsumerKey,StringdisplayName,StringconnectURI)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classregisterConsumer...");Stringsecret=makeRandomString();try{update("INSERTINTOconsumers(c_key,secret,display_name,connect_uri)"+"VALUES('"+consumerKey+"','"+secret+"'"+","+(displayName==null?null:"'"+displayName+"'")+","+(connectURI==null?null:"'"+connectURI+"'")+")");}catch(SQLExceptionex){thrownewOAuthException(HttpURLConnection.HTTP_UNAUTHORIZED,"Consumerwithkey"+consumerKey+"cannotbecreated");}returnnewOAuthConsumer(consumerKey,secret,displayName,connectURI);}privatestaticStringmakeRandomString(){returnUUID.randomUUID().toString();}/***注册应用范围*/publicvoidregisterConsumerScopes(StringconsumerKey,String[]scopes)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classregisterConsumerScopes...");}/***注册应用认可*/publicvoidregisterConsumerPermissions(StringconsumerKey,String[]permissions)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classregisterConsumerPermissions...");}/***获取范围*/publicStringgetRealm(){Logs.getLogger().debug("OAuthDBProvider.classgetRealm...");return"default";}/***获取应用信息*/publicOAuthConsumergetConsumer(StringconsumerKey)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classgetConsumer...");Logs.getLogger().debug("time:"+newDate().getTime());try{Statementst=conn.createStatement();ResultSetrs=st.executeQuery("SELECT*FROMconsumersWHEREc_key='"+consumerKey+"'");if(rs.next()){Stringkey=rs.getString("c_key");Stringsecret=rs.getString("secret");StringdisplayName=rs.getString("display_name");StringconnectURI=rs.getString("connect_uri");Stringscopes=rs.getString("scopes");Stringperms=rs.getString("permissions");OAuthConsumerconsumer=newOAuthConsumer(key,secret,displayName,connectURI,perms!=null?newString[]{perms}:null);consumer.setScopes(newString[]{scopes});returnconsumer;}else{thrownewOAuthException(HttpURLConnection.HTTP_UNAUTHORIZED,"Nosuchconsumerkey"+consumerKey);}}catch(SQLExceptionex){thrownewOAuthException(HttpURLConnection.HTTP_UNAUTHORIZED,"Nosuchconsumerkey"+consumerKey);}}/***获取用户Token*/publicOAuthRequestTokengetRequestToken(StringconsumerKey,StringrequestToken)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classgetRequestToken...");returnnull;}/***获取用户accessToken*/publicOAuthTokengetAccessToken(StringconsumerKey,StringaccessToken)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classgetAccessToken...");returnnull;}/***生成请求Token*/publicOAuthTokenmakeRequestToken(StringconsumerKey,Stringcallback,String[]scopes,String[]permissions)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classmakeRequestToken...");returnnull;}/***生成AccessToken*/publicOAuthTokenmakeAccessToken(StringconsumerKey,StringrequestToken,Stringverifier)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classmakeAccessToken...");returnnull;}/***授权请求Token*/publicStringauthoriseRequestToken(StringconsumerKey,StringrequestToken)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classauthoriseRequestToken...");returnnull;}/***检查时间戳*/publicvoidcheckTimestamp(OAuthTokentoken,longtimestamp)throwsOAuthException{Logs.getLogger().debug("OAuthDBProvider.classcheckTimestamp...");}/***转换角色的权限*/publicSet<String>convertPermissionsToRoles(String[]permissions){Logs.getLogger().debug("OAuthDBProvider.classconvertPermissionsToRoles...");returnnull;}}
解决方案三:
[/code]数据库:/*NavicatMySQLDataTransferSourceServer:localhostSourceServerVersion:50161SourceHost:localhost:3306SourceDatabase:iovereye_testTargetServerType:MYSQLTargetServerVersion:50161FileEncoding:65001Date:2014-04-1418:31:19*/SETFOREIGN_KEY_CHECKS=0;--------------------------------Tablestructurefor`access_tokens`------------------------------DROPTABLEIFEXISTS`access_tokens`;CREATETABLE`access_tokens`(`id`int(11)NOTNULLAUTO_INCREMENT,`consumer_key`varchar(150)DEFAULTNULL,`token`varchar(256)DEFAULTNULL,`secret`varchar(256)DEFAULTNULL,`scopes`varchar(256)DEFAULTNULL,`permissions`varchar(256)DEFAULTNULL,PRIMARYKEY(`id`),KEY`consumer_key`(`consumer_key`),CONSTRAINT`access_tokens_ibfk_1`FOREIGNKEY(`consumer_key`)REFERENCES`consumers`(`c_key`))ENGINE=InnoDBDEFAULTCHARSET=utf8;--------------------------------Recordsofaccess_tokens--------------------------------------------------------------Tablestructurefor`consumers`------------------------------DROPTABLEIFEXISTS`consumers`;CREATETABLE`consumers`(`id`int(11)NOTNULLAUTO_INCREMENT,`c_key`varchar(150)DEFAULTNULL,`secret`varchar(256)DEFAULTNULL,`display_name`varchar(256)DEFAULTNULL,`connect_uri`varchar(256)DEFAULTNULL,`scopes`varchar(256)DEFAULTNULL,`permissions`varchar(256)DEFAULTNULL,PRIMARYKEY(`id`),UNIQUEKEY`c_key`(`c_key`))ENGINE=InnoDBAUTO_INCREMENT=4DEFAULTCHARSET=utf8;--------------------------------Recordsofconsumers------------------------------INSERTINTO`consumers`VALUES('1','110','4c088c17-6461-40a3-ab77-6aa4dde1d0dc','JieMo','http://localhost:8080/iovereye-test-restEasy/',null,null);INSERTINTO`consumers`VALUES('3','jiemo','91b17bf9-b9e3-479d-9450-2099e624c93d','JieMo','http://localhost:8080/iovereye-test-restEasy/',null,null);--------------------------------Tablestructurefor`ie_install`------------------------------DROPTABLEIFEXISTS`ie_install`;CREATETABLE`ie_install`(`id`bigint(20)NOTNULLAUTO_INCREMENT,`name`varchar(255)DEFAULTNULL,`description`varchar(255)DEFAULTNULL,PRIMARYKEY(`id`))ENGINE=InnoDBDEFAULTCHARSET=utf8;--------------------------------Recordsofie_install--------------------------------------------------------------Tablestructurefor`permissions`------------------------------DROPTABLEIFEXISTS`permissions`;CREATETABLE`permissions`(`id`int(11)NOTNULLAUTO_INCREMENT,`permission`varchar(256)DEFAULTNULL,`role`varchar(256)DEFAULTNULL,PRIMARYKEY(`id`))ENGINE=InnoDBDEFAULTCHARSET=utf8;--------------------------------Recordsofpermissions--------------------------------------------------------------Tablestructurefor`request_tokens`------------------------------DROPTABLEIFEXISTS`request_tokens`;CREATETABLE`request_tokens`(`id`int(11)NOTNULLAUTO_INCREMENT,`consumer_key`varchar(150)DEFAULTNULL,`token`varchar(256)DEFAULTNULL,`secret`varchar(256)DEFAULTNULL,`callback`varchar(256)DEFAULTNULL,`scopes`varchar(256)DEFAULTNULL,`permissions`varchar(256)DEFAULTNULL,`verifier`varchar(256)DEFAULTNULL,PRIMARYKEY(`id`),KEY`consumer_key`(`consumer_key`),CONSTRAINT`request_tokens_ibfk_1`FOREIGNKEY(`consumer_key`)REFERENCES`consumers`(`c_key`))ENGINE=InnoDBDEFAULTCHARSET=utf8;--------------------------------Recordsofrequest_tokens------------------------------

创建consumershttp://localhost:8080/iovereye-test-restEasy/oauth/consumer/registration?oauth_consumer_key=jiemo&xoauth_consumer_display_name=JieMo&xoauth_consumer_connect_uri=http://localhost:8080/iovereye-test-restEasy/requestTokenhttp://localhost:8080/iovereye-test-restEasy/oauth/requestToken?oauth_consumer_key=110&oauth_signature=4c088c17-6461-40a3-ab77-6aa4dde1d0dc&oauth_timestamp=1325632323&oauth_nonce=123&oauth_signature_method=HMAC-SHA1&oauth_callback=localho==============================请求失败返回状态码:401错误输出:signature_invalid==============================求解,请多多指教
解决方案四:
不好意思,晚上加班,解决了,是因为没有加密请求参数。
解决方案五:
我看你,学了不会少,可以留个联系方式吗?
解决方案六:
大侠能把那个加密参数补上吗?

时间: 2024-10-28 02:01:14

求restEasy oauth signature_invalid解决方案的相关文章

pringmvc-求教,SpringMVC整合hessian,客户端找不到服务端的接口类!求配置代码活解决方案!谢谢!

问题描述 求教,SpringMVC整合hessian,客户端找不到服务端的接口类!求配置代码活解决方案!谢谢! 求教,SpringMVC整合hessian,客户端找不到服务端的接口类!求配置代码活解决方案!谢谢!

asp.net把框架转换成4.5.2上传到国外服务器一直报错,求一个详细的解决方案

问题描述 asp.net把框架转换成4.5.2上传到国外服务器一直报错,求一个详细的解决方案 帮一个国外客户做的网站,上传到服务器后提示版本不对,特意去下载了4.5.2,转换后把webconfig的一些配置改好,覆盖,可以还是一直显示不了网站,希望能有好心人帮助下

sqlserver-两张无关联表 根据时间这么累计金额?求SQL语句或解决方案

问题描述 两张无关联表 根据时间这么累计金额?求SQL语句或解决方案 表A id datetime pay(收入表) 表B id Bdatetime pay(支出表) A: 1 2012-08-19 22.00 2 2012-09-23 32.00 3 2012-09-30 33.00 B: 1 2012-08-20 -11.00 2 2012-09-24 -20.00 输出: C:(id Cdatetime pay paycount) 1 2012-08-19 22.00 22.00 2 20

java.lang.IllegalArgumentException 异常,求大牛说下解决方案

问题描述 java.lang.IllegalArgumentException 异常,求大牛说下解决方案 解决方案 java.lang.IllegalArgumentException的解决方案java.lang.IllegalArgumentException:(读取配置文件异常) 解决方案二: 这是用了spring框架吧,报是非法的参数错误,你看一下配置文件中是否有不存在的类,或者其它地方有不存在的一些类或者其它的内容.还有同样问题的参考:http://bbs.csdn.net/topics

求个正则表达式或者解决方案

问题描述 <objectclassid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6"id=WindowsMediaPlayer1width=1height=1><paramname=URLvalue="C:cs.mp3"><paramname=ratevalue=1><paramname=balancevalue=0><paramname=currentPosition

跪求 C#传输文件解决方案(很有挑战性...)

问题描述 要从客户端传送压缩文件到指定服务器,客户端能提供的是该压缩文件的url,(不一定要点手动点上传按钮,所以fileupload控件好像不好用),还有就是量的问题,既要考虑传输速度,而且还是大量上传的,(我们的客户端有几千万的用户),谢谢,最好能提供个例子,只要回答有参考价值都给分,不够我再加,再次感谢大家 解决方案 解决方案二:那就只能在服务器端用WebClient类去下载文件吧解决方案三:HTTP或者TCP/IP吧,FTP安全性还是个问题,Webservice,Socket,remot

求一个网站整体解决方案

问题描述 我原来用过一些网站管理系统,论坛系统,但是,论坛和网站各是各的用户,管理起来挺麻烦,我想请人做整合,本地没人会.我又去网上找,结果收费挺高的,用什么办法可以比较便宜的把这个作好呢? 解决方案 解决方案二:两个都独立,分开管理又何妨,还是蛮方便的解决方案三:<P>我用过许多网站建设的系统,以我自己的经历来说,我推荐用网站快车,这个系统的安全性还还是功能都不错.</P>解决方案四:数据库合并一下,不是很难解决方案五:不难,但是麻烦--

求单机版软件过期解决方案

问题描述 开发了一个软件,是单机版的,如何在用户使用过程中判断产品过期?我自己的想法不够完美,不说以免扰乱视听,征询大家的方案!3个基本要求:1.产品过期后,用户修改了系统时间也没用:2.产品过期后,用户重装本软件也没用,包括拷贝一些组件或者文件等等:3.产品过期后,用户自己修改注册表之类的也没用: 解决方案 解决方案二:不联网,无解.------个人想法.解决方案三:几乎是不可能的!解决方案四:安装时获取客户机的唯一标识在软件内部实现计时判定在注册表中写相应的唯一安装标识从而避免从复安装使用个

高分求图片的一个解决方案

问题描述 目前的功能是一个图片会被一个表格罩着,而这个表格是由24个等分开的小单元格就类似网格线在图片上,而每个格里面会有一个类似radiobutton样的控件在里面,24格只允许选择其中一个radiobutton,然后保存所选择的那个radio上绑定的值.这样一个功能有人能给个思路吗非常感谢也祝愿大家端午节快乐. 解决方案 解决方案二:设置图片为表格的背景图片,不会被罩着!解决方案三:1.把table的背景设为那个图片,或者用div,把图片的zorder设0,表格的设为12.radiobutt