├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── pom.xml └── src ├── main └── java │ └── com │ └── github │ └── vaibhavsinha │ └── kong │ ├── api │ ├── admin │ │ ├── ApiPluginService.java │ │ ├── ApiService.java │ │ ├── CertificateService.java │ │ ├── ConsumerService.java │ │ ├── PluginRepoService.java │ │ ├── PluginService.java │ │ ├── SniService.java │ │ ├── TargetService.java │ │ └── UpstreamService.java │ └── plugin │ │ ├── authentication │ │ ├── BasicAuthService.java │ │ ├── HmacAuthService.java │ │ ├── JwtService.java │ │ ├── KeyAuthService.java │ │ ├── OAuth2ManageService.java │ │ └── OAuth2ProcessService.java │ │ └── security │ │ └── AclService.java │ ├── exception │ └── KongClientException.java │ ├── impl │ ├── KongClient.java │ ├── helper │ │ ├── CustomGsonConverterFactory.java │ │ ├── CustomGsonRequestBodyConverter.java │ │ ├── CustomGsonResponseBodyConverter.java │ │ ├── RetrofitBodyExtractorInvocationHandler.java │ │ └── RetrofitServiceCreator.java │ └── service │ │ └── plugin │ │ ├── authentication │ │ ├── BasicAuthServiceImpl.java │ │ ├── HmacAuthServiceImpl.java │ │ ├── JwtAuthServiceImpl.java │ │ └── KeyAuthServiceImpl.java │ │ └── security │ │ └── AclServiceImpl.java │ ├── internal │ ├── admin │ │ ├── RetrofitApiPluginService.java │ │ ├── RetrofitApiService.java │ │ ├── RetrofitCertificateService.java │ │ ├── RetrofitConsumerService.java │ │ ├── RetrofitPluginRepoService.java │ │ ├── RetrofitPluginService.java │ │ ├── RetrofitSniService.java │ │ ├── RetrofitTargetService.java │ │ └── RetrofitUpstreamService.java │ └── plugin │ │ ├── authentication │ │ ├── RetrofitBasicAuthService.java │ │ ├── RetrofitHmacAuthService.java │ │ ├── RetrofitJwtService.java │ │ ├── RetrofitKeyAuthService.java │ │ ├── RetrofitOAuth2ManageService.java │ │ └── RetrofitOAuth2ProcessService.java │ │ └── security │ │ └── RetrofitAclService.java │ ├── model │ ├── admin │ │ ├── api │ │ │ ├── Api.java │ │ │ └── ApiList.java │ │ ├── certificate │ │ │ ├── Certificate.java │ │ │ └── CertificateList.java │ │ ├── consumer │ │ │ ├── Consumer.java │ │ │ └── ConsumerList.java │ │ ├── plugin │ │ │ ├── EnabledPlugins.java │ │ │ ├── OAuth2Config.java │ │ │ ├── Plugin.java │ │ │ └── PluginList.java │ │ ├── sni │ │ │ ├── Sni.java │ │ │ └── SniList.java │ │ ├── target │ │ │ ├── Target.java │ │ │ └── TargetList.java │ │ └── upstream │ │ │ ├── Upstream.java │ │ │ └── UpstreamList.java │ ├── common │ │ └── AbstractEntityList.java │ └── plugin │ │ ├── authentication │ │ ├── basic │ │ │ ├── BasicAuthConfig.java │ │ │ └── BasicAuthCredential.java │ │ ├── hmac │ │ │ ├── HmacAuthConfig.java │ │ │ └── HmacAuthCredential.java │ │ ├── jwt │ │ │ ├── JwtConfig.java │ │ │ ├── JwtCredential.java │ │ │ └── JwtCredentialList.java │ │ ├── key │ │ │ ├── KeyAuthConfig.java │ │ │ ├── KeyAuthCredential.java │ │ │ └── KeyAuthCredentialList.java │ │ ├── ldap │ │ │ └── LdapConfig.java │ │ └── oauth2 │ │ │ ├── Application.java │ │ │ ├── ApplicationList.java │ │ │ ├── AuthorizationRequest.java │ │ │ ├── GrantTokenRequest.java │ │ │ ├── OAuth2Config.java │ │ │ ├── Redirect.java │ │ │ ├── RefreshRequest.java │ │ │ ├── Token.java │ │ │ └── TokenList.java │ │ ├── security │ │ ├── acl │ │ │ ├── Acl.java │ │ │ ├── AclConfig.java │ │ │ └── AclList.java │ │ └── iprestriction │ │ │ └── IpRestrictionConfig.java │ │ └── trafficcontrol │ │ ├── ratelimiting │ │ └── RateLimitingConfig.java │ │ ├── requestsizelimiting │ │ └── RequestSizeLimitingConfig.java │ │ └── requesttermination │ │ └── RequestTerminationConfig.java │ └── utils │ ├── HttpsUtil.java │ └── UrlUtil.java └── test ├── java └── com │ └── github │ └── vaibhavsinha │ └── kong │ ├── BaseTest.java │ ├── RetrofitAclServiceTest.java │ ├── RetrofitApiPluginServiceTest.java │ ├── RetrofitApiServiceTest.java │ ├── RetrofitCertificateServiceTest.java │ ├── RetrofitConsumerServiceTest.java │ ├── RetrofitJwtServiceTest.java │ ├── RetrofitKeyAuthServiceTest.java │ ├── RetrofitPluginRepoServiceTest.java │ ├── RetrofitPluginServiceTest.java │ ├── RetrofitSniServiceTest.java │ ├── RetrofitTargetServiceTest.java │ ├── RetrofitUpstreamServiceTest.java │ └── plugin │ ├── RetrofitOAuth2ManageServiceTest.java │ └── RetrofitOAuth2ProcessServiceTest.java └── resources └── log4j.properties /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Log file 4 | *.log 5 | 6 | # BlueJ files 7 | *.ctxt 8 | 9 | # Mobile Tools for Java (J2ME) 10 | .mtj.tmp/ 11 | 12 | # Package Files # 13 | *.jar 14 | *.war 15 | *.ear 16 | *.zip 17 | *.tar.gz 18 | *.rar 19 | 20 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 21 | hs_err_pid* 22 | 23 | # Eclipse 24 | .classpath 25 | .project 26 | .settings/ 27 | 28 | # Intellij 29 | .idea/ 30 | *.iml 31 | *.iws 32 | 33 | # Mac 34 | .DS_Store 35 | 36 | # Maven 37 | log/ 38 | target/ 39 | 40 | rebel.xml 41 | logs/ 42 | zs/ 43 | lib 44 | *.bak 45 | !/com/github/vaibhavsinha/kong/model/admin/target/ 46 | !/src/main/java/com/github/vaibhavsinha/kong/model/admin/target/ 47 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at vaibhavsinh@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kong Java Client 2 | 3 | [Kong](https://getkong.org/) is a popular Open Source API Gateway. Kong Java Client makes it easy to configure the API Gateway through your code. 4 | 5 | ## Installation 6 | 7 | The artifact is available on Maven Central Repository and be downloaded by adding the following dependency in pom.xml 8 | 9 | 10 | com.github.vaibhav-sinha 11 | kong-java-client 12 | 0.2.0 13 | 14 | 15 | ## Usage 16 | 17 | KongClient kongClient = new KongClient("http://localhost:8001"); 18 | Consumer request = new Consumer(); 19 | request.setCustomId("1234-5678-9012"); 20 | Consumer response = kongClient.getConsumerService().createConsumer(request); 21 | 22 | Look in the tests to find more examples. 23 | 24 | ## Supported Plugins 25 | 26 | Besides the Admin APIs, Plugin configuration is also supported. 27 | 28 | ### Authentication Plugins 29 | * Basic Auth 30 | * Key Auth 31 | * HMAC Auth 32 | * JWT Auth 33 | * OAuth2 34 | * LDAP 35 | 36 | ### Security Plugins 37 | * ACL 38 | * IP Restriction 39 | 40 | ### Traffic Control Plugins 41 | * Rate Limiting 42 | * Request Size Limiting 43 | * Request Termination 44 | 45 | Only those plugins are supported which might need configuration through code. For example, adding rate limit for a new consumer when there is a new signup. Plugins which require one time configuration are not supported. 46 | 47 | ### Example Usage 48 | 49 | To add credentials for a new Consumer for Basic Auth 50 | 51 | kongClient.getBasicAuthService().addCredentials("con-su-mer-id", "username", "password"); 52 | 53 | 54 | To add OAuth2 Plugin for an API 55 | 56 | //See: RetrofitApiPluginServiceTest.java 57 | kongClient.getApiPluginService().addPluginForApi(API_NAME, oauth2Plugin); 58 | 59 | To add an Application for a Consumer for OAuth2 60 | 61 | //See: RetrofitOAuth2ManageServiceTest.java 62 | kongClient.getOAuth2ManageService().createConsumerApplication(CONSUMER_ID, 63 | new Application(appName, appRedirectUrl, appClientId, appClientSecret)); 64 | 65 | To do the OAuth2 Process (Authorization Code) 66 | 67 | //See: RetrofitOAuth2ProcessServiceTest.java 68 | kongClient.getOAuth2ProcessService().authorize(API_URI, authorizationRequest); 69 | kongClient.getOAuth2ProcessService().grantToken(API_URI, grantTokenRequest) 70 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.github.vaibhav-sinha 8 | kong-java-client 9 | 0.2.0 10 | 11 | jar 12 | 13 | kong-java-client 14 | Kong is a popular Open Source API Gateway. Kong Java Client makes it easy to configure the API Gateway through your code. 15 | https://github.com/vaibhav-sinha/kong-java-client 16 | 17 | 18 | 19 | The Apache License, Version 2.0 20 | http://www.apache.org/licenses/LICENSE-2.0.txt 21 | 22 | 23 | 24 | 25 | 26 | Vaibhav Sinha 27 | vaibhavsinh@gmail.com 28 | 29 | 30 | 31 | 32 | scm:git:git://github.com/vaibhav-sinha/kong-java-client.git 33 | scm:git:ssh://github.com:vaibhav-sinha/kong-java-client.git 34 | http://github.com/vaibhav-sinha/kong-java-client/tree/master 35 | 36 | 37 | 38 | 2.3.0 39 | 1.16.16 40 | 1.6.2 41 | 1.1 42 | 1.2.16 43 | 1.0.6 44 | 4.12 45 | 46 | 47 | 48 | 49 | com.squareup.retrofit2 50 | retrofit 51 | ${retrofit.version} 52 | 53 | 54 | com.squareup.retrofit2 55 | converter-gson 56 | ${retrofit.version} 57 | 58 | 59 | com.google.code.gson 60 | gson 61 | 62 | 63 | 64 | 65 | com.google.code.gson 66 | gson 67 | 2.8.1 68 | 69 | 76 | 83 | 84 | 85 | org.projectlombok 86 | lombok 87 | ${lombok.version} 88 | provided 89 | 90 | 91 | 92 | 93 | org.slf4j 94 | slf4j-api 95 | ${slf4j.version} 96 | 97 | 98 | org.slf4j 99 | slf4j-log4j12 100 | ${slf4j.version} 101 | 102 | 103 | commons-logging 104 | commons-logging-api 105 | ${jcl.version} 106 | 107 | 108 | log4j 109 | log4j 110 | ${log4j.version} 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | junit 120 | junit 121 | ${junit.version} 122 | test 123 | 124 | 125 | 126 | 127 | 128 | ossrh 129 | https://oss.sonatype.org/content/repositories/snapshots 130 | 131 | 132 | ossrh 133 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 134 | 135 | 136 | 137 | 138 | 139 | 140 | maven-compiler-plugin 141 | 3.1 142 | 143 | 1.8 144 | 1.8 145 | 146 | 147 | 148 | org.apache.maven.plugins 149 | maven-source-plugin 150 | 2.2.1 151 | 152 | 153 | attach-sources 154 | 155 | jar-no-fork 156 | 157 | 158 | 159 | 160 | 161 | org.apache.maven.plugins 162 | maven-javadoc-plugin 163 | 2.9.1 164 | 165 | 166 | attach-javadocs 167 | 168 | jar 169 | 170 | 171 | 172 | 173 | 174 | org.apache.maven.plugins 175 | maven-gpg-plugin 176 | 1.5 177 | 178 | 179 | sign-artifacts 180 | verify 181 | 182 | sign 183 | 184 | 185 | 186 | 187 | 188 | org.sonatype.plugins 189 | nexus-staging-maven-plugin 190 | 1.6.7 191 | true 192 | 193 | ossrh 194 | https://oss.sonatype.org/ 195 | true 196 | 197 | 198 | 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/admin/ApiPluginService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; 4 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; 5 | 6 | /** 7 | * 8 | * You can add a plugin in four different ways: 9 | * For every API and Consumer. Don't set api_id and consumer_id. 10 | * For every API and a specific Consumer. Only set consumer_id. 11 | * For every Consumer and a specific API. Only set api_id. 12 | * For a specific Consumer and API. Set both api_id and consumer_id. 13 | * Note that not all plugins allow to specify consumer_id. Check the plugin documentation. 14 | */ 15 | public interface ApiPluginService { 16 | 17 | 18 | Plugin addPluginForApi(String apiNameOrId, Plugin plugin); 19 | 20 | Plugin getPluginForApi(String apiNameOrId, String pluginId); 21 | 22 | Plugin updatePluginForApi(String apiNameOrId, String pluginNameOrId, Plugin request); 23 | 24 | @Deprecated 25 | Plugin createOrUpdatePluginForApi(String apiNameOrId, Plugin plugin); 26 | 27 | void deletePluginForApi(String apiNameOrId, String pluginNameOrId); 28 | 29 | PluginList listPluginsForApi(String apiNameOrId, String pluginNameOrId, String apiId, String consumerId, String name, Long size, String offset); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/admin/ApiService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.api.Api; 4 | import com.github.vaibhavsinha.kong.model.admin.api.ApiList; 5 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; 6 | 7 | /** 8 | * Created by vaibhav on 13/06/17. 9 | */ 10 | public interface ApiService { 11 | 12 | Api createApi(Api request); 13 | 14 | Api getApi(String nameOrId); 15 | 16 | Api updateApi(String nameOrId, Api request); 17 | 18 | /** 19 | * This interface has issue in Kong. 20 | * 1. Usually, when we put a API(which not exist in Kong) as a parameter, it should be added as a new one. 21 | * But it only take effect when API id is empty. 22 | * 2. When the API id input is not empty, it will consider to update the existing API. So, we can either 23 | * create a API (without id), or update a API (with id). 24 | * 3. When you try to create a API with name and id, it will become odd. Kong will give you the 200(ok) response, 25 | * but won't create the API that you wanted. (That's why we'd better not use this interface. 26 | * 27 | * */ 28 | @Deprecated 29 | Api createOrUpdateApi(Api request); 30 | 31 | void deleteApi(String nameOrId); 32 | 33 | ApiList listApis(String id, String upstreamUrl, String name, Long retries, Long size, String offset); 34 | PluginList listApiPlugins(String id); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/admin/CertificateService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.certificate.Certificate; 4 | import com.github.vaibhavsinha.kong.model.admin.certificate.CertificateList; 5 | 6 | /** 7 | * Created by vaibhav on 13/06/17. 8 | */ 9 | @Deprecated 10 | public interface CertificateService { 11 | Certificate createCertificate(Certificate request); 12 | Certificate getCertificate(String sniOrId); 13 | Certificate updateCertificate(String sniOrId, Certificate request); 14 | Certificate createOrUpdateCertificate(Certificate request); 15 | Certificate deleteCertificate(String sniOrId); 16 | CertificateList listCertificates(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/admin/ConsumerService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer; 4 | import com.github.vaibhavsinha.kong.model.admin.consumer.ConsumerList; 5 | 6 | /** 7 | * Created by vaibhav on 13/06/17. 8 | */ 9 | public interface ConsumerService { 10 | 11 | Consumer createConsumer(Consumer request); 12 | 13 | Consumer getConsumer(String usernameOrId); 14 | 15 | Consumer updateConsumer(String usernameOrId, Consumer request); 16 | 17 | @Deprecated 18 | Consumer createOrUpdateConsumer(Consumer request); 19 | 20 | void deleteConsumer(String usernameOrId); 21 | 22 | ConsumerList listConsumers(String id, String customId, String username, Long size, String offset); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/admin/PluginRepoService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.plugin.EnabledPlugins; 4 | 5 | public interface PluginRepoService { 6 | 7 | EnabledPlugins retrieveEnabledPlugins(); 8 | 9 | Object retrievePluginSchema(String pluginName); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/admin/PluginService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.plugin.EnabledPlugins; 4 | import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; 5 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; 6 | 7 | /** 8 | * Created by vaibhav on 13/06/17. 9 | * 10 | * You can add a plugin in four different ways: 11 | * For every API and Consumer. Don't set api_id and consumer_id. 12 | * For every API and a specific Consumer. Only set consumer_id. 13 | * For every Consumer and a specific API. Only set api_id. 14 | * For a specific Consumer and API. Set both api_id and consumer_id. 15 | * Note that not all plugins allow to specify consumer_id. Check the plugin documentation. 16 | */ 17 | public interface PluginService { 18 | 19 | 20 | Plugin addPlugin(Plugin request); 21 | 22 | Plugin getPlugin(String nameOrId); 23 | 24 | Plugin updatePlugin(String nameOrId, Plugin request); 25 | 26 | @Deprecated 27 | Plugin createOrUpdatePlugin(Plugin request); 28 | 29 | void deletePlugin(String nameOrId); 30 | 31 | PluginList listPlugins(String id, String apiId, String consumerId, String name, Long size, String offset); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/admin/SniService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.sni.Sni; 4 | import com.github.vaibhavsinha.kong.model.admin.sni.SniList; 5 | 6 | /** 7 | * Created by vaibhav on 13/06/17. 8 | */ 9 | @Deprecated 10 | public interface SniService { 11 | Sni createSni(Sni request); 12 | Sni getSni(String name); 13 | Sni updateSni(String name, Sni request); 14 | Sni createOrUpdateSni(Sni request); 15 | Sni deleteSni(String name); 16 | SniList listSnis(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/admin/TargetService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.target.Target; 4 | import com.github.vaibhavsinha.kong.model.admin.target.TargetList; 5 | 6 | /** 7 | * Created by vaibhav on 13/06/17. 8 | */ 9 | @Deprecated 10 | public interface TargetService { 11 | Target createTarget(String upstreamNameOrId, Target request); 12 | Target deleteTarget(String upstreamNameOrId, String target); 13 | TargetList listTargets(String upstreamNameOrId, String id, Integer weight, String target, Long size, String offset); 14 | TargetList listActiveTargets(String upstreamNameOrId); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/admin/UpstreamService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.upstream.Upstream; 4 | import com.github.vaibhavsinha.kong.model.admin.upstream.UpstreamList; 5 | 6 | /** 7 | * Created by vaibhav on 13/06/17. 8 | */ 9 | @Deprecated 10 | public interface UpstreamService { 11 | Upstream createUpstream(Upstream request); 12 | Upstream getUpstream(String nameOrId); 13 | Upstream updateUpstream(String nameOrId, Upstream request); 14 | Upstream createOrUpdateUpstream(Upstream request); 15 | Upstream deleteUpstream(String nameOrId); 16 | UpstreamList listUpstreams(String id, Integer slots, String name, Long size, String offset); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/BasicAuthService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.plugin.authentication; 2 | 3 | /** 4 | * Created by vaibhav on 15/06/17. 5 | */ 6 | public interface BasicAuthService { 7 | void addCredentials(String consumerIdOrUsername, String username, String password); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/HmacAuthService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.plugin.authentication; 2 | 3 | /** 4 | * Created by vaibhav on 15/06/17. 5 | */ 6 | public interface HmacAuthService { 7 | void addCredentials(String consumerIdOrUsername, String username, String secret); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/JwtService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredential; 4 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredentialList; 5 | 6 | /** 7 | * Created by vaibhav on 16/06/17. 8 | * 9 | * Updated by dvilela on 17/10/17. 10 | */ 11 | public interface JwtService { 12 | JwtCredential addCredentials(String consumerIdOrUsername, JwtCredential request); 13 | void deleteCredentials(String consumerIdOrUsername, String id); 14 | JwtCredentialList listCredentials(String consumerIdOrUsername, Long size, String offset); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/KeyAuthService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredential; 4 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredentialList; 5 | 6 | /** 7 | * Created by vaibhav on 15/06/17. 8 | * 9 | * Updated by dvilela on 17/10/17. 10 | */ 11 | public interface KeyAuthService { 12 | KeyAuthCredential addCredentials(String consumerIdOrUsername, String key); 13 | KeyAuthCredentialList listCredentials(String consumerIdOrUsername, Long size, String offset); 14 | void deleteCredential(String consumerIdOrUsername, String id); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/OAuth2ManageService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.plugin.authentication; 2 | 3 | 4 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Application; 5 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.ApplicationList; 6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Token; 7 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.TokenList; 8 | 9 | public interface OAuth2ManageService { 10 | 11 | // App Management --------------------------------------------------------------------------------------------------- 12 | 13 | Application createConsumerApplication(String consumerId, Application request); 14 | 15 | Application getConsumerApplication(String consumerId, String applicationId); 16 | 17 | Application updateConsumerApplication(String consumerId, String applicationId, Application request); 18 | 19 | void deleteConsumerApplication(String consumerId, String applicationId); 20 | 21 | ApplicationList listConsumerApplications(String consumerId); 22 | 23 | ApplicationList listClientApplications(String applicationId, String applicatonName, String clientId, String clientSecret, String consumerId); 24 | 25 | // Token Management --------------------------------------------------------------------------------------------------- 26 | 27 | Token createToken(Token request); 28 | 29 | Token getToken(String tokenId); 30 | 31 | Token updateToken(String tokenId, Token request); 32 | 33 | TokenList listTokens(); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/plugin/authentication/OAuth2ProcessService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.*; 4 | 5 | import java.util.Map; 6 | 7 | public interface OAuth2ProcessService { 8 | 9 | 10 | // OAuth2 Process --------------------------------------------------------------------------------------------------- 11 | 12 | 13 | Map authorize(String apiUri, AuthorizationRequest request); 14 | 15 | Token grantToken(String apiUri, GrantTokenRequest request); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/api/plugin/security/AclService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.api.plugin.security; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.AclList; 4 | 5 | /** 6 | * Created by vaibhav on 18/06/17. 7 | * 8 | * Upated by dvilela on 22/10/17. 9 | */ 10 | public interface AclService { 11 | void associateConsumer(String usernameOrId, String group); 12 | AclList listAcls(String usernameOrId, Long size, String offset); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/exception/KongClientException.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.exception; 2 | 3 | /** 4 | * Created by vaibhav on 13/06/17. 5 | * 6 | * Updated by dvilela on 11/08/17. 7 | */ 8 | public class KongClientException extends RuntimeException { 9 | 10 | private int code; 11 | 12 | private String error; 13 | 14 | public KongClientException(String message) { 15 | super(message); 16 | } 17 | 18 | public KongClientException(String message, int code, String error) { 19 | super(message); 20 | this.code = code; 21 | this.error = error; 22 | } 23 | 24 | public int getCode() { 25 | return code; 26 | } 27 | 28 | public String getError() { 29 | return error; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/KongClient.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl; 2 | 3 | import com.github.vaibhavsinha.kong.api.admin.*; 4 | import com.github.vaibhavsinha.kong.api.plugin.authentication.*; 5 | import com.github.vaibhavsinha.kong.api.plugin.security.AclService; 6 | import com.github.vaibhavsinha.kong.impl.helper.RetrofitServiceCreator; 7 | import com.github.vaibhavsinha.kong.impl.service.plugin.authentication.BasicAuthServiceImpl; 8 | import com.github.vaibhavsinha.kong.impl.service.plugin.authentication.HmacAuthServiceImpl; 9 | import com.github.vaibhavsinha.kong.impl.service.plugin.authentication.JwtAuthServiceImpl; 10 | import com.github.vaibhavsinha.kong.impl.service.plugin.authentication.KeyAuthServiceImpl; 11 | import com.github.vaibhavsinha.kong.impl.service.plugin.security.AclServiceImpl; 12 | import com.github.vaibhavsinha.kong.internal.admin.*; 13 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.*; 14 | import com.github.vaibhavsinha.kong.internal.plugin.security.RetrofitAclService; 15 | import lombok.Data; 16 | 17 | /** 18 | * Created by vaibhav on 12/06/17. 19 | * 20 | * Updated by fanhua on 2017-08-07. 21 | * 22 | * Updated by dvilela on 17/10/17. 23 | */ 24 | @Data 25 | public class KongClient { 26 | 27 | private ConsumerService consumerService; 28 | 29 | private ApiService apiService; 30 | private ApiPluginService apiPluginService; 31 | 32 | private PluginService pluginService; 33 | private PluginRepoService pluginRepoService; 34 | private CertificateService certificateService; 35 | private SniService sniService; 36 | private UpstreamService upstreamService; 37 | private TargetService targetService; 38 | 39 | private BasicAuthService basicAuthService; 40 | private KeyAuthService keyAuthService; 41 | private HmacAuthService hmacAuthService; 42 | private JwtService jwtService; 43 | 44 | private OAuth2ProcessService oAuth2ProcessService; 45 | private OAuth2ManageService oAuth2ManageService; 46 | 47 | private AclService aclService; 48 | 49 | 50 | public KongClient(String adminUrl) { 51 | this(adminUrl, null, false); 52 | } 53 | 54 | 55 | public KongClient(String adminUrl, String proxyUrl, boolean needOAuth2Support) { 56 | 57 | if (adminUrl == null || adminUrl.isEmpty()) { 58 | throw new IllegalArgumentException("The adminUrl cannot be null or empty!"); 59 | } 60 | 61 | if (needOAuth2Support) { 62 | if (proxyUrl == null || proxyUrl.isEmpty()) { 63 | throw new IllegalArgumentException("The proxyUrl cannot be null or empty!"); 64 | } 65 | if (!proxyUrl.startsWith("https://")) { 66 | throw new IllegalArgumentException("The proxyUrl must use https if you need OAuth2 support!"); 67 | } 68 | } 69 | 70 | 71 | RetrofitServiceCreator retrofitServiceCreatorForAdminUrl = new RetrofitServiceCreator(adminUrl); 72 | 73 | { 74 | consumerService = retrofitServiceCreatorForAdminUrl.create(ConsumerService.class, RetrofitConsumerService.class); 75 | 76 | apiService = retrofitServiceCreatorForAdminUrl.create(ApiService.class, RetrofitApiService.class); 77 | apiPluginService = retrofitServiceCreatorForAdminUrl.create(ApiPluginService.class, RetrofitApiPluginService.class); 78 | 79 | pluginService = retrofitServiceCreatorForAdminUrl.create(PluginService.class, RetrofitPluginService.class); 80 | pluginRepoService = retrofitServiceCreatorForAdminUrl.create(PluginRepoService.class, RetrofitPluginRepoService.class); 81 | 82 | certificateService = retrofitServiceCreatorForAdminUrl.create(CertificateService.class, RetrofitCertificateService.class); 83 | sniService = retrofitServiceCreatorForAdminUrl.create(SniService.class, RetrofitSniService.class); 84 | upstreamService = retrofitServiceCreatorForAdminUrl.create(UpstreamService.class, RetrofitUpstreamService.class); 85 | targetService = retrofitServiceCreatorForAdminUrl.create(TargetService.class, RetrofitTargetService.class); 86 | } 87 | 88 | { 89 | basicAuthService = new BasicAuthServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitBasicAuthService.class)); 90 | keyAuthService = new KeyAuthServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitKeyAuthService.class)); 91 | hmacAuthService = new HmacAuthServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitHmacAuthService.class)); 92 | jwtService = new JwtAuthServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitJwtService.class)); 93 | aclService = new AclServiceImpl(retrofitServiceCreatorForAdminUrl.createRetrofitService(RetrofitAclService.class)); 94 | } 95 | 96 | if(needOAuth2Support) { 97 | 98 | RetrofitServiceCreator retrofitServiceCreatorForProxyUrl = new RetrofitServiceCreator(proxyUrl); 99 | 100 | //oauth2 process is on proxy port 101 | oAuth2ProcessService = retrofitServiceCreatorForProxyUrl.create(OAuth2ProcessService.class, RetrofitOAuth2ProcessService.class); 102 | 103 | //oauth2 manage is on admin port 104 | oAuth2ManageService = retrofitServiceCreatorForAdminUrl.create(OAuth2ManageService.class, RetrofitOAuth2ManageService.class); 105 | } 106 | 107 | } 108 | 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/helper/CustomGsonConverterFactory.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.helper; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.TypeAdapter; 5 | import com.google.gson.reflect.TypeToken; 6 | import okhttp3.RequestBody; 7 | import okhttp3.ResponseBody; 8 | import retrofit2.Converter; 9 | import retrofit2.Retrofit; 10 | 11 | import java.lang.annotation.Annotation; 12 | import java.lang.reflect.Type; 13 | 14 | class CustomGsonConverterFactory extends Converter.Factory { 15 | 16 | private final Gson gson; 17 | 18 | private CustomGsonConverterFactory(Gson gson) { 19 | if (gson == null) throw new NullPointerException("gson == null"); 20 | this.gson = gson; 21 | } 22 | 23 | public static CustomGsonConverterFactory create() { 24 | return create(new Gson()); 25 | } 26 | 27 | public static CustomGsonConverterFactory create(Gson gson) { 28 | return new CustomGsonConverterFactory(gson); 29 | } 30 | 31 | @Override 32 | public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { 33 | TypeAdapter adapter = gson.getAdapter(TypeToken.get(type)); 34 | return new CustomGsonResponseBodyConverter<>(gson, adapter); 35 | } 36 | 37 | @Override 38 | public Converter requestBodyConverter(Type type,Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) { 39 | TypeAdapter adapter = gson.getAdapter(TypeToken.get(type)); 40 | return new CustomGsonRequestBodyConverter<>(gson, adapter); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/helper/CustomGsonRequestBodyConverter.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.helper; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.TypeAdapter; 5 | import com.google.gson.stream.JsonWriter; 6 | import okhttp3.MediaType; 7 | import okhttp3.RequestBody; 8 | import okio.Buffer; 9 | import retrofit2.Converter; 10 | 11 | import java.io.IOException; 12 | import java.io.OutputStreamWriter; 13 | import java.io.Writer; 14 | import java.nio.charset.Charset; 15 | 16 | final class CustomGsonRequestBodyConverter implements Converter { 17 | 18 | private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8"); 19 | private static final Charset UTF_8 = Charset.forName("UTF-8"); 20 | 21 | private final Gson gson; 22 | private final TypeAdapter adapter; 23 | 24 | CustomGsonRequestBodyConverter(Gson gson, TypeAdapter adapter) { 25 | this.gson = gson; 26 | this.adapter = adapter; 27 | } 28 | 29 | @Override 30 | public RequestBody convert(T value) throws IOException { 31 | Buffer buffer = new Buffer(); 32 | Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8); 33 | JsonWriter jsonWriter = gson.newJsonWriter(writer); 34 | adapter.write(jsonWriter, value); 35 | jsonWriter.close(); 36 | return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/helper/CustomGsonResponseBodyConverter.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.helper; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.TypeAdapter; 5 | import com.google.gson.stream.JsonReader; 6 | import lombok.extern.slf4j.Slf4j; 7 | import okhttp3.MediaType; 8 | import okhttp3.ResponseBody; 9 | import retrofit2.Converter; 10 | 11 | import java.io.ByteArrayInputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.io.InputStreamReader; 15 | import java.io.Reader; 16 | import java.nio.charset.Charset; 17 | 18 | @Slf4j 19 | final class CustomGsonResponseBodyConverter implements Converter { 20 | 21 | private static final Charset UTF_8 = Charset.forName("UTF-8"); 22 | 23 | private final Gson gson; 24 | private final TypeAdapter adapter; 25 | 26 | CustomGsonResponseBodyConverter(Gson gson, TypeAdapter adapter) { 27 | this.gson = gson; 28 | this.adapter = adapter; 29 | } 30 | 31 | @Override 32 | public T convert(ResponseBody value) throws IOException { 33 | 34 | String response = value.string(); 35 | 36 | if(response == null || response.isEmpty()) { 37 | //It may response empty body... 38 | log.debug("Response empty body..."); 39 | return null; 40 | } 41 | 42 | MediaType contentType = value.contentType(); 43 | Charset charset = contentType != null ? contentType.charset(UTF_8) : UTF_8; 44 | InputStream inputStream = new ByteArrayInputStream(response.getBytes()); 45 | Reader reader = new InputStreamReader(inputStream, charset); 46 | JsonReader jsonReader = gson.newJsonReader(reader); 47 | 48 | try { 49 | return adapter.read(jsonReader); 50 | } finally { 51 | value.close(); 52 | } 53 | 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/helper/RetrofitBodyExtractorInvocationHandler.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.helper; 2 | 3 | import com.github.vaibhavsinha.kong.exception.KongClientException; 4 | import lombok.extern.slf4j.Slf4j; 5 | import retrofit2.Call; 6 | import retrofit2.Response; 7 | 8 | import java.lang.reflect.InvocationHandler; 9 | import java.lang.reflect.Method; 10 | 11 | /** 12 | * Created by vaibhav on 13/06/17. 13 | */ 14 | @Slf4j 15 | public class RetrofitBodyExtractorInvocationHandler implements InvocationHandler { 16 | 17 | private Object proxied; 18 | 19 | public RetrofitBodyExtractorInvocationHandler(Object proxied) { 20 | this.proxied = proxied; 21 | } 22 | 23 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 24 | String methodName = method.getName(); 25 | Class[] parameterTypes = method.getParameterTypes(); 26 | Method method1 = proxied.getClass().getMethod(methodName, parameterTypes); 27 | Call call = (Call) method1.invoke(proxied, args); 28 | Response response = call.execute(); 29 | log.debug("Http Request: " + response.raw().request()); 30 | log.debug("Http Response: " + response.raw().toString()); 31 | if(!response.isSuccessful()) { 32 | throw new KongClientException(response.errorBody() != null ? response.errorBody().string() : String.valueOf(response.code())); 33 | } 34 | return response.body(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/helper/RetrofitServiceCreator.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.helper; 2 | 3 | //import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; 4 | import com.github.vaibhavsinha.kong.utils.HttpsUtil; 5 | import okhttp3.OkHttpClient; 6 | import retrofit2.Retrofit; 7 | //import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 8 | //import retrofit2.converter.gson.GsonConverterFactory; 9 | 10 | import java.lang.reflect.Proxy; 11 | 12 | /** 13 | * Created by vaibhav on 13/06/17. 14 | * 15 | * Update by fanhua on 2017-07-28. 16 | */ 17 | public class RetrofitServiceCreator { 18 | 19 | private Retrofit retrofit; 20 | 21 | 22 | // ------------------------------------------------------------------- 23 | 24 | public RetrofitServiceCreator(String baseUrl) { 25 | 26 | retrofit = new Retrofit.Builder() 27 | .baseUrl(baseUrl) 28 | .client(initOkHttpClient(baseUrl.toLowerCase().startsWith("https"))) // support https 29 | .addConverterFactory(CustomGsonConverterFactory.create()) // replace GsonConverterFactory 30 | // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // add rxJava1 support 31 | // .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // add rxJava2 support 32 | .build(); 33 | 34 | } 35 | 36 | // ------------------------------------------------------------------- 37 | 38 | @SuppressWarnings("unchecked") 39 | public T create(Class serviceInterface, Class retrofitServiceInterface) { 40 | Object proxied = retrofit.create(retrofitServiceInterface); 41 | return (T) Proxy.newProxyInstance( 42 | RetrofitServiceCreator.class.getClassLoader(), 43 | new Class[] { serviceInterface }, 44 | new RetrofitBodyExtractorInvocationHandler(proxied)); 45 | } 46 | 47 | public T createRetrofitService(Class retrofitServiceInterface) { 48 | return retrofit.create(retrofitServiceInterface); 49 | } 50 | 51 | // ------------------------------------------------------------------- 52 | 53 | private OkHttpClient initOkHttpClient(boolean supportHttps) { 54 | 55 | if(supportHttps) { 56 | HttpsUtil.SSLParams sslParams = HttpsUtil.getSslSocketFactory(null, null, null); 57 | OkHttpClient okHttpClient = new OkHttpClient.Builder() 58 | .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager) 59 | .build(); 60 | return okHttpClient; 61 | } 62 | 63 | return new OkHttpClient.Builder().build(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/BasicAuthServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.service.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.api.plugin.authentication.BasicAuthService; 4 | import com.github.vaibhavsinha.kong.exception.KongClientException; 5 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitBasicAuthService; 6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.basic.BasicAuthCredential; 7 | import retrofit2.Retrofit; 8 | import retrofit2.converter.gson.GsonConverterFactory; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by vaibhav on 15/06/17. 14 | * 15 | * Updated by fanhua on 2017-08-07. 16 | */ 17 | public class BasicAuthServiceImpl implements BasicAuthService { 18 | 19 | private RetrofitBasicAuthService retrofitBasicAuthService; 20 | 21 | public BasicAuthServiceImpl(RetrofitBasicAuthService retrofitBasicAuthService) { 22 | this.retrofitBasicAuthService = retrofitBasicAuthService; 23 | } 24 | 25 | @Override 26 | public void addCredentials(String consumerIdOrUsername, String username, String password) { 27 | try { 28 | retrofitBasicAuthService.addCredentials(consumerIdOrUsername, new BasicAuthCredential(username, password)).execute(); 29 | } catch (IOException e) { 30 | throw new KongClientException(e.getMessage()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/HmacAuthServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.service.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.api.plugin.authentication.HmacAuthService; 4 | import com.github.vaibhavsinha.kong.exception.KongClientException; 5 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitHmacAuthService; 6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.hmac.HmacAuthCredential; 7 | import retrofit2.Retrofit; 8 | import retrofit2.converter.gson.GsonConverterFactory; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by vaibhav on 15/06/17. 14 | * 15 | * Updated by fanhua on 2017-08-07. 16 | */ 17 | public class HmacAuthServiceImpl implements HmacAuthService { 18 | 19 | private RetrofitHmacAuthService retrofitHmacAuthService; 20 | 21 | public HmacAuthServiceImpl(RetrofitHmacAuthService retrofitHmacAuthService) { 22 | this.retrofitHmacAuthService = retrofitHmacAuthService; 23 | } 24 | 25 | @Override 26 | public void addCredentials(String consumerIdOrUsername, String username, String secret) { 27 | try { 28 | retrofitHmacAuthService.addCredentials(consumerIdOrUsername, new HmacAuthCredential(username, secret)).execute(); 29 | } catch (IOException e) { 30 | throw new KongClientException(e.getMessage()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/JwtAuthServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.service.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.api.plugin.authentication.JwtService; 4 | import com.github.vaibhavsinha.kong.exception.KongClientException; 5 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitJwtService; 6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredential; 7 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredentialList; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Created by dvilela on 10/16/17. 13 | */ 14 | public class JwtAuthServiceImpl implements JwtService { 15 | 16 | private RetrofitJwtService retrofitJwtService; 17 | 18 | public JwtAuthServiceImpl(RetrofitJwtService retrofitJwtService) { 19 | this.retrofitJwtService = retrofitJwtService; 20 | } 21 | 22 | @Override 23 | public JwtCredential addCredentials(String consumerIdOrUsername, JwtCredential request) { 24 | try { 25 | return retrofitJwtService.addCredentials(consumerIdOrUsername, request).execute().body(); 26 | } catch (IOException e) { 27 | throw new KongClientException(e.getMessage()); 28 | } 29 | } 30 | 31 | @Override 32 | public void deleteCredentials(String consumerIdOrUsername, String id) { 33 | try { 34 | retrofitJwtService.deleteCredentials(consumerIdOrUsername, id).execute(); 35 | } catch (IOException e) { 36 | throw new KongClientException(e.getMessage()); 37 | } 38 | } 39 | 40 | @Override 41 | public JwtCredentialList listCredentials(String consumerIdOrUsername, Long size, String offset) { 42 | try { 43 | return retrofitJwtService.listCredentials(consumerIdOrUsername, size, offset).execute().body(); 44 | } catch (IOException e) { 45 | throw new KongClientException(e.getMessage()); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/authentication/KeyAuthServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.service.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.api.plugin.authentication.KeyAuthService; 4 | import com.github.vaibhavsinha.kong.exception.KongClientException; 5 | import com.github.vaibhavsinha.kong.internal.plugin.authentication.RetrofitKeyAuthService; 6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredential; 7 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredentialList; 8 | import retrofit2.Response; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by vaibhav on 15/06/17. 14 | * 15 | * Updated by fanhua on 2017-08-07. 16 | * 17 | * Updated by dvilela on 17/10/17. 18 | */ 19 | public class KeyAuthServiceImpl implements KeyAuthService { 20 | 21 | private RetrofitKeyAuthService retrofitKeyAuthService; 22 | 23 | public KeyAuthServiceImpl(RetrofitKeyAuthService retrofitKeyAuthService) { 24 | this.retrofitKeyAuthService = retrofitKeyAuthService; 25 | } 26 | 27 | @Override 28 | public KeyAuthCredential addCredentials(String consumerIdOrUsername, String key) { 29 | try { 30 | Response res = retrofitKeyAuthService.addCredentials(consumerIdOrUsername, 31 | new KeyAuthCredential(key)).execute(); 32 | if (res.code() == 201) { 33 | return res.body(); 34 | } 35 | throw new KongClientException("Could not create credentials", res.code(), res.message()); 36 | } catch (IOException e) { 37 | throw new KongClientException(e.getMessage()); 38 | } 39 | } 40 | 41 | @Override 42 | public KeyAuthCredentialList listCredentials(String consumerIdOrUsername, Long size, String offset) { 43 | try { 44 | return retrofitKeyAuthService.listCredentials(consumerIdOrUsername, size, offset).execute().body(); 45 | } catch (IOException e) { 46 | throw new KongClientException(e.getMessage()); 47 | } 48 | } 49 | 50 | @Override 51 | public void deleteCredential(String consumerIdOrUsername, String id) { 52 | try { 53 | retrofitKeyAuthService.deleteCredential(consumerIdOrUsername, id).execute(); 54 | } catch (IOException e) { 55 | throw new KongClientException(e.getMessage()); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/impl/service/plugin/security/AclServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.impl.service.plugin.security; 2 | 3 | import com.github.vaibhavsinha.kong.api.plugin.security.AclService; 4 | import com.github.vaibhavsinha.kong.exception.KongClientException; 5 | import com.github.vaibhavsinha.kong.internal.plugin.security.RetrofitAclService; 6 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.Acl; 7 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.AclList; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Created by vaibhav on 18/06/17. 13 | * 14 | * Updated by fanhua on 2017-08-07. 15 | * 16 | * Upated by dvilela on 22/10/17. 17 | */ 18 | public class AclServiceImpl implements AclService { 19 | 20 | private RetrofitAclService retrofitAclService; 21 | 22 | public AclServiceImpl(RetrofitAclService retrofitAclService) { 23 | this.retrofitAclService = retrofitAclService; 24 | } 25 | @Override 26 | public void associateConsumer(String usernameOrId, String group) { 27 | try { 28 | retrofitAclService.associateConsumer(usernameOrId, new Acl(group)).execute(); 29 | } catch (IOException e) { 30 | throw new KongClientException(e.getMessage()); 31 | } 32 | } 33 | 34 | @Override 35 | public AclList listAcls(String usernameOrId, Long size, String offset) { 36 | try { 37 | return retrofitAclService.listAcls(usernameOrId, size, offset).execute().body(); 38 | } catch (IOException e) { 39 | throw new KongClientException(e.getMessage()); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitApiPluginService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; 4 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; 5 | 6 | import retrofit2.Call; 7 | import retrofit2.http.Body; 8 | import retrofit2.http.DELETE; 9 | import retrofit2.http.GET; 10 | import retrofit2.http.PATCH; 11 | import retrofit2.http.POST; 12 | import retrofit2.http.PUT; 13 | import retrofit2.http.Path; 14 | import retrofit2.http.Query; 15 | 16 | /** 17 | * Created by fanhua on 2017-08-05. 18 | */ 19 | public interface RetrofitApiPluginService { 20 | 21 | 22 | @POST("/apis/{api}/plugins") 23 | Call addPluginForApi(@Path("api") String apiNameOrId, @Body Plugin plugin); 24 | 25 | @GET("/apis/{api}/plugins/{id}") 26 | Call getPluginForApi(@Path("api") String apiNameOrId, @Path("id") String pluginId); 27 | 28 | @PATCH("/apis/{api}/plugins/{id}") 29 | Call updatePluginForApi(@Path("api") String apiNameOrId, @Path("id") String pluginNameOrId, @Body Plugin request); 30 | 31 | @PUT("/apis/{api}/plugins") 32 | Call createOrUpdatePluginForApi(@Path("api") String apiNameOrId, @Body Plugin plugin); 33 | 34 | @DELETE("/apis/{api}/plugins/{id}") 35 | Call deletePluginForApi(@Path("api") String apiNameOrId, @Path("id") String pluginNameOrId); 36 | 37 | @GET("/apis/{api}/plugins/") 38 | Call listPluginsForApi(@Path("api") String apiNameOrId, @Query("id") String pluginNameOrId, @Query("api_id") String apiId, 39 | @Query("consumer_id") String consumerId, @Query("name") String name, @Query("size") Long size, @Query("offset") String offset); 40 | 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitApiService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.api.Api; 4 | import com.github.vaibhavsinha.kong.model.admin.api.ApiList; 5 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; 6 | import retrofit2.Call; 7 | import retrofit2.http.*; 8 | 9 | /** 10 | * Created by vaibhav on 12/06/17. 11 | */ 12 | public interface RetrofitApiService { 13 | 14 | @POST("apis/") 15 | Call createApi(@Body Api request); 16 | 17 | @GET("apis/{id}") 18 | Call getApi(@Path("id") String nameOrId); 19 | 20 | @PATCH("apis/{id}") 21 | Call updateApi(@Path("id") String nameOrId, @Body Api request); 22 | 23 | @Deprecated 24 | @PUT("apis/") 25 | Call createOrUpdateApi(@Body Api request); 26 | 27 | @DELETE("apis/{id}") 28 | Call deleteApi(@Path("id") String nameOrId); 29 | 30 | @GET("apis/") 31 | Call listApis(@Query("id") String id, @Query("upstream_url") String upstreamUrl, @Query("name") String name, @Query("retries") Long retries, @Query("size") Long size, @Query("offset") String offset); 32 | 33 | 34 | @GET("apis/{id}/plugins") 35 | Call listApiPlugins(@Path("id") String nameOrId); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitCertificateService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.certificate.Certificate; 4 | import com.github.vaibhavsinha.kong.model.admin.certificate.CertificateList; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | /** 9 | * Created by vaibhav on 12/06/17. 10 | */ 11 | public interface RetrofitCertificateService { 12 | 13 | @POST("certificates/") 14 | Call createCertificate(@Body Certificate request); 15 | 16 | @GET("certificates/{id}") 17 | Call getCertificate(@Path("id") String sniOrId); 18 | 19 | @PATCH("certificates/{id}") 20 | Call updateCertificate(@Path("id") String sniOrId, @Body Certificate request); 21 | 22 | @PUT("certificates/") 23 | Call createOrUpdateCertificate(@Body Certificate request); 24 | 25 | @DELETE("certificates/{id}") 26 | Call deleteCertificate(@Path("id") String sniOrId); 27 | 28 | @GET("certificates/") 29 | Call listCertificates(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitConsumerService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer; 4 | import com.github.vaibhavsinha.kong.model.admin.consumer.ConsumerList; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | /** 9 | * Created by vaibhav on 12/06/17. 10 | */ 11 | public interface RetrofitConsumerService { 12 | 13 | @POST("consumers/") 14 | Call createConsumer(@Body Consumer request); 15 | 16 | @GET("consumers/{id}") 17 | Call getConsumer(@Path("id") String usernameOrId); 18 | 19 | @PATCH("consumers/{id}") 20 | Call updateConsumer(@Path("id") String usernameOrId, @Body Consumer request); 21 | 22 | @PUT("consumers/") 23 | Call createOrUpdateConsumer(@Body Consumer request); 24 | 25 | @DELETE("consumers/{id}") 26 | Call deleteConsumer(@Path("id") String usernameOrId); 27 | 28 | @GET("consumers/") 29 | Call listConsumers(@Query("id") String id, @Query("custom_id") String customId, @Query("username") String username, @Query("size") Long size, @Query("offset") String offset); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitPluginRepoService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.plugin.EnabledPlugins; 4 | import retrofit2.Call; 5 | import retrofit2.http.GET; 6 | import retrofit2.http.Path; 7 | 8 | /** 9 | * Created by fanhua on 2017-08-05. 10 | */ 11 | public interface RetrofitPluginRepoService { 12 | 13 | @GET("/plugins/enabled") 14 | Call retrieveEnabledPlugins(); 15 | 16 | 17 | @GET("/plugins/schema/{plugin}") 18 | Call retrievePluginSchema(@Path("plugin") String pluginName); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitPluginService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.admin; 2 | 3 | 4 | import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; 5 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; 6 | import retrofit2.Call; 7 | import retrofit2.http.*; 8 | 9 | /** 10 | * Created by vaibhav on 12/06/17. 11 | * 12 | * Updated by fanhua on 2017-08-05. 13 | */ 14 | public interface RetrofitPluginService { 15 | 16 | @POST("plugins/") 17 | Call addPlugin(@Body Plugin request); 18 | 19 | @GET("plugins/{id}") 20 | Call getPlugin(@Path("id") String nameOrId); 21 | 22 | @PATCH("plugins/{id}") 23 | Call updatePlugin(@Path("id") String nameOrId, @Body Plugin request); 24 | 25 | @PUT("plugins/") 26 | Call createOrUpdatePlugin(@Body Plugin request); 27 | 28 | @DELETE("plugins/{id}") 29 | Call deletePlugin(@Path("id") String nameOrId); 30 | 31 | @GET("plugins/") 32 | Call listPlugins(@Query("id") String id, @Query("api_id") String apiId, @Query("consumer_id") String consumerId, @Query("name") String name, @Query("size") Long size, @Query("offset") String offset); 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitSniService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.sni.Sni; 4 | import com.github.vaibhavsinha.kong.model.admin.sni.SniList; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | /** 9 | * Created by vaibhav on 12/06/17. 10 | */ 11 | public interface RetrofitSniService { 12 | 13 | @POST("snis/") 14 | Call createSni(@Body Sni request); 15 | 16 | @GET("snis/{name}") 17 | Call getSni(@Path("name") String name); 18 | 19 | @PATCH("snis/{name}") 20 | Call updateSni(@Path("name") String name, @Body Sni request); 21 | 22 | @PUT("snis/") 23 | Call createOrUpdateSni(@Body Sni request); 24 | 25 | @DELETE("snis/{name}") 26 | Call deleteSni(@Path("name") String name); 27 | 28 | @GET("snis/") 29 | Call listSnis(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitTargetService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.target.Target; 4 | import com.github.vaibhavsinha.kong.model.admin.target.TargetList; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | public interface RetrofitTargetService { 12 | 13 | @POST("upstreams/{id}/targets") 14 | Call createTarget(@Path("id") String upstreamNameOrId, @Body Target request); 15 | 16 | @DELETE("upstreams/{id}/targets/{target}") 17 | Call deleteTarget(@Path("id") String upstreamNameOrId, @Path("target") String target); 18 | 19 | @GET("upstreams/{id}/targets") 20 | Call listTargets(@Path("id") String upstreamNameOrId, @Query("id") String id, @Query("weight") Integer weight, @Query("target") String target, @Query("size") Long size, @Query("offset") String offset); 21 | 22 | @GET("upstreams/{id}/targets/active") 23 | Call listActiveTargets(@Path("id") String upstreamNameOrId); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/admin/RetrofitUpstreamService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.admin; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.upstream.Upstream; 4 | import com.github.vaibhavsinha.kong.model.admin.upstream.UpstreamList; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | /** 9 | * Created by vaibhav on 12/06/17. 10 | */ 11 | public interface RetrofitUpstreamService { 12 | 13 | @POST("upstreams/") 14 | Call createUpstream(@Body Upstream request); 15 | 16 | @GET("upstreams/{id}") 17 | Call getUpstream(@Path("id") String nameOrId); 18 | 19 | @PATCH("upstreams/{id}") 20 | Call updateUpstream(@Path("id") String nameOrId, @Body Upstream request); 21 | 22 | @PUT("upstreams/") 23 | Call createOrUpdateUpstream(@Body Upstream request); 24 | 25 | @DELETE("upstreams/{id}") 26 | Call deleteUpstream(@Path("id") String nameOrId); 27 | 28 | @GET("upstreams/") 29 | Call listUpstreams(@Query("id") String id, @Query("slots") Integer slots, @Query("name") String name, @Query("size") Long size, @Query("offset") String offset); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/plugin/authentication/RetrofitBasicAuthService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.basic.BasicAuthCredential; 4 | import retrofit2.Call; 5 | import retrofit2.http.Body; 6 | import retrofit2.http.POST; 7 | import retrofit2.http.Path; 8 | 9 | /** 10 | * Created by vaibhav on 15/06/17. 11 | */ 12 | public interface RetrofitBasicAuthService { 13 | 14 | @POST("consumers/{id}/basic-auth") 15 | Call addCredentials(@Path("id") String consumerIdOrUsername, @Body BasicAuthCredential request); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/plugin/authentication/RetrofitHmacAuthService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.hmac.HmacAuthCredential; 4 | import retrofit2.Call; 5 | import retrofit2.http.Body; 6 | import retrofit2.http.POST; 7 | import retrofit2.http.Path; 8 | 9 | /** 10 | * Created by vaibhav on 15/06/17. 11 | */ 12 | public interface RetrofitHmacAuthService { 13 | 14 | @POST("consumers/{id}/hmac-auth") 15 | Call addCredentials(@Path("id") String consumerIdOrUsername, @Body HmacAuthCredential request); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/plugin/authentication/RetrofitJwtService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredential; 4 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredentialList; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | /** 9 | * Created by vaibhav on 16/06/17. 10 | * 11 | * Updated by dvilela on 17/10/17. 12 | */ 13 | public interface RetrofitJwtService { 14 | 15 | @POST("consumers/{consumer}/jwt") 16 | Call addCredentials(@Path("consumer") String consumerIdOrUsername, @Body JwtCredential request); 17 | 18 | @DELETE("consumers/{consumer}/jwt/{id}") 19 | Call deleteCredentials(@Path("consumer") String consumerIdOrUsername, @Path("id") String id); 20 | 21 | @GET("consumers/{consumer}/jwt") 22 | Call listCredentials(@Path("consumer") String consumerIdOrUsername, @Query("size") Long size, @Query("offset") String offset); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/plugin/authentication/RetrofitKeyAuthService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredential; 4 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredentialList; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | /** 9 | * Created by vaibhav on 15/06/17. 10 | * 11 | * Updated by dvilela on 17/10/17. 12 | */ 13 | public interface RetrofitKeyAuthService { 14 | 15 | @POST("consumers/{id}/key-auth") 16 | Call addCredentials(@Path("id") String consumerIdOrUsername, @Body KeyAuthCredential request); 17 | 18 | @GET("consumers/{id}/key-auth") 19 | Call listCredentials(@Path("id") String consumerIdOrUsername, @Query("size") Long size, @Query("offset") String offset); 20 | 21 | @DELETE("consumers/{consumer}/key-auth/{id}") 22 | Call deleteCredential(@Path("consumer") String consumer, @Path("id") String id); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/plugin/authentication/RetrofitOAuth2ManageService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.plugin.authentication; 2 | 3 | import java.util.Map; 4 | 5 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Application; 6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.ApplicationList; 7 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.AuthorizationRequest; 8 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.GrantTokenRequest; 9 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Token; 10 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.TokenList; 11 | 12 | import retrofit2.Call; 13 | import retrofit2.http.Body; 14 | import retrofit2.http.DELETE; 15 | import retrofit2.http.GET; 16 | import retrofit2.http.PATCH; 17 | import retrofit2.http.POST; 18 | import retrofit2.http.Path; 19 | import retrofit2.http.Query; 20 | 21 | /** 22 | * Created by fanhua on 2017-08-07. 23 | */ 24 | public interface RetrofitOAuth2ManageService { 25 | 26 | 27 | // App Management --------------------------------------------------------------------------------------------------- 28 | 29 | /** 30 | * Create OAuth2 application for the consumer 31 | * */ 32 | @POST("/consumers/{consumer_id}/oauth2") 33 | Call createConsumerApplication(@Path("consumer_id") String consumerId, @Body Application request); 34 | 35 | @GET("/consumers/{consumer_id}/oauth2/{id}") 36 | Call getConsumerApplication(@Path("consumer_id") String consumerId, @Path("id") String applicationId); 37 | 38 | @PATCH("/consumers/{consumer_id}/oauth2/{id}") 39 | Call updateConsumerApplication(@Path("consumer_id") String consumerId, @Path("id") String applicationId, @Body Application request); 40 | 41 | @DELETE("/consumers/{consumer_id}/oauth2/{id}") 42 | Call deleteConsumerApplication(@Path("consumer_id") String consumerId, @Path("id") String applicationId); 43 | 44 | 45 | /** 46 | * Get OAuth2 application list of the consumer, only consumerId accepted... 47 | * */ 48 | @GET("/consumers/{consumer_id}/oauth2") 49 | Call listConsumerApplications(@Path("consumer_id") String consumerId); 50 | 51 | 52 | /** 53 | * List Client OAuth2 applications, by id / name / client_id / client_secret / consumer_id (and or) 54 | * */ 55 | @GET("/oauth2") 56 | Call listClientApplications(@Query("id") String applicationId, @Query("name") String applicatonName, @Query("client_id") String clientId, 57 | @Query("client_secret") String clientSecret, @Query("consumer_id") String consumerId); 58 | 59 | 60 | // Token Management --------------------------------------------------------------------------------------------------- 61 | 62 | 63 | @POST("/oauth2_tokens") 64 | Call createToken(@Body Token request); 65 | 66 | 67 | @GET("/oauth2_tokens/{id}") 68 | Call getToken(@Path("id") String tokenId); 69 | 70 | @PATCH("/oauth2_tokens/{id}") 71 | Call updateToken(@Path("id") String tokenId, @Body Token request); 72 | 73 | @DELETE("/oauth2_tokens/{id}") 74 | Call deleteToken(@Path("id") String tokenId); 75 | 76 | 77 | @POST("/oauth2_tokens") 78 | Call listTokens(); 79 | 80 | 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/plugin/authentication/RetrofitOAuth2ProcessService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.plugin.authentication; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.*; 4 | import retrofit2.Call; 5 | import retrofit2.http.*; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * Created by fanhua on 2017-08-07. 11 | * 12 | * Attention: 13 | * According to the @Path regulation, the @Path parameter name must match \{([a-zA-Z][a-zA-Z0-9_-]*)\ 14 | * Which means, you cannot input slash "/" inside the content of "api_uri" 15 | */ 16 | public interface RetrofitOAuth2ProcessService { 17 | 18 | 19 | // OAuth2 Process --------------------------------------------------------------------------------------------------- 20 | 21 | @POST("/{api_uri}/oauth2/authorize") 22 | Call> authorize(@Path(value = "api_uri", encoded = true) String apiUri, @Body AuthorizationRequest request); 23 | 24 | 25 | @POST("/{api_uri}/oauth2/token") 26 | Call grantToken(@Path(value = "api_uri", encoded = true) String apiUri, @Body GrantTokenRequest request); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/internal/plugin/security/RetrofitAclService.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.internal.plugin.security; 2 | 3 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.Acl; 4 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.AclList; 5 | import retrofit2.Call; 6 | import retrofit2.http.*; 7 | 8 | /** 9 | * Created by vaibhav on 18/06/17. 10 | * 11 | * Upated by dvilela on 22/10/17. 12 | */ 13 | public interface RetrofitAclService { 14 | @POST("consumers/{id}/acls") 15 | Call associateConsumer(@Path("id") String consumerIdOrUsername, @Body Acl request); 16 | 17 | @GET("consumers/{id}/acls") 18 | Call listAcls(@Path("id") String consumerIdOrUsername, @Query("size") Long size, @Query("offset") String offset); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/api/Api.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.api; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | @Data 12 | public class Api { 13 | 14 | @SerializedName("created_at") 15 | private Long createdAt; 16 | 17 | @SerializedName("hosts") 18 | private Object hosts; //sometimes array, sometimes map 19 | // private List hosts = null; 20 | 21 | @SerializedName("uris") 22 | private List uris; 23 | 24 | @SerializedName("methods") 25 | private List methods; 26 | 27 | @SerializedName("http_if_terminated") 28 | private Boolean httpIfTerminated; 29 | 30 | @SerializedName("https_only") 31 | private Boolean httpsOnly; 32 | 33 | @SerializedName("id") 34 | private String id; 35 | 36 | @SerializedName("name") 37 | private String name; 38 | 39 | @SerializedName("preserve_host") 40 | private Boolean preserveHost; 41 | 42 | @SerializedName("retries") 43 | private Integer retries; 44 | 45 | @SerializedName("strip_uri") 46 | private Boolean stripUri; 47 | 48 | @SerializedName("upstream_connect_timeout") 49 | private Integer upstreamConnectTimeout; 50 | 51 | @SerializedName("upstream_read_timeout") 52 | private Integer upstreamReadTimeout; 53 | 54 | @SerializedName("upstream_send_timeout") 55 | private Integer upstreamSendTimeout; 56 | 57 | @SerializedName("upstream_url") 58 | private String upstreamUrl; 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/api/ApiList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.api; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | @Data 12 | public class ApiList extends AbstractEntityList { 13 | Long total; 14 | String next; 15 | List data; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/certificate/Certificate.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.certificate; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 14/06/17. 10 | */ 11 | @Data 12 | public class Certificate { 13 | 14 | @SerializedName("id") 15 | private String id; 16 | @SerializedName("cert") 17 | private String cert; 18 | @SerializedName("key") 19 | private String key; 20 | @SerializedName("snis") 21 | private List snis; 22 | @SerializedName("created_at") 23 | private Long createdAt; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/certificate/CertificateList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.certificate; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | @Data 12 | public class CertificateList extends AbstractEntityList { 13 | Long total; 14 | List data; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/consumer/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.consumer; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 12/06/17. 8 | */ 9 | @Data 10 | public class Consumer { 11 | 12 | String id; 13 | 14 | @SerializedName("custom_id") 15 | String customId; 16 | 17 | @SerializedName("created_at") 18 | Long createdAt; 19 | 20 | String username; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/consumer/ConsumerList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.consumer; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | @Data 12 | public class ConsumerList extends AbstractEntityList { 13 | Long total; 14 | String next; 15 | List data; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/plugin/EnabledPlugins.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.plugin; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 14/06/17. 10 | */ 11 | @Data 12 | public class EnabledPlugins { 13 | 14 | @SerializedName("enabled_plugins") 15 | List enabledPlugins; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/plugin/OAuth2Config.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.plugin; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by fanhua on 2017-8-28 10 | */ 11 | @Data 12 | public class OAuth2Config { 13 | 14 | @SerializedName("provision_key") 15 | private String provisionKey; 16 | 17 | @SerializedName("scopes") 18 | private List scopes; 19 | 20 | @SerializedName("mandatory_scope") 21 | private boolean mandatoryScope; 22 | 23 | @SerializedName("token_expiration") 24 | private int tokenExpiration; 25 | 26 | @SerializedName("anonymous") 27 | private String anonymous; 28 | 29 | @SerializedName("accept_http_if_already_terminated") 30 | private boolean acceptHttpIfAlreadyTerminated; 31 | 32 | @SerializedName("enable_authorization_code") 33 | private boolean enableAuthorizationCode; 34 | 35 | @SerializedName("enable_implicit_grant") 36 | private boolean enableImplicitGrant; 37 | 38 | @SerializedName("enable_password_grant") 39 | private boolean enablePasswordGrant; 40 | 41 | @SerializedName("enable_client_credentials") 42 | private boolean enableClientCredentials; 43 | 44 | @SerializedName("global_credentials") 45 | private boolean globalCredentials; 46 | 47 | @SerializedName("hide_credentials") 48 | private boolean hideCredentials; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/plugin/Plugin.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.plugin; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | * 11 | * You can add a plugin in four different ways: 12 | * For every API and Consumer. Don't set api_id and consumer_id. 13 | * For every API and a specific Consumer. Only set consumer_id. 14 | * For every Consumer and a specific API. Only set api_id. 15 | * For a specific Consumer and API. Set both api_id and consumer_id. 16 | * Note that not all plugins allow to specify consumer_id. Check the plugin documentation. 17 | * 18 | */ 19 | @Data 20 | public class Plugin { 21 | 22 | @SerializedName("id") 23 | private String id; 24 | 25 | @SerializedName("api_id") 26 | private String apiId; 27 | 28 | @SerializedName("consumer_id") 29 | private String consumerId; 30 | 31 | @SerializedName("name") 32 | private String name; //must 33 | 34 | @SerializedName("config") 35 | private Object config; //must 36 | 37 | @SerializedName("enabled") 38 | private Boolean enabled; 39 | 40 | @SerializedName("created_at") 41 | private Long createdAt; 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/plugin/PluginList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.plugin; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | @Data 12 | public class PluginList extends AbstractEntityList { 13 | Long total; 14 | String next; 15 | List data; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/sni/Sni.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.sni; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 13/06/17. 8 | */ 9 | @Data 10 | public class Sni { 11 | @SerializedName("ssl_certificate_id") 12 | private String sslCertificateId; 13 | @SerializedName("name") 14 | private String name; 15 | @SerializedName("created_at") 16 | private Long createdAt; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/sni/SniList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.sni; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | @Data 12 | public class SniList extends AbstractEntityList { 13 | Long total; 14 | List data; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/target/Target.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.target; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 14/06/17. 8 | */ 9 | @Data 10 | public class Target { 11 | 12 | @SerializedName("id") 13 | private String id; 14 | @SerializedName("target") 15 | private String target; 16 | @SerializedName("weight") 17 | private Long weight; 18 | @SerializedName("upstream_id") 19 | private String upstreamId; 20 | @SerializedName("created_at") 21 | private Long createdAt; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/target/TargetList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.target; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | @Data 12 | public class TargetList extends AbstractEntityList { 13 | Long total; 14 | String next; 15 | List data; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/upstream/Upstream.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.upstream; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | @Data 12 | public class Upstream { 13 | 14 | @SerializedName("id") 15 | private String id; 16 | @SerializedName("slots") 17 | private Integer slots; 18 | @SerializedName("name") 19 | private String name; 20 | @SerializedName("orderlist") 21 | private List orderList; 22 | @SerializedName("created_at") 23 | private Long createdAt; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/admin/upstream/UpstreamList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.admin.upstream; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 13/06/17. 10 | */ 11 | @Data 12 | public class UpstreamList extends AbstractEntityList { 13 | Long total; 14 | String next; 15 | List data; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/common/AbstractEntityList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.common; 2 | 3 | import com.github.vaibhavsinha.kong.utils.UrlUtil; 4 | 5 | /** 6 | * Created by vaibhav on 13/06/17. 7 | */ 8 | public abstract class AbstractEntityList { 9 | 10 | public String getNext() { 11 | return null; 12 | } 13 | 14 | public String getOffset() { 15 | if(getNext() == null) { 16 | return null; 17 | } 18 | else { 19 | return UrlUtil.splitQueryString(getNext()).get("offset"); 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/basic/BasicAuthConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.basic; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 17/06/17. 8 | */ 9 | @Data 10 | public class BasicAuthConfig { 11 | 12 | @SerializedName("hide_credentials") 13 | Boolean hideCredentials; 14 | @SerializedName("anonymous") 15 | String anonymous; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/basic/BasicAuthCredential.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.basic; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * Created by vaibhav on 15/06/17. 9 | */ 10 | @Data 11 | @NoArgsConstructor 12 | public class BasicAuthCredential { 13 | 14 | @SerializedName("id") 15 | private String id; 16 | @SerializedName("username") 17 | private String username; 18 | @SerializedName("password") 19 | private String password; 20 | @SerializedName("consumer_id") 21 | private String consumerId; 22 | @SerializedName("created_at") 23 | private Long createdAt; 24 | 25 | public BasicAuthCredential(String username, String password) { 26 | this.username = username; 27 | this.password = password; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/hmac/HmacAuthConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.hmac; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 17/06/17. 8 | */ 9 | @Data 10 | public class HmacAuthConfig { 11 | 12 | @SerializedName("hide_credentials") 13 | Boolean hideCredentials; 14 | @SerializedName("anonymous") 15 | String anonymous; 16 | @SerializedName("clock_skew") 17 | Integer clockSkew; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/hmac/HmacAuthCredential.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.hmac; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * Created by vaibhav on 15/06/17. 9 | */ 10 | @Data 11 | @NoArgsConstructor 12 | public class HmacAuthCredential { 13 | 14 | @SerializedName("id") 15 | private String id; 16 | @SerializedName("username") 17 | private String username; 18 | @SerializedName("secret") 19 | private String secret; 20 | @SerializedName("consumer_id") 21 | private String consumerId; 22 | @SerializedName("created_at") 23 | private Long createdAt; 24 | 25 | public HmacAuthCredential(String username, String secret) { 26 | this.username = username; 27 | this.secret = secret; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/jwt/JwtConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.jwt; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 17/06/17. 10 | */ 11 | @Data 12 | public class JwtConfig { 13 | 14 | @SerializedName("key_claim_name") 15 | String keyClaimName; 16 | @SerializedName("anonymous") 17 | String anonymous; 18 | @SerializedName("claims_to_verify") 19 | List claimsToVerify; 20 | @SerializedName("uri_param_names") 21 | List uriParamNames; 22 | @SerializedName("secret_is_base64") 23 | Boolean secretIsBase64; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/jwt/JwtCredential.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.jwt; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * Created by vaibhav on 16/06/17. 9 | * 10 | * Updated by dvilela on 17/10/17. 11 | */ 12 | @Data 13 | @NoArgsConstructor 14 | public class JwtCredential { 15 | 16 | @SerializedName("rsa_public_key") 17 | private String rsaPublicKey; 18 | @SerializedName("consumer_id") 19 | private String consumerId; 20 | @SerializedName("id") 21 | private String id; 22 | @SerializedName("created_at") 23 | private Long createdAt; 24 | @SerializedName("key") 25 | private String key; 26 | @SerializedName("algorithm") 27 | private String algorithm; 28 | @SerializedName("secret") 29 | private String secret; 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/jwt/JwtCredentialList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.jwt; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 16/06/17. 10 | */ 11 | @Data 12 | public class JwtCredentialList extends AbstractEntityList { 13 | Long total; 14 | List data; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/key/KeyAuthConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.key; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 17/06/17. 10 | */ 11 | @Data 12 | public class KeyAuthConfig { 13 | 14 | @SerializedName("hide_credentials") 15 | Boolean hideCredentials; 16 | @SerializedName("anonymous") 17 | String anonymous; 18 | @SerializedName("key_names") 19 | List keyNames; 20 | @SerializedName("key_in_body") 21 | Boolean keyInBody; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/key/KeyAuthCredential.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.key; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * Created by vaibhav on 15/06/17. 9 | */ 10 | @Data 11 | @NoArgsConstructor 12 | public class KeyAuthCredential { 13 | 14 | @SerializedName("id") 15 | private String id; 16 | @SerializedName("key") 17 | private String key; 18 | @SerializedName("consumer_id") 19 | private String consumerId; 20 | @SerializedName("created_at") 21 | private Long createdAt; 22 | 23 | public KeyAuthCredential(String key) { 24 | this.key = key; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/key/KeyAuthCredentialList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.key; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by dvilela on 17/10/2017. 10 | */ 11 | @Data 12 | public class KeyAuthCredentialList extends AbstractEntityList { 13 | Long total; 14 | List data; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/ldap/LdapConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.ldap; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 17/06/17. 10 | */ 11 | @Data 12 | public class LdapConfig { 13 | 14 | @SerializedName("hide_credentials") 15 | Boolean hideCredentials; 16 | @SerializedName("anonymous") 17 | String anonymous; 18 | @SerializedName("ldap_host") 19 | String ldapHost; 20 | @SerializedName("ldap_port") 21 | Integer ldapPort; 22 | @SerializedName("start_tls") 23 | Boolean startTls; 24 | @SerializedName("base_dn") 25 | String baseDn; 26 | @SerializedName("verify_ldap_host") 27 | Boolean verifyLdapHost; 28 | @SerializedName("attribute") 29 | String attribute; 30 | @SerializedName("cache_ttl") 31 | Integer cacheTtl; 32 | @SerializedName("timeout") 33 | Integer timeout; 34 | @SerializedName("keepalive") 35 | Integer keepalive; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/Application.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 15/06/17. 10 | */ 11 | @Data 12 | public class Application { 13 | 14 | @SerializedName("id") 15 | private String id; 16 | 17 | @SerializedName("name") 18 | private String name; 19 | 20 | @SerializedName("client_secret") 21 | private String clientSecret; 22 | 23 | @SerializedName("client_id") 24 | private String clientId; 25 | 26 | @SerializedName("redirect_uri") 27 | private List redirectUri; 28 | 29 | @SerializedName("created_at") 30 | private Long createdAt; 31 | 32 | public Application(String name, List redirectUri, String clientId, String clientSecret) { 33 | this.name = name; 34 | this.redirectUri = redirectUri; 35 | this.clientId = clientId; 36 | this.clientSecret = clientSecret; 37 | } 38 | 39 | public Application(String name, List redirectUri) { 40 | this(name, redirectUri, null, null); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/ApplicationList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 15/06/17. 10 | */ 11 | @Data 12 | public class ApplicationList extends AbstractEntityList { 13 | 14 | Long total; 15 | 16 | List data; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/AuthorizationRequest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 15/06/17. 8 | * 9 | * Updated by fanhua on 2017-08-07. 10 | */ 11 | @Data 12 | public class AuthorizationRequest { 13 | 14 | @SerializedName("id") 15 | private String id; 16 | 17 | @SerializedName("client_id") 18 | private String clientId; 19 | 20 | /** 21 | * The response type, "code" or "token". 22 | * "code" for Authorization Code process, "token" for implicit grant process. 23 | * */ 24 | @SerializedName("response_type") 25 | private String responseType; 26 | 27 | @SerializedName("created_at") 28 | private Long createdAt; 29 | 30 | @SerializedName("provision_key") 31 | private String provisionKey; 32 | 33 | @SerializedName("scope") 34 | private String scope; 35 | 36 | @SerializedName("authenticated_userid") 37 | private String authenticatedUserid; 38 | 39 | @SerializedName("username") 40 | private String username; 41 | 42 | @SerializedName("password") 43 | private String password; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/GrantTokenRequest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import lombok.Data; 6 | 7 | /** 8 | * Created by fanhua on 2017-08-07. 9 | */ 10 | @Data 11 | public class GrantTokenRequest { 12 | 13 | @SerializedName("id") 14 | private String id; 15 | 16 | @SerializedName("client_id") 17 | private String clientId; 18 | 19 | @SerializedName("client_secret") 20 | private String clientSecret; 21 | 22 | /** 23 | * The grant type: "authorization_code", "password", "client_credentials", or "refresh_token". 24 | * "authorization_code" for Authorization Code process, the response will contain both access_token & refresh_token. 25 | * "password" for Password Credentials process, the response will contain both access_token & refresh_token. 26 | * "client_credentials" for Client Credentials process, the response will contain access_token only. 27 | * "refresh_token" for Refresh Token process, the response will contain both access_token & refresh_token. 28 | * */ 29 | @SerializedName("grant_type") 30 | private String grantType; 31 | 32 | @SerializedName("created_at") 33 | private Long createdAt; 34 | 35 | @SerializedName("provision_key") 36 | private String provisionKey; 37 | 38 | @SerializedName("scope") 39 | private String scope; 40 | 41 | @SerializedName("authenticated_userid") 42 | private String authenticatedUserid; 43 | 44 | @SerializedName("username") 45 | private String username; 46 | 47 | @SerializedName("password") 48 | private String password; 49 | 50 | /** 51 | * Only used in "Authorization Code" process 52 | * */ 53 | @SerializedName("code") 54 | private String code; 55 | 56 | /** 57 | * Only used in "Refresh Token" process 58 | * */ 59 | @SerializedName("refresh_token") 60 | private String refreshToken; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/OAuth2Config.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by vaibhav on 17/06/17. 10 | * 11 | * Updated by fanhua on 2017-08-04. 12 | */ 13 | @Deprecated 14 | @Data 15 | public class OAuth2Config { 16 | 17 | @SerializedName("provision_key") 18 | private String provisionKey; 19 | 20 | @SerializedName("scopes") 21 | List scopes; 22 | 23 | @SerializedName("mandatory_scope") 24 | Boolean mandatoryScope; 25 | 26 | @SerializedName("token_expiration") 27 | Integer tokenExpiration; 28 | 29 | @SerializedName("enable_authorization_code") 30 | Boolean enableAuthorizationCode; 31 | 32 | @SerializedName("enable_client_credentials") 33 | Boolean enableClientCredentials; 34 | 35 | @SerializedName("enable_implicit_grant") 36 | Boolean enableImplicitGrant; 37 | 38 | @SerializedName("enable_password_grant") 39 | Boolean enablePasswordGrant; 40 | 41 | @SerializedName("hide_credentials") 42 | Boolean hideCredentials; 43 | 44 | @SerializedName("global_credentials") 45 | Boolean globalCredentials; 46 | 47 | @SerializedName("accept_http_if_already_terminated") 48 | Boolean acceptHttpIfAlreadyTerminated; 49 | 50 | @SerializedName("anonymous") 51 | String anonymous; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/Redirect.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 15/06/17. 8 | */ 9 | @Data 10 | public class Redirect { 11 | @SerializedName("redirect_uri") 12 | String redirectUri; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/RefreshRequest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 15/06/17. 8 | */ 9 | @Deprecated 10 | @Data 11 | public class RefreshRequest { 12 | 13 | @SerializedName("refresh_token") 14 | private String refreshToken; 15 | 16 | @SerializedName("client_id") 17 | private String clientId; 18 | 19 | @SerializedName("client_secret") 20 | private String clientSecret; 21 | 22 | @SerializedName("grant_type") 23 | private String grantType = "refresh_token"; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/Token.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 15/06/17. 8 | */ 9 | @Data 10 | public class Token { 11 | 12 | @SerializedName("id") 13 | private String id; 14 | 15 | @SerializedName("credential_id") 16 | private String credentialId; 17 | 18 | @SerializedName("token_type") 19 | private String tokenType; 20 | 21 | @SerializedName("access_token") 22 | private String accessToken; 23 | 24 | @SerializedName("refresh_token") 25 | private String refreshToken; 26 | 27 | @SerializedName("created_at") 28 | private Long createdAt; 29 | 30 | @SerializedName("expires_in") 31 | private Long expiresIn; 32 | 33 | @SerializedName("scope") 34 | private String scope; 35 | 36 | @SerializedName("authenticated_userid") 37 | private String authenticatedUserid; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/authentication/oauth2/TokenList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2; 2 | 3 | import java.util.List; 4 | 5 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 6 | 7 | import lombok.Data; 8 | 9 | /** 10 | * Created by fanhua on 2017-08-07. 11 | */ 12 | @Data 13 | public class TokenList extends AbstractEntityList { 14 | 15 | Long total; 16 | 17 | List data; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/security/acl/Acl.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.security.acl; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * Created by vaibhav on 18/06/17. 9 | */ 10 | @Data 11 | @NoArgsConstructor 12 | public class Acl { 13 | @SerializedName("id") 14 | private String id; 15 | @SerializedName("group") 16 | private String group; 17 | @SerializedName("consumer_id") 18 | private String consumerId; 19 | @SerializedName("created_at") 20 | private Long createdAt; 21 | 22 | public Acl(String group) { 23 | this.group = group; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/security/acl/AclConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.security.acl; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by vaibhav on 18/06/17. 9 | */ 10 | @Data 11 | public class AclConfig { 12 | List whitelist; 13 | List blacklist; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/security/acl/AclList.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.security.acl; 2 | 3 | import com.github.vaibhavsinha.kong.model.common.AbstractEntityList; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by dvilela on 10/22/17. 10 | */ 11 | @Data 12 | public class AclList extends AbstractEntityList { 13 | Long total; 14 | List data; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/security/iprestriction/IpRestrictionConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.security.iprestriction; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by vaibhav on 18/06/17. 9 | */ 10 | @Data 11 | public class IpRestrictionConfig { 12 | List whitelist; 13 | List blacklist; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/trafficcontrol/ratelimiting/RateLimitingConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.trafficcontrol.ratelimiting; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 17/06/17. 8 | */ 9 | @Data 10 | public class RateLimitingConfig { 11 | 12 | @SerializedName("second") 13 | Integer second; 14 | @SerializedName("minute") 15 | Integer minute; 16 | @SerializedName("hour") 17 | Integer hour; 18 | @SerializedName("day") 19 | Integer day; 20 | @SerializedName("month") 21 | Integer month; 22 | @SerializedName("year") 23 | Integer year; 24 | @SerializedName("limit_by") 25 | LimitBy limitBy; 26 | @SerializedName("policy") 27 | Policy policy; 28 | @SerializedName("fault_tolerant") 29 | Boolean faultTolerant; 30 | @SerializedName("redis_host") 31 | String redisHost; 32 | @SerializedName("redis_port") 33 | Integer redisPort; 34 | @SerializedName("redis_password") 35 | String redisPassword; 36 | @SerializedName("redis_timeout") 37 | Integer redisTimeout; 38 | @SerializedName("redis_database") 39 | Integer redisDatabase; 40 | 41 | public enum Policy { 42 | local, cluster, redis 43 | } 44 | 45 | public enum LimitBy { 46 | consumer, credential, ip 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/trafficcontrol/requestsizelimiting/RequestSizeLimitingConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.trafficcontrol.requestsizelimiting; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 18/06/17. 8 | */ 9 | @Data 10 | public class RequestSizeLimitingConfig { 11 | @SerializedName("allowed_payload_size") 12 | Integer allowedPayloadSize; 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/model/plugin/trafficcontrol/requesttermination/RequestTerminationConfig.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.model.plugin.trafficcontrol.requesttermination; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by vaibhav on 18/06/17. 8 | */ 9 | @Data 10 | public class RequestTerminationConfig { 11 | @SerializedName("status_code") 12 | Integer statusCode; 13 | @SerializedName("message") 14 | String message; 15 | @SerializedName("body") 16 | String body; 17 | @SerializedName("content_type") 18 | String contentType; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/utils/HttpsUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.utils; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.security.KeyManagementException; 6 | import java.security.KeyStore; 7 | import java.security.KeyStoreException; 8 | import java.security.NoSuchAlgorithmException; 9 | import java.security.UnrecoverableKeyException; 10 | import java.security.cert.CertificateException; 11 | import java.security.cert.CertificateFactory; 12 | import java.security.cert.X509Certificate; 13 | 14 | import javax.net.ssl.HostnameVerifier; 15 | import javax.net.ssl.KeyManager; 16 | import javax.net.ssl.KeyManagerFactory; 17 | import javax.net.ssl.SSLContext; 18 | import javax.net.ssl.SSLSession; 19 | import javax.net.ssl.SSLSocketFactory; 20 | import javax.net.ssl.TrustManager; 21 | import javax.net.ssl.TrustManagerFactory; 22 | import javax.net.ssl.X509TrustManager; 23 | 24 | 25 | /** 26 | * Https Util. 27 | * Refer to : https://github.com/hongyangAndroid/okhttputils 28 | * 29 | * 设置可访问所有的https网站 30 | * HttpsUtil.SSLParams sslParams = HttpsUtil.getSslSocketFactory(null, null, null); 31 | * OkHttpClient okHttpClient = new OkHttpClient.Builder() 32 | * .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager) 33 | * //其他配置 34 | * .build(); 35 | * 36 | * 设置具体的证书 37 | * HttpsUtil.SSLParams sslParams = HttpsUtil.getSslSocketFactory(证书的inputstream, null, null); 38 | * OkHttpClient okHttpClient = new OkHttpClient.Builder() 39 | * .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)) 40 | * //其他配置 41 | * .build(); 42 | * 43 | * 双向认证 44 | * HttpsUtil.getSslSocketFactory( 45 | * 证书的inputstream, 46 | * 本地证书的inputstream, 47 | * 本地证书的密码) 48 | * 49 | * */ 50 | public class HttpsUtil { 51 | 52 | private static final String HTTPS_SSL_TYPE_TLS = "TLS"; 53 | private static final String CERTIFICATE_TYPE_X509 = "X.509"; 54 | private static final String LOCAL_KEY_STORE_TYPE_BKS = "BKS"; 55 | 56 | public static class SSLParams { 57 | public SSLSocketFactory sSLSocketFactory; 58 | public X509TrustManager trustManager; 59 | } 60 | 61 | public static SSLParams getSslSocketFactory(InputStream[] certificates, InputStream bksFile, String password) { 62 | SSLParams sslParams = new SSLParams(); 63 | try { 64 | TrustManager[] trustManagers = prepareTrustManager(certificates); 65 | KeyManager[] keyManagers = prepareKeyManager(bksFile, password); 66 | SSLContext sslContext = SSLContext.getInstance(HTTPS_SSL_TYPE_TLS); 67 | X509TrustManager trustManager = null; 68 | if (trustManagers != null) { 69 | trustManager = new MyTrustManager(chooseTrustManager(trustManagers)); 70 | } else { 71 | trustManager = new UnSafeTrustManager(); 72 | } 73 | sslContext.init(keyManagers, new TrustManager[] { trustManager }, null); 74 | sslParams.sSLSocketFactory = sslContext.getSocketFactory(); 75 | sslParams.trustManager = trustManager; 76 | return sslParams; 77 | } catch (NoSuchAlgorithmException e) { 78 | throw new AssertionError(e); 79 | } catch (KeyManagementException e) { 80 | throw new AssertionError(e); 81 | } catch (KeyStoreException e) { 82 | throw new AssertionError(e); 83 | } 84 | } 85 | 86 | private class UnSafeHostnameVerifier implements HostnameVerifier { 87 | @Override 88 | public boolean verify(String hostname, SSLSession session) { 89 | return true; 90 | } 91 | } 92 | 93 | private static class UnSafeTrustManager implements X509TrustManager { 94 | @Override 95 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 96 | } 97 | 98 | @Override 99 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 100 | } 101 | 102 | @Override 103 | public X509Certificate[] getAcceptedIssuers() { 104 | return new java.security.cert.X509Certificate[] {}; 105 | } 106 | } 107 | 108 | private static TrustManager[] prepareTrustManager(InputStream... certificates) { 109 | if (certificates == null || certificates.length <= 0) 110 | return null; 111 | try { 112 | 113 | CertificateFactory certificateFactory = CertificateFactory.getInstance(CERTIFICATE_TYPE_X509); 114 | KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); 115 | keyStore.load(null); 116 | int index = 0; 117 | for (InputStream certificate : certificates) { 118 | String certificateAlias = Integer.toString(index++); 119 | keyStore.setCertificateEntry(certificateAlias, certificateFactory.generateCertificate(certificate)); 120 | try { 121 | if (certificate != null) 122 | certificate.close(); 123 | } catch (IOException e) { 124 | //ignore 125 | } 126 | } 127 | TrustManagerFactory trustManagerFactory = null; 128 | 129 | trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 130 | trustManagerFactory.init(keyStore); 131 | 132 | TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); 133 | 134 | return trustManagers; 135 | } catch (NoSuchAlgorithmException e) { 136 | e.printStackTrace(); 137 | } catch (CertificateException e) { 138 | e.printStackTrace(); 139 | } catch (KeyStoreException e) { 140 | e.printStackTrace(); 141 | } catch (Exception e) { 142 | e.printStackTrace(); 143 | } 144 | return null; 145 | 146 | } 147 | 148 | private static KeyManager[] prepareKeyManager(InputStream bksFile, String password) { 149 | try { 150 | if (bksFile == null || password == null) 151 | return null; 152 | 153 | KeyStore clientKeyStore = KeyStore.getInstance(LOCAL_KEY_STORE_TYPE_BKS); 154 | clientKeyStore.load(bksFile, password.toCharArray()); 155 | KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 156 | keyManagerFactory.init(clientKeyStore, password.toCharArray()); 157 | return keyManagerFactory.getKeyManagers(); 158 | 159 | } catch (KeyStoreException e) { 160 | e.printStackTrace(); 161 | } catch (NoSuchAlgorithmException e) { 162 | e.printStackTrace(); 163 | } catch (UnrecoverableKeyException e) { 164 | e.printStackTrace(); 165 | } catch (CertificateException e) { 166 | e.printStackTrace(); 167 | } catch (IOException e) { 168 | e.printStackTrace(); 169 | } catch (Exception e) { 170 | e.printStackTrace(); 171 | } 172 | return null; 173 | } 174 | 175 | private static X509TrustManager chooseTrustManager(TrustManager[] trustManagers) { 176 | for (TrustManager trustManager : trustManagers) { 177 | if (trustManager instanceof X509TrustManager) { 178 | return (X509TrustManager) trustManager; 179 | } 180 | } 181 | return null; 182 | } 183 | 184 | private static class MyTrustManager implements X509TrustManager { 185 | private X509TrustManager defaultTrustManager; 186 | private X509TrustManager localTrustManager; 187 | 188 | public MyTrustManager(X509TrustManager localTrustManager) throws NoSuchAlgorithmException, KeyStoreException { 189 | TrustManagerFactory var4 = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 190 | var4.init((KeyStore) null); 191 | defaultTrustManager = chooseTrustManager(var4.getTrustManagers()); 192 | this.localTrustManager = localTrustManager; 193 | } 194 | 195 | @Override 196 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { 197 | 198 | } 199 | 200 | @Override 201 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { 202 | try { 203 | defaultTrustManager.checkServerTrusted(chain, authType); 204 | } catch (CertificateException ce) { 205 | localTrustManager.checkServerTrusted(chain, authType); 206 | } 207 | } 208 | 209 | @Override 210 | public X509Certificate[] getAcceptedIssuers() { 211 | return new X509Certificate[0]; 212 | } 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /src/main/java/com/github/vaibhavsinha/kong/utils/UrlUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.utils; 2 | 3 | import com.google.gson.Gson; 4 | 5 | import java.io.UnsupportedEncodingException; 6 | import java.net.MalformedURLException; 7 | import java.net.URL; 8 | import java.net.URLDecoder; 9 | import java.util.LinkedHashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * Created by fanhua on 2017-07-28. 14 | */ 15 | public class UrlUtil { 16 | 17 | public static Map splitQueryString(String urlString) { 18 | try { 19 | URL url = new URL(urlString); 20 | Map query_pairs = new LinkedHashMap<>(); 21 | String queryString = url.getQuery(); 22 | if(queryString != null) { 23 | String[] pairs = queryString.split("&"); 24 | for (String pair : pairs) { 25 | int idx = pair.indexOf("="); 26 | query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); 27 | } 28 | } 29 | return query_pairs; 30 | } 31 | catch (MalformedURLException | UnsupportedEncodingException e) { 32 | throw new IllegalArgumentException("Could not parse URL: " + urlString, e); 33 | } 34 | } 35 | 36 | 37 | public static Map splitFragmentString(String urlString) { 38 | try { 39 | URL url = new URL(urlString); 40 | Map query_pairs = new LinkedHashMap<>(); 41 | String fragmentString = url.getRef(); 42 | if(fragmentString != null) { 43 | String[] pairs = fragmentString.split("&"); 44 | for (String pair : pairs) { 45 | int idx = pair.indexOf("="); 46 | query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"), URLDecoder.decode(pair.substring(idx + 1), "UTF-8")); 47 | } 48 | } 49 | return query_pairs; 50 | } 51 | catch (MalformedURLException | UnsupportedEncodingException e) { 52 | throw new IllegalArgumentException("Could not parse URL: " + urlString, e); 53 | } 54 | } 55 | 56 | 57 | public static void main(String[] args) throws Exception { 58 | 59 | String url1 = "http://kong.test.com/simulate/getCode?access_token=4ddb06a7c9c44ea1a1f3043ee8de9938&expires_in=7200"; 60 | 61 | String url2 = "http://kong.test.com/simulate/getCode#access_token=4ddb06a7c9c44ea1a1f3043ee8de9938&expires_in=7200"; 62 | 63 | System.out.println(new Gson().toJson(splitQueryString(url1))); 64 | 65 | System.out.println(new Gson().toJson(splitFragmentString(url2))); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.impl.KongClient; 4 | import com.google.gson.FieldNamingPolicy; 5 | import com.google.gson.Gson; 6 | import com.google.gson.GsonBuilder; 7 | import org.apache.log4j.helpers.ISO8601DateFormat; 8 | import org.junit.Before; 9 | 10 | import java.text.SimpleDateFormat; 11 | import java.util.Date; 12 | 13 | /** 14 | * Created by fanhua on 2017-07-28. 15 | */ 16 | public class BaseTest { 17 | 18 | public static final String KONG_ADMIN_URL = "http://test.com:8001"; 19 | public static final String KONG_API_URL = "https://test.com:8443"; 20 | 21 | protected static KongClient kongClient; 22 | 23 | protected Gson gson; 24 | 25 | @Before 26 | public void before() { 27 | 28 | kongClient = new KongClient(KONG_ADMIN_URL, KONG_API_URL, true); 29 | 30 | gson = new GsonBuilder() 31 | // .excludeFieldsWithoutExposeAnnotation() //不导出实体中没有用@Expose注解的属性 32 | .enableComplexMapKeySerialization() //支持Map的key为复杂对象的形式 33 | .serializeNulls().setDateFormat("yyyy-MM-dd HH:mm:ss:SSS") //时间转化为特定格式 34 | // .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) //会把字段首字母大写,注:对于实体上使用了@SerializedName注解的不会生效. 35 | .setPrettyPrinting() //对json结果格式化. 36 | .setVersion(1.0) //有的字段不是一开始就有的,会随着版本的升级添加进来,那么在进行序列化和返序列化的时候就会根据版本号来选择是否要序列化. 37 | //@Since(版本号)能完美地实现这个功能.还的字段可能,随着版本的升级而删除,那么 38 | //@Until(版本号)也能实现这个功能,GsonBuilder.setVersion(double)方法需要调用. 39 | .create(); 40 | } 41 | 42 | 43 | protected void printJson(Object object) { 44 | System.out.println(gson.toJson(object)); 45 | } 46 | 47 | protected void printString(String str) { 48 | System.out.println(str); 49 | } 50 | 51 | protected static String getCurrentDateTimeString() { 52 | return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitAclServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer; 4 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.Acl; 5 | import com.github.vaibhavsinha.kong.model.plugin.security.acl.AclList; 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.util.UUID; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | 14 | /** 15 | * Created by dvilela on 10/22/17. 16 | */ 17 | public class RetrofitAclServiceTest extends BaseTest { 18 | 19 | private Consumer consumer; 20 | 21 | @Before 22 | public void createConsumer() throws Exception { 23 | consumer = new Consumer(); 24 | String id = UUID.randomUUID().toString(); 25 | consumer.setCustomId(id); 26 | 27 | consumer = kongClient.getConsumerService().createConsumer(consumer); 28 | } 29 | 30 | @After 31 | public void deleteConsumer() throws Exception { 32 | kongClient.getConsumerService().deleteConsumer(consumer.getId()); 33 | } 34 | 35 | @Test 36 | public void testAssociateAndListAcls() throws Exception { 37 | kongClient.getAclService().associateConsumer(consumer.getId(), "default"); 38 | 39 | AclList list = kongClient.getAclService().listAcls(consumer.getId(), 1L, null); 40 | 41 | Acl acl = list.getData().get(0); 42 | assertEquals(consumer.getId(), acl.getConsumerId()); 43 | assertEquals("default", acl.getGroup()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitApiPluginServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | import com.github.vaibhavsinha.kong.model.admin.plugin.OAuth2Config; 9 | import org.junit.Assert; 10 | import org.junit.FixMethodOrder; 11 | import org.junit.Test; 12 | import org.junit.runners.MethodSorters; 13 | 14 | import com.github.vaibhavsinha.kong.exception.KongClientException; 15 | import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; 16 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; 17 | 18 | /** 19 | * Created by fanhua on 2017-08-05. 20 | */ 21 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 22 | public class RetrofitApiPluginServiceTest extends BaseTest { 23 | 24 | private String PLUGIN_ID = "3d3ee453-161c-449b-a468-42f06b7c0dc5"; 25 | private String PLUGIN_NAME = "oauth2"; 26 | private OAuth2Config OAUTH2_CONFIG = new OAuth2Config(); 27 | private String OAUTH2_PROVISION_KEY = "1f2b8d4baadb4b6f93c82b1599cad575"; 28 | 29 | private String API_NAME = "Test.V2.Api"; 30 | 31 | // ------------------------------------------------------------------------------- 32 | 33 | @Test 34 | public void test01_CreatePluginForApi() throws IOException { 35 | Plugin request = new Plugin(); 36 | request.setId(PLUGIN_ID); 37 | request.setName(PLUGIN_NAME); 38 | 39 | OAUTH2_CONFIG.setProvisionKey(OAUTH2_PROVISION_KEY); 40 | OAUTH2_CONFIG.setEnableAuthorizationCode(true); 41 | OAUTH2_CONFIG.setEnableImplicitGrant(true); 42 | OAUTH2_CONFIG.setEnablePasswordGrant(true); 43 | OAUTH2_CONFIG.setEnableClientCredentials(true); 44 | OAUTH2_CONFIG.setTokenExpiration(7200); 45 | request.setConfig(OAUTH2_CONFIG); 46 | 47 | Plugin response = kongClient.getApiPluginService().addPluginForApi(API_NAME, request); 48 | printJson(response); 49 | Assert.assertEquals(request.getName(), response.getName()); 50 | } 51 | 52 | @Test 53 | public void test02_GetPluginForApi() throws IOException { 54 | Plugin response = kongClient.getApiPluginService().getPluginForApi(API_NAME, PLUGIN_ID); 55 | printJson(response); 56 | Assert.assertEquals(PLUGIN_NAME, response.getName()); 57 | } 58 | 59 | 60 | @Test(expected = KongClientException.class) 61 | public void test03_exceptionTestForApi() throws IOException { 62 | kongClient.getApiPluginService().getPluginForApi(API_NAME, "some-random-id"); 63 | } 64 | 65 | 66 | @Test 67 | public void test04_UpdatePluginForApi() throws IOException { 68 | Plugin request = new Plugin(); 69 | request.setName(PLUGIN_NAME); 70 | 71 | Plugin response = kongClient.getApiPluginService().updatePluginForApi(API_NAME, PLUGIN_ID, request); 72 | printJson(response); 73 | Assert.assertEquals(request.getName(), response.getName()); 74 | } 75 | 76 | // @Test 77 | public void test05_CreateOrUpdatePluginForApi() throws IOException { 78 | Plugin request = new Plugin(); 79 | request.setName(PLUGIN_NAME); 80 | request.setId(PLUGIN_ID); 81 | request.setCreatedAt(new Date().getTime()); 82 | 83 | Plugin response = kongClient.getApiPluginService().createOrUpdatePluginForApi(API_NAME, request); 84 | printJson(response); 85 | Assert.assertEquals(request.getName(), response.getName()); 86 | } 87 | 88 | @Test 89 | public void test09_DeletePluginForApi() throws IOException { 90 | kongClient.getApiPluginService().deletePluginForApi(API_NAME, PLUGIN_ID); 91 | } 92 | 93 | @Test 94 | public void test10_ListPluginsForApi() throws IOException { 95 | List plugins = new ArrayList<>(); 96 | PluginList pluginList = kongClient.getApiPluginService().listPluginsForApi(API_NAME, null, null, null, null, 1L, null); 97 | plugins.addAll(pluginList.getData()); 98 | while (pluginList.getOffset() != null) { 99 | pluginList = kongClient.getApiPluginService().listPluginsForApi(API_NAME, null, null, null, null, 1L, pluginList.getOffset()); 100 | plugins.addAll(pluginList.getData()); 101 | } 102 | printJson(plugins); 103 | Assert.assertNotEquals(plugins.size(), 0); 104 | } 105 | 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitApiServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.exception.KongClientException; 4 | import com.github.vaibhavsinha.kong.model.admin.api.Api; 5 | import com.github.vaibhavsinha.kong.model.admin.api.ApiList; 6 | import org.junit.Assert; 7 | import org.junit.FixMethodOrder; 8 | import org.junit.Test; 9 | import org.junit.runners.MethodSorters; 10 | 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | import java.util.Arrays; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by vaibhav on 12/06/17. 18 | * 19 | * Updated by fanhua on 2017-08-04. 20 | */ 21 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 22 | public class RetrofitApiServiceTest extends BaseTest { 23 | 24 | private String API_NAME_V1 = "Test_V1_Api"; 25 | // private String API_ID_V1 = "f813a66b-bac6-4951-831b-f04d53ae0bf0"; // not exist 26 | private String API_ID_V1 = "3a9fa5b9-5f99-4ab8-a949-d676becd30b3"; 27 | 28 | private String API_NAME_V2 = "Test_V2_Api"; 29 | private String API_NAME_V2_NEW = "Test.V2.Api"; 30 | private String API_ID_V2 = "f813a66b-bac6-4952-831b-f04d53ae0bf0"; 31 | 32 | private String API_UPSTREAM_URL = "http://httpbin.org"; 33 | private String[] API_HOSTS = new String[] {"example.com"}; 34 | private String[] API_URIS = new String[] {"/v1/example", "/v2/example"}; 35 | 36 | 37 | // ----------------------------------------------------------------------- 38 | 39 | @Test 40 | public void test01_CreateApi() throws IOException { 41 | Api request = new Api(); 42 | request.setId(API_ID_V2); 43 | request.setName(API_NAME_V2); 44 | request.setUpstreamUrl(API_UPSTREAM_URL); 45 | // request.setHosts(Arrays.asList(API_HOSTS)); 46 | request.setUris(Arrays.asList(API_URIS)); 47 | 48 | Api response = kongClient.getApiService().createApi(request); 49 | printJson(response); 50 | Assert.assertEquals(request.getName(), response.getName()); 51 | } 52 | 53 | @Test 54 | public void test02_GetApi() throws IOException { 55 | Api response = kongClient.getApiService().getApi(API_NAME_V2); 56 | printJson(response); 57 | Assert.assertEquals(API_NAME_V2, response.getName()); 58 | } 59 | 60 | @Test(expected = KongClientException.class) 61 | public void test03_exceptionTest() throws IOException { 62 | kongClient.getApiService().getApi("some.random.id"); 63 | } 64 | 65 | @Test 66 | public void test04_testUpdateApi() throws IOException { 67 | Api request = new Api(); 68 | request.setName(API_NAME_V2_NEW); 69 | 70 | Api response = kongClient.getApiService().updateApi(API_ID_V2, request); 71 | printJson(response); 72 | Assert.assertEquals(request.getName(), response.getName()); 73 | } 74 | 75 | 76 | // @Test 77 | public void test05_CreateOrUpdateApi() throws IOException { 78 | //Test by HTTP PUT method.... 79 | // API name is required, otherwise you will get exception. 80 | // if API id is not set, then Kong will add API by name. 81 | // if API id is set, the Kong will update API by id and name. 82 | // if API id is set, but the API is actually not exist, then Kong will response 200(OK), but the API won't be created!!! 83 | Api request = new Api(); 84 | request.setName(API_NAME_V1); 85 | // request.setId(API_ID_V1); 86 | request.setUpstreamUrl(API_UPSTREAM_URL); 87 | request.setUris(Arrays.asList(API_URIS)); 88 | request.setCreatedAt(System.currentTimeMillis()); 89 | Api response = kongClient.getApiService().createOrUpdateApi(request); 90 | Assert.assertNotNull(response); 91 | printJson(response); 92 | Assert.assertEquals(request.getName(), response.getName()); 93 | } 94 | 95 | @Test 96 | public void test09_testDeleteApi() throws IOException { 97 | kongClient.getApiService().deleteApi(API_ID_V2); 98 | } 99 | 100 | 101 | @Test 102 | public void test10_ListApis() throws IOException { 103 | List apis = new ArrayList<>(); 104 | ApiList apiList = kongClient.getApiService().listApis(null, null, null, null, 1L, null); 105 | apis.addAll(apiList.getData()); 106 | while (apiList.getOffset() != null) { 107 | apiList = kongClient.getApiService().listApis(null, null, null, null, 1L, apiList.getOffset()); 108 | apis.addAll(apiList.getData()); 109 | } 110 | printJson(apis); 111 | Assert.assertNotEquals(apis.size(), 0); 112 | } 113 | 114 | 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitCertificateServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.BaseTest; 4 | import com.github.vaibhavsinha.kong.exception.KongClientException; 5 | import com.github.vaibhavsinha.kong.impl.KongClient; 6 | import com.github.vaibhavsinha.kong.model.admin.certificate.Certificate; 7 | import com.github.vaibhavsinha.kong.model.admin.certificate.CertificateList; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import java.io.IOException; 13 | import java.util.ArrayList; 14 | import java.util.Date; 15 | import java.util.List; 16 | 17 | /** 18 | * Created by vaibhav on 12/06/17. 19 | */ 20 | public class RetrofitCertificateServiceTest extends BaseTest { 21 | 22 | 23 | 24 | // @Test 25 | public void testCreateCertificate() throws IOException { 26 | Certificate request = new Certificate(); 27 | request.setCert("jwt"); 28 | request.setKey("abc"); 29 | 30 | Certificate response = kongClient.getCertificateService().createCertificate(request); 31 | System.out.print(response); 32 | Assert.assertEquals(request.getCert(), response.getCert()); 33 | } 34 | 35 | // @Test 36 | public void testGetCertificate() throws IOException { 37 | Certificate response = kongClient.getCertificateService().getCertificate("2e9c5805-ea4e-4d38-ba7c-5e878d38489c"); 38 | System.out.print(response); 39 | Assert.assertEquals("jwt", response.getCert()); 40 | } 41 | 42 | // @Test 43 | public void testListCertificates() throws IOException { 44 | List certificates = new ArrayList<>(); 45 | CertificateList certificateList = kongClient.getCertificateService().listCertificates(); 46 | certificates.addAll(certificateList.getData()); 47 | while (certificateList.getOffset() != null) { 48 | certificateList = kongClient.getCertificateService().listCertificates(); 49 | certificates.addAll(certificateList.getData()); 50 | } 51 | System.out.println(certificates); 52 | Assert.assertNotEquals(certificates.size(), 0); 53 | } 54 | 55 | // @Test(expected = KongClientException.class) 56 | public void exceptionTest() throws IOException { 57 | kongClient.getCertificateService().getCertificate("some-random-id"); 58 | } 59 | 60 | // @Test 61 | public void testUpdateCertificate() throws IOException { 62 | Certificate request = new Certificate(); 63 | request.setCert("jwt2"); 64 | 65 | Certificate response = kongClient.getCertificateService().updateCertificate("2e9c5805-ea4e-4d38-ba7c-5e878d38489c", request); 66 | System.out.print(response); 67 | Assert.assertEquals(request.getCert(), response.getCert()); 68 | } 69 | 70 | // @Test 71 | public void testCreateOrUpdateCertificate() throws IOException { 72 | Certificate request = new Certificate(); 73 | request.setCert("jwt"); 74 | request.setKey("jwt"); 75 | request.setId("2e9c5805-ea4e-4d38-ba7c-5e878d38489c"); 76 | request.setCreatedAt(new Date().getTime()); 77 | 78 | Certificate response = kongClient.getCertificateService().createOrUpdateCertificate(request); 79 | System.out.print(response); 80 | Assert.assertEquals(request.getCert(), response.getCert()); 81 | } 82 | 83 | // @Test 84 | public void testDeleteCertificate() throws IOException { 85 | kongClient.getCertificateService().deleteCertificate("2e9c5805-ea4e-4d38-ba7c-5e878d38489c"); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitConsumerServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.exception.KongClientException; 4 | import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer; 5 | import com.github.vaibhavsinha.kong.model.admin.consumer.ConsumerList; 6 | import org.junit.Assert; 7 | import org.junit.FixMethodOrder; 8 | import org.junit.Test; 9 | import org.junit.runners.MethodSorters; 10 | 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by vaibhav on 12/06/17. 17 | */ 18 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 19 | public class RetrofitConsumerServiceTest extends BaseTest { 20 | 21 | private String CONSUMER_ID = "12faf661-3529-40c6-98e0-5a54894ad22f"; 22 | private String CONSUMER_USERNAME = ""; 23 | private String CONSUMER_CUSTOM_ID = "1234-5678-9012"; 24 | 25 | @Test 26 | public void test01_CreateConsumer() throws IOException { 27 | Consumer request = new Consumer(); 28 | request.setId(CONSUMER_ID); 29 | request.setCustomId(CONSUMER_CUSTOM_ID); 30 | 31 | Consumer response = kongClient.getConsumerService().createConsumer(request); 32 | printJson(response); 33 | Assert.assertEquals(request.getCustomId(), response.getCustomId()); 34 | } 35 | 36 | @Test 37 | public void test02_GetConsumer() throws IOException { 38 | Consumer response = kongClient.getConsumerService().getConsumer(CONSUMER_ID); 39 | printJson(response); 40 | Assert.assertEquals(CONSUMER_ID, response.getId()); 41 | } 42 | 43 | @Test(expected = KongClientException.class) 44 | public void test03_exceptionTest() throws IOException { 45 | kongClient.getConsumerService().getConsumer("some-random-id"); 46 | } 47 | 48 | @Test 49 | public void test04_UpdateConsumer() throws IOException { 50 | Consumer request = new Consumer(); 51 | request.setCustomId("1234-5678-9012-3456"); 52 | 53 | Consumer response = kongClient.getConsumerService().updateConsumer(CONSUMER_ID, request); 54 | printJson(response); 55 | Assert.assertEquals(request.getCustomId(), response.getCustomId()); 56 | } 57 | 58 | // @Test 59 | public void test05_CreateOrUpdateConsumer() throws IOException { 60 | Consumer request = new Consumer(); 61 | request.setCustomId(CONSUMER_CUSTOM_ID); 62 | request.setId(CONSUMER_ID); 63 | // request.setUsername(CONSUMER_USERNAME); 64 | request.setCreatedAt(123456789L); 65 | 66 | Consumer response = kongClient.getConsumerService().createOrUpdateConsumer(request); 67 | printJson(response); 68 | Assert.assertEquals(request.getCustomId(), response.getCustomId()); 69 | } 70 | 71 | @Test 72 | public void test09_DeleteConsumer() throws IOException { 73 | kongClient.getConsumerService().deleteConsumer(CONSUMER_ID); 74 | } 75 | 76 | @Test 77 | public void test10_ListConsumers() throws IOException { 78 | List consumers = new ArrayList<>(); 79 | ConsumerList consumerList = kongClient.getConsumerService().listConsumers(null, null, null, 1L, null); 80 | consumers.addAll(consumerList.getData()); 81 | while (consumerList.getOffset() != null) { 82 | consumerList = kongClient.getConsumerService().listConsumers(null, null, null, 1L, consumerList.getOffset()); 83 | consumers.addAll(consumerList.getData()); 84 | } 85 | printJson(consumers); 86 | Assert.assertNotEquals(consumers.size(), 0); 87 | } 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitJwtServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer; 4 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredential; 5 | import com.github.vaibhavsinha.kong.model.plugin.authentication.jwt.JwtCredentialList; 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.FixMethodOrder; 9 | import org.junit.Test; 10 | import org.junit.runners.MethodSorters; 11 | 12 | import java.util.UUID; 13 | 14 | import static org.junit.Assert.assertEquals; 15 | 16 | /** 17 | * Created by dvilela on 10/22/17. 18 | */ 19 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 20 | public class RetrofitJwtServiceTest extends BaseTest { 21 | 22 | private static Consumer consumer; 23 | 24 | @Before 25 | public void createConsumerAndAddCredential() throws Exception { 26 | Consumer c = new Consumer(); 27 | c.setCustomId(UUID.randomUUID().toString()); 28 | consumer = kongClient.getConsumerService().createConsumer(c); 29 | 30 | JwtCredential credential = kongClient.getJwtService().addCredentials(consumer.getId(), new JwtCredential()); 31 | assertEquals(consumer.getId(), credential.getConsumerId()); 32 | } 33 | 34 | @After 35 | public void deleteConsumer() throws Exception { 36 | kongClient.getConsumerService().deleteConsumer(consumer.getId()); 37 | } 38 | 39 | @Test 40 | public void test01_listCredentialsTest() throws Exception { 41 | JwtCredentialList list = kongClient.getJwtService().listCredentials(consumer.getId(), null, null); 42 | JwtCredential c = list.getData().get(0); 43 | assertEquals(consumer.getId(), c.getConsumerId()); 44 | } 45 | 46 | @Test 47 | public void test02_deleteCredentialTest() throws Exception { 48 | JwtCredentialList list = kongClient.getJwtService().listCredentials(consumer.getId(), null, null); 49 | JwtCredential credential = list.getData().get(0); 50 | kongClient.getJwtService().deleteCredentials(consumer.getId(), credential.getId()); 51 | JwtCredentialList list2 = kongClient.getJwtService().listCredentials(consumer.getId(), null, null); 52 | assertEquals(0L, (long) list2.getTotal()); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitKeyAuthServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.exception.KongClientException; 4 | import com.github.vaibhavsinha.kong.model.admin.consumer.Consumer; 5 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredential; 6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.key.KeyAuthCredentialList; 7 | import org.junit.After; 8 | import org.junit.Before; 9 | import org.junit.FixMethodOrder; 10 | import org.junit.Test; 11 | import org.junit.runners.MethodSorters; 12 | 13 | import java.util.List; 14 | import java.util.UUID; 15 | 16 | import static org.junit.Assert.*; 17 | 18 | /** 19 | * Created by dvilela on 11/08/17. 20 | */ 21 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 22 | public class RetrofitKeyAuthServiceTest extends BaseTest { 23 | 24 | private Consumer consumer; 25 | 26 | @Before 27 | public void createConsumer() throws Exception { 28 | Consumer c = new Consumer(); 29 | c.setCustomId(UUID.randomUUID().toString()); 30 | consumer = kongClient.getConsumerService().createConsumer(c); 31 | 32 | KeyAuthCredential credential = kongClient.getKeyAuthService().addCredentials(consumer.getId(), null); 33 | assertEquals(consumer.getId(), credential.getConsumerId()); 34 | assertNotNull(consumer.getId(), credential.getKey()); 35 | } 36 | 37 | @After 38 | public void deleteConsumer() throws Exception { 39 | kongClient.getConsumerService().deleteConsumer(consumer.getId()); 40 | } 41 | 42 | @Test 43 | public void test01_addRepeatedCredentialTest() throws Exception { 44 | KeyAuthCredential credential1 = kongClient.getKeyAuthService().addCredentials(consumer.getId(), null); 45 | assertEquals(consumer.getId(), credential1.getConsumerId()); 46 | assertNotNull(consumer.getId(), credential1.getKey()); 47 | 48 | try { 49 | KeyAuthCredential credential2 = kongClient.getKeyAuthService().addCredentials(consumer.getId(), 50 | credential1.getKey()); 51 | fail("RetrofitKeyAuthService did not throw"); 52 | } catch (KongClientException e) { 53 | assertEquals(409, e.getCode()); 54 | assertEquals("Conflict", e.getError()); 55 | } 56 | } 57 | 58 | @Test 59 | public void test02_listCredentialsTest() throws Exception { 60 | KeyAuthCredentialList list = kongClient.getKeyAuthService().listCredentials(consumer.getId(), null, 61 | null); 62 | KeyAuthCredential credential = list.getData().get(0); 63 | assertEquals(consumer.getId(), credential.getConsumerId()); 64 | } 65 | 66 | @Test 67 | public void test03_deleteCredentialTest() throws Exception { 68 | KeyAuthCredentialList list = kongClient.getKeyAuthService().listCredentials(consumer.getId(), null, 69 | null); 70 | List credentials = list.getData(); 71 | for (KeyAuthCredential credential : credentials) { 72 | kongClient.getKeyAuthService().deleteCredential(credential.getConsumerId(), credential.getId()); 73 | } 74 | KeyAuthCredentialList list2 = kongClient.getKeyAuthService().listCredentials(consumer.getId(), null, 75 | null); 76 | assertEquals(0L, (long) list2.getTotal()); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitPluginRepoServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import java.io.IOException; 4 | 5 | import org.junit.Test; 6 | 7 | import com.github.vaibhavsinha.kong.model.admin.plugin.EnabledPlugins; 8 | 9 | /** 10 | * Created by fanhua on 2017-08-05. 11 | */ 12 | public class RetrofitPluginRepoServiceTest extends BaseTest { 13 | 14 | 15 | @Test 16 | public void retrieveEnabledPlugins() throws IOException { 17 | EnabledPlugins response = kongClient.getPluginRepoService().retrieveEnabledPlugins(); 18 | printJson(response); 19 | } 20 | 21 | @Test 22 | public void retrievePluginSchema() throws IOException { 23 | Object response = kongClient.getPluginRepoService().retrievePluginSchema("oauth2"); 24 | printJson(response); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitPluginServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.exception.KongClientException; 4 | import com.github.vaibhavsinha.kong.model.admin.plugin.Plugin; 5 | import com.github.vaibhavsinha.kong.model.admin.plugin.PluginList; 6 | import org.junit.Assert; 7 | import org.junit.FixMethodOrder; 8 | import org.junit.Test; 9 | import org.junit.runners.MethodSorters; 10 | 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | import java.util.Date; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by vaibhav on 12/06/17. 18 | * 19 | * Updated by fanhua on 2017-08-04. 20 | */ 21 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 22 | public class RetrofitPluginServiceTest extends BaseTest { 23 | 24 | 25 | private String PLUGIN_ID = "61e5b656-7b68-4761-aeae-d9c94a5782c8"; 26 | private String PLUGIN_NAME = "jwt"; 27 | 28 | private String API_ID = "3a9fa5b9-5f99-4ab8-a949-d676becd30b3"; 29 | 30 | @Test 31 | public void test11_CreatePlugin() throws IOException { 32 | Plugin request = new Plugin(); 33 | request.setId(PLUGIN_ID); 34 | request.setApiId(API_ID); // make sure you put the valid API_ID here, if you don't put API_ID, the the plugin will take effect on all APIs 35 | request.setName(PLUGIN_NAME); 36 | 37 | Plugin response = kongClient.getPluginService().addPlugin(request); 38 | printJson(response); 39 | Assert.assertEquals(request.getName(), response.getName()); 40 | } 41 | 42 | @Test 43 | public void test12_GetPlugin() throws IOException { 44 | Plugin response = kongClient.getPluginService().getPlugin(PLUGIN_ID); 45 | printJson(response); 46 | Assert.assertEquals(PLUGIN_NAME, response.getName()); 47 | } 48 | 49 | 50 | @Test(expected = KongClientException.class) 51 | public void test13_exceptionTest() throws IOException { 52 | kongClient.getPluginService().getPlugin("some-random-id"); 53 | } 54 | 55 | 56 | @Test 57 | public void test14_UpdatePlugin() throws IOException { 58 | Plugin request = new Plugin(); 59 | request.setName(PLUGIN_NAME); 60 | 61 | Plugin response = kongClient.getPluginService().updatePlugin(PLUGIN_ID, request); 62 | printJson(response); 63 | Assert.assertEquals(request.getName(), response.getName()); 64 | } 65 | 66 | // @Test 67 | public void test15_CreateOrUpdatePlugin() throws IOException { 68 | Plugin request = new Plugin(); 69 | request.setName(PLUGIN_NAME); 70 | request.setId(PLUGIN_ID); 71 | request.setCreatedAt(new Date().getTime()); 72 | 73 | Plugin response = kongClient.getPluginService().createOrUpdatePlugin(request); 74 | printJson(response); 75 | Assert.assertEquals(request.getName(), response.getName()); 76 | } 77 | 78 | @Test 79 | public void test19_DeletePlugin() throws IOException { 80 | kongClient.getPluginService().deletePlugin(PLUGIN_ID); 81 | } 82 | 83 | @Test 84 | public void test20_ListPlugins() throws IOException { 85 | List plugins = new ArrayList<>(); 86 | PluginList pluginList = kongClient.getPluginService().listPlugins(null, null, null, null, 1L, null); 87 | plugins.addAll(pluginList.getData()); 88 | while (pluginList.getOffset() != null) { 89 | pluginList = kongClient.getPluginService().listPlugins(null, null, null, null, 1L, pluginList.getOffset()); 90 | plugins.addAll(pluginList.getData()); 91 | } 92 | printJson(plugins); 93 | Assert.assertNotEquals(plugins.size(), 0); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitSniServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.exception.KongClientException; 4 | import com.github.vaibhavsinha.kong.impl.KongClient; 5 | import com.github.vaibhavsinha.kong.model.admin.sni.Sni; 6 | import com.github.vaibhavsinha.kong.model.admin.sni.SniList; 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | import java.util.Date; 14 | import java.util.List; 15 | import java.util.UUID; 16 | 17 | /** 18 | * Created by vaibhav on 12/06/17. 19 | */ 20 | public class RetrofitSniServiceTest extends BaseTest { 21 | 22 | 23 | 24 | // @Test 25 | public void testCreateSni() throws IOException { 26 | Sni request = new Sni(); 27 | request.setName("jwt"); 28 | request.setSslCertificateId(UUID.randomUUID().toString()); 29 | 30 | Sni response = kongClient.getSniService().createSni(request); 31 | System.out.print(response); 32 | Assert.assertEquals(request.getName(), response.getName()); 33 | } 34 | 35 | // @Test 36 | public void testGetSni() throws IOException { 37 | Sni response = kongClient.getSniService().getSni("2e9c5805-ea4e-4d38-ba7c-5e878d38489c"); 38 | System.out.print(response); 39 | Assert.assertEquals("jwt", response.getName()); 40 | } 41 | 42 | // @Test 43 | public void testListSnis() throws IOException { 44 | List snis = new ArrayList<>(); 45 | SniList sniList = kongClient.getSniService().listSnis(); 46 | snis.addAll(sniList.getData()); 47 | while (sniList.getOffset() != null) { 48 | sniList = kongClient.getSniService().listSnis(); 49 | snis.addAll(sniList.getData()); 50 | } 51 | System.out.println(snis); 52 | Assert.assertNotEquals(snis.size(), 0); 53 | } 54 | 55 | // @Test(expected = KongClientException.class) 56 | public void exceptionTest() throws IOException { 57 | kongClient.getSniService().getSni("some-random-id"); 58 | } 59 | 60 | // @Test 61 | public void testUpdateSni() throws IOException { 62 | Sni request = new Sni(); 63 | request.setName("jwt"); 64 | request.setSslCertificateId(UUID.randomUUID().toString()); 65 | 66 | Sni response = kongClient.getSniService().updateSni("2e9c5805-ea4e-4d38-ba7c-5e878d38489c", request); 67 | System.out.print(response); 68 | Assert.assertEquals(request.getSslCertificateId(), response.getSslCertificateId()); 69 | } 70 | 71 | // @Test 72 | public void testCreateOrUpdateSni() throws IOException { 73 | Sni request = new Sni(); 74 | request.setName("jwt"); 75 | request.setSslCertificateId(UUID.randomUUID().toString()); 76 | request.setCreatedAt(new Date().getTime()); 77 | 78 | Sni response = kongClient.getSniService().createOrUpdateSni(request); 79 | System.out.print(response); 80 | Assert.assertEquals(request.getSslCertificateId(), response.getSslCertificateId()); 81 | } 82 | 83 | // @Test 84 | public void testDeleteSni() throws IOException { 85 | kongClient.getSniService().deleteSni("2e9c5805-ea4e-4d38-ba7c-5e878d38489c"); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitTargetServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.impl.KongClient; 4 | import com.github.vaibhavsinha.kong.model.admin.target.Target; 5 | import com.github.vaibhavsinha.kong.model.admin.target.TargetList; 6 | import org.junit.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.io.IOException; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by vaibhav on 12/06/17. 16 | */ 17 | public class RetrofitTargetServiceTest extends BaseTest { 18 | 19 | 20 | 21 | // @Test 22 | public void testCreateTarget() throws IOException { 23 | Target request = new Target(); 24 | request.setTarget("1.2.3.4:80"); 25 | 26 | Target response = kongClient.getTargetService().createTarget("local.com", request); 27 | System.out.print(response); 28 | Assert.assertEquals(request.getTarget(), response.getTarget()); 29 | } 30 | 31 | // @Test 32 | public void testListTargets() throws IOException { 33 | List targets = new ArrayList<>(); 34 | TargetList targetList = kongClient.getTargetService().listTargets("local.com", null, null, null, 1L, null); 35 | targets.addAll(targetList.getData()); 36 | while (targetList.getOffset() != null) { 37 | targetList = kongClient.getTargetService().listTargets("local.com", null, null, null, 1L, targetList.getOffset()); 38 | targets.addAll(targetList.getData()); 39 | } 40 | System.out.println(targets); 41 | Assert.assertNotEquals(targets.size(), 0); 42 | } 43 | 44 | // @Test 45 | public void testListActiveTargets() throws IOException { 46 | List targets = new ArrayList<>(); 47 | TargetList targetList = kongClient.getTargetService().listActiveTargets("local.com"); 48 | targets.addAll(targetList.getData()); 49 | while (targetList.getOffset() != null) { 50 | targetList = kongClient.getTargetService().listActiveTargets("listActiveTargets.com"); 51 | targets.addAll(targetList.getData()); 52 | } 53 | System.out.println(targets); 54 | Assert.assertNotEquals(targets.size(), 0); 55 | } 56 | 57 | // @Test 58 | public void testDeleteTarget() throws IOException { 59 | kongClient.getTargetService().deleteTarget("local.com", "1.2.3.4:80"); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/RetrofitUpstreamServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong; 2 | 3 | import com.github.vaibhavsinha.kong.exception.KongClientException; 4 | import com.github.vaibhavsinha.kong.impl.KongClient; 5 | import com.github.vaibhavsinha.kong.model.admin.upstream.Upstream; 6 | import com.github.vaibhavsinha.kong.model.admin.upstream.UpstreamList; 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | import java.io.IOException; 12 | import java.util.ArrayList; 13 | import java.util.Date; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by vaibhav on 12/06/17. 18 | */ 19 | public class RetrofitUpstreamServiceTest extends BaseTest { 20 | 21 | 22 | 23 | // @Test 24 | public void testCreateUpstream() throws IOException { 25 | Upstream request = new Upstream(); 26 | request.setName("local.com"); 27 | 28 | Upstream response = kongClient.getUpstreamService().createUpstream(request); 29 | System.out.print(response); 30 | Assert.assertEquals(request.getName(), response.getName()); 31 | } 32 | 33 | // @Test 34 | public void testGetUpstream() throws IOException { 35 | Upstream response = kongClient.getUpstreamService().getUpstream("0ba0f245-0fda-43a1-a96f-ac33e1b4cf41"); 36 | System.out.print(response); 37 | Assert.assertEquals("local.com", response.getName()); 38 | } 39 | 40 | // @Test 41 | public void testListUpstreams() throws IOException { 42 | List upstreams = new ArrayList<>(); 43 | UpstreamList upstreamList = kongClient.getUpstreamService().listUpstreams(null, null, null, 1L, null); 44 | upstreams.addAll(upstreamList.getData()); 45 | while (upstreamList.getOffset() != null) { 46 | upstreamList = kongClient.getUpstreamService().listUpstreams(null, null, null, 1L, upstreamList.getOffset()); 47 | upstreams.addAll(upstreamList.getData()); 48 | } 49 | System.out.println(upstreams); 50 | Assert.assertNotEquals(upstreams.size(), 0); 51 | } 52 | 53 | // @Test(expected = KongClientException.class) 54 | public void exceptionTest() throws IOException { 55 | kongClient.getUpstreamService().getUpstream("some-random-id"); 56 | } 57 | 58 | // @Test 59 | public void testUpdateUpstream() throws IOException { 60 | Upstream request = new Upstream(); 61 | request.setName("local.com"); 62 | 63 | Upstream response = kongClient.getUpstreamService().updateUpstream("0ba0f245-0fda-43a1-a96f-ac33e1b4cf41", request); 64 | System.out.print(response); 65 | Assert.assertEquals(request.getName(), response.getName()); 66 | } 67 | 68 | // @Test 69 | public void testCreateOrUpdateUpstream() throws IOException { 70 | Upstream request = new Upstream(); 71 | request.setName("local.com"); 72 | request.setId("0ba0f245-0fda-43a1-a96f-ac33e1b4cf41"); 73 | request.setCreatedAt(new Date().getTime()); 74 | 75 | Upstream response = kongClient.getUpstreamService().createOrUpdateUpstream(request); 76 | System.out.print(response); 77 | Assert.assertEquals(request.getName(), response.getName()); 78 | } 79 | 80 | // @Test 81 | public void testDeleteUpstream() throws IOException { 82 | kongClient.getUpstreamService().deleteUpstream("0ba0f245-0fda-43a1-a96f-ac33e1b4cf41"); 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/plugin/RetrofitOAuth2ManageServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.plugin; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.junit.Assert; 8 | import org.junit.FixMethodOrder; 9 | import org.junit.Test; 10 | import org.junit.runners.MethodSorters; 11 | 12 | import com.github.vaibhavsinha.kong.BaseTest; 13 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Application; 14 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.ApplicationList; 15 | 16 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 17 | public class RetrofitOAuth2ManageServiceTest extends BaseTest { 18 | 19 | private static String CONSUMER_ID = "53fe86c9-59d8-48c1-94ef-2e6142fadf85"; 20 | 21 | 22 | // ------------------------------------------------------------------------------------ 23 | 24 | private static String appName = "testApp-20170807113035732"; 25 | private static String appClientId = "dc80e4ebf33445faafad96c1b4701d48"; 26 | private static String appClientSecret = "22435791881e40dc97fd05f28eb86488"; 27 | private static List appRedirectUrl = new ArrayList<>(); 28 | static { 29 | appRedirectUrl.add("http://10.5.227.17:3000/callback"); 30 | } 31 | 32 | 33 | private Application cachedApp; 34 | 35 | 36 | // App Management --------------------------------------------------------------------------------------------------- 37 | 38 | @Test 39 | public void test01_CreateOAuth2App() throws IOException { 40 | 41 | Application appRequest = new Application(appName, appRedirectUrl, appClientId, appClientSecret); 42 | 43 | Application appResponse = kongClient.getOAuth2ManageService().createConsumerApplication(CONSUMER_ID, appRequest); 44 | 45 | printJson(appResponse); 46 | 47 | Assert.assertEquals(appName, appResponse.getName()); 48 | 49 | cachedApp = appResponse; 50 | } 51 | 52 | @Test 53 | public void test02_GetOAuth2App() throws IOException { 54 | 55 | Application appResponse = kongClient.getOAuth2ManageService().getConsumerApplication(CONSUMER_ID, appClientId); 56 | 57 | printJson(appResponse); 58 | 59 | Assert.assertEquals(appName, appResponse.getName()); 60 | 61 | cachedApp = appResponse; 62 | } 63 | 64 | 65 | @Test 66 | public void test03_UpdateOAuth2App() throws IOException { 67 | 68 | Application appRequest = new Application(appName + "-2", appRedirectUrl); 69 | appRequest.setId(appClientId); //important 70 | 71 | Application appResponse = kongClient.getOAuth2ManageService().updateConsumerApplication(CONSUMER_ID, appClientId, appRequest); 72 | 73 | printJson(appResponse); 74 | 75 | Assert.assertEquals(appName + "-2", appResponse.getName()); 76 | 77 | cachedApp = appResponse; 78 | } 79 | 80 | @Test 81 | public void test04_DeleteOAuth2App() throws IOException { 82 | 83 | kongClient.getOAuth2ManageService().deleteConsumerApplication(CONSUMER_ID, appClientId); 84 | 85 | } 86 | 87 | 88 | @Test 89 | public void test05_ListOAuth2Apps() throws IOException { 90 | 91 | ApplicationList appList = kongClient.getOAuth2ManageService().listConsumerApplications(CONSUMER_ID); 92 | 93 | printJson(appList); 94 | } 95 | 96 | 97 | @Test 98 | public void test06_ListOAuth2Apps() throws IOException { 99 | 100 | ApplicationList appList = kongClient.getOAuth2ManageService().listClientApplications( 101 | null, appName, null, null, CONSUMER_ID); 102 | 103 | printJson(appList); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/test/java/com/github/vaibhavsinha/kong/plugin/RetrofitOAuth2ProcessServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.github.vaibhavsinha.kong.plugin; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.AuthorizationRequest; 7 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.GrantTokenRequest; 8 | import com.github.vaibhavsinha.kong.model.plugin.authentication.oauth2.Token; 9 | 10 | import com.github.vaibhavsinha.kong.BaseTest; 11 | import org.junit.FixMethodOrder; 12 | import org.junit.Test; 13 | import org.junit.runners.MethodSorters; 14 | 15 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) 16 | public class RetrofitOAuth2ProcessServiceTest extends BaseTest { 17 | 18 | private static String API_URI = "v2/example"; // which actually "/v2/example", without the slash 19 | 20 | private static String API_PROVISION_KEY = "1f2b8d4baadb4b6f93c82b1599cad575"; 21 | 22 | // ------------------------------------------------------------------------------------ 23 | 24 | private static String appClientId = "dc80e4ebf33445faafad96c1b4701d48"; 25 | private static String appClientSecret = "22435791881e40dc97fd05f28eb86488"; 26 | 27 | private static ConcurrentHashMap cache = new ConcurrentHashMap<>(); 28 | 29 | // Authorization Code Process --------------------------------------------------------------------------------------------------- 30 | 31 | @Test 32 | public void test01_authorize_ac() { 33 | 34 | printString(" ================ " + Thread.currentThread().getStackTrace()[1].getMethodName() + " ================ "); 35 | 36 | AuthorizationRequest request = new AuthorizationRequest(); 37 | request.setClientId(appClientId); 38 | request.setResponseType("code"); 39 | request.setProvisionKey(API_PROVISION_KEY); //must 40 | request.setAuthenticatedUserid("testUserId"); //must 41 | 42 | Map response = kongClient.getOAuth2ProcessService().authorize(API_URI, request); 43 | 44 | printJson(response); 45 | 46 | String redirectUrl = (String) response.get("redirect_uri"); 47 | cache.put("code", redirectUrl.substring(redirectUrl.indexOf("?code=") + 6)); 48 | printJson(cache); 49 | } 50 | 51 | @Test 52 | public void test02_grantToken_ac() { 53 | 54 | printString(" ================ " + Thread.currentThread().getStackTrace()[1].getMethodName() + " ================ "); 55 | 56 | String code = (String) cache.get("code"); 57 | 58 | GrantTokenRequest request = new GrantTokenRequest(); 59 | request.setClientId(appClientId); 60 | request.setClientSecret(appClientSecret); //must 61 | request.setGrantType("authorization_code"); 62 | request.setCode(code); 63 | 64 | Token token = kongClient.getOAuth2ProcessService().grantToken(API_URI, request); 65 | cache.put("token", token); 66 | printJson(cache); 67 | } 68 | 69 | @Test 70 | public void test03_grantToken_refresh() { 71 | 72 | printString(" ================ " + Thread.currentThread().getStackTrace()[1].getMethodName() + " ================ "); 73 | 74 | Token token = (Token) cache.get("token"); 75 | 76 | GrantTokenRequest request = new GrantTokenRequest(); 77 | request.setClientId(appClientId); 78 | request.setClientSecret(appClientSecret); 79 | request.setGrantType("refresh_token"); 80 | request.setRefreshToken(token.getRefreshToken()); 81 | 82 | Token newToken = kongClient.getOAuth2ProcessService().grantToken(API_URI, request); 83 | cache.put("token", token); 84 | printJson(cache); 85 | } 86 | 87 | // Implicit Grant Process --------------------------------------------------------------------------------------------------- 88 | 89 | @Test 90 | public void test11_authorize_ig() { 91 | 92 | printString(" ================ " + Thread.currentThread().getStackTrace()[1].getMethodName() + " ================ "); 93 | 94 | AuthorizationRequest request = new AuthorizationRequest(); 95 | request.setClientId(appClientId); 96 | request.setResponseType("token"); 97 | request.setProvisionKey(API_PROVISION_KEY); //must 98 | request.setAuthenticatedUserid("testUserId"); //must 99 | 100 | Map response = kongClient.getOAuth2ProcessService().authorize(API_URI, request); 101 | 102 | printJson(response); 103 | 104 | String redirectUrl = (String) response.get("redirect_uri"); 105 | //cache.put("code", redirectUrl.substring(redirectUrl.indexOf("#code=") + 6)); 106 | //printJson(cache); 107 | 108 | printString(redirectUrl); 109 | } 110 | 111 | // Password Credentials Process --------------------------------------------------------------------------------------------------- 112 | 113 | @Test 114 | public void test21_grantToken_pc() { 115 | 116 | printString(" ================ " + Thread.currentThread().getStackTrace()[1].getMethodName() + " ================ "); 117 | 118 | GrantTokenRequest request = new GrantTokenRequest(); 119 | request.setClientId(appClientId); 120 | request.setClientSecret(appClientSecret); //must 121 | request.setGrantType("password"); 122 | request.setProvisionKey(API_PROVISION_KEY); //must 123 | request.setAuthenticatedUserid("testUserId"); //must 124 | 125 | Token token = kongClient.getOAuth2ProcessService().grantToken(API_URI, request); 126 | cache.put("token", token); 127 | printJson(cache); 128 | } 129 | 130 | // Client Credentials Process --------------------------------------------------------------------------------------------------- 131 | 132 | @Test 133 | public void test31_grantToken_cc() { 134 | 135 | printString(" ================ " + Thread.currentThread().getStackTrace()[1].getMethodName() + " ================ "); 136 | 137 | GrantTokenRequest request = new GrantTokenRequest(); 138 | request.setClientId(appClientId); 139 | request.setClientSecret(appClientSecret); //must 140 | request.setGrantType("client_credentials"); 141 | request.setProvisionKey(API_PROVISION_KEY); //must 142 | request.setAuthenticatedUserid("testUserId"); //must 143 | 144 | Token token = kongClient.getOAuth2ProcessService().grantToken(API_URI, request); 145 | cache.put("token", token); 146 | printJson(cache); 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | #DEBUG < INFO < WARN < ERROR < FATAL 2 | log4j.rootLogger=INFO,stdout,fileout 3 | log4j.logger.com.github=DEBUG 4 | 5 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 6 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 7 | log4j.appender.stdout.layout.conversionPattern= [%-d{yyyy-MM-dd HH:mm:ss}] [kong-java-client] [%p] [%c] %m%n 8 | 9 | log4j.appender.fileout=org.apache.log4j.DailyRollingFileAppender 10 | log4j.appender.fileout.layout=org.apache.log4j.PatternLayout 11 | log4j.appender.fileout.File=./logs/kong-java-client.log 12 | log4j.appender.fileout.DatePattern='_'yyyy-MM-dd 13 | log4j.appender.fileout.layout.ConversionPattern=[%-d{yyyy-MM-dd HH:mm:ss}] [kong-java-client] [%p] [%c] %m%n 14 | --------------------------------------------------------------------------------