Permalink
Browse files

v0.1 of SDK

  • Loading branch information...
0 parents commit cb094c96b99ca2bdc174fe63307deda4e25ec8a8 @sh1mmer sh1mmer committed Apr 30, 2010
786 LICENSE.txt
@@ -0,0 +1,786 @@
+Social API SDK for Java
+
+Software License Agreement (BSD License)
+Copyright (c) 2010, Yahoo! Inc.
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms, with
+or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of Yahoo! Inc. nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of Yahoo! Inc.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+This code also depends on software from the following sources:
+
+This code also depends on software packages from other 3rd party sources. These
+3rd party software packages are not distributed as part of this project, but
+instead are separately downloaded from, and licensed to you by, the respective
+provider, and used as development tools in their unmodified form.
+
+
+
+JSON in Java Version 20080701
+JSON.org - http://json.org/java/
+
+The JSON License
+Copyright (c) 2002 JSON.org
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+The Software shall be used for Good, not Evil.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+****************************************************************************************
+
+SLF4J 1.5.6 - http://www.slf4j.org/download.html
+
+Copyright (c) 2004-2008 QOS.ch All rights reserved. Permission is hereby
+granted, free of charge, to any person obtaining a copy of this software and
+associated documentation files (the "Software"), to deal in the Software
+without restriction, including without limitation the rights to use, copy,
+modify, merge, publish, distribute, sublicense, and/or sell copies of the
+Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions: The above copyright notice and this
+permission notice shall be included in all copies or substantial portions of
+the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
+EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
+OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+****************************************************************************************
+
+Mockito 1.7 - http://mockito.org/
+Szczepan Faber and friends
+
+The MIT License
+
+Copyright (c) <year> <copyright holders>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+
+****************************************************************************************
+
+Commons Codec Version 1.3 - http://commons.apache.org/codec/
+Commons Logging Version 1.0.4 - http://commons.apache.org/logging/
+Commons Httpclient 3.1 - http://hc.apache.org/
+Commons Httpclient 4.0-beta2 - http://hc.apache.org/
+Commons Httpcore 4.0-beta3 - http://hc.apache.org/
+log4j 1.2.14 - http://logging.apache.org/
+The Apache Software Foundation
+
+Java OAuth Library (from http://code.google.com/p/oauth)
+John Kristian, Praveen Alavilli and Dirk Balfanz
+
+TestNG 5.8 - http://testng.org
+Cédric Beust
+
+Apache 2.0 License
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+****************************************************************************************
+
+Java Servlet Technology - http://java.sun.com
+
+Sun Microsystems, Inc. Binary Code License
+Agreement
+
+READ THE TERMS OF THIS AGREEMENT AND ANY PROVIDED
+SUPPLEMENTAL LICENSE TERMS (COLLECTIVELY
+"AGREEMENT") CAREFULLY BEFORE OPENING THE
+SOFTWARE MEDIA PACKAGE. BY OPENING THE SOFTWARE
+MEDIA PACKAGE, YOU AGREE TO THE TERMS OF THIS
+AGREEMENT.
+ IF YOU ARE ACCESSING THE SOFTWARE
+ ELECTRONICALLY, INDICATE YOUR ACCEPTANCE OF
+THESE TERMS BY SELECTING THE "ACCEPT" BUTTON AT
+THE END OF THIS AGREEMENT. IF YOU DO NOT AGREE
+TO ALL THESE TERMS, PROMPTLY RETURN THE UNUSED
+SOFTWARE TO YOUR PLACE OF PURCHASE FOR A REFUND
+OR, IF THE SOFTWARE IS ACCESSED ELECTRONICALLY,
+SELECT THE "DECLINE" BUTTON AT THE END OF THIS
+AGREEMENT.
+
+1. LICENSE TO USE. Sun grants you a
+non-exclusive and non-transferable license for
+the internal use only of the accompanying
+software and documentation and any error
+corrections provided by Sun (collectively
+"Software"), by the number of users and the class
+of computer hardware for which the corresponding
+fee has been paid.
+
+2. RESTRICTIONS Software is confidential and
+copyrighted. Title to Software and all associated
+intellectual property rights is retained by Sun
+and/or its licensors. Except as specifically
+authorized in any Supplemental License Terms, you
+may not make copies of Software, other than a
+single copy of Software for archival purposes.
+Unless enforcement is prohibited by applicable
+law, you may not modify, decompile, or reverse
+engineer Software. Software is not designed or
+licensed for use in on-line control of aircraft,
+air traffic, aircraft navigation or aircraft
+communications; or in the design, construction,
+operation or maintenance of any nuclear
+facility. No right, title or interest in or to
+any trademark, service mark, logo or trade name
+of Sun or its licensors is granted under this
+Agreement.
+
+3. LIMITED WARRANTY. Sun warrants to you that
+for a period of ninety (90) days from the date of
+purchase, as evidenced by a copy of the receipt,
+the media on which Software is furnished (if any)
+will be free of defects in materials and
+workmanship under normal use. Except for the
+foregoing, Software is provided "AS IS". Your
+exclusive remedy and Sun's entire liability under
+this limited warranty will be at Sun's option to
+replace Software media or refund the fee paid for
+Software.
+
+4. DISCLAIMER OF WARRANTY. UNLESS SPECIFIED IN
+THIS AGREEMENT, ALL EXPRESS OR IMPLIED
+CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+INCLUDING ANY IMPLIED WARRANTY OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
+OR NON-INFRINGEMENT ARE DISCLAIMED, EXCEPT TO THE
+EXTENT THAT THESE DISCLAIMERS ARE HELD TO BE
+LEGALLY INVALID.
+
+5. LIMITATION OF LIABILITY. TO THE EXTENT NOT
+PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS
+LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL,
+INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED
+REGARDLESS OF THE THEORY OF LIABILITY, ARISING
+OUT OF OR RELATED TO THE USE OF OR INABILITY TO
+USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES. In no event will
+Sun's liability to you, whether in contract, tort
+(including negligence), or otherwise, exceed the
+amount paid by you for Software under this
+Agreement. The foregoing limitations will apply
+even if the above stated warranty fails of its
+essential purpose.
+
+6. Termination. This Agreement is effective
+until terminated. You may terminate this
+Agreement at any time by destroying all copies of
+Software. This Agreement will terminate
+immediately without notice from Sun if you fail
+to comply with any provision of this Agreement.
+Upon Termination, you must destroy all copies of
+Software.
+
+7. Export Regulations. All Software and
+technical data delivered under this Agreement are
+subject to US export control laws and may be
+subject to export or import regulations in other
+countries. You agree to comply strictly with all
+such laws and regulations and acknowledge that
+you have the responsibility to obtain such
+licenses to export, re-export, or import as may
+be required after delivery to you.
+
+8. U.S. Government Restricted Rights. If
+Software is being acquired by or on behalf of the
+U.S. Government or by a U.S. Government prime
+contractor or subcontractor (at any tier), then
+the Government's rights in Software and
+accompanying documentation will be only as set
+forth in this Agreement; this is in accordance
+with 48 CFR 227.7201 through 227.7202-4 (for
+Department of Defense (DOD) acquisitions) and
+with 48 CFR 2.101 and 12.212 (for non-DOD
+acquisitions).
+
+9. Governing Law. Any action related to this
+Agreement will be governed by California law and
+controlling U.S. federal law. No choice of law
+rules of any jurisdiction will apply.
+
+10. Severability. If any provision of this
+Agreement is held to be unenforceable, this
+Agreement will remain in effect with the
+provision omitted, unless omission would
+frustrate the intent of the parties, in which
+case this Agreement will immediately terminate.
+
+11. Integration. This Agreement is the entire
+agreement between you and Sun relating to its
+subject matter. It supersedes all prior or
+contemporaneous oral or written communications,
+proposals, representations and warranties and
+prevails over any conflicting or additional terms
+of any quote, order, acknowledgment, or other
+communication between the parties relating to its
+subject matter during the term of this
+Agreement. No modification of this Agreement
+will be binding, unless in writing and signed by
+an authorized representative of each party.
+
+For inquiries please contact: Sun Microsystems,
+Inc. 901 San Antonio Road, Palo Alto, California
+94303
+
+PROGRAM DEVELOPMENT AND SERVLET JAR FILE
+DISTRIBUTION SUPPLEMENTAL LICENSE TERMS
+
+These supplemental license terms ("Supplement")
+add to or modify the terms of the Binary Code
+License Agreement (collectively, the
+"Agreement"). Capitalized terms not defined in
+this Supplement shall have the same meanings
+ascribed to them in the Agreement. These
+Supplement terms shall supersede any inconsistent
+or conflicting terms in the Agreement, or in any
+license contained within the Software.
+
+1. License to Develop.
+
+ Sun grants you a non-exclusive,
+ non-transferable, royalty-free limited
+ license to use the Software for the
+ development of Java TM compatible servlets
+ (the "Programs") and reproduce and distribute
+ the Programs to third party end users
+ provided that you: (i) do not redistribute
+ the Software in whole or in part, either
+ separately or included in any Program except
+ as authorized for the Servlet JAR Files as
+ specified in Section 2 below, and (ii) agree
+ to indemnify, hold harmless, and defend Sun
+ and its licensors from and against any claims
+ or lawsuits, including attorney's fees, that
+ arise or result from the use or distribution
+ of any and all Programs.
+
+2. License to Distribute.
+
+ Sun grants you a non-exclusive,
+ non-transferable, royalty-free limited
+ license to reproduce and distribute the
+ servlet classes contained in the Software in
+ the archive files "servlet.jar" and
+ "server.jar" ("Servlet JAR Files") to third
+ party end users solely as a component of your
+ Programs provided that you: (i) distribute
+ the Servlet JAR Files complete and unmodified
+ in their original Java Archive file; (ii) do
+ not distribute additional software intended
+ to replace any component(s) of the Servlet
+ JAR Files; (iii) do not remove or alter any
+ proprietary legends or notices contained in
+ or on the Software; (iv) only distribute the
+ Servlet JAR Files pursuant to a license
+ agreement that protects Sun's interests
+ consistent with the terms contained in the
+ Agreement; (v) agree to incorporate the most
+ current version of the Servlet JAR Files that
+ was available from Sun no later than 180 days
+ prior to each production release of your
+ Program; and (vi) agree to indemnify, hold
+ harmless, and defend Sun and its licensors
+ from and against any claims or lawsuits,
+ including attorney's fees, that arise or
+ result from the use or distribution of any
+ and all Programs.
+
+3. Trademarks and Logos.
+
+ You acknowledge as between you and Sun that
+ Sun owns the Java trademark and all
+ Java-related trademarks, logos and icons
+ including the Coffee Cup and Duke ("Java
+ Marks") and agree to comply with the Java
+ Trademark Guidelines at
+ http://java.sun.com/trademarks.html.
+
+
+
+JUnit 3.8.1 (http://www.junit.org/.)
+
+
+Common Public License - v 1.0
+
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON PUBLIC
+LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
+CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+1. DEFINITIONS
+
+"Contribution" means:
+
+ a) in the case of the initial Contributor, the initial code and
+documentation distributed under this Agreement, and
+ b) in the case of each subsequent Contributor:
+
+ i) changes to the Program, and
+
+ ii) additions to the Program;
+
+ where such changes and/or additions to the Program originate from and
+are distributed by that particular Contributor. A Contribution 'originates'
+from a Contributor if it was added to the Program by such Contributor itself
+or anyone acting on such Contributor's behalf. Contributions do not include
+additions to the Program which: (i) are separate modules of software
+distributed in conjunction with the Program under their own license agreement,
+and (ii) are not derivative works of the Program.
+
+"Contributor" means any person or entity that distributes the Program.
+
+"Licensed Patents " mean patent claims licensable by a Contributor which are
+necessarily infringed by the use or sale of its Contribution alone or when
+combined with the Program.
+
+"Program" means the Contributions distributed in accordance with this
+Agreement.
+
+"Recipient" means anyone who receives the Program under this Agreement,
+including all Contributors.
+
+2. GRANT OF RIGHTS
+
+ a) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free copyright license to
+reproduce, prepare derivative works of, publicly display, publicly perform,
+distribute and sublicense the Contribution of such Contributor, if any, and
+such derivative works, in source code and object code form.
+
+ b) Subject to the terms of this Agreement, each Contributor hereby
+grants Recipient a non-exclusive, worldwide, royalty-free patent license under
+Licensed Patents to make, use, sell, offer to sell, import and otherwise
+transfer the Contribution of such Contributor, if any, in source code and
+object code form. This patent license shall apply to the combination of the
+Contribution and the Program if, at the time the Contribution is added by the
+Contributor, such addition of the Contribution causes such combination to be
+covered by the Licensed Patents. The patent license shall not apply to any
+other combinations which include the Contribution. No hardware per se is
+licensed hereunder.
+
+ c) Recipient understands that although each Contributor grants the
+licenses to its Contributions set forth herein, no assurances are provided by
+any Contributor that the Program does not infringe the patent or other
+intellectual property rights of any other entity. Each Contributor disclaims
+any liability to Recipient for claims brought by any other entity based on
+infringement of intellectual property rights or otherwise. As a condition to
+exercising the rights and licenses granted hereunder, each Recipient hereby
+assumes sole responsibility to secure any other intellectual property rights
+needed, if any. For example, if a third party patent license is required to
+allow Recipient to distribute the Program, it is Recipient's responsibility to
+acquire that license before distributing the Program.
+
+ d) Each Contributor represents that to its knowledge it has sufficient
+copyright rights in its Contribution, if any, to grant the copyright license
+set forth in this Agreement.
+
+3. REQUIREMENTS
+
+A Contributor may choose to distribute the Program in object code form under
+its own license agreement, provided that:
+
+ a) it complies with the terms and conditions of this Agreement; and
+
+ b) its license agreement:
+
+ i) effectively disclaims on behalf of all Contributors all warranties
+and conditions, express and implied, including warranties or conditions of
+title and non-infringement, and implied warranties or conditions of
+merchantability and fitness for a particular purpose;
+
+ ii) effectively excludes on behalf of all Contributors all liability for
+damages, including direct, indirect, special, incidental and consequential
+damages, such as lost profits;
+
+ iii) states that any provisions which differ from this Agreement are
+offered by that Contributor alone and not by any other party; and
+
+ iv) states that source code for the Program is available from such
+Contributor, and informs licensees how to obtain it in a reasonable manner on
+or through a medium customarily used for software exchange.
+
+When the Program is made available in source code form:
+
+ a) it must be made available under this Agreement; and
+
+ b) a copy of this Agreement must be included with each copy of the
+Program.
+
+Contributors may not remove or alter any copyright notices contained within
+the Program.
+
+Each Contributor must identify itself as the originator of its Contribution,
+if any, in a manner that reasonably allows subsequent Recipients to identify
+the originator of the Contribution.
+
+4. COMMERCIAL DISTRIBUTION
+
+Commercial distributors of software may accept certain responsibilities with
+respect to end users, business partners and the like. While this license is
+intended to facilitate the commercial use of the Program, the Contributor who
+includes the Program in a commercial product offering should do so in a manner
+which does not create potential liability for other Contributors. Therefore,
+if a Contributor includes the Program in a commercial product offering, such
+Contributor ("Commercial Contributor") hereby agrees to defend and indemnify
+every other Contributor ("Indemnified Contributor") against any losses,
+damages and costs (collectively "Losses") arising from claims, lawsuits and
+other legal actions brought by a third party against the Indemnified
+Contributor to the extent caused by the acts or omissions of such Commercial
+Contributor in connection with its distribution of the Program in a commercial
+product offering. The obligations in this section do not apply to any claims
+or Losses relating to any actual or alleged intellectual property
+infringement. In order to qualify, an Indemnified Contributor must: a)
+promptly notify the Commercial Contributor in writing of such claim, and b)
+allow the Commercial Contributor to control, and cooperate with the Commercial
+Contributor in, the defense and any related settlement negotiations. The
+Indemnified Contributor may participate in any such claim at its own expense.
+
+For example, a Contributor might include the Program in a commercial product
+offering, Product X. That Contributor is then a Commercial Contributor. If
+that Commercial Contributor then makes performance claims, or offers
+warranties related to Product X, those performance claims and warranties are
+such Commercial Contributor's responsibility alone. Under this section, the
+Commercial Contributor would have to defend claims against the other
+Contributors related to those performance claims and warranties, and if a
+court requires any other Contributor to pay any damages as a result, the
+Commercial Contributor must pay those damages.
+
+5. NO WARRANTY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
+IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE,
+NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each
+Recipient is solely responsible for determining the appropriateness of using
+and distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement, including but not limited to the
+risks and costs of program errors, compliance with applicable laws, damage to
+or loss of data, programs or equipment, and unavailability or interruption of
+operations.
+
+6. DISCLAIMER OF LIABILITY
+
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
+CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
+LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
+EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGES.
+
+7. GENERAL
+
+If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of the
+remainder of the terms of this Agreement, and without further action by the
+parties hereto, such provision shall be reformed to the minimum extent
+necessary to make such provision valid and enforceable.
+
+If Recipient institutes patent litigation against a Contributor with respect
+to a patent applicable to software (including a cross-claim or counterclaim in
+a lawsuit), then any patent licenses granted by that Contributor to such
+Recipient under this Agreement shall terminate as of the date such litigation
+is filed. In addition, if Recipient institutes patent litigation against any
+entity (including a cross-claim or counterclaim in a lawsuit) alleging that
+the Program itself (excluding combinations of the Program with other software
+or hardware) infringes such Recipient's patent(s), then such Recipient's
+rights granted under Section 2(b) shall terminate as of the date such
+litigation is filed.
+
+All Recipient's rights under this Agreement shall terminate if it fails to
+comply with any of the material terms or conditions of this Agreement and does
+not cure such failure in a reasonable period of time after becoming aware of
+such noncompliance. If all Recipient's rights under this Agreement terminate,
+Recipient agrees to cease use and distribution of the Program as soon as
+reasonably practicable. However, Recipient's obligations under this Agreement
+and any licenses granted by Recipient relating to the Program shall continue
+and survive.
+
+Everyone is permitted to copy and distribute copies of this Agreement, but in
+order to avoid inconsistency the Agreement is copyrighted and may only be
+modified in the following manner. The Agreement Steward reserves the right to
+publish new versions (including revisions) of this Agreement from time to
+time. No one other than the Agreement Steward has the right to modify this
+Agreement. IBM is the initial Agreement Steward. IBM may assign the
+responsibility to serve as the Agreement Steward to a suitable separate
+entity. Each new version of the Agreement will be given a distinguishing
+version number. The Program (including Contributions) may always be
+distributed subject to the version of the Agreement under which it was
+received. In addition, after a new version of the Agreement is published,
+Contributor may elect to distribute the Program (including its Contributions)
+under the new version. Except as expressly stated in Sections 2(a) and 2(b)
+above, Recipient receives no rights or licenses to the intellectual property
+of any Contributor under this Agreement, whether expressly, by implication,
+estoppel or otherwise. All rights in the Program not expressly granted under
+this Agreement are reserved.
+
+This Agreement is governed by the laws of the State of New York and the
+intellectual property laws of the United States of America. No party to this
+Agreement will bring a legal action under this Agreement more than one year
+after the cause of action arose. Each party waives its rights to a jury trial
+in any resulting litigation.
+
+
227 README.txt
@@ -0,0 +1,227 @@
+To obtain keys for your YOS application please visit:
+
+http://developer.yahoo.com/dashboard/
+
+================================================================================
+
+To build:
+Invoke mvn package
+
+================================================================================
+
+
+Quick start:
+
+1) Copy yossdk-0.1.0.jar, and dependent jars to WEB-INF/lib
+2) Add com.yahoo.yos.oauth.YahooFilter servlet filter to web.xml, for example:
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+ <display-name>sample</display-name>
+ <filter>
+ <filter-name>YOSFilter</filter-name>
+ <filter-class>com.yahoo.yos.YahooFilter</filter-class>
+
+ <!--
+ optional param -
+ underlying oauth client class
+ possible values:
+ net.oauth.client.URLConnectionClient (default)
+ net.oauth.client.httpclient3.HttpClient3
+ net.oauth.client.httpclient4.HttpClient4
+ -->
+ <init-param>
+ <param-name>oauthConnectionClass</param-name>
+ <param-value>net.oauth.client.httpclient4.HttpClient4</param-value>
+ </init-param>
+ <!--
+ optional param -
+ redirect end-user if an access token is not found, set to false if you
+ are only making two-legged oauth calls e.g. oauth calls without an
+ access token to retrieve public information
+ defauts to true
+ -->
+ <init-param>
+ <param-name>redirect</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+
+ <!--
+ The URL where the filter is mapped to will redirect the user to Yahoo for
+ authorization if an OAuth authorization token has not been obtained for the
+ user. Should correspond to your callback url
+ -->
+
+ <filter-mapping>
+ <filter-name>YOSFilter</filter-name>
+ <url-pattern>/login.jsp</url-pattern>
+ </filter-mapping>
+</web-app>
+
+3) Sample JSP:
+
+<%@ page import="com.yahoo.yos.YahooSession" %><%@ page import="net.oauth.OAuthProblemException" %><%@ page import="org.json.JSONObject" %><%
+ YahooSession state = (YahooSession) request.getAttribute("yahooSession");
+ if ("POST".equals(request.getMethod())) {
+ String format = request.getParameter("format");
+ try {
+ if ("yql".equals(request.getParameter("form"))) {
+ String method = request.getParameter("method");
+ String url = request.getParameter("url");
+ String callback = request.getParameter("callback");
+ String query = request.getParameter("query");
+
+ String[] params = null;
+ if ("xml".equals(format)) {
+ response.setContentType("text/xml");
+ params = new String[] {"q", query, "format", format};
+ } else {
+ response.setContentType("text/plain");
+ params = new String[] {"q", query, "format", format, "callback", callback};
+ }
+ String output = state.invokeString(url, method, params);
+ out.println(output);
+ } else if ("yap".equals(request.getParameter("form"))) {
+ String method = request.getParameter("method");
+ String url = request.getParameter("url");
+ String content = request.getParameter("content");
+ String[] params = {"format", format, "content", content};
+ if ("xml".equals(format)) {
+ response.setContentType("text/xml");
+ out.println(state.invokeStringWithBody(url, method, content, params));
+ } else {
+ response.setContentType("text/plain");
+ JSONObject object = new JSONObject(state.invokeStringWithBody(url, method, content, params));
+ out.println("JSON Object:");
+ out.println(object.toString(10));
+ }
+ } else {
+ out.println("<html><body>unknown form</body></html>");
+ }
+ } catch (Exception e) {
+ response.setContentType("text/plain");
+ e.printStackTrace();
+ }
+ } else if ("GET".equals(request.getMethod()) && "true".equals(request.getParameter("clear"))) {
+ state.clearSession(request, response);
+ } else {
+%>
+<html>
+<body>
+<h1>YAP:</h1>
+
+<a href="./test.jsp?clear=true">logout</a>
+
+<br/>
+
+<form name="yap" method="post" action="test.jsp">
+ <input type="hidden" name="form" value="yap"/>
+ Method:
+ <select name="method">
+ <option>GET</option>
+ <option selected="true">PUT</option>
+ <option>POST</option>
+ </select>
+ <br/>
+ URL: <input name="url" type="text" size="75"
+ value="http://social.yahooapis.com/v1/user/<%= state.getGUID() %>/presence/presence"/>
+ <br/>
+ Content: <textarea name="content" rows="10" cols="50">
+ {
+ "status": "Reading paper"
+ }
+</textarea>
+ <br/>
+ Format:
+ <select name="format">
+ <option>xml</option>
+ <option>json</option>
+ </select>
+ <br/>
+ <input type="submit"/>
+</form>
+
+<h1>YQL:</h1>
+
+<form name="yql" method="post" action="test.jsp">
+ <input type="hidden" name="form" value="yql"/>
+ Method:
+ <select name="method">
+ <option>GET</option>
+ <option>PUT</option>
+ <option>POST</option>
+ </select>
+ <br/>
+ URL: <input name="url" type="text" size="75" value="http://query.yahooapis.com/v1/yql"/>
+ <br/>
+ Query: <input name="query" type="text" size="75" value="select * from social.profile where guid=me"/>
+ <br/>
+ Format:
+ <select name="format">
+ <option>xml</option>
+ <option>json</option>
+ </select>
+ <br/>
+ Callback: <input name="callback" type="text" size="10" value="foo"/>
+ <br/>
+ <input type="submit"/>
+</form>
+</body>
+</html>
+<%
+ }
+%>
+
+
+================================================================================
+
+
+
+
+This project only accepts contributions licensed under the BSD open source license. See the Open Source Initiative's approved template below.
+Each file submitted should contain the following information in the header:
+
+// Created by [contributor]
+// Copyright (c) [enter owning person entity, year]. All Rights Reserved.
+// Licensed under the BSD (revised) open source license.
+
+Here is the Open Source Initiative BSD License Template (http://opensource.org/licenses/bsd-license.php ):
+
+-------------------------------------
+Copyright (c) <YEAR>, <OWNER>
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms, with
+or without modification, are permitted provided that the following
+conditions are met:
+
+* Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+* Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+* Neither the name of <ORGANIZATION> nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-------------------------------------
163 pom.xml
@@ -0,0 +1,163 @@
+<!--
+
+// Created by Sumit Shah on 7/02/09.
+// Copyright (c) 2009 Yahoo! Inc. All rights reserved.
+//
+// The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.yahoo.yos</groupId>
+ <artifactId>sdk</artifactId>
+ <packaging>jar</packaging>
+ <version>0.1.0</version>
+ <name>YOS SDK</name>
+ <url>http://developer.yahoo.com</url>
+ <repositories>
+ <repository>
+ <id>oauth</id>
+ <name>Google Code OAuth Maven Repo</name>
+ <layout>default</layout>
+ <url>http://oauth.googlecode.com/svn/code/maven</url>
+ </repository>
+ </repositories>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/src.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <!--
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ -->
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- apache 2.0 http://mojo.codehaus.org/shitty-maven-plugin/license.html -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>shitty-maven-plugin</artifactId>
+ <version>1.0-alpha-3</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>clean</goal>
+ <goal>install</goal>
+ <goal>test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <!-- apache 2.0 http://code.google.com/p/oauth/ -->
+ <groupId>net.oauth.core</groupId>
+ <artifactId>oauth</artifactId>
+ <version>20090825</version>
+ </dependency>
+ <dependency>
+ <groupId>net.oauth.core</groupId>
+ <artifactId>oauth-provider</artifactId>
+ <version>20090531</version>
+ </dependency>
+ <dependency>
+ <groupId>net.oauth.core</groupId>
+ <artifactId>oauth-httpclient4</artifactId>
+ <version>20090913</version>
+ </dependency>
+ <dependency>
+ <groupId>net.oauth.core</groupId>
+ <artifactId>oauth-httpclient3</artifactId>
+ <version>20090617</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <!-- the json license http://www.json.org/license.html -->
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20080701</version>
+ </dependency>
+ <dependency>
+ <!-- apache 2.0 http://code.google.com/p/testng/ -->
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.8</version>
+ <scope>test</scope>
+ <classifier>jdk15</classifier>
+ </dependency>
+ <dependency>
+ <!-- MIT license http://code.google.com/p/mockito/ -->
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.7</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <!-- MIT license http://www.slf4j.org/license.html -->
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.6</version>
+ </dependency>
+ <dependency>
+ <!-- MIT license http://www.slf4j.org/license.html -->
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.6</version>
+ </dependency>
+ </dependencies>
+</project>
1 src/it/yql/goals.txt
@@ -0,0 +1 @@
+integration-test
138 src/it/yql/pom.xml
@@ -0,0 +1,138 @@
+<!--
+// Created by Sumit Shah on 7/02/09.
+// Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+//
+// The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.yahoo.yos.it</groupId>
+ <artifactId>yql</artifactId>
+ <packaging>war</packaging>
+ <version>0.1.0</version>
+ <properties>
+ <baseUrl>http://localhost:39999/</baseUrl>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>com.yahoo.yos</groupId>
+ <artifactId>sdk</artifactId>
+ <version>testing</version>
+ </dependency>
+ <dependency>
+ <!-- bsd/apache http://groovy.codehaus.org/faq.html#licence -->
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.6.3</version>
+ </dependency>
+ <dependency>
+ <!-- apache 2.0 http://groovy.codehaus.org/modules/http-builder/license.html -->
+ <groupId>org.codehaus.groovy.modules.http-builder</groupId>
+ <artifactId>http-builder</artifactId>
+ <version>0.5.0-RC1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>yql</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo.groovy</groupId>
+ <artifactId>groovy-maven-plugin</artifactId>
+ <version>1.0-beta-3</version>
+ <configuration>
+ <source>
+ import groovyx.net.http.HTTPBuilder
+ import static groovyx.net.http.Method.GET
+ import static groovyx.net.http.ContentType.XML
+ import static groovyx.net.http.ContentType.TEXT
+
+ def contains(tables, table) {
+ def contains = false
+ tables.table.each {
+ if(table.equals(it.toString().trim())) {
+ contains = true
+ }
+ }
+ return contains
+ }
+
+ def http = new HTTPBuilder("${baseUrl}")
+ http.request(GET, XML) {
+ uri.path = '/yql.groovy'
+ uri.query = [query:'show tables']
+ println "test retrieving: " + uri
+ response.success = { resp, query ->
+ def success = true
+ success &amp;= contains(query.results, "csv")
+ //success &amp;= contains(query.results, "a")
+ success &amp;= contains(query.results, "flickr.places")
+ if(!success) {
+ System.exit(1)
+ } else {
+ System.exit(0)
+ }
+ }
+ response.failure = { resp ->
+ failures.add("FAILURE: " + resp.statusLine + " " + url + "\n")
+ }
+ }
+ </source>
+ </configuration>
+ <executions>
+ <execution>
+ <id>default-integration-test</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <!-- apache 2.0 http://www.eclipse.org/jetty/licenses.php -->
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>maven-jetty-plugin</artifactId>
+ <version>6.1.18</version>
+ <configuration>
+ <scanIntervalSeconds>10</scanIntervalSeconds>
+ <stopKey>yql</stopKey>
+ <stopPort>49999</stopPort>
+ <contextPath>/</contextPath>
+ <connectors>
+ <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
+ <port>39999</port>
+ </connector>
+ </connectors>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start-jetty</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <scanIntervalSeconds>0</scanIntervalSeconds>
+ <daemon>true</daemon>
+ </configuration>
+ </execution>
+ <execution>
+ <id>stop-jetty</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
12 src/it/yql/src/main/resources/log4j.properties
@@ -0,0 +1,12 @@
+# Created by Sumit Shah on 7/02/09.
+# Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+#
+# The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+log4j.rootCategory=TRACE, A
+log4j.logger.org.apache.http=WARN
+log4j.appender.A.layout=org.apache.log4j.PatternLayout
+log4j.appender.A.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
+log4j.appender.A=org.apache.log4j.ConsoleAppender
+#log4j.appender.A=org.apache.log4j.FileAppender
+#log4j.appender.A.File=target/unit-test.log
+#log4j.appender.A.Append=false
6 src/it/yql/src/main/resources/oauth.properties.sample
@@ -0,0 +1,6 @@
+# Created by Sumit Shah on 7/02/09.
+# Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+#
+# The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+yos.consumerKey=<INSERT A REAL KEY HERE>
+yos.consumerSecret=<INSERT A REAL SECRET HERE>
41 src/it/yql/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,41 @@
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<!--
+// Created by Sumit Shah on 7/02/09.
+// Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+//
+// The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+-->
+
+<web-app>
+
+ <servlet>
+ <servlet-name>GroovyServlet</servlet-name>
+ <servlet-class>groovy.servlet.GroovyServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>GroovyServlet</servlet-name>
+ <url-pattern>*.groovy</url-pattern>
+ </servlet-mapping>
+
+ <filter>
+ <filter-name>YahooFilter</filter-name>
+ <filter-class>com.yahoo.yos.YahooFilter</filter-class>
+ <init-param>
+ <param-name>redirect</param-name>
+ <param-value>false</param-value>
+ </init-param>
+ <init-param>
+ <param-name>oauthConnectionClass</param-name>
+ <param-value>net.oauth.client.httpclient4.HttpClient4</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>YahooFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+</web-app>
12 src/it/yql/src/main/webapp/yql.groovy
@@ -0,0 +1,12 @@
+/*
+// Created by Sumit Shah on 7/02/09.
+// Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+//
+// The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+*/
+def query = request.getParameter("query")
+def yahooSession = request.getAttribute("yahooSession")
+def params = ["q", query, "format", "xml"] as String[]
+def url = "http://query.yahooapis.com/v1/yql";
+response.setContentType("text/xml");
+println(yahooSession.invokeString(url, "GET", params));
30 src/main/assembly/src.xml
@@ -0,0 +1,30 @@
+<assembly>
+ <id>bin</id>
+ <formats>
+ <format>tar.gz</format>
+ <format>zip</format>
+ </formats>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>lib</outputDirectory>
+ <scope>runtime</scope>
+ <useProjectArtifact>false</useProjectArtifact>
+ </dependencySet>
+ </dependencySets>
+ <fileSets>
+ <fileSet>
+ <includes>
+ <include>README*</include>
+ <include>LICENSE*</include>
+ <include>NOTICE*</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target</directory>
+ <outputDirectory></outputDirectory>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </fileSet>
+ </fileSets>
+</assembly>
BIN src/main/java/com/yahoo/yos/.YahooFilter.java.swp
Binary file not shown.
129 src/main/java/com/yahoo/yos/AccessToken.java
@@ -0,0 +1,129 @@
+// Created by Sumit Shah on 7/02/09.
+// Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+//
+// The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+package com.yahoo.yos;
+
+import java.io.UnsupportedEncodingException;
+import javax.servlet.http.Cookie;
+
+import org.apache.commons.codec.binary.Base64;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class AccessToken {
+
+ private String key;
+ private String secret;
+ private String guid;
+ private String owner;
+ private long tokenExpires;
+ private String sessionHandle;
+ private String consumer;
+ private long handleExpires;
+
+ public AccessToken() {
+ }
+
+ public AccessToken(Cookie cookie) throws UnsupportedEncodingException, JSONException {
+ JSONObject json = new JSONObject(new String(Base64.decodeBase64(cookie.getValue().getBytes("UTF-8")), "UTF-8"));
+ setKey(json.optString("key", null));
+ setSecret(json.optString("secret", null));
+ setGuid(json.optString("guid", null));
+ setOwner(json.optString("owner", null));
+ setTokenExpires(json.optLong("tokenExpires", -1));
+ setHandleExpires(json.optLong("handleExpires", -1));
+ setSessionHandle(json.optString("sessionHandle", null));
+ setConsumer(json.optString("consumer", null));
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getSecret() {
+ return secret;
+ }
+
+ public void setSecret(String secret) {
+ this.secret = secret;
+ }
+
+ public String getGuid() {
+ return guid;
+ }
+
+ public void setGuid(String guid) {
+ this.guid = guid;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+ public long getTokenExpires() {
+ return tokenExpires;
+ }
+
+ public void setTokenExpires(long tokenExpires) {
+ this.tokenExpires = tokenExpires;
+ }
+
+ public String getSessionHandle() {
+ return sessionHandle;
+ }
+
+ public void setSessionHandle(String sessionHandle) {
+ this.sessionHandle = sessionHandle;
+ }
+
+ public String getConsumer() {
+ return consumer;
+ }
+
+ public void setConsumer(String consumer) {
+ this.consumer = consumer;
+ }
+
+ public long getHandleExpires() {
+ return handleExpires;
+ }
+
+ public void setHandleExpires(long handleExpires) {
+ this.handleExpires = handleExpires;
+ }
+
+ public Cookie getCookie() throws UnsupportedEncodingException, JSONException {
+ return new Cookie("yosdk_at", new String(Base64.encodeBase64(toJSONObject().toString().getBytes("UTF-8")), "UTF-8"));
+ }
+
+ private JSONObject toJSONObject() throws JSONException {
+ JSONObject object = new JSONObject();
+ object.put("key", key);
+ object.put("secret", secret);
+ object.put("guid", guid);
+ object.put("owner", owner);
+ object.put("tokenExpires", tokenExpires);
+ object.put("sessionHandle", sessionHandle);
+ object.put("consumer", consumer);
+ object.put("handleExpires", handleExpires);
+ return object;
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return toJSONObject().toString();
+ } catch (Exception e) {
+ return super.toString();
+ }
+ }
+}
74 src/main/java/com/yahoo/yos/RequestToken.java
@@ -0,0 +1,74 @@
+// Created by Sumit Shah on 7/02/09.
+// Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+//
+// The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+package com.yahoo.yos;
+
+import java.io.UnsupportedEncodingException;
+import javax.servlet.http.Cookie;
+
+import org.apache.commons.codec.binary.Base64;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class RequestToken {
+ private String key;
+ private String secret;
+ private String sessionHandle;
+
+ public RequestToken() {
+ }
+
+ public RequestToken(Cookie cookie) throws UnsupportedEncodingException, JSONException {
+ JSONObject json = new JSONObject(new String(Base64.decodeBase64(cookie.getValue().getBytes("UTF-8")), "UTF-8"));
+ setKey(json.optString("key", null));
+ setSecret(json.optString("secret", null));
+ setSessionHandle(json.optString("sessionHandle", null));
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getSecret() {
+ return secret;
+ }
+
+ public void setSecret(String secret) {
+ this.secret = secret;
+ }
+
+ public String getSessionHandle() {
+ return sessionHandle;
+ }
+
+ public void setSessionHandle(String sessionHandle) {
+ this.sessionHandle = sessionHandle;
+ }
+
+ public Cookie getCookie() throws UnsupportedEncodingException, JSONException {
+ return new Cookie("yosdk_rt", new String(Base64.encodeBase64(toJSONObject().toString().getBytes("UTF-8")), "UTF-8"));
+ }
+
+ private JSONObject toJSONObject() throws JSONException {
+ JSONObject object = new JSONObject();
+ object.put("key", key);
+ object.put("secret", secret);
+ object.put("sessionHandle", sessionHandle);
+ return object;
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return toJSONObject().toString();
+ } catch (Exception e) {
+ return super.toString();
+ }
+ }
+
+}
419 src/main/java/com/yahoo/yos/YahooFilter.java
@@ -0,0 +1,419 @@
+// Created by Sumit Shah on 7/02/09.
+// Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+//
+// The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+package com.yahoo.yos;
+
+import net.oauth.OAuth;
+import net.oauth.OAuthAccessor;
+import net.oauth.OAuthConsumer;
+import net.oauth.OAuthException;
+import net.oauth.OAuthMessage;
+import net.oauth.OAuthProblemException;
+import net.oauth.OAuthServiceProvider;
+import net.oauth.ParameterStyle;
+import net.oauth.client.OAuthClient;
+import net.oauth.http.HttpClient;
+import net.oauth.server.OAuthServlet;
+import net.oauth.signature.OAuthSignatureMethod;
+import org.json.JSONException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * This is a servlet filter that assists in OAuth validation and authorization as well
+ * as some boilerplate when dealing with Yahoo! Open APIs. Access and request tokens
+ * are stored in cookies in a similar manner to the PHP SDK.
+ *
+ * @author Sam Pullara
+ * @author Sumit Shah
+ */
+public class YahooFilter implements Filter {
+ private final static Logger logger = LoggerFactory.getLogger(YahooFilter.class);
+
+ private static enum SESSION_TYPE {
+ YAHOO_YAP_SESSION_TYPE,
+ YAHOO_OAUTH_AT_SESSION_TYPE,
+ YAHOO_OAUTH_RT_SESSION_TYPE,
+ }
+
+ private Properties oauthConfig;
+ private boolean redirect = false;
+ private OAuthClient client;
+ private OAuthServiceProvider provider;
+ private OAuthConsumer consumer;
+ private String callbackUrl;
+
+ /**
+ * Set the 'oauth' init parameter for this filter to change from the default
+ * oauth.properties resource for configuration. The file should define:
+ * <p/>
+ * yos.consumerKey=...
+ * yos.consumerSecret=...
+ * oauth.requesttoken.url=https://api.login.yahoo.com/oauth/v2/get_request_token
+ * oauth.requestauth.url=https://api.login.yahoo.com/oauth/v2/request_auth
+ * oauth.accesstoken.url=https://api.login.yahoo.com/oauth/v2/get_token
+ * oauth.callback.url=http://myapplication:8080/
+ * <p/>
+ * To access production OAuth services from Yahoo. This filter relies on session
+ * information stored by cookies to operate.
+ *
+ * @param filterConfig see upstream docs
+ * @throws ServletException
+ */
+ public void init(FilterConfig filterConfig) throws ServletException {
+ String filename = filterConfig.getInitParameter("oauth");
+ if (filename == null) {
+ filename = "oauth.properties";
+ }
+ logger.debug("oauth properties file: {}", filename);
+ oauthConfig = new Properties();
+ try {
+ oauthConfig.load(getClass().getResourceAsStream("/" + filename));
+ } catch (IOException e) {
+ throw new ServletException("Could not load oauth properties from resource: " + filename, e);
+ }
+ String redirectString = filterConfig.getInitParameter("redirect");
+ // defaults to redirect if null, zero-length
+ redirect = redirectString == null
+ || redirectString.trim().length() <= 0
+ || "true".equalsIgnoreCase(redirectString.trim());
+ logger.debug("redirect if access token not found: {}", redirect);
+ String oauthConnectionClass = filterConfig.getInitParameter("oauthConnectionClass");
+ if (oauthConnectionClass == null) {
+ oauthConnectionClass = "net.oauth.client.URLConnectionClient";
+ }
+ logger.debug("oauth client connection class: {}", oauthConnectionClass);
+ try {
+ client = new OAuthClient((HttpClient)Class.forName(oauthConnectionClass).newInstance());
+ } catch (Exception cce) {
+ throw new ServletException("unable to create OAuthClient from: " + oauthConnectionClass, cce);
+ }
+ provider = new OAuthServiceProvider(
+ oauthConfig.getProperty("oauth.requesttoken.url", "https://api.login.yahoo.com/oauth/v2/get_request_token"),
+ oauthConfig.getProperty("oauth.requestauth.url", "https://api.login.yahoo.com/oauth/v2/request_auth"),
+ oauthConfig.getProperty("oauth.accesstoken.url", "https://api.login.yahoo.com/oauth/v2/get_token")
+ );
+ consumer = new OAuthConsumer(oauthConfig.getProperty("oauth.callback.url"), oauthConfig.getProperty("yos.consumerKey"), oauthConfig.getProperty("yos.consumerSecret"), provider);
+ consumer.setProperty("oauth_signature_method", oauthConfig.getProperty("yos.oauth_signature_method", "HMAC-SHA1"));
+ callbackUrl = oauthConfig.getProperty("oauth.callback.url", "");
+ }
+
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ HttpServletRequest request = (HttpServletRequest) servletRequest;
+ HttpServletResponse response = (HttpServletResponse) servletResponse;
+
+ String yap_appid = getParam(request, "yap_appid");
+ SESSION_TYPE sessionType;
+ if ("POST".equals(request.getMethod()) && yap_appid != null && yap_appid.length() > 0) {
+ sessionType = SESSION_TYPE.YAHOO_YAP_SESSION_TYPE;
+ } else if (cookieExists(request.getCookies(), "yosdk_at")) {
+ sessionType = SESSION_TYPE.YAHOO_OAUTH_AT_SESSION_TYPE;
+ } else if (cookieExists(request.getCookies(), "yosdk_rt")) {
+ sessionType = SESSION_TYPE.YAHOO_OAUTH_RT_SESSION_TYPE;
+ } else {
+ sessionType = null;
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("sessionType: {}", sessionType);
+ }
+
+ OAuthAccessor accessor = new OAuthAccessor(consumer);
+
+ if (sessionType == null) {
+ if (redirect) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("redirecting user to yahoo acquire access token");
+ }
+ redirectForAuthorization(accessor, request, response);
+ return;
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("inserting YahooSession suitable for 2-legged oauth calls into request attribute");
+ }
+ String appId = oauthConfig.getProperty("yos.appid");
+ request.setAttribute("yahooSession", new YahooSession(client, consumer, null, appId));
+ }
+ } else if (sessionType == SESSION_TYPE.YAHOO_YAP_SESSION_TYPE) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("inserting YahooSession suitable for 2-legged oauth calls into request attribute");
+ }
+ if (consumer.consumerKey == null || !consumer.consumerKey.equals(getParam(request, "yap_consumer_key"))) {
+ logger.error("Consumer key from YAP does not match config.");
+ clearSession(request, response);
+ if (redirect) {
+ redirectForAuthorization(accessor, request, response);
+ return;
+ }
+ }
+ try {
+ OAuthSignatureMethod method = OAuthSignatureMethod.newMethod("HMAC-SHA1", accessor);
+ OAuthMessage msg = OAuthServlet.getMessage(request, null);
+ method.validate(msg);
+ } catch (OAuthProblemException ex) {
+ logger.error("Signature from YAP failed.", ex);
+ clearSession(request, response);
+ if (redirect) {
+ redirectForAuthorization(accessor, request, response);
+ return;
+ }
+ } catch (Exception ex) {
+ throw new ServletException(ex);
+ }
+ AccessToken at = new AccessToken();
+ at.setKey(getParam(request, "yap_viewer_access_token"));
+ at.setSecret(getParam(request, "yap_viewer_access_token_secret"));
+ at.setGuid(getParam(request, "yap_viewer_guid"));
+ at.setOwner(getParam(request, "yap_owner_guid"));
+ at.setTokenExpires(-1);
+ String appId = getParam(request, "yap_appid");
+ YahooSession yahooSession = new YahooSession(client, consumer, at, appId);
+ request.setAttribute("yahooSession", yahooSession);
+ } else if (sessionType == SESSION_TYPE.YAHOO_OAUTH_AT_SESSION_TYPE) {
+ long now = System.currentTimeMillis() / 1000;
+ try {
+ AccessToken accessToken = new AccessToken(cookie(request.getCookies(), "yosdk_at"));
+ if (consumer.consumerKey == null || !consumer.consumerKey.equals(accessToken.getConsumer())) {
+ logger.error("Consumer key for token does not match the defined Consumer Key. The Consumer Key has probably changed since the user last authorized the application.");
+ clearSession(request, response);
+ if (redirect) {
+ redirectForAuthorization(accessor, request, response);
+ return;
+ }
+ }
+ if (accessToken.getTokenExpires() >= 0 && logger.isDebugEnabled()) {
+ logger.debug("AT Expires in: {}", (accessToken.getTokenExpires() - now));
+ }
+ if (accessToken.getTokenExpires() >= 0 && (accessToken.getTokenExpires() - now) < 30) {
+ try {
+ accessTokenExpired(accessor, request, response, accessToken, filterChain);
+ } catch (OAuthException ex) {
+ if (ex instanceof OAuthProblemException) {
+ OAuthProblemException oape = (OAuthProblemException) ex;
+ String s = oape.getProblem() + oape.getParameters();
+ throw new ServletException(s, ex);
+ }
+ throw new ServletException(ex);
+ } catch (URISyntaxException ex) {
+ throw new ServletException(ex);
+ }
+ return;
+ } else {
+ String appId = oauthConfig.getProperty("yos.appid");
+ YahooSession yahooSession = new YahooSession(client, consumer, accessToken, appId);
+ request.setAttribute("yahooSession", yahooSession);
+ }
+ } catch (JSONException e) {
+ throw new ServletException(e);
+ }
+ } else if (sessionType == SESSION_TYPE.YAHOO_OAUTH_RT_SESSION_TYPE) {
+ try {
+ RequestToken rt = new RequestToken(cookie(request.getCookies(), "yosdk_rt"));
+ accessor.tokenSecret = rt.getSecret();
+
+ String verifier = getParam(request, "oauth_verifier");
+ if (logger.isDebugEnabled()) {
+ logger.debug("got oauth_verifier {}", verifier);
+ }
+
+ try {
+ if(logger.isDebugEnabled()) {
+ logger.error("request token found, fetching access token for user");
+ }
+ AccessToken at = fetchAccessToken(accessor, rt, verifier);
+ Cookie yosdk_at = at.getCookie();
+ Cookie yosdk_rt = new Cookie("yosdk_rt", "");
+ yosdk_at.setMaxAge(30 * 24 * 60 * 60);
+ yosdk_rt.setMaxAge(0);
+ response.addCookie(yosdk_at);
+ response.addCookie(yosdk_rt);
+ String appId = oauthConfig.getProperty("yos.appid");
+ YahooSession yahooSession = new YahooSession(client, consumer, at, appId);
+ request.setAttribute("yahooSession", yahooSession);
+ } catch (URISyntaxException ex) {
+ throw new ServletException(ex);
+ } catch (OAuthException ex) {
+ clearSession(request, response);
+ if (redirect) {
+ redirectForAuthorization(accessor, request, response);
+ return;
+ } else {
+ throw new ServletException(ex);
+ }
+ }
+ } catch (JSONException e) {
+ throw new ServletException(e);
+ }
+ }
+
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+
+ private String getParam(HttpServletRequest request, String key) {
+ String param = request.getParameter(key);
+ if (param == null) {
+ return request.getHeader("x-" + key.replace("_", "-"));
+ }
+ return param;
+ }
+
+ private AccessToken fetchAccessToken(OAuthAccessor accessor, RequestToken requestToken, String verifier) throws IOException, URISyntaxException, OAuthException {
+ List<OAuth.Parameter> params;
+ if (requestToken.getSessionHandle() != null) {
+ params = OAuth.newList("oauth_token", requestToken.getKey(), "oauth_session_handle", requestToken.getSessionHandle());
+ } else {
+ params = OAuth.newList("oauth_token", requestToken.getKey());
+ }
+ // Add the verifier which is required for OAuth1.0a
+ if (verifier != null) {
+ params.addAll(OAuth.newList("oauth_verifier", verifier));
+ }
+ OAuthMessage getTokenMsg = new OAuthMessage("GET", provider.accessTokenURL, params);
+ getTokenMsg.addRequiredParameters(accessor);
+ OAuthMessage msg = client.invoke(getTokenMsg, ParameterStyle.QUERY_STRING);
+ Map<String, String> map = OAuth.newMap(msg.getParameters());
+ AccessToken at = new AccessToken();
+ at.setKey(map.get("oauth_token"));
+ at.setSecret(map.get("oauth_token_secret"));
+ at.setGuid(map.get("xoauth_yahoo_guid"));
+ at.setConsumer(accessor.consumer.consumerKey);
+ at.setSessionHandle(map.get("oauth_session_handle"));
+ long now = System.currentTimeMillis() / 1000;
+ if (map.containsKey("oauth_expires_in")) {
+ at.setTokenExpires(now + Long.parseLong(msg.getParameter("oauth_expires_in")));
+ } else {
+ at.setTokenExpires(-1);
+ }
+ if (map.containsKey("oauth_authorization_expires_in")) {
+ at.setHandleExpires(now + Long.parseLong(map.get("oauth_authorization_expires_in")));
+ } else {
+ at.setHandleExpires(-1);
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("setting access token expires in: {}", at.getTokenExpires());
+ logger.debug("setting access token handle expires in: {}", at.getHandleExpires());
+ }
+ return at;
+ }
+
+ private void accessTokenExpired(OAuthAccessor accessor, HttpServletRequest request, HttpServletResponse response, AccessToken accessToken, FilterChain filterChain) throws IOException, ServletException, JSONException, OAuthException, URISyntaxException {
+ if(logger.isDebugEnabled()) {
+ logger.debug("access token expired, attempting to renew");
+ }
+ long now = System.currentTimeMillis() / 1000;
+ if (accessToken.getHandleExpires() == -1 || (now < accessToken.getHandleExpires())) {
+ RequestToken requestToken = new RequestToken();
+ requestToken.setKey(accessToken.getKey());
+ requestToken.setSessionHandle(accessToken.getSessionHandle());
+ accessor.tokenSecret = accessToken.getSecret();
+ AccessToken at = fetchAccessToken(accessor, requestToken, null);
+ Cookie yosdk_at = at.getCookie();
+ yosdk_at.setMaxAge(30 * 24 * 60 * 60);
+ response.addCookie(yosdk_at);
+ String appId = oauthConfig.getProperty("yos.appid");
+ YahooSession yahooSession = new YahooSession(client, consumer, at, appId);
+ request.setAttribute("yahooSession", yahooSession);
+ filterChain.doFilter(request, response);
+ } else {
+ Cookie at = new Cookie("yosdk_at", "");
+ at.setMaxAge(0);
+ at.setMaxAge(0);
+ response.addCookie(at);
+ request.setAttribute("yahooSession", null);
+ request.setAttribute("yahooRedirect", null);
+ filterChain.doFilter(request, response);
+ if (redirect) {
+ redirectForAuthorization(accessor, request, response);
+ }
+ }
+ }
+
+ private void redirectForAuthorization(OAuthAccessor accessor, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
+ try {
+ // get the request token
+ List<OAuth.Parameter> callback = OAuth.newList(OAuth.OAUTH_CALLBACK, callbackUrl);
+ //client.getRequestToken(accessor, null, callback);
+ OAuthMessage message = client.getRequestTokenResponse(accessor, null, callback);
+ } catch (URISyntaxException ex) {
+ throw new ServletException(ex);
+ } catch (OAuthException ex) {
+ throw new ServletException(ex);
+ }
+ if (accessor.requestToken != null) {
+ try {
+ RequestToken rt = new RequestToken();
+ rt.setKey(accessor.requestToken);
+ rt.setSecret(accessor.tokenSecret);
+ Cookie yosdk_rt = rt.getCookie();
+ yosdk_rt.setMaxAge(600);
+ response.addCookie(yosdk_rt);
+ } catch (JSONException ex) {
+ throw new ServletException(ex);
+ }
+ } else {
+ throw new ServletException("Failed to create request token");
+ }
+ String redirectUrl = OAuth.addParameters(provider.userAuthorizationURL,
+ "oauth_token", accessor.requestToken,
+ "oauth_callback", callbackUrl);
+ request.setAttribute("yahooRedirect", redirectUrl);
+ response.sendRedirect(redirectUrl);
+ }
+
+ public void clearSession(HttpServletRequest req, HttpServletResponse res) {
+ if(logger.isDebugEnabled()) {
+ logger.debug("clear session requested");
+ }
+ Cookie at = new Cookie("yosdk_at", "");
+ at.setMaxAge(0);
+ Cookie rt = new Cookie("yosdk_rt", "");
+ rt.setMaxAge(0);
+ res.addCookie(at);
+ res.addCookie(rt);
+ req.setAttribute("yahooSession", null);
+ req.setAttribute("yahooRedirect", null);
+ }
+
+ private boolean cookieExists(Cookie[] cookies, String cookieName) {
+ if (cookies != null) {
+ for (Cookie cookie : cookies) {
+ if (cookie.getName() != null && cookie.getName().equals(cookieName)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+ private Cookie cookie(Cookie[] cookies, String cookieName) {
+ if (cookies != null) {
+ for (Cookie cookie : cookies) {
+ if (cookie.getName() != null && cookie.getName().equals(cookieName)) {
+ return cookie;
+ }
+ }
+ }
+ return null;
+ }
+
+ public void destroy() {
+ //empty
+ }
+}
132 src/main/java/com/yahoo/yos/YahooSession.java
@@ -0,0 +1,132 @@
+// Created by Sumit Shah on 7/02/09.
+// Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+//
+// The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+package com.yahoo.yos;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.io.ByteArrayInputStream;
+import java.net.URISyntaxException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.Cookie;
+
+import net.oauth.OAuth;
+import net.oauth.OAuthAccessor;
+import net.oauth.OAuthConsumer;
+import net.oauth.OAuthException;
+import net.oauth.OAuthMessage;
+import net.oauth.ParameterStyle;
+import net.oauth.client.OAuthClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Required properties:
+ * yos.consumerKey - your OAuth consumer key
+ * yos.consumerSecret - your OAuth consumer secret
+ * <p/>
+ * Optional properties:
+ * yos.appid - if you need the AppID for an API call
+ * oauth.*.url - if you are using different end points than the standard YOS endpoints
+ *
+ * @author Sam Pullara
+ * @author Sumit Shah
+ */
+public class YahooSession implements Serializable {
+
+ private static final long serialVersionUID = 6409879252229261080L;
+ private final static Logger logger = LoggerFactory.getLogger(YahooSession.class);
+ private AccessToken accessToken;
+ private String applicationId;
+ private OAuthClient client;
+ private OAuthAccessor accessor;
+
+ public YahooSession(OAuthClient client, OAuthConsumer consumer, AccessToken accessToken, String applicationId) {
+ this.accessToken = accessToken;
+ this.applicationId = applicationId;
+ this.client = client;
+ this.accessor = new OAuthAccessor(consumer);
+ if (accessToken != null) {
+ accessor.accessToken = accessToken.getKey();
+ accessor.tokenSecret = accessToken.getSecret();
+ }
+ }
+
+ public InputStream invokeStream(String url, String httpMethod, String... params) throws IOException, OAuthException, URISyntaxException {
+ return invoke(url, httpMethod, params).getBodyAsStream();
+ }
+
+ public String invokeString(String url, String httpMethod, String... params) throws IOException, OAuthException, URISyntaxException {
+ return invoke(url, httpMethod, params).readBodyAsString();
+ }
+
+ public InputStream invokeStreamWithBody(String url, String httpMethod, String body, String... params) throws IOException, OAuthException, URISyntaxException {
+ return invoke(url, httpMethod, body, params).getBodyAsStream();
+ }
+
+ public String invokeStringWithBody(String url, String httpMethod, String body, String... params) throws IOException, OAuthException, URISyntaxException {
+ return invoke(url, httpMethod, body, params).readBodyAsString();
+ }
+
+ private OAuthMessage invoke(String url, String httpMethod, String... params) throws IOException, OAuthException, URISyntaxException {
+ return client.invoke(accessor, httpMethod, url, OAuth.newList(params));
+ }
+
+ private OAuthMessage invoke(String url, String httpMethod, final String body, String... params) throws IOException, OAuthException, URISyntaxException {
+ OAuthMessage msg = new OAuthMessage(httpMethod, url, OAuth.newList(params)) {
+
+ @Override
+ public InputStream getBodyAsStream() throws IOException {
+ return new ByteArrayInputStream(body.getBytes("utf-8"));
+ }
+ };
+ msg.addRequiredParameters(accessor);
+ try {
+ return client.invoke(msg, ParameterStyle.QUERY_STRING);
+ } catch (OAuthException oe) {
+ return client.invoke(msg, ParameterStyle.AUTHORIZATION_HEADER);
+ }
+ }
+
+ public void clearSession(HttpServletRequest request, HttpServletResponse response) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("clear session requested");
+ }
+ Cookie at = new Cookie("yosdk_at", "");
+ at.setMaxAge(0);
+ Cookie rt = new Cookie("yosdk_rt", "");
+ rt.setMaxAge(0);
+ response.addCookie(at);
+ response.addCookie(rt);
+ request.setAttribute("yahooSession", null);
+ }
+
+ /**
+ * Returns the current users GUID. There is a one to one mapping of the
+ * GUID to a yahoo account, e.g. foo@yahoo.com or bar@ymail.com. Returns null
+ * if the sdk is used to only act upon behalf of the application rather than
+ * the user. See 2-legged versus 3-legged calls.
+ *
+ * @return the GUID
+ */
+ public String getGUID() {
+ if (accessToken != null) {
+ return accessToken.getGuid();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the appid specified in the properties file.
+ *
+ * @return the appid
+ */
+ public String getAppID() {
+ return applicationId;
+ }
+}
59 src/test/java/com/yahoo/yos/YahooFilterTest.java
@@ -0,0 +1,59 @@
+// Created by Sumit Shah on 7/02/09.
+// Copyright (c) 2010 Yahoo! Inc. All rights reserved.
+//
+// The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license.
+package com.yahoo.yos;
+
+import java.util.Hashtable;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.testng.annotations.Test;
+import org.mockito.Mockito;
+
+public class YahooFilterTest {
+
+ @Test
+ public void testDefaultInitNoRedirect() throws Exception {
+ YahooFilter filter = new YahooFilter();
+ FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
+ Mockito.when(filterConfig.getInitParameter("redirect")).thenReturn("false");
+ filter.init(filterConfig);
+ HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
+ HttpServletResponse res = Mockito.mock(HttpServletResponse.class);
+ FilterChain chain = Mockito.mock(FilterChain.class);
+ filter.doFilter(req, res, chain);
+ Mockito.verify(req).setAttribute(Mockito.eq("yahooSession"), Mockito.any(YahooSession.class));
+ }
+
+ @Test
+ public void testHttpClient3InitNoRedirect() throws Exception {
+ YahooFilter filter = new YahooFilter();
+ FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
+ Mockito.when(filterConfig.getInitParameter("oauthConnectionClass")).thenReturn("net.oauth.client.httpclient3.HttpClient3");
+ Mockito.when(filterConfig.getInitParameter("redirect")).thenReturn("false");
+ filter.init(filterConfig);
+ HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
+ HttpServletResponse res = Mockito.mock(HttpServletResponse.class);
+ FilterChain chain = Mockito.mock(FilterChain.class);
+ filter.doFilter(req, res, chain);
+ Mockito.verify(req).setAttribute(Mockito.eq("yahooSession"), Mockito.any(YahooSession.class));
+ }
+
+ @Test
+ public void testHttpClient4InitNoRedirect() throws Exception {
+ YahooFilter filter = new YahooFilter();
+ FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
+ Mockito.when(filterConfig.getInitParameter("oauthConnectionClass")).thenReturn("net.oauth.client.httpclient4.HttpClient4");
+ Mockito.when(filterConfig.getInitParameter("redirect")).thenReturn("false");
+ filter.init(filterConfig);
+ HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
+ HttpServletResponse res = Mockito.mock(HttpServletResponse.class);
+ FilterChain chain = Mockito.mock(FilterChain.class);
+ filter.doFilter(req, res, chain);
+ Mockito.verify(req).setAttribute(Mockito.eq("yahooSession"), Mockito.any(YahooSession.class));
+ }
+}
7 src/test/resources/log4j.properties
@@ -0,0 +1,7 @@
+log4j.rootCategory=TRACE, A
+log4j.appender.A.layout=org.apache.log4j.PatternLayout
+log4j.appender.A.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
+#log4j.appender.A=org.apache.log4j.ConsoleAppender
+log4j.appender.A=org.apache.log4j.FileAppender
+log4j.appender.A.File=target/unit-test.log
+log4j.appender.A.Append=false
3 src/test/resources/oauth.properties
@@ -0,0 +1,3 @@
+#http://www.hueniverse.com/hueniverse/2008/10/beginners-gui-1.html
+yos.consumerKey=dpf43f3p2l4k3l03
+yos.consumerSecret=DUMMYSECRETFORUNITTESTS

0 comments on commit cb094c9

Please sign in to comment.