├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── COPYING ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src └── main └── java ├── com └── amazon │ └── neptune │ └── gremlin │ └── driver │ ├── example │ ├── NeptuneGremlinSigV4Example.java │ └── package-info.java │ ├── exception │ ├── SigV4PropertiesNotFoundException.java │ └── package-info.java │ └── sigv4 │ ├── AwsSigV4ClientHandshaker.java │ ├── ChainedSigV4PropertiesProvider.java │ ├── SigV4Properties.java │ └── package-info.java └── org └── apache └── tinkerpop └── gremlin └── driver ├── SigV4WebSocketChannelizer.java └── package-info.java /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | 6 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea 3 | *.iml 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check [existing open](https://github.com/aws/amazon-neptune-gremlin-java-sigv4/issues), or [recently closed](https://github.com/aws/amazon-neptune-gremlin-java-sigv4/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *master* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws/amazon-neptune-gremlin-java-sigv4/labels/help%20wanted) issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](https://github.com/aws/amazon-neptune-gremlin-java-sigv4/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | 61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 62 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2018 Amazon.com, Inc. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2018 Amazon.com, Inc. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Amazon Neptune Gremlin Java Sigv4 2 | Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Amazon Neptune Gremlin Java Sigv4 2 | 3 | An extension to GremlinDriver with a custom channelizer that enables AWS Signature Version 4 signed requests to [Amazon Neptune](https://aws.amazon.com/neptune). 4 | 5 | For example usage refer to: 6 | 7 | - [NeptuneGremlinSigV4Example.java](https://github.com/aws/amazon-neptune-gremlin-java-sigv4/blob/master/src/main/java/com/amazon/neptune/gremlin/driver/example/NeptuneGremlinSigV4Example.java): This package can also be used to enable Gremlin Console to send signed requests to Neptune, refer to [Connecting to Neptune Using the Gremlin Console with Signature Version 4 Signing](https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connecting-gremlin-console.html). 8 | - If you are using versions of TinkerPop after 3.4.11 or higher you should prefer using the [amazon-neptune-sigv4-signer](https://github.com/aws/amazon-neptune-sigv4-signer) directly as discussed [here](https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connecting-gremlin-java.html#iam-auth-connecting-gremlin-java-current). 9 | 10 | For the official Amazon Neptune page refer to: https://aws.amazon.com/neptune 11 | 12 | ## Version 13 | 14 | 1.x - This series uses TinkerPop 3.3.x client. Note that active maintenance on TinkerPop 3.3.x has stopped and hence, this version is not recommended. 15 | 16 | 2.x - This series uses TinkerPop 3.4.x client. This major version tracks the latest stable release for this package. Note that a minor version (y in 2.x.y) is bumped whenever a new version of Apache TinkerPop is added as a dependency or a major feature is introduced. All minor versions in 2.x series are backward compatible. 17 | 18 | 3.x - This series continues use of TinkerPop 3.4.x client and was incremented to simply match the major increment to the [amazon-neptune-sigv4-signer](https://github.com/aws/amazon-neptune-sigv4-signer). 19 | 20 | For more information on compatibility with Amazon Neptune engine releases, see [Use the Latest Version of the Gremlin Java Client](https://docs.aws.amazon.com/neptune/latest/userguide/best-practices-gremlin-java-latest.html). 21 | 22 | ## License 23 | 24 | This library is licensed under the Apache 2.0 License. 25 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 15 | 17 | 18 | 4.0.0 19 | com.amazonaws 20 | amazon-neptune-gremlin-java-sigv4 21 | jar 22 | 3.1.1-SNAPSHOT 23 | 24 | amazon-neptune-gremlin-java-sigv4 25 | 26 | A Gremlin client for Amazon Neptune that includes AWS Signature Version 4 signing. 27 | 28 | https://github.com/aws/amazon-neptune-gremlin-java-sigv4 29 | 30 | 31 | 32 | Apache License, Version 2.0 33 | https://aws.amazon.com/apache2.0 34 | repo 35 | 36 | 37 | 38 | 39 | 40 | amazonwebservices 41 | Amazon Web Services 42 | https://aws.amazon.com 43 | 44 | developer 45 | 46 | 47 | 48 | 49 | 50 | 51 | ossrh 52 | https://aws.oss.sonatype.org/content/repositories/snapshots/ 53 | 54 | 55 | ossrh 56 | https://aws.oss.sonatype.org/content/groups/staging/ 57 | 58 | 59 | 60 | 61 | scm:git:git@github.com:aws/amazon-neptune-gremlin-java-sigv4.git 62 | scm:git:git@github.com:aws/amazon-neptune-gremlin-java-sigv4.git 63 | git@github.com:aws/amazon-neptune-gremlin-java-sigv4.git 64 | 65 | 66 | 67 | UTF-8 68 | 1.8 69 | 1.8 70 | 71 | 72 | 73 | 74 | 75 | com.fasterxml.jackson.core 76 | jackson-databind 77 | 2.18.2 78 | 79 | 80 | com.fasterxml.jackson.dataformat 81 | jackson-dataformat-cbor 82 | 2.18.2 83 | 84 | 85 | 86 | 87 | 88 | 89 | org.apache.tinkerpop 90 | gremlin-driver 91 | 3.4.10 92 | 93 | 94 | commons-cli 95 | commons-cli 96 | 1.4 97 | 98 | 99 | org.slf4j 100 | slf4j-api 101 | 1.7.30 102 | 103 | 104 | org.projectlombok 105 | lombok 106 | 1.18.20 107 | provided 108 | 109 | 110 | com.fasterxml.jackson.core 111 | jackson-databind 112 | 113 | 114 | com.amazonaws 115 | aws-java-sdk-core 116 | 1.12.780 117 | 118 | 119 | software.amazon.awssdk 120 | http-auth-aws 121 | 2.30.15 122 | 123 | 124 | software.amazon.awssdk 125 | auth 126 | 2.30.15 127 | 128 | 129 | software.amazon.awssdk 130 | utils 131 | 2.30.15 132 | 133 | 134 | com.amazonaws 135 | amazon-neptune-sigv4-signer 136 | ${project.version} 137 | 138 | 139 | 140 | 141 | junit 142 | junit 143 | 4.13.2 144 | test 145 | 146 | 147 | 148 | 149 | 150 | release 151 | 152 | 153 | 154 | 155 | 156 | org.apache.maven.plugins 157 | maven-source-plugin 158 | 3.2.1 159 | 160 | 161 | attach-sources 162 | 163 | jar-no-fork 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | org.apache.maven.plugins 172 | maven-javadoc-plugin 173 | 3.2.0 174 | 175 | Amazon Neptune Gremlin Java Sigv4 176 | UTF-8 177 | 178 | Copyright © 2018 Amazon.com. All Rights Reserved.]]> 179 | 180 | -Xdoclint:none 181 | 182 | 183 | 184 | attach-javadocs 185 | 186 | jar 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | org.apache.maven.plugins 195 | maven-gpg-plugin 196 | 3.0.1 197 | 198 | 199 | sign-artifacts 200 | verify 201 | 202 | sign 203 | 204 | 205 | ${gpg.keyname} 206 | ${gpg.passphrase} 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | org.sonatype.plugins 215 | nexus-staging-maven-plugin 216 | 1.6.8 217 | true 218 | 219 | ossrh 220 | https://aws.oss.sonatype.org/ 221 | true 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/neptune/gremlin/driver/example/NeptuneGremlinSigV4Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.neptune.gremlin.driver.example; 17 | 18 | import org.apache.commons.cli.BasicParser; 19 | import org.apache.commons.cli.CommandLine; 20 | import org.apache.commons.cli.CommandLineParser; 21 | import org.apache.commons.cli.HelpFormatter; 22 | import org.apache.commons.cli.Option; 23 | import org.apache.commons.cli.Options; 24 | import org.apache.commons.cli.ParseException; 25 | import org.apache.tinkerpop.gremlin.driver.Client; 26 | import org.apache.tinkerpop.gremlin.driver.Cluster; 27 | import org.apache.tinkerpop.gremlin.driver.Result; 28 | import org.apache.tinkerpop.gremlin.driver.ResultSet; 29 | import org.apache.tinkerpop.gremlin.driver.SigV4WebSocketChannelizer; 30 | 31 | /** 32 | * An example client code to demonstrate the process of making auth enabled Gremlin calls to Neptune Server. 33 | * If auth is enabled on the server side then the neptune db region should be set either as a system property of as 34 | * an environment variable. 35 | * For instance, set the region as system property: -DSERVICE_REGION=us-east-1 36 | *

37 | * The request signing logic requires IAM credentials to sign the requests. Two of the methods to provide the IAM 38 | * credentials: 39 | *

    40 | *
  1. Setting environment variables AWS_ACCESS_KEY_ID=[your-access-key-id] and AWS_SECRET_KEY=[your-access-secret].
  2. 41 | *
  3. Passing as JVM arg: -Daws.accessKeyId=[your-access-key-id] and -Daws.secretKey=[your-access-secret].
  4. 42 | *
43 | * 44 | * @see 45 | * DefaultAWSCredentialsProviderChain" for more information and additional methods for providing IAM credentials. 46 | */ 47 | public final class NeptuneGremlinSigV4Example { 48 | /** 49 | * Command line option name for the db cluster/instance endpoint. 50 | */ 51 | private static final String ENDPOINT = "endpoint"; 52 | /** 53 | * Command line option name for the db cluster/instance port. 54 | */ 55 | private static final String PORT = "port"; 56 | /** 57 | * Command line option name for the whether to use ssl connection. 58 | */ 59 | private static final String SSL = "ssl"; 60 | 61 | /** 62 | * The gremlin query to test. 63 | */ 64 | private static final String SAMPLE_QUERY = "g.V().count()"; 65 | 66 | /** 67 | * Default private constructor. 68 | */ 69 | private NeptuneGremlinSigV4Example() { 70 | 71 | } 72 | 73 | /** 74 | * Test code to make gremlin java calls. 75 | * @param args program args. 76 | */ 77 | public static void main(final String[] args) { 78 | 79 | final Options options = setupCliOptions(); 80 | final CommandLine cli = parseArgs(args, options); 81 | final Cluster.Builder builder = Cluster.build(); 82 | builder.addContactPoint(cli.getOptionValue(ENDPOINT)); 83 | builder.port(Integer.parseInt(cli.getOptionValue(PORT))); 84 | 85 | //If the neptune db is auth enabled then add use the following channelizer. Otherwise omit the below line. 86 | builder.channelizer(SigV4WebSocketChannelizer.class); 87 | builder.enableSsl(Boolean.parseBoolean(cli.getOptionValue(SSL, "false"))); 88 | 89 | 90 | final Cluster cluster = builder.create(); 91 | try { 92 | final Client client = cluster.connect(); 93 | final ResultSet rs = client.submit(SAMPLE_QUERY); 94 | 95 | for (Result r : rs) { 96 | System.out.println(r); 97 | } 98 | } finally { 99 | cluster.close(); 100 | } 101 | } 102 | 103 | /** 104 | * Parses the command line args and returns a {@link CommandLine} with the properties. 105 | * @param args the command line args. 106 | * @param options the options object containing the args that can be passed. 107 | * @return a {@link CommandLine} instance with the option properties set. 108 | */ 109 | private static CommandLine parseArgs(final String[] args, final Options options) { 110 | final CommandLineParser parser = new BasicParser(); 111 | final HelpFormatter formatter = new HelpFormatter(); 112 | 113 | try { 114 | return parser.parse(options, args); 115 | } catch (ParseException e) { 116 | formatter.printHelp(NeptuneGremlinSigV4Example.class.getSimpleName(), options); 117 | throw new RuntimeException("Invalid command line args"); 118 | } 119 | } 120 | 121 | /** 122 | * Private utility to set the CLI options required to run the program. 123 | * @return {@link Options} that can be accepted by the program. 124 | */ 125 | private static Options setupCliOptions() { 126 | final Options options = new Options(); 127 | 128 | final Option endpoint = new Option("e", ENDPOINT, true, "The db cluster/instance endpoint"); 129 | endpoint.setRequired(true); 130 | options.addOption(endpoint); 131 | 132 | final Option port = new Option("p", PORT, true, "The db cluster/instance port"); 133 | port.setRequired(true); 134 | options.addOption(port); 135 | 136 | final Option ssl = new Option("s", SSL, true, "Whether to enable ssl on the connection"); 137 | ssl.setRequired(false); 138 | ssl.setType(Boolean.class); 139 | options.addOption(ssl); 140 | 141 | return options; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/neptune/gremlin/driver/example/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * Examples demonstrating making gremlin calls to neptune when SigV4 auth is enabled. 18 | */ 19 | package com.amazon.neptune.gremlin.driver.example; 20 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/neptune/gremlin/driver/exception/SigV4PropertiesNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.neptune.gremlin.driver.exception; 17 | 18 | /** 19 | * Denotes an exception when trying to extract properties required for SigV4 signing. 20 | */ 21 | public class SigV4PropertiesNotFoundException extends RuntimeException { 22 | /** 23 | * @param message the error message. 24 | */ 25 | public SigV4PropertiesNotFoundException(final String message) { 26 | super(message); 27 | } 28 | 29 | /** 30 | * @param message the error message. 31 | * @param cause the root cause exception. 32 | */ 33 | public SigV4PropertiesNotFoundException(final String message, final Throwable cause) { 34 | super(message, cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/neptune/gremlin/driver/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * Exceptions related to gremlin driver code. 18 | */ 19 | package com.amazon.neptune.gremlin.driver.exception; 20 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/neptune/gremlin/driver/sigv4/AwsSigV4ClientHandshaker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.neptune.gremlin.driver.sigv4; 17 | 18 | import java.net.URI; 19 | 20 | import com.amazonaws.auth.AWSCredentialsProvider; 21 | import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; 22 | import com.amazonaws.neptune.auth.NeptuneNettyHttpSigV4Signer; 23 | import com.amazonaws.neptune.auth.NeptuneSigV4SignerException; 24 | 25 | import io.netty.handler.codec.http.FullHttpRequest; 26 | import io.netty.handler.codec.http.HttpHeaders; 27 | import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13; 28 | import io.netty.handler.codec.http.websocketx.WebSocketVersion; 29 | 30 | /** 31 | * Extends the functionality of {@link WebSocketClientHandshaker13} by adding SIGV4 authentication headers to the 32 | * request. 33 | */ 34 | public class AwsSigV4ClientHandshaker extends WebSocketClientHandshaker13 { 35 | /** 36 | * Instance of the properties provider to get properties for SIGV4 signing. 37 | */ 38 | private final ChainedSigV4PropertiesProvider sigV4PropertiesProvider; 39 | 40 | /** 41 | * SigV4 properties required to perform the signing. 42 | */ 43 | private final SigV4Properties sigV4Properties; 44 | 45 | /** 46 | * Credentials provider to use to generate signature 47 | */ 48 | private final AWSCredentialsProvider awsCredentialsProvider; 49 | 50 | /** 51 | * Creates a new instance with default credentials provider (for backward compatibility). 52 | * @param webSocketURL - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket 53 | * frames will be sent to this URL. 54 | * @param version - Version of web socket specification to use to connect to the server 55 | * @param subprotocol - Sub protocol request sent to the server. 56 | * @param allowExtensions - Allow extensions to be used in the reserved bits of the web socket frame 57 | * @param customHeaders - Map of custom headers to add to the client request 58 | * @param maxFramePayloadLength - Maximum length of a frame's payload 59 | * @param sigV4PropertiesProvider - a properties provider to get sigV4 auth related properties 60 | */ 61 | @Deprecated 62 | public AwsSigV4ClientHandshaker(final URI webSocketURL, 63 | final WebSocketVersion version, 64 | final String subprotocol, 65 | final boolean allowExtensions, 66 | final HttpHeaders customHeaders, 67 | final int maxFramePayloadLength, 68 | final ChainedSigV4PropertiesProvider sigV4PropertiesProvider) { 69 | this( 70 | webSocketURL, 71 | version, 72 | subprotocol, 73 | allowExtensions, 74 | customHeaders, 75 | maxFramePayloadLength, 76 | sigV4PropertiesProvider, 77 | new DefaultAWSCredentialsProviderChain() 78 | ); 79 | } 80 | 81 | /** 82 | * Creates a new instance. 83 | * @param webSocketURL - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket 84 | * frames will be sent to this URL. 85 | * @param version - Version of web socket specification to use to connect to the server 86 | * @param subprotocol - Sub protocol request sent to the server. 87 | * @param allowExtensions - Allow extensions to be used in the reserved bits of the web socket frame 88 | * @param customHeaders - Map of custom headers to add to the client request 89 | * @param maxFramePayloadLength - Maximum length of a frame's payload 90 | * @param sigV4PropertiesProvider - a properties provider to get sigV4 auth related properties 91 | * @param awsCredentialsProvider - an AWS credentials provider to use to generate signature 92 | */ 93 | public AwsSigV4ClientHandshaker(final URI webSocketURL, 94 | final WebSocketVersion version, 95 | final String subprotocol, 96 | final boolean allowExtensions, 97 | final HttpHeaders customHeaders, 98 | final int maxFramePayloadLength, 99 | final ChainedSigV4PropertiesProvider sigV4PropertiesProvider, 100 | final AWSCredentialsProvider awsCredentialsProvider 101 | ) { 102 | super(webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength); 103 | this.awsCredentialsProvider = awsCredentialsProvider; 104 | this.sigV4PropertiesProvider = sigV4PropertiesProvider; 105 | this.sigV4Properties = loadProperties(); 106 | } 107 | 108 | /** 109 | * Gets the request as generated by {@link WebSocketClientHandshaker13} and adds additional headers and a SIGV4 110 | * signature required for SigV4Auth. 111 | * Sends the opening request to the server: 112 | * GET /chat HTTP/1.1 113 | * Host: server.example.com 114 | * Upgrade: websocket 115 | * Connection: Upgrade 116 | * Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== 117 | * Sec-WebSocket-Origin: http://example.com 118 | * Sec-WebSocket-Protocol: chat, superchat 119 | * Sec-WebSocket-Version: 13 120 | * x-amz-date: 20180214T002049Z 121 | * Authorization: [SIGV4AuthHeader] 122 | * @return SIGV4 signed {@link FullHttpRequest}. 123 | */ 124 | @Override 125 | protected FullHttpRequest newHandshakeRequest() { 126 | final FullHttpRequest request = super.newHandshakeRequest(); 127 | final NeptuneNettyHttpSigV4Signer sigV4Signer; 128 | try { 129 | sigV4Signer = new NeptuneNettyHttpSigV4Signer(this.sigV4Properties.getServiceRegion(), 130 | awsCredentialsProvider); 131 | sigV4Signer.signRequest(request); 132 | } catch (NeptuneSigV4SignerException e) { 133 | throw new RuntimeException("Exception occurred while signing the request", e); 134 | } 135 | return request; 136 | } 137 | 138 | /** 139 | * Calls the {@link ChainedSigV4PropertiesProvider} to get the properties required for SigV4 signing. 140 | * @return an instance of {@link SigV4Properties}. 141 | */ 142 | private SigV4Properties loadProperties() { 143 | return sigV4PropertiesProvider.getSigV4Properties(); 144 | } 145 | } 146 | 147 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/neptune/gremlin/driver/sigv4/ChainedSigV4PropertiesProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.neptune.gremlin.driver.sigv4; 17 | 18 | import com.amazon.neptune.gremlin.driver.exception.SigV4PropertiesNotFoundException; 19 | 20 | import java.util.function.Supplier; 21 | 22 | import org.apache.commons.lang3.StringUtils; 23 | 24 | import lombok.extern.slf4j.Slf4j; 25 | 26 | /** 27 | * A chained Sig4Properties provider. 28 | * It tries to get the properties from environment variables and if not found looks in Java system properties. 29 | */ 30 | @Slf4j 31 | public class ChainedSigV4PropertiesProvider { 32 | 33 | /** 34 | * The chain of provider lambdas that can read properties required for SigV4 signing. 35 | */ 36 | private final Supplier[] providers; 37 | 38 | /** 39 | * Creates an instance with default suppliers. 40 | */ 41 | public ChainedSigV4PropertiesProvider() { 42 | this.providers = new Supplier[]{this::getSigV4PropertiesFromEnv, this::getSigV4PropertiesFromSystem}; 43 | } 44 | 45 | /** 46 | * Creates an instance with the supplied chain of {@link SigV4Properties} providers. 47 | * @param providers the chain of sigv4 properties provider. 48 | */ 49 | public ChainedSigV4PropertiesProvider(final Supplier[] providers) { 50 | this.providers = new Supplier[providers.length]; 51 | System.arraycopy(providers, 0, this.providers, 0, providers.length); 52 | } 53 | 54 | /** 55 | * Gets the {@link SigV4Properties} from the chain of lambdas. 56 | * @return the {@link SigV4Properties}. 57 | * @throws SigV4PropertiesNotFoundException when SigV4 properties are not set. 58 | */ 59 | public SigV4Properties getSigV4Properties() throws SigV4PropertiesNotFoundException { 60 | SigV4Properties properties; 61 | 62 | for (Supplier provider : providers) { 63 | try { 64 | properties = provider.get(); 65 | log.info("Successfully loaded SigV4 properties from provider: {}", provider.getClass()); 66 | return properties; 67 | } catch (SigV4PropertiesNotFoundException e) { 68 | log.info("Unable to load SigV4 properties from provider: {}", provider.getClass()); 69 | } 70 | } 71 | 72 | final String message = "Unable to load SigV4 properties from any of the providers"; 73 | log.warn(message); 74 | throw new SigV4PropertiesNotFoundException(message); 75 | } 76 | 77 | /** 78 | * Reads the SigV4 properties from the environment properties and constructs the {@link SigV4Properties} object. 79 | * @return the {@link SigV4Properties} constructed from system properties. 80 | * @throws SigV4PropertiesNotFoundException when properties are not found in the environment variables. 81 | */ 82 | public SigV4Properties getSigV4PropertiesFromEnv() throws SigV4PropertiesNotFoundException { 83 | final String serviceRegion = StringUtils.trim(System.getenv(SigV4Properties.SERVICE_REGION)); 84 | 85 | if (StringUtils.isBlank(serviceRegion)) { 86 | final String msg = "SigV4 properties not found as a environment variable"; 87 | log.info(msg); 88 | throw new SigV4PropertiesNotFoundException(msg); 89 | } 90 | 91 | return new SigV4Properties(serviceRegion); 92 | } 93 | 94 | /** 95 | * Reads the SigV4 properties from the system properties and constructs the {@link SigV4Properties} object. 96 | * @return the {@link SigV4Properties} constructed from system properties. 97 | * @throws SigV4PropertiesNotFoundException when the properties are not found in the system properties. 98 | */ 99 | public SigV4Properties getSigV4PropertiesFromSystem() { 100 | final String serviceRegion = StringUtils.trim(System.getProperty(SigV4Properties.SERVICE_REGION)); 101 | 102 | if (StringUtils.isBlank(serviceRegion)) { 103 | final String msg = "SigV4 properties not found in system properties"; 104 | log.info(msg); 105 | throw new SigV4PropertiesNotFoundException(msg); 106 | } 107 | 108 | return new SigV4Properties(serviceRegion); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/neptune/gremlin/driver/sigv4/SigV4Properties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | package com.amazon.neptune.gremlin.driver.sigv4; 17 | 18 | /** 19 | * Holds the properties required to perform SIGV4 auth. 20 | */ 21 | public class SigV4Properties { 22 | 23 | /** 24 | * The service region property name. 25 | */ 26 | public static final String SERVICE_REGION = "SERVICE_REGION"; 27 | 28 | /** 29 | * The region of the service. E.g. us-east-1. 30 | */ 31 | private final String serviceRegion; 32 | 33 | /** 34 | * @param serviceRegion the region name for the service. 35 | */ 36 | public SigV4Properties(final String serviceRegion) { 37 | this.serviceRegion = serviceRegion; 38 | } 39 | 40 | /** 41 | * @return the serviceRegion. 42 | */ 43 | public String getServiceRegion() { 44 | return serviceRegion; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/amazon/neptune/gremlin/driver/sigv4/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * Authorization related code for Amazon Neptune, e.g. 18 | * WebSocketHandshake handler and auth related code to handle gremlin calls with SigV4 authentication. 19 | */ 20 | package com.amazon.neptune.gremlin.driver.sigv4; 21 | -------------------------------------------------------------------------------- /src/main/java/org/apache/tinkerpop/gremlin/driver/SigV4WebSocketChannelizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /* 17 | * Licensed to the Apache Software Foundation (ASF) under one 18 | * or more contributor license agreements. See the NOTICE file 19 | * distributed with this work for additional information 20 | * regarding copyright ownership. The ASF licenses this file 21 | * to you under the Apache License, Version 2.0 (the 22 | * "License"); you may not use this file except in compliance 23 | * with the License. You may obtain a copy of the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, 28 | * software distributed under the License is distributed on an 29 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 30 | * KIND, either express or implied. See the License for the 31 | * specific language governing permissions and limitations 32 | * under the License. 33 | */ 34 | 35 | package org.apache.tinkerpop.gremlin.driver; 36 | 37 | import com.amazon.neptune.gremlin.driver.sigv4.AwsSigV4ClientHandshaker; 38 | import com.amazon.neptune.gremlin.driver.sigv4.ChainedSigV4PropertiesProvider; 39 | 40 | import com.amazonaws.auth.AWSCredentialsProvider; 41 | import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; 42 | 43 | import io.netty.channel.Channel; 44 | import io.netty.channel.ChannelPipeline; 45 | import io.netty.handler.codec.http.EmptyHttpHeaders; 46 | import io.netty.handler.codec.http.HttpClientCodec; 47 | import io.netty.handler.codec.http.HttpObjectAggregator; 48 | import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; 49 | import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; 50 | import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker; 51 | import io.netty.handler.codec.http.websocketx.WebSocketVersion; 52 | import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketClientCompressionHandler; 53 | import org.apache.tinkerpop.gremlin.driver.Channelizer.AbstractChannelizer; 54 | import org.apache.tinkerpop.gremlin.driver.exception.ConnectionException; 55 | import org.apache.tinkerpop.gremlin.driver.handler.WebSocketClientHandler; 56 | import org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinRequestEncoder; 57 | import org.apache.tinkerpop.gremlin.driver.handler.WebSocketGremlinResponseDecoder; 58 | 59 | import java.util.concurrent.TimeoutException; 60 | 61 | /** 62 | * An {@link AbstractChannelizer}, with most of the code from {@link WebSocketChannelizer}. Except it uses a 63 | * different WebSocketClientHandshaker which uses SIGV4 auth. This class should be used as a Channelizer when SIGV4 64 | * auth is enabled. 65 | * 66 | * @see 67 | * https://github.com/apache/tinkerpop/blob/master/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Channelizer.java 68 | */ 69 | public class SigV4WebSocketChannelizer extends AbstractChannelizer { 70 | /** 71 | * Constant to denote the websocket protocol. 72 | */ 73 | private static final String WEB_SOCKET = "ws"; 74 | 75 | /** 76 | * Constant to denote the websocket secure protocol. 77 | */ 78 | 79 | private static final String WEB_SOCKET_SECURE = "wss"; 80 | /** 81 | * Name of the HttpCodec handler. 82 | */ 83 | 84 | private static final String HTTP_CODEC = "http-codec"; 85 | /** 86 | * Name of the HttpAggregator handler. 87 | */ 88 | 89 | private static final String AGGREGATOR = "aggregator"; 90 | /** 91 | * Name of the WebSocket handler. 92 | */ 93 | 94 | private static final String WEB_SOCKET_HANDLER = "ws-handler"; 95 | /** 96 | * Name of the GremlinEncoder handler. 97 | */ 98 | 99 | private static final String GREMLIN_ENCODER = "gremlin-encoder"; 100 | /** 101 | * Name of the GremlinDecoder handler. 102 | */ 103 | private static final String GRELIN_DECODER = "gremlin-decoder"; 104 | 105 | /** 106 | * Name of the WebSocket compression handler. 107 | */ 108 | public static final String WEBSOCKET_COMPRESSION_HANDLER = "web-socket-compression-handler"; 109 | 110 | /** 111 | * The handler to process websocket messages from the server. 112 | */ 113 | private WebSocketClientHandler handler; 114 | 115 | /** 116 | * Encoder to encode websocket requests. 117 | */ 118 | private WebSocketGremlinRequestEncoder webSocketGremlinRequestEncoder; 119 | 120 | /** 121 | * Decoder to decode websocket requests. 122 | */ 123 | private WebSocketGremlinResponseDecoder webSocketGremlinResponseDecoder; 124 | 125 | /** 126 | * Initializes the channelizer. 127 | * @param connection the {@link Connection} object. 128 | */ 129 | @Override 130 | public void init(final Connection connection) { 131 | super.init(connection); 132 | webSocketGremlinRequestEncoder = new WebSocketGremlinRequestEncoder(true, cluster.getSerializer()); 133 | webSocketGremlinResponseDecoder = new WebSocketGremlinResponseDecoder(cluster.getSerializer()); 134 | } 135 | 136 | /** 137 | * Keep-alive is supported through the ping/pong websocket protocol. 138 | * @see IETF RFC 6455 139 | */ 140 | @Override 141 | public boolean supportsKeepAlive() { 142 | return true; 143 | } 144 | 145 | @Override 146 | public Object createKeepAliveMessage() { 147 | return new PingWebSocketFrame(); 148 | } 149 | 150 | /** 151 | * Sends a {@code CloseWebSocketFrame} to the server for the specified channel. 152 | */ 153 | @Override 154 | public void close(final Channel channel) { 155 | if (channel.isOpen()) { 156 | channel.writeAndFlush(new CloseWebSocketFrame()); 157 | } 158 | } 159 | 160 | @Override 161 | public boolean supportsSsl() { 162 | final String scheme = connection.getUri().getScheme(); 163 | return "wss".equalsIgnoreCase(scheme); 164 | } 165 | 166 | @Override 167 | public void configure(final ChannelPipeline pipeline) { 168 | final String scheme = connection.getUri().getScheme(); 169 | if (!WEB_SOCKET.equalsIgnoreCase(scheme) && !WEB_SOCKET_SECURE.equalsIgnoreCase(scheme)) { 170 | throw new IllegalStateException(String.format("Unsupported scheme (only %s: or %s: supported): %s", 171 | WEB_SOCKET, WEB_SOCKET_SECURE, scheme)); 172 | } 173 | 174 | if (!supportsSsl() && WEB_SOCKET_SECURE.equalsIgnoreCase(scheme)) { 175 | throw new IllegalStateException(String.format("To use %s scheme ensure that enableSsl is set to true in " 176 | + "configuration", 177 | WEB_SOCKET_SECURE)); 178 | } 179 | 180 | final int maxContentLength = cluster.connectionPoolSettings().maxContentLength; 181 | handler = createHandler(); 182 | 183 | pipeline.addLast(HTTP_CODEC, new HttpClientCodec()); 184 | pipeline.addLast(AGGREGATOR, new HttpObjectAggregator(maxContentLength)); 185 | // Add compression extension for WebSocket defined in https://tools.ietf.org/html/rfc7692 186 | pipeline.addLast(WEBSOCKET_COMPRESSION_HANDLER, WebSocketClientCompressionHandler.INSTANCE); 187 | pipeline.addLast(WEB_SOCKET_HANDLER, handler); 188 | pipeline.addLast(GREMLIN_ENCODER, webSocketGremlinRequestEncoder); 189 | pipeline.addLast(GRELIN_DECODER, webSocketGremlinResponseDecoder); 190 | } 191 | 192 | @Override 193 | public void connected() { 194 | try { 195 | // Block until the handshake is complete either successfully or with an error. The handshake future 196 | // will complete with a timeout exception after some time so it is guaranteed that this future will 197 | // complete. The timeout for the handshake is configured by cluster.getConnectionSetupTimeout(). 198 | // 199 | // If future completed with an exception more than likely, SSL is enabled on the server, but the client 200 | // forgot to enable it or perhaps the server is not configured for websockets. 201 | handler.handshakeFuture().sync(); 202 | } catch (Exception ex) { 203 | final String errMsg; 204 | if (ex instanceof TimeoutException) { 205 | // Note that we are not using catch(TimeoutException ex) because the compiler throws an error for 206 | // catching a checked exception which is not thrown from the code inside try. However, the compiler 207 | // check is incorrect since Netty bypasses the compiler check and sync() is able to rethrow underlying 208 | // exception even if it is a check exception. 209 | // More information about how Netty bypasses compiler check at https://github.com/netty/netty/blob/d371b1bbaa3b98f957f6b025673098ad3adb5131/common/src/main/java/io/netty/util/internal/PlatformDependent.java#L418 210 | errMsg = "Timed out while waiting to complete the connection setup. Consider increasing the " + 211 | "WebSocket handshake timeout duration."; 212 | } else { 213 | errMsg = "Could not complete connection setup to the server. Ensure that SSL is correctly " + 214 | "configured at both the client and the server. Ensure that client WebSocket handshake " + 215 | "protocol matches the server. Ensure that the server is still reachable."; 216 | } 217 | throw new ConnectionException(connection.getUri(), errMsg, ex); 218 | } 219 | } 220 | 221 | /** 222 | * This protected method provides a way for customizing the channelize through inheritance 223 | * to override credentials used to establish sign requests 224 | * 225 | * @return credentials provider that will be used to generate SigV4 signatures 226 | */ 227 | protected AWSCredentialsProvider getCredentialsProvider() { 228 | return new DefaultAWSCredentialsProviderChain(); 229 | } 230 | 231 | /** 232 | * Creates an instance of {@link WebSocketClientHandler} with {@link AwsSigV4ClientHandshaker} as the handshaker 233 | * for SigV4 auth. 234 | * @return the instance of clientHandler. 235 | */ 236 | private WebSocketClientHandler createHandler() { 237 | 238 | WebSocketClientHandshaker handshaker = new AwsSigV4ClientHandshaker( 239 | connection.getUri(), 240 | WebSocketVersion.V13, 241 | null, 242 | true, // allow extensions to support WebSocket compression 243 | EmptyHttpHeaders.INSTANCE, 244 | cluster.getMaxContentLength(), 245 | new ChainedSigV4PropertiesProvider(), 246 | getCredentialsProvider()); 247 | return new WebSocketClientHandler(handshaker, cluster.getConnectionSetupTimeout()); 248 | } 249 | } 250 | -------------------------------------------------------------------------------- /src/main/java/org/apache/tinkerpop/gremlin/driver/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * Package to provide custom channelizers. Channelizers that extend 18 | * {@link org.apache.tinkerpop.gremlin.driver.Channelizer.AbstractChannelizer} should be in this package. 19 | */ 20 | package org.apache.tinkerpop.gremlin.driver; 21 | 22 | --------------------------------------------------------------------------------