├── .gitattributes ├── .gitignore ├── License ├── README.md ├── pom.xml ├── xcloud-common ├── pom.xml └── src │ └── main │ └── java │ └── cn │ └── exrick │ └── xcloud │ └── common │ ├── base │ ├── BaseXCloudController.java │ ├── BaseXCloudDao.java │ ├── BaseXCloudEntity.java │ └── BaseXCloudService.java │ ├── config │ └── Swagger2Config.java │ ├── constant │ ├── CommonConstant.java │ └── SecurityConstant.java │ ├── exception │ ├── RestCtrlExceptionHandler.java │ └── XCloudException.java │ ├── utils │ ├── AESUtil.java │ ├── IpInfoUtil.java │ ├── JasyptUtil.java │ ├── PageUtil.java │ ├── ResultUtil.java │ ├── SecurityUtil.java │ └── SnowFlakeUtil.java │ └── vo │ ├── City.java │ ├── IpLocate.java │ ├── PageVo.java │ └── Result.java ├── xcloud-config ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── exrick │ │ └── xcloud │ │ └── config │ │ └── ConfigServerApplication.java │ └── resources │ ├── application.yml │ ├── banner.txt │ └── favicon.ico ├── xcloud-eureka ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── exrick │ │ └── xcloud │ │ └── eureka │ │ └── EurekaServerApplication.java │ └── resources │ ├── application.yml │ ├── banner.txt │ └── favicon.ico ├── xcloud-gateway ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── exrick │ │ └── xcloud │ │ └── gateway │ │ ├── GatewayServerApplication.java │ │ ├── config │ │ ├── SwaggerDocumentationConfig.java │ │ └── WebSecurityConfig.java │ │ ├── fallbacks │ │ └── ServiceFallbackProvider.java │ │ └── filter │ │ ├── AccessFilter.java │ │ └── ErrorFilter.java │ └── resources │ ├── application.yml │ ├── banner.txt │ ├── bootstrap.yml │ └── favicon.ico ├── xcloud-modules ├── pom.xml └── xcloud-base │ ├── pom.xml │ ├── xcloud-base-api │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── cn │ │ └── exrick │ │ └── xcloud │ │ └── base │ │ ├── entity │ │ ├── Permission.java │ │ ├── Role.java │ │ ├── RolePermission.java │ │ └── User.java │ │ └── service │ │ └── UserService.java │ └── xcloud-base-service │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── cn │ │ └── exrick │ │ └── xcloud │ │ └── base │ │ ├── BaseServerApplication.java │ │ ├── controller │ │ └── UserController.java │ │ ├── dao │ │ └── UserDao.java │ │ └── service │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ ├── banner.txt │ ├── bootstrap.yml │ └── favicon.ico └── xcloud-oauth ├── pom.xml └── src └── main ├── java └── cn │ └── exrick │ └── xcloud │ └── oauth │ ├── OAuthServerApplication.java │ ├── config │ ├── AuthorizationServerConfig.java │ ├── ResourceServerConfig.java │ └── WebSecurityConfig.java │ ├── controller │ └── OauthController.java │ └── fegin │ ├── UserService.java │ └── fallback │ └── UserServiceImplFallback.java └── resources ├── application.yml ├── banner.txt ├── bootstrap.yml └── favicon.ico /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=Java 2 | *.css linguist-language=Java 3 | *.vm linguist-language=Java 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #.idea/ 2 | 3 | target/ 4 | 5 | *.iml 6 | 7 | *.bak 8 | 9 | application-prod.yml 10 | -------------------------------------------------------------------------------- /License: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 3, 29 June 2007 4 | 5 | Copyright © 2007 Free Software Foundation, Inc. 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 14 | 15 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 16 | 17 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. 18 | 19 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 20 | 21 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. 22 | 23 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. 24 | 25 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 26 | 27 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 28 | 29 | The precise terms and conditions for copying, distribution and modification follow. 30 | 31 | TERMS AND CONDITIONS 32 | 33 | 0. Definitions. 34 | 35 | “This License” refers to version 3 of the GNU General Public License. 36 | 37 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 38 | 39 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. 40 | 41 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. 42 | 43 | A “covered work” means either the unmodified Program or a work based on the Program. 44 | 45 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 46 | 47 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 48 | 49 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 50 | 51 | 1. Source Code. 52 | 53 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. 54 | 55 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 56 | 57 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 58 | 59 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 60 | 61 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 62 | 63 | The Corresponding Source for a work in source code form is that same work. 64 | 65 | 2. Basic Permissions. 66 | 67 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 68 | 69 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. 70 | 71 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 72 | 73 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 74 | 75 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 76 | 77 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 78 | 79 | 4. Conveying Verbatim Copies. 80 | 81 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 82 | 83 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 84 | 85 | 5. Conveying Modified Source Versions. 86 | 87 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 88 | 89 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 90 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. 91 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 92 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 93 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 94 | 95 | 6. Conveying Non-Source Forms. 96 | 97 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 98 | 99 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 100 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. 101 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 102 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 103 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 104 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 105 | 106 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 107 | 108 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 109 | 110 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 111 | 112 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. 113 | 114 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 115 | 116 | 7. Additional Terms. 117 | 118 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 119 | 120 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 121 | 122 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 123 | 124 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 125 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 126 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 127 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 128 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 129 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 130 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 131 | 132 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 133 | 134 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 135 | 136 | 8. Termination. 137 | 138 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 139 | 140 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 141 | 142 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 143 | 144 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 145 | 146 | 9. Acceptance Not Required for Having Copies. 147 | 148 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 149 | 150 | 10. Automatic Licensing of Downstream Recipients. 151 | 152 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 153 | 154 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 155 | 156 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 157 | 158 | 11. Patents. 159 | 160 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. 161 | 162 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 163 | 164 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 165 | 166 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 167 | 168 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 169 | 170 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 171 | 172 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 173 | 174 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 175 | 176 | 12. No Surrender of Others' Freedom. 177 | 178 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 179 | 180 | 13. Use with the GNU Affero General Public License. 181 | 182 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 183 | 184 | 14. Revised Versions of this License. 185 | 186 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 187 | 188 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 189 | 190 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 191 | 192 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 193 | 194 | 15. Disclaimer of Warranty. 195 | 196 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 197 | 198 | 16. Limitation of Liability. 199 | 200 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 201 | 202 | 17. Interpretation of Sections 15 and 16. 203 | 204 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 205 | 206 | END OF TERMS AND CONDITIONS 207 | 208 | How to Apply These Terms to Your New Programs 209 | 210 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. 211 | 212 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. 213 | 214 | 215 | Copyright (C) 216 | 217 | This program is free software: you can redistribute it and/or modify 218 | it under the terms of the GNU General Public License as published by 219 | the Free Software Foundation, either version 3 of the License, or 220 | (at your option) any later version. 221 | 222 | This program is distributed in the hope that it will be useful, 223 | but WITHOUT ANY WARRANTY; without even the implied warranty of 224 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 225 | GNU General Public License for more details. 226 | 227 | You should have received a copy of the GNU General Public License 228 | along with this program. If not, see . 229 | Also add information on how to contact you by electronic and paper mail. 230 | 231 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 232 | 233 | Copyright (C) 234 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 235 | This is free software, and you are welcome to redistribute it 236 | under certain conditions; type `show c' for details. 237 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. 238 | 239 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . 240 | 241 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 开发中 2 | eureka:1000 3 | config:1001 4 | gateway:1002 5 | oauth:1003 6 | base:1004 7 | 8 | ### 当前版本 9 | - Spring Cloud Finchley.SR1 / Spring Boot 2.0.1.RELEASE 10 | ### 开发提醒 11 | - 配置文件编码格式为UTF-8 12 | - 使用Lombok简化开发 开发时记得安装Lombok插件避免编译器报错 13 | - 配置文件加密 Jasypt加密 可到xcloud-common服务中找到JasyptUtil工具类生成加密结果 14 | ### 学习记录(更新中) 15 | - [Eureka注册中心的高可用](https://github.com/Exrick/x-cloud/wiki/Eureka%E6%B3%A8%E5%86%8C%E4%B8%AD%E5%BF%83%E7%9A%84%E9%AB%98%E5%8F%AF%E7%94%A8) 16 | - [统一配置中心及使用Spring Cloud Bus自动刷新配置](https://github.com/Exrick/x-cloud/wiki/%E7%BB%9F%E4%B8%80%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83%E5%8F%8A%E4%BD%BF%E7%94%A8Spring-Cloud-Bus%E8%87%AA%E5%8A%A8%E5%88%B7%E6%96%B0%E9%85%8D%E7%BD%AE) -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | cn.exrick 8 | x-cloud 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | 13 | 14 | Exrick 15 | 1012139570@qq.com 16 | 17 | 18 | 19 | xcloud-eureka 20 | xcloud-common 21 | xcloud-config 22 | xcloud-gateway 23 | xcloud-modules 24 | xcloud-oauth 25 | 26 | 27 | 28 | UTF-8 29 | 1.8 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-parent 35 | 2.0.1.RELEASE 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.cloud 42 | spring-cloud-dependencies 43 | Finchley.SR1 44 | pom 45 | import 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.cloud 53 | spring-cloud-starter-config 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-starter-netflix-eureka-client 58 | 59 | 60 | org.springframework.cloud 61 | spring-cloud-starter-bus-amqp 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-starter-web 66 | 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-starter-actuator 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-starter-test 76 | test 77 | 78 | 79 | 80 | org.projectlombok 81 | lombok 82 | 1.18.2 83 | 84 | 85 | 86 | com.github.ulisesbocchio 87 | jasypt-spring-boot-starter 88 | 2.1.0 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | aliyun 102 | aliyun 103 | http://maven.aliyun.com/nexus/content/groups/public/ 104 | 105 | true 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /xcloud-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | x-cloud 7 | cn.exrick 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | xcloud-common 13 | 14 | 15 | UTF-8 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-data-redis 27 | 28 | 29 | 30 | cn.hutool 31 | hutool-all 32 | 4.1.9 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-data-jpa 38 | 39 | 40 | 41 | com.baomidou 42 | mybatis-plus-boot-starter 43 | 2.2.0 44 | 45 | 46 | 47 | com.google.code.gson 48 | gson 49 | 2.8.5 50 | 51 | 52 | 53 | io.springfox 54 | springfox-swagger2 55 | 2.7.0 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/base/BaseXCloudController.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.base; 2 | 3 | import cn.exrick.xcloud.common.utils.PageUtil; 4 | import cn.exrick.xcloud.common.utils.ResultUtil; 5 | import cn.exrick.xcloud.common.vo.PageVo; 6 | import cn.exrick.xcloud.common.vo.Result; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import java.io.Serializable; 13 | import java.util.List; 14 | 15 | /** 16 | * @author Exrickx 17 | */ 18 | public abstract class BaseXCloudController { 19 | 20 | /** 21 | * 获取service 22 | * @return 23 | */ 24 | @Autowired 25 | public abstract BaseXCloudService getService(); 26 | 27 | @RequestMapping(value = "/get/{id}",method = RequestMethod.GET) 28 | @ResponseBody 29 | @ApiOperation(value = "通过id获取") 30 | public Result get(@PathVariable ID id){ 31 | 32 | E entity = getService().get(id); 33 | return new ResultUtil().setData(entity); 34 | } 35 | 36 | @RequestMapping(value = "/getAll",method = RequestMethod.GET) 37 | @ResponseBody 38 | @ApiOperation(value = "获取全部数据") 39 | public Result> getAll(){ 40 | 41 | List list = getService().getAll(); 42 | return new ResultUtil>().setData(list); 43 | } 44 | 45 | @RequestMapping(value = "/getByPage",method = RequestMethod.GET) 46 | @ResponseBody 47 | @ApiOperation(value = "分页获取") 48 | public Result> getByPage(@ModelAttribute PageVo page){ 49 | 50 | Page data = getService().findAll(PageUtil.initPage(page)); 51 | return new ResultUtil>().setData(data); 52 | } 53 | 54 | @RequestMapping(value = "/save",method = RequestMethod.POST) 55 | @ResponseBody 56 | @ApiOperation(value = "保存数据") 57 | public Result save(@ModelAttribute E entity){ 58 | 59 | E e = getService().save(entity); 60 | return new ResultUtil().setData(e); 61 | } 62 | 63 | @RequestMapping(value = "/update",method = RequestMethod.PUT) 64 | @ResponseBody 65 | @ApiOperation(value = "更新数据") 66 | public Result update(@ModelAttribute E entity){ 67 | 68 | E e = getService().update(entity); 69 | return new ResultUtil().setData(e); 70 | } 71 | 72 | @RequestMapping(value = "/delByIds",method = RequestMethod.DELETE) 73 | @ResponseBody 74 | @ApiOperation(value = "批量通过id删除") 75 | public Result delAllByIds(@RequestParam ID[] ids){ 76 | 77 | for(ID id:ids){ 78 | getService().delete(id); 79 | } 80 | return new ResultUtil().setSuccessMsg("批量通过id删除数据成功"); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/base/BaseXCloudDao.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.base; 2 | 3 | 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 6 | import org.springframework.data.repository.NoRepositoryBean; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * @author Exrickx 12 | */ 13 | // 自定义接口 不会创建接口的实例 必须加此注解 14 | @NoRepositoryBean 15 | public interface BaseXCloudDao extends JpaRepository, JpaSpecificationExecutor { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/base/BaseXCloudEntity.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.base; 2 | 3 | import cn.exrick.xcloud.common.constant.CommonConstant; 4 | import cn.exrick.xcloud.common.utils.SnowFlakeUtil; 5 | import com.baomidou.mybatisplus.annotations.TableId; 6 | import com.fasterxml.jackson.annotation.JsonFormat; 7 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 8 | import io.swagger.annotations.ApiModelProperty; 9 | import lombok.Data; 10 | import org.springframework.data.annotation.CreatedDate; 11 | import org.springframework.data.annotation.LastModifiedDate; 12 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; 13 | import org.springframework.format.annotation.DateTimeFormat; 14 | 15 | import javax.persistence.EntityListeners; 16 | import javax.persistence.Id; 17 | import javax.persistence.MappedSuperclass; 18 | import javax.persistence.Table; 19 | import java.io.Serializable; 20 | import java.util.Date; 21 | 22 | /** 23 | * @author Exrickx 24 | */ 25 | @Data 26 | @MappedSuperclass 27 | @EntityListeners(AuditingEntityListener.class) 28 | @JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"}) 29 | public abstract class BaseXCloudEntity implements Serializable{ 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | @Id 34 | @TableId 35 | @ApiModelProperty(value = "唯一标识") 36 | private String id = String.valueOf(SnowFlakeUtil.getFlowIdInstance().nextId()); 37 | 38 | @ApiModelProperty(value = "创建者") 39 | private String createBy; 40 | 41 | @CreatedDate 42 | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") 43 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 44 | @ApiModelProperty(value = "创建时间") 45 | private Date createTime; 46 | 47 | @ApiModelProperty(value = "更新者") 48 | private String updateBy; 49 | 50 | @LastModifiedDate 51 | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") 52 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 53 | @ApiModelProperty(value = "更新时间") 54 | private Date updateTime; 55 | 56 | @ApiModelProperty(value = "删除标志 默认0") 57 | private Integer delFlag = CommonConstant.STATUS_NORMAL; 58 | } 59 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/base/BaseXCloudService.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.base; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.jpa.domain.Specification; 6 | 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | 11 | /** 12 | * @author Exrickx 13 | */ 14 | //JDK8函数式接口注解 仅能包含一个抽象方法 15 | @FunctionalInterface 16 | public interface BaseXCloudService { 17 | 18 | public BaseXCloudDao getRepository(); 19 | 20 | /** 21 | * 根据ID获取 22 | * @param id 23 | * @return 24 | */ 25 | public default E get(ID id) { 26 | return getRepository().getOne(id); 27 | } 28 | 29 | /** 30 | * 获取所有列表 31 | * @return 32 | */ 33 | public default List getAll() { 34 | return getRepository().findAll(); 35 | } 36 | 37 | /** 38 | * 获取总数 39 | * @return 40 | */ 41 | public default Long getTotalCount() { 42 | return getRepository().count(); 43 | } 44 | 45 | /** 46 | * 保存 47 | * @param entity 48 | * @return 49 | */ 50 | public default E save(E entity) { 51 | 52 | return getRepository().save(entity); 53 | } 54 | 55 | /** 56 | * 修改 57 | * @param entity 58 | * @return 59 | */ 60 | public default E update(E entity) { 61 | return getRepository().saveAndFlush(entity); 62 | } 63 | 64 | /** 65 | * 批量保存与修改 66 | * @param entities 67 | * @return 68 | */ 69 | public default Iterable saveOrUpdateAll(Iterable entities) { 70 | return getRepository().saveAll(entities); 71 | } 72 | 73 | /** 74 | * 删除 75 | * @param entity 76 | */ 77 | public default void delete(E entity) { 78 | getRepository().delete(entity); 79 | } 80 | 81 | /** 82 | * 根据Id删除 83 | * @param id 84 | */ 85 | public default void delete(ID id) { 86 | getRepository().deleteById(id); 87 | } 88 | 89 | /** 90 | * 批量删除 91 | * @param entities 92 | */ 93 | public default void delete(Iterable entities) { 94 | getRepository().deleteAll(entities); 95 | } 96 | 97 | /** 98 | * 清空缓存,提交持久化 99 | */ 100 | public default void flush() { 101 | getRepository().flush(); 102 | } 103 | 104 | /** 105 | * 根据条件查询获取 106 | * @param spec 107 | * @return 108 | */ 109 | public default List findAll(Specification spec) { 110 | return getRepository().findAll(spec); 111 | } 112 | 113 | /** 114 | * 分页获取 115 | * @param pageable 116 | * @return 117 | */ 118 | public default Page findAll(Pageable pageable){ 119 | return getRepository().findAll(pageable); 120 | } 121 | 122 | /** 123 | * 根据查询条件分页获取 124 | * @param spec 125 | * @param pageable 126 | * @return 127 | */ 128 | public default Page findAll(Specification spec, Pageable pageable) { 129 | return getRepository().findAll(spec, pageable); 130 | } 131 | 132 | /** 133 | * 获取查询条件的结果数 134 | * @param spec 135 | * @return 136 | */ 137 | public default long count(Specification spec) { 138 | return getRepository().count(spec); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/config/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.config; 2 | 3 | import io.swagger.annotations.ApiOperation; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import springfox.documentation.builders.ApiInfoBuilder; 9 | import springfox.documentation.builders.PathSelectors; 10 | import springfox.documentation.builders.RequestHandlerSelectors; 11 | import springfox.documentation.service.ApiInfo; 12 | import springfox.documentation.service.Contact; 13 | import springfox.documentation.spi.DocumentationType; 14 | import springfox.documentation.spring.web.plugins.Docket; 15 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 16 | 17 | /** 18 | * @author Exrickx 19 | */ 20 | @Slf4j 21 | @Configuration 22 | @EnableSwagger2 23 | public class Swagger2Config { 24 | 25 | @Value("${swagger.title}") 26 | private String title; 27 | 28 | @Value("${swagger.description}") 29 | private String description; 30 | 31 | @Value("${swagger.version}") 32 | private String version; 33 | 34 | @Value("${swagger.termsOfServiceUrl}") 35 | private String termsOfServiceUrl; 36 | 37 | @Value("${swagger.contact.name}") 38 | private String name; 39 | 40 | @Value("${swagger.contact.url}") 41 | private String url; 42 | 43 | @Value("${swagger.contact.email}") 44 | private String email; 45 | 46 | @Bean 47 | public Docket createRestApi() { 48 | 49 | log.info("加载Swagger2"); 50 | 51 | return new Docket(DocumentationType.SWAGGER_2) 52 | .apiInfo(apiInfo()).select() 53 | //扫描所有有注解的api,用这种方式更灵活 54 | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) 55 | .paths(PathSelectors.any()) 56 | .build(); 57 | } 58 | 59 | private ApiInfo apiInfo() { 60 | return new ApiInfoBuilder() 61 | .title(title) 62 | .description(description) 63 | .termsOfServiceUrl(termsOfServiceUrl) 64 | .contact(new Contact(name, url, email)) 65 | .version(version) 66 | .build(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/constant/CommonConstant.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.constant; 2 | 3 | /** 4 | * 常量 5 | * @author Exrickx 6 | */ 7 | public interface CommonConstant { 8 | 9 | /** 10 | * 用户默认头像 11 | */ 12 | String USER_DEFAULT_AVATAR = "https://s1.ax1x.com/2018/05/19/CcdVQP.png"; 13 | 14 | /** 15 | * 用户正常状态 16 | */ 17 | Integer USER_STATUS_NORMAL = 0; 18 | 19 | /** 20 | * 用户禁用状态 21 | */ 22 | Integer USER_STATUS_LOCK = -1; 23 | 24 | /** 25 | * 普通用户 26 | */ 27 | Integer USER_TYPE_NORMAL = 0; 28 | 29 | /** 30 | * 管理员 31 | */ 32 | Integer USER_TYPE_ADMIN = 1; 33 | 34 | /** 35 | * 性别男 36 | */ 37 | Integer SEX_MAN = 0; 38 | 39 | /** 40 | * 性别女 41 | */ 42 | Integer SEX_WOMAN = 1; 43 | 44 | /** 45 | * 性别保密 46 | */ 47 | Integer SEX_SECRET = 2; 48 | 49 | /** 50 | * 正常状态 51 | */ 52 | Integer STATUS_NORMAL = 0; 53 | 54 | /** 55 | * 禁用状态 56 | */ 57 | Integer STATUS_DISABLE = -1; 58 | 59 | /** 60 | * 删除标志 61 | */ 62 | Integer DEL_FLAG = 1; 63 | 64 | /** 65 | * 限流标识 66 | */ 67 | String LIMIT_ALL = "XBOOT_LIMIT_ALL"; 68 | 69 | /** 70 | * 页面类型权限 71 | */ 72 | Integer PERMISSION_PAGE = 0; 73 | 74 | /** 75 | * 操作类型权限 76 | */ 77 | Integer PERMISSION_OPERATION = 1; 78 | 79 | /** 80 | * 1级菜单父id 81 | */ 82 | String PARENT_ID = "0"; 83 | 84 | /** 85 | * 1级菜单 86 | */ 87 | Integer LEVEL_ONE = 1; 88 | 89 | /** 90 | * 2级菜单 91 | */ 92 | Integer LEVEL_TWO = 2; 93 | 94 | /** 95 | * 3级菜单 96 | */ 97 | Integer LEVEL_THREE = 3; 98 | 99 | /** 100 | * 消息发送范围 101 | */ 102 | Integer MESSAGE_RANGE_ALL = 0; 103 | 104 | /** 105 | * 公告 106 | */ 107 | Integer MESSAGE_TYPE_SYSTEM = 0; 108 | 109 | /** 110 | * 提醒 111 | */ 112 | Integer MESSAGE_TYPE_REMIND = 1; 113 | 114 | /** 115 | * 私信 116 | */ 117 | Integer MESSAGE_TYPE_PERSONAL = 2; 118 | 119 | /** 120 | * 未读 121 | */ 122 | Integer MESSAGE_STATUS_UNREAD = 0; 123 | 124 | /** 125 | * 已读 126 | */ 127 | Integer MESSAGE_STATUS_READ = 1; 128 | 129 | /** 130 | * github登录 131 | */ 132 | Integer SOCIAL_TYPE_GITHUB = 0; 133 | 134 | /** 135 | * qq登录 136 | */ 137 | Integer SOCIAL_TYPE_QQ = 1; 138 | 139 | /** 140 | * 微博登录 141 | */ 142 | Integer SOCIAL_TYPE_WEIBO = 2; 143 | 144 | /** 145 | * 短信验证码key前缀 146 | */ 147 | String PRE_SMS = "XBOOT_PRE_SMS:"; 148 | } 149 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/constant/SecurityConstant.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.constant; 2 | 3 | /** 4 | * @author Exrickx 5 | */ 6 | public interface SecurityConstant { 7 | 8 | /** 9 | * token分割 10 | */ 11 | String TOKEN_SPLIT = "Bearer "; 12 | 13 | /** 14 | * JWT签名加密key 15 | */ 16 | String JWT_SIGN_KEY = "xboot"; 17 | 18 | /** 19 | * token参数头 20 | */ 21 | String HEADER = "accessToken"; 22 | 23 | /** 24 | * 权限参数头 25 | */ 26 | String AUTHORITIES = "authorities"; 27 | 28 | /** 29 | * 用户选择JWT保存时间参数头 30 | */ 31 | String SAVE_LOGIN = "saveLogin"; 32 | 33 | /** 34 | * github保存state前缀key 35 | */ 36 | String GITHUB_STATE = "XBOOT_GITHUB_"; 37 | 38 | /** 39 | * qq保存state前缀key 40 | */ 41 | String QQ_STATE = "XBOOT_QQ_"; 42 | } 43 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/exception/RestCtrlExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.exception; 2 | 3 | 4 | import cn.exrick.xcloud.common.utils.ResultUtil; 5 | import cn.exrick.xcloud.common.vo.Result; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | /** 11 | * @author Exrickx 12 | */ 13 | @Slf4j 14 | @RestControllerAdvice 15 | public class RestCtrlExceptionHandler { 16 | 17 | @ExceptionHandler(XCloudException.class) 18 | @ResponseStatus(value = HttpStatus.OK) 19 | public Result handleXCloudException(XCloudException e) { 20 | String errorMsg = "XCloud exception"; 21 | if (e!=null){ 22 | errorMsg=e.getMessage(); 23 | log.warn(e.toString()); 24 | } 25 | return new ResultUtil<>().setErrorMsg(500, errorMsg); 26 | } 27 | 28 | @ExceptionHandler(Exception.class) 29 | @ResponseStatus(value = HttpStatus.OK) 30 | public Result handleException(Exception e) { 31 | String errorMsg = "Exception"; 32 | if (e!=null){ 33 | errorMsg=e.getMessage(); 34 | log.warn(e.toString()); 35 | } 36 | return new ResultUtil<>().setErrorMsg(500, errorMsg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/exception/XCloudException.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.exception; 2 | 3 | /** 4 | * @author Exrickx 5 | */ 6 | public class XCloudException extends RuntimeException { 7 | 8 | public XCloudException(String msg){ 9 | super(msg); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/utils/AESUtil.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.utils; 2 | 3 | 4 | import cn.hutool.core.codec.Base64; 5 | import cn.hutool.core.util.StrUtil; 6 | import javax.crypto.Cipher; 7 | import javax.crypto.KeyGenerator; 8 | import javax.crypto.spec.SecretKeySpec; 9 | import java.security.SecureRandom; 10 | 11 | /** 12 | * AES加解密 13 | * @author Exrickx 14 | */ 15 | public class AESUtil { 16 | 17 | /** 18 | * 默认key 请保管好您的密钥 19 | */ 20 | public final static String KEY = "XCloudIsANiceFramePresentedByExrick"; 21 | 22 | public static String aesEncrypt(String value){ 23 | 24 | String result = null; 25 | try { 26 | if(value != null && !"".equals(value.trim())){ 27 | result = base64Encode(aesEncryptToBytes(value, KEY)); 28 | } 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | 33 | return result; 34 | } 35 | 36 | public static String aesEncrypt(String value, String key){ 37 | 38 | String result = null; 39 | key = StrUtil.isBlank(key) ? KEY : key; 40 | try { 41 | if(value != null && !"".equals(value.trim())){ 42 | result = base64Encode(aesEncryptToBytes(value, key)); 43 | } 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | } 47 | 48 | return result; 49 | } 50 | 51 | public static String aesDecrypt(String value){ 52 | 53 | String result = null; 54 | try { 55 | if(value != null && !"".equals(value.trim())){ 56 | result = aesDecryptByBytes(base64Decode(value), KEY); 57 | } 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | } 61 | 62 | return result; 63 | } 64 | 65 | public static String aesDecrypt(String value, String key){ 66 | 67 | String result = null; 68 | key = StrUtil.isBlank(key) ? KEY : key; 69 | try { 70 | if(value != null && !"".equals(value.trim())){ 71 | result = aesDecryptByBytes(base64Decode(value), key); 72 | } 73 | } catch (Exception e) { 74 | e.printStackTrace(); 75 | } 76 | 77 | return result; 78 | } 79 | 80 | private static String base64Encode(byte[] bytes){ 81 | return Base64.encode(bytes); 82 | } 83 | 84 | @SuppressWarnings("static-access") 85 | private static byte[] base64Decode(String base64Code) throws Exception{ 86 | return base64Code == null ? null : Base64.decode((base64Code)); 87 | } 88 | 89 | private static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception { 90 | KeyGenerator kgen = KeyGenerator.getInstance("AES"); 91 | SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); 92 | random.setSeed(encryptKey.getBytes()); 93 | kgen.init(128, random); 94 | 95 | Cipher cipher = Cipher.getInstance("AES"); 96 | cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES")); 97 | 98 | return cipher.doFinal(content.getBytes("utf-8")); 99 | } 100 | 101 | private static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception { 102 | KeyGenerator kgen = KeyGenerator.getInstance("AES"); 103 | SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); 104 | random.setSeed(decryptKey.getBytes()); 105 | kgen.init(128, random); 106 | 107 | Cipher cipher = Cipher.getInstance("AES"); 108 | cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES")); 109 | byte[] decryptBytes = cipher.doFinal(encryptBytes); 110 | 111 | return new String(decryptBytes); 112 | } 113 | 114 | public static void main(String[] args){ 115 | 116 | //加密 117 | System.out.println(aesEncrypt("123456",KEY)); 118 | //解密 默认AESUtil.KEY 119 | System.out.println(aesDecrypt("Vv7lts9JW2/mR0DEaylI1w==")); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/utils/IpInfoUtil.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.utils; 2 | 3 | import cn.exrick.xcloud.common.vo.IpLocate; 4 | import cn.hutool.core.util.StrUtil; 5 | import cn.hutool.http.HttpUtil; 6 | import com.google.gson.Gson; 7 | import lombok.extern.slf4j.Slf4j; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import java.net.InetAddress; 11 | import java.net.UnknownHostException; 12 | 13 | 14 | /** 15 | * @author Exrickx 16 | */ 17 | @Slf4j 18 | public class IpInfoUtil { 19 | 20 | /** 21 | * Mob api 22 | */ 23 | private static final String APPKEY = "你的appkey"; 24 | 25 | private static final String LOCAL_HOST = "0:0:0:0:0:0:0:1"; 26 | 27 | /** 28 | * 获取客户端IP地址 29 | * @param request 请求 30 | * @return 31 | */ 32 | public static String getIp(HttpServletRequest request) { 33 | String ip = request.getHeader("x-forwarded-for"); 34 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 35 | ip = request.getHeader("Proxy-Client-IP"); 36 | } 37 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 38 | ip = request.getHeader("WL-Proxy-Client-IP"); 39 | } 40 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 41 | ip = request.getRemoteAddr(); 42 | if (ip.equals("127.0.0.1")) { 43 | //根据网卡取本机配置的IP 44 | InetAddress inet = null; 45 | try { 46 | inet = InetAddress.getLocalHost(); 47 | } catch (UnknownHostException e) { 48 | e.printStackTrace(); 49 | } 50 | ip = inet.getHostAddress(); 51 | } 52 | } 53 | // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 54 | if (ip != null && ip.length() > 15) { 55 | if (ip.indexOf(",") > 0) { 56 | ip = ip.substring(0, ip.indexOf(",")); 57 | } 58 | } 59 | if(LOCAL_HOST.equals(ip)){ 60 | ip = "127.0.0.1"; 61 | } 62 | return ip; 63 | } 64 | 65 | /** 66 | * 获取IP返回地理天气信息 67 | * @param ip ip地址 68 | * @return 69 | */ 70 | public String getIpWeatherInfo(String ip){ 71 | 72 | String GET_IP_WEATHER = "http://apicloud.mob.com/v1/weather/ip?key="+ APPKEY +"&ip="; 73 | if(StrUtil.isNotBlank(ip)){ 74 | String url = GET_IP_WEATHER + ip; 75 | String result= HttpUtil.get(url); 76 | return result; 77 | } 78 | return null; 79 | } 80 | 81 | /** 82 | * 获取IP返回地理信息 83 | * @param ip ip地址 84 | * @return 85 | */ 86 | public String getIpCity(String ip){ 87 | 88 | String GET_IP_LOCATE = "http://apicloud.mob.com/ip/query?key="+ APPKEY +"&ip="; 89 | if(null != ip){ 90 | String url = GET_IP_LOCATE + ip; 91 | String result="未知"; 92 | try{ 93 | String json= HttpUtil.get(url, 3000); 94 | IpLocate locate=new Gson().fromJson(json, IpLocate.class); 95 | if(("200").equals(locate.getRetCode())){ 96 | if(StrUtil.isNotBlank(locate.getResult().getProvince())){ 97 | result=locate.getResult().getProvince()+" "+locate.getResult().getCity(); 98 | }else{ 99 | result=locate.getResult().getCountry(); 100 | } 101 | } 102 | }catch (Exception e){ 103 | log.info("获取IP信息失败"); 104 | } 105 | return result; 106 | } 107 | return null; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/utils/JasyptUtil.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.utils; 2 | 3 | import org.jasypt.encryption.pbe.PooledPBEStringEncryptor; 4 | import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig; 5 | 6 | /** 7 | * @author Exrickx 8 | */ 9 | public class JasyptUtil { 10 | 11 | /** 12 | * Jasypt生成加密结果 13 | * @param password 配置文件中设定的加密密码 jasypt.encryptor.password 14 | * @param value 待加密值 15 | * @return 16 | */ 17 | public static String encyptPwd(String password,String value){ 18 | PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); 19 | encryptor.setConfig(cryptor(password)); 20 | String result = encryptor.encrypt(value); 21 | return result; 22 | } 23 | 24 | /** 25 | * 解密 26 | * @param password 配置文件中设定的加密密码 jasypt.encryptor.password 27 | * @param value 待解密密文 28 | * @return 29 | */ 30 | public static String decyptPwd(String password,String value){ 31 | PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor(); 32 | encryptor.setConfig(cryptor(password)); 33 | String result = encryptor.decrypt(value); 34 | return result; 35 | } 36 | 37 | public static SimpleStringPBEConfig cryptor(String password){ 38 | SimpleStringPBEConfig config = new SimpleStringPBEConfig(); 39 | config.setPassword(password); 40 | config.setAlgorithm("PBEWithMD5AndDES"); 41 | config.setKeyObtentionIterations("1000"); 42 | config.setPoolSize("1"); 43 | config.setProviderName("SunJCE"); 44 | config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator"); 45 | config.setStringOutputType("base64"); 46 | return config; 47 | } 48 | 49 | public static void main(String[] args){ 50 | System.out.println(encyptPwd("xcloud","xcloud")); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/utils/PageUtil.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.utils; 2 | 3 | import cn.exrick.xcloud.common.vo.PageVo; 4 | import cn.hutool.core.util.StrUtil; 5 | import org.springframework.data.domain.PageRequest; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.data.domain.Sort; 8 | 9 | 10 | /** 11 | * @author Exrickx 12 | */ 13 | public class PageUtil { 14 | 15 | public static Pageable initPage(PageVo page){ 16 | 17 | Pageable pageable = null; 18 | int pageNumber = page.getPageNumber(); 19 | int pageSize = page.getPageSize(); 20 | String sort = page.getSort(); 21 | String order = page.getOrder(); 22 | 23 | if(pageNumber<1){ 24 | pageNumber = 1; 25 | } 26 | if(pageSize<1){ 27 | pageSize = 10; 28 | } 29 | if(StrUtil.isNotBlank(sort)) { 30 | Sort.Direction d; 31 | if(StrUtil.isBlank(order)) { 32 | d = Sort.Direction.DESC; 33 | }else { 34 | d = Sort.Direction.valueOf(order.toUpperCase()); 35 | } 36 | Sort s = new Sort(d,sort); 37 | pageable = PageRequest.of(pageNumber-1, pageSize,s); 38 | }else { 39 | pageable = PageRequest.of(pageNumber-1, pageSize); 40 | } 41 | return pageable; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/utils/ResultUtil.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.utils; 2 | 3 | 4 | import cn.exrick.xcloud.common.vo.Result; 5 | 6 | /** 7 | * @author Exrick 8 | */ 9 | public class ResultUtil { 10 | 11 | private Result result; 12 | 13 | public ResultUtil(){ 14 | result=new Result<>(); 15 | result.setSuccess(true); 16 | result.setMessage("success"); 17 | result.setCode(200); 18 | } 19 | 20 | public Result setData(T t){ 21 | this.result.setResult(t); 22 | this.result.setCode(200); 23 | return this.result; 24 | } 25 | 26 | public Result setSuccessMsg(String msg){ 27 | this.result.setSuccess(true); 28 | this.result.setMessage(msg); 29 | this.result.setCode(200); 30 | this.result.setResult(null); 31 | return this.result; 32 | } 33 | 34 | public Result setData(T t, String msg){ 35 | this.result.setResult(t); 36 | this.result.setCode(200); 37 | this.result.setMessage(msg); 38 | return this.result; 39 | } 40 | 41 | public Result setErrorMsg(String msg){ 42 | this.result.setSuccess(false); 43 | this.result.setMessage(msg); 44 | this.result.setCode(500); 45 | return this.result; 46 | } 47 | 48 | public Result setErrorMsg(Integer code, String msg){ 49 | this.result.setSuccess(false); 50 | this.result.setMessage(msg); 51 | this.result.setCode(code); 52 | return this.result; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/utils/SecurityUtil.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.utils; 2 | // 3 | //import org.springframework.security.authentication.AnonymousAuthenticationToken; 4 | //import org.springframework.security.core.Authentication; 5 | //import org.springframework.security.core.context.SecurityContextHolder; 6 | // 7 | /** 8 | * @author Exrickx 9 | */ 10 | public class SecurityUtil { 11 | 12 | // public static String getCurrentUsername() { 13 | // 14 | // Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 15 | // String currentUserName = null; 16 | // if (!(authentication instanceof AnonymousAuthenticationToken)) { 17 | // currentUserName = authentication.getName(); 18 | // } 19 | // return currentUserName; 20 | // } 21 | } 22 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/utils/SnowFlakeUtil.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.utils; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | 5 | /** 6 | * 原作者 zzxadi https://github.com/zzxadi/Snowflake-IdWorker 7 | * @author Exrickx 8 | */ 9 | @Slf4j 10 | public class SnowFlakeUtil { 11 | 12 | private final long id; 13 | /** 14 | * 时间起始标记点,作为基准,一般取系统的最近时间 15 | */ 16 | private final long epoch = 1524291141010L; 17 | /** 18 | * 机器标识位数 19 | */ 20 | private final long workerIdBits = 10L; 21 | /** 22 | * 机器ID最大值: 1023 23 | */ 24 | private final long maxWorkerId = -1L ^ -1L << this.workerIdBits; 25 | /** 26 | * 0,并发控制 27 | */ 28 | private long sequence = 0L; 29 | /** 30 | * 毫秒内自增位 31 | */ 32 | private final long sequenceBits = 12L; 33 | 34 | /** 35 | * 12 36 | */ 37 | private final long workerIdShift = this.sequenceBits; 38 | /** 39 | * 22 40 | */ 41 | private final long timestampLeftShift = this.sequenceBits + this.workerIdBits; 42 | /** 43 | * 4095,111111111111,12位 44 | */ 45 | private final long sequenceMask = -1L ^ -1L << this.sequenceBits; 46 | private long lastTimestamp = -1L; 47 | 48 | private SnowFlakeUtil(long id) { 49 | if (id > this.maxWorkerId || id < 0) { 50 | throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", this.maxWorkerId)); 51 | } 52 | this.id = id; 53 | } 54 | 55 | public synchronized long nextId() { 56 | long timestamp = timeGen(); 57 | if (this.lastTimestamp == timestamp) { 58 | //如果上一个timestamp与新产生的相等,则sequence加一(0-4095循环); 对新的timestamp,sequence从0开始 59 | this.sequence = this.sequence + 1 & this.sequenceMask; 60 | if (this.sequence == 0) { 61 | // 重新生成timestamp 62 | timestamp = this.tilNextMillis(this.lastTimestamp); 63 | } 64 | } else { 65 | this.sequence = 0; 66 | } 67 | 68 | if (timestamp < this.lastTimestamp) { 69 | log.error(String.format("clock moved backwards.Refusing to generate id for %d milliseconds", (this.lastTimestamp - timestamp))); 70 | return -1; 71 | } 72 | 73 | this.lastTimestamp = timestamp; 74 | return timestamp - this.epoch << this.timestampLeftShift | this.id << this.workerIdShift | this.sequence; 75 | } 76 | 77 | private static SnowFlakeUtil flowIdWorker = new SnowFlakeUtil(1); 78 | public static SnowFlakeUtil getFlowIdInstance() { 79 | return flowIdWorker; 80 | } 81 | 82 | /** 83 | * 等待下一个毫秒的到来, 保证返回的毫秒数在参数lastTimestamp之后 84 | */ 85 | private long tilNextMillis(long lastTimestamp) { 86 | long timestamp = timeGen(); 87 | while (timestamp <= lastTimestamp) { 88 | timestamp = timeGen(); 89 | } 90 | return timestamp; 91 | } 92 | 93 | /** 94 | * 获得系统当前毫秒数 95 | */ 96 | private static long timeGen() { 97 | return System.currentTimeMillis(); 98 | } 99 | 100 | public static void main(String[] args) { 101 | for(int i=0;i<100;i++){ 102 | SnowFlakeUtil snowFlakeUtil = SnowFlakeUtil.getFlowIdInstance(); 103 | System.out.println(snowFlakeUtil.nextId()); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/vo/City.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author Exrickx 9 | */ 10 | @Data 11 | public class City implements Serializable { 12 | 13 | String country; 14 | 15 | String province; 16 | 17 | String city; 18 | } 19 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/vo/IpLocate.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @author Exrickx 9 | */ 10 | @Data 11 | public class IpLocate implements Serializable { 12 | 13 | private String retCode; 14 | 15 | private City result; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/vo/PageVo.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.vo; 2 | 3 | import io.swagger.annotations.ApiModelProperty; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Exrickx 10 | */ 11 | @Data 12 | public class PageVo implements Serializable{ 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | @ApiModelProperty(value = "页号") 17 | private int pageNumber; 18 | 19 | @ApiModelProperty(value = "页面大小") 20 | private int pageSize; 21 | 22 | @ApiModelProperty(value = "排序字段") 23 | private String sort; 24 | 25 | @ApiModelProperty(value = "排序方式 asc/desc") 26 | private String order; 27 | } 28 | -------------------------------------------------------------------------------- /xcloud-common/src/main/java/cn/exrick/xcloud/common/vo/Result.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.common.vo; 2 | 3 | 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Exrickx 10 | * 前后端交互数据标准 11 | */ 12 | @Data 13 | public class Result implements Serializable{ 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | /** 18 | * 成功标志 19 | */ 20 | private boolean success; 21 | 22 | /** 23 | * 失败消息 24 | */ 25 | private String message; 26 | 27 | /** 28 | * 返回代码 29 | */ 30 | private Integer code; 31 | 32 | /** 33 | * 时间戳 34 | */ 35 | private long timestamp = System.currentTimeMillis(); 36 | 37 | /** 38 | * 结果对象 39 | */ 40 | private T result; 41 | } 42 | -------------------------------------------------------------------------------- /xcloud-config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | x-cloud 7 | cn.exrick 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | xcloud-config 13 | 14 | 15 | UTF-8 16 | 1.8 17 | 18 | 19 | 20 | 21 | org.springframework.cloud 22 | spring-cloud-config-server 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /xcloud-config/src/main/java/cn/exrick/xcloud/config/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | /** 9 | * @author Exrickx 10 | */ 11 | @SpringBootApplication 12 | @EnableConfigServer 13 | @EnableEurekaClient 14 | public class ConfigServerApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ConfigServerApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /xcloud-config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 1001 3 | 4 | eureka: 5 | instance: 6 | # 使用ip注册 7 | prefer-ip-address: true 8 | ip-address: 127.0.0.1 9 | # 默认hostname注册 10 | hostname: localhost 11 | client: 12 | serviceUrl: 13 | defaultZone: http://localhost:1000/eureka/ 14 | 15 | spring: 16 | application: 17 | name: config-server 18 | cloud: 19 | config: 20 | server: 21 | # Git/SVN配置 更换svn此处改为svn: 22 | git: 23 | # 仓库地址与账密 24 | uri: https://github.com/Exrick/xcloud-config 25 | # private仓库需配置账密 26 | username: 27 | password: 28 | # 指定文件夹 相对搜索路径 可以配置多个 29 | search-paths: 30 | # 指定从git上拉取至本地保存路径 31 | # basedir: 32 | # 快速返回失败信息 33 | fail-fast: true 34 | rabbitmq: 35 | host: 148.70.109.242 36 | port: 5672 37 | username: guest 38 | password: guest 39 | 40 | management: 41 | endpoints: 42 | web: 43 | exposure: 44 | include: '*' 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /xcloud-config/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ___________ .__ __ 2 | \_ _____/__ __________|__| ____ | | __ 3 | | __)_\ \/ /\_ __ \ |/ ___\| |/ / 4 | | \> < | | \/ \ \___| < 5 | /_______ /__/\_ \ |__| |__|\___ >__|_ \ 6 | \/ \/ \/ \/ -------------------------------------------------------------------------------- /xcloud-config/src/main/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Exrick/x-cloud/ff2d20169ab3946c271691a5a07e71bbfb902533/xcloud-config/src/main/resources/favicon.ico -------------------------------------------------------------------------------- /xcloud-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | x-cloud 7 | cn.exrick 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | xcloud-eureka 13 | 14 | 15 | UTF-8 16 | 1.8 17 | 18 | 19 | 20 | 21 | org.springframework.cloud 22 | spring-cloud-starter-netflix-eureka-server 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /xcloud-eureka/src/main/java/cn/exrick/xcloud/eureka/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.eureka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | /** 8 | * @author Exrickx 9 | */ 10 | @SpringBootApplication 11 | @EnableEurekaServer 12 | public class EurekaServerApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(EurekaServerApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /xcloud-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: eureka-server 4 | 5 | server: 6 | port: 1000 7 | 8 | eureka: 9 | server: 10 | # 关闭保护机制 生产环境建议开启 11 | enable-self-preservation: false 12 | # 间隔多久拉取服务注册信息 默认30秒 13 | eviction-interval-timer-in-ms: 5000 14 | instance: 15 | # 使用ip注册 16 | prefer-ip-address: true 17 | ip-address: 127.0.0.1 18 | # 默认hostname注册 可修改为其他名称 19 | hostname: localhost 20 | client: 21 | # 是否同步其他eureka节点数据 单个时关闭 22 | register-with-eureka: false 23 | # 不注册自己 24 | fetch-registry: false 25 | service-url: 26 | # 默认交互地址 多个以逗号分隔 27 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /xcloud-eureka/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ___________ .__ __ 2 | \_ _____/__ __________|__| ____ | | __ 3 | | __)_\ \/ /\_ __ \ |/ ___\| |/ / 4 | | \> < | | \/ \ \___| < 5 | /_______ /__/\_ \ |__| |__|\___ >__|_ \ 6 | \/ \/ \/ \/ -------------------------------------------------------------------------------- /xcloud-eureka/src/main/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Exrick/x-cloud/ff2d20169ab3946c271691a5a07e71bbfb902533/xcloud-eureka/src/main/resources/favicon.ico -------------------------------------------------------------------------------- /xcloud-gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | x-cloud 7 | cn.exrick 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | xcloud-gateway 13 | 14 | 15 | UTF-8 16 | 1.8 17 | 18 | 19 | 20 | 21 | cn.exrick 22 | xcloud-common 23 | 1.0-SNAPSHOT 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-netflix-zuul 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-openfeign 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-oauth2 36 | 37 | 38 | 39 | io.springfox 40 | springfox-swagger-ui 41 | 2.7.0 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /xcloud-gateway/src/main/java/cn/exrick/xcloud/gateway/GatewayServerApplication.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 7 | import org.springframework.cloud.client.SpringCloudApplication; 8 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | import org.springframework.context.annotation.ComponentScan; 11 | 12 | /** 13 | * @author Exrickx 14 | */ 15 | @EnableZuulProxy 16 | @SpringCloudApplication 17 | @EnableFeignClients 18 | @ComponentScan(value = {"cn.exrick.xcloud.gateway", "cn.exrick.xcloud.common"}) 19 | @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) 20 | public class GatewayServerApplication { 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(GatewayServerApplication.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /xcloud-gateway/src/main/java/cn/exrick/xcloud/gateway/config/SwaggerDocumentationConfig.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.gateway.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.cloud.netflix.zuul.filters.ZuulProperties; 6 | import org.springframework.context.annotation.Primary; 7 | import org.springframework.stereotype.Component; 8 | import springfox.documentation.swagger.web.SwaggerResource; 9 | import springfox.documentation.swagger.web.SwaggerResourcesProvider; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | /** 16 | * 网关整合Swagger文档在同一页面 17 | * @author Exrickx 18 | */ 19 | @Component 20 | @Primary 21 | @Slf4j 22 | public class SwaggerDocumentationConfig implements SwaggerResourcesProvider { 23 | 24 | @Autowired 25 | private ZuulProperties zuulProperties; 26 | 27 | @Override 28 | public List get() { 29 | 30 | List resources = new ArrayList<>(); 31 | for(Map.Entry entry: zuulProperties.getRoutes().entrySet()){ 32 | String service = entry.getValue().getServiceId(); 33 | if(service != null && entry.getValue().isStripPrefix()){ 34 | SwaggerResource resource = new SwaggerResource(); 35 | resource.setName(entry.getKey() + ":" + service); 36 | resource.setSwaggerVersion("2.0"); 37 | resource.setLocation("/" + entry.getKey() + "/v2/api-docs"); 38 | resources.add(resource); 39 | } 40 | } 41 | return resources; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /xcloud-gateway/src/main/java/cn/exrick/xcloud/gateway/config/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.gateway.config; 2 | 3 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | 9 | /** 10 | * @author Exrickx 11 | */ 12 | @Configuration 13 | @EnableOAuth2Sso 14 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 15 | 16 | @Override 17 | public void configure(HttpSecurity http) throws Exception { 18 | 19 | http. 20 | antMatcher("/**") 21 | //所有请求都得经过认证和授权 22 | .authorizeRequests().anyRequest().authenticated() 23 | .and().authorizeRequests().antMatchers("/","/anon").permitAll() 24 | .and() 25 | //禁用csrf为了方便,否则退出链接必须要发送一个带csrf_token的post请求 26 | .csrf().disable() 27 | // 退出的URL 28 | .logout().logoutUrl("/logout").permitAll() 29 | // 退出成功后跳转路径 30 | .logoutSuccessUrl("/login"); 31 | } 32 | 33 | @Override 34 | public void configure(WebSecurity web) throws Exception { 35 | 36 | //过滤 37 | web.ignoring().antMatchers("*.css","*.js","*.html","*.ico","*.json","*.png","/druid/*"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /xcloud-gateway/src/main/java/cn/exrick/xcloud/gateway/fallbacks/ServiceFallbackProvider.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.gateway.fallbacks; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider; 5 | import org.springframework.http.HttpHeaders; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.http.client.ClientHttpResponse; 9 | 10 | import java.io.ByteArrayInputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | 14 | /** 15 | * @author Exrickx 16 | */ 17 | @Slf4j 18 | public class ServiceFallbackProvider implements FallbackProvider { 19 | 20 | @Override 21 | public String getRoute() { 22 | return "*"; 23 | } 24 | 25 | @Override 26 | public ClientHttpResponse fallbackResponse(String route, Throwable cause) { 27 | 28 | log.error("网关路由: {} 异常: {}", route, cause.getMessage()); 29 | 30 | return new ClientHttpResponse() { 31 | 32 | @Override 33 | public HttpStatus getStatusCode() throws IOException { 34 | return HttpStatus.OK; 35 | } 36 | 37 | @Override 38 | public int getRawStatusCode() throws IOException { 39 | return 200; 40 | } 41 | 42 | @Override 43 | public String getStatusText() throws IOException { 44 | return HttpStatus.SERVICE_UNAVAILABLE.getReasonPhrase(); 45 | } 46 | 47 | @Override 48 | public void close() { 49 | 50 | } 51 | 52 | @Override 53 | public InputStream getBody() throws IOException { 54 | return new ByteArrayInputStream(("Service Unavailable " + route).getBytes()); 55 | } 56 | 57 | @Override 58 | public HttpHeaders getHeaders() { 59 | HttpHeaders headers = new HttpHeaders(); 60 | headers.setContentType(MediaType.APPLICATION_JSON_UTF8); 61 | return headers; 62 | } 63 | }; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /xcloud-gateway/src/main/java/cn/exrick/xcloud/gateway/filter/AccessFilter.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.gateway.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.cloud.netflix.zuul.filters.ZuulProperties; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE; 12 | 13 | /** 14 | * @author Exrickx 15 | */ 16 | @Slf4j 17 | public class AccessFilter extends ZuulFilter { 18 | 19 | @Autowired 20 | private ZuulProperties zuulProperties; 21 | 22 | @Override 23 | public String filterType() { 24 | //过滤器在请求指定生命周期中执行,"pre"代表在被路由之前执行 25 | return PRE_TYPE; 26 | } 27 | 28 | @Override 29 | public int filterOrder() { 30 | //过滤器的执行顺序 31 | return 0; 32 | } 33 | 34 | @Override 35 | public boolean shouldFilter() { 36 | //该过滤器是否需要被执行 37 | return true; 38 | } 39 | 40 | @Override 41 | public Object run() { 42 | 43 | RequestContext ctx = RequestContext.getCurrentContext(); 44 | HttpServletRequest request = ctx.getRequest(); 45 | 46 | Object accessToken = request.getParameter("accessToken"); 47 | if(accessToken == null) { 48 | log.warn("AccessToken is empty!"+zuulProperties.getPrefix()+" "+zuulProperties.getServletPath()+" "+zuulProperties.getServletPattern()); 49 | ctx.setSendZuulResponse(false); 50 | ctx.setResponseStatusCode(401); 51 | return null; 52 | } 53 | log.info("AccessToken ok"); 54 | return null; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /xcloud-gateway/src/main/java/cn/exrick/xcloud/gateway/filter/ErrorFilter.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.gateway.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.ERROR_TYPE; 10 | 11 | /** 12 | * @author Exrickx 13 | */ 14 | @Slf4j 15 | public class ErrorFilter extends ZuulFilter { 16 | 17 | @Override 18 | public String filterType() { 19 | return ERROR_TYPE; 20 | } 21 | 22 | @Override 23 | public int filterOrder() { 24 | return 10; 25 | } 26 | 27 | @Override 28 | public boolean shouldFilter() { 29 | return true; 30 | } 31 | 32 | @Override 33 | public Object run() { 34 | RequestContext ctx = RequestContext.getCurrentContext(); 35 | Throwable throwable = ctx.getThrowable(); 36 | log.error("ErrorFilter : {}", throwable.getCause().getMessage()); 37 | ctx.set("error.status_code", HttpServletResponse.SC_INTERNAL_SERVER_ERROR); 38 | ctx.set("error.exception", throwable.getCause()); 39 | return null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /xcloud-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: gateway-server 4 | # Redis 5 | redis: 6 | host: 127.0.0.1 7 | password: 8 | # 数据库索引 默认0 9 | database: 0 10 | port: 6379 11 | timeout: 10000 12 | 13 | server: 14 | port: 1002 15 | 16 | eureka: 17 | instance: 18 | ip-address: 127.0.0.1 19 | prefer-ip-address: true 20 | client: 21 | serviceUrl: 22 | defaultZone: http://localhost:1000/eureka/ 23 | 24 | zuul: 25 | # 解决会话保持Cookie问题 26 | add-host-header: true 27 | # 解决重定向问题 28 | sensitive-headers: '*' 29 | routes: 30 | # 路由配置 2种方式皆可 31 | oauth: 32 | path: /oauth/** 33 | url: http://localhost:1003/oauth 34 | base: 35 | path: /base/** 36 | serviceId: base-server 37 | 38 | # 多实例配置以举例 开头对应serviceId 39 | #base-server: 40 | # ribbon: 41 | # listOfServers: http://localhost:8080/,http://localhost:8081/ 42 | 43 | # OAuth2 44 | security: 45 | oauth2: 46 | client: 47 | access-token-uri: http://localhost:1003/oauth/token 48 | client-id: xcloud 49 | user-authorization-uri: http://localhost:1003/oauth/authorize 50 | resource: 51 | user-info-uri: http://localhost:1003/user 52 | prefer-token-info: false 53 | 54 | # Swagger界面内容配置 55 | swagger: 56 | title: XCloud Gateway API接口文档 57 | description: XCloud Gateway Api Documentation 58 | version: 1.0.0 59 | termsOfServiceUrl: http://blog.exrick.cn 60 | contact: 61 | name: Exrick 62 | url: http://blog.exrick.cn 63 | email: 1012139570@qq.com 64 | -------------------------------------------------------------------------------- /xcloud-gateway/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ___________ .__ __ 2 | \_ _____/__ __________|__| ____ | | __ 3 | | __)_\ \/ /\_ __ \ |/ ___\| |/ / 4 | | \> < | | \/ \ \___| < 5 | /_______ /__/\_ \ |__| |__|\___ >__|_ \ 6 | \/ \/ \/ \/ -------------------------------------------------------------------------------- /xcloud-gateway/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | # 以下配置需放在bootstrap中,因为加载顺序: bootstrap > config配置中心 > application 2 | spring: 3 | cloud: 4 | config: 5 | # 启用读取远程配置中心 此处已关闭 节省开发资源 建议根据你硬件配置选择是否启用xcloud-config配置中心服务 6 | enabled: false 7 | discovery: 8 | # 使用服务发现组件的xcloud-config 启用远程配置中心时记得设为true 此处关闭防止报错 9 | enabled: false 10 | # 指定服务发现组件中config的serviceId 11 | service-id: config-server 12 | # 对应配置文件名规则: /{label}/{search-paths}/{name或application.name}-{profile}} 13 | name: gateway 14 | profile: dev 15 | # 分支 16 | label: master -------------------------------------------------------------------------------- /xcloud-gateway/src/main/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Exrick/x-cloud/ff2d20169ab3946c271691a5a07e71bbfb902533/xcloud-gateway/src/main/resources/favicon.ico -------------------------------------------------------------------------------- /xcloud-modules/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | x-cloud 7 | cn.exrick 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | xcloud-modules 13 | pom 14 | 15 | xcloud-base 16 | 17 | 18 | 19 | UTF-8 20 | 1.8 21 | 22 | 23 | 24 | 25 | cn.exrick 26 | xcloud-common 27 | 1.0-SNAPSHOT 28 | 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-netflix-hystrix 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-openfeign 37 | 38 | 39 | 40 | com.alibaba 41 | druid-spring-boot-starter 42 | 1.1.10 43 | 44 | 45 | 46 | mysql 47 | mysql-connector-java 48 | 5.1.45 49 | 50 | 51 | 52 | io.springfox 53 | springfox-swagger-ui 54 | 2.7.0 55 | 56 | 57 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | xcloud-modules 7 | cn.exrick 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | xcloud-base 13 | pom 14 | 15 | xcloud-base-api 16 | xcloud-base-service 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | xcloud-base 7 | cn.exrick 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | xcloud-base-api 13 | 14 | 15 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-api/src/main/java/cn/exrick/xcloud/base/entity/Permission.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.base.entity; 2 | 3 | import cn.exrick.xcloud.common.base.BaseXCloudEntity; 4 | import cn.exrick.xcloud.common.constant.CommonConstant; 5 | import com.baomidou.mybatisplus.annotations.TableField; 6 | import com.baomidou.mybatisplus.annotations.TableName; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.Data; 9 | 10 | import javax.persistence.Column; 11 | import javax.persistence.Entity; 12 | import javax.persistence.Table; 13 | import javax.persistence.Transient; 14 | import java.math.BigDecimal; 15 | import java.util.List; 16 | 17 | /** 18 | * 菜单/权限 19 | * @author Exrick 20 | */ 21 | @Data 22 | @Entity 23 | @Table(name = "t_permission") 24 | @TableName("t_permission") 25 | public class Permission extends BaseXCloudEntity { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | @ApiModelProperty(value = "菜单/权限名称") 30 | private String name; 31 | 32 | @ApiModelProperty(value = "层级") 33 | private Integer level; 34 | 35 | @ApiModelProperty(value = "类型 0页面 1具体操作") 36 | private Integer type; 37 | 38 | @ApiModelProperty(value = "菜单标题") 39 | private String title; 40 | 41 | @ApiModelProperty(value = "页面路径/资源链接url") 42 | @Column(nullable = false) 43 | private String path; 44 | 45 | @ApiModelProperty(value = "前端组件") 46 | private String component; 47 | 48 | @ApiModelProperty(value = "图标") 49 | private String icon; 50 | 51 | @ApiModelProperty(value = "按钮权限类型") 52 | private String buttonType; 53 | 54 | @ApiModelProperty(value = "父id") 55 | private String parentId; 56 | 57 | @ApiModelProperty(value = "说明备注") 58 | private String description; 59 | 60 | @ApiModelProperty(value = "排序值") 61 | @Column(precision = 10, scale = 2) 62 | private BigDecimal sortOrder; 63 | 64 | @ApiModelProperty(value = "是否启用 0启用 -1禁用") 65 | private Integer status = CommonConstant.STATUS_NORMAL; 66 | 67 | @ApiModelProperty(value = "网页链接") 68 | private String url; 69 | 70 | @Transient 71 | @TableField(exist=false) 72 | @ApiModelProperty(value = "子菜单/权限") 73 | private List children; 74 | 75 | @Transient 76 | @TableField(exist=false) 77 | @ApiModelProperty(value = "页面拥有的权限类型") 78 | private List permTypes; 79 | 80 | @Transient 81 | @TableField(exist=false) 82 | @ApiModelProperty(value = "节点展开 前端所需") 83 | private Boolean expand = true; 84 | 85 | @Transient 86 | @TableField(exist=false) 87 | @ApiModelProperty(value = "是否勾选 前端所需") 88 | private Boolean checked = false; 89 | 90 | @Transient 91 | @TableField(exist=false) 92 | @ApiModelProperty(value = "是否选中 前端所需") 93 | private Boolean selected = false; 94 | } -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-api/src/main/java/cn/exrick/xcloud/base/entity/Role.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.base.entity; 2 | 3 | import cn.exrick.xcloud.common.base.BaseXCloudEntity; 4 | import com.baomidou.mybatisplus.annotations.TableField; 5 | import com.baomidou.mybatisplus.annotations.TableName; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import javax.persistence.Entity; 10 | import javax.persistence.Table; 11 | import javax.persistence.Transient; 12 | import java.util.List; 13 | 14 | /** 15 | * @author Exrickx 16 | */ 17 | @Data 18 | @Entity 19 | @Table(name = "t_role") 20 | @TableName("t_role") 21 | public class Role extends BaseXCloudEntity { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | @ApiModelProperty(value = "角色名 以ROLE_开头") 26 | private String name; 27 | 28 | @ApiModelProperty(value = "是否为注册默认角色") 29 | private Boolean defaultRole; 30 | 31 | @ApiModelProperty(value = "备注") 32 | private String description; 33 | 34 | @Transient 35 | @TableField(exist=false) 36 | @ApiModelProperty(value = "拥有权限") 37 | private List permissions; 38 | } 39 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-api/src/main/java/cn/exrick/xcloud/base/entity/RolePermission.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.base.entity; 2 | 3 | import cn.exrick.xcloud.common.base.BaseXCloudEntity; 4 | import com.baomidou.mybatisplus.annotations.TableName; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import javax.persistence.Entity; 9 | import javax.persistence.Table; 10 | 11 | /** 12 | * @author Exrick 13 | */ 14 | @Data 15 | @Entity 16 | @Table(name = "t_role_permission") 17 | @TableName("t_role_permission") 18 | public class RolePermission extends BaseXCloudEntity { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | @ApiModelProperty(value = "角色id") 23 | private String roleId; 24 | 25 | @ApiModelProperty(value = "权限id") 26 | private String permissionId; 27 | } -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-api/src/main/java/cn/exrick/xcloud/base/entity/User.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.base.entity; 2 | 3 | import cn.exrick.xcloud.common.base.BaseXCloudEntity; 4 | import cn.exrick.xcloud.common.constant.CommonConstant; 5 | import com.baomidou.mybatisplus.annotations.TableField; 6 | import com.baomidou.mybatisplus.annotations.TableName; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.Data; 9 | 10 | import javax.persistence.*; 11 | import java.util.List; 12 | 13 | /** 14 | * @author Exrickx 15 | */ 16 | @Data 17 | @Entity 18 | @Table(name = "t_user") 19 | @TableName("t_user") 20 | public class User extends BaseXCloudEntity { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | @ApiModelProperty(value = "用户名") 25 | @Column(unique = true,nullable = false) 26 | private String username; 27 | 28 | @ApiModelProperty(value = "密码") 29 | private String password; 30 | 31 | @ApiModelProperty(value = "昵称") 32 | private String nickName; 33 | 34 | @ApiModelProperty(value = "手机") 35 | private String mobile; 36 | 37 | @ApiModelProperty(value = "邮件") 38 | private String email; 39 | 40 | @ApiModelProperty(value = "地址") 41 | private String address; 42 | 43 | @ApiModelProperty(value = "0女 1男 2保密") 44 | private Integer sex; 45 | 46 | @ApiModelProperty(value = "用户头像") 47 | @Column(length=1000) 48 | private String avatar = CommonConstant.USER_DEFAULT_AVATAR; 49 | 50 | @ApiModelProperty(value = "用户类型 0普通用户 1管理员") 51 | private Integer type = CommonConstant.USER_TYPE_NORMAL; 52 | 53 | @ApiModelProperty(value = "状态 默认0正常 -1拉黑") 54 | private Integer status = CommonConstant.USER_STATUS_NORMAL; 55 | 56 | @ApiModelProperty(value = "描述/详情/备注") 57 | private String description; 58 | 59 | @ApiModelProperty(value = "所属部门id") 60 | private String departmentId; 61 | 62 | @Transient 63 | @TableField(exist=false) 64 | @ApiModelProperty(value = "所属部门名称") 65 | private String departmentTitle; 66 | 67 | @Transient 68 | @TableField(exist=false) 69 | @ApiModelProperty(value = "用户拥有角色") 70 | private List roles; 71 | 72 | @Transient 73 | @TableField(exist=false) 74 | @ApiModelProperty(value = "用户拥有的权限") 75 | private List permissions; 76 | } 77 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-api/src/main/java/cn/exrick/xcloud/base/service/UserService.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.base.service; 2 | 3 | import cn.exrick.xcloud.base.entity.User; 4 | import cn.exrick.xcloud.common.base.BaseXCloudService; 5 | 6 | /** 7 | * @author Exrickx 8 | */ 9 | public interface UserService extends BaseXCloudService { 10 | 11 | /** 12 | * 通过用户名获取用户 13 | * @param username 14 | * @return 15 | */ 16 | User findUserByUsername(String username); 17 | } 18 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | xcloud-base 7 | cn.exrick 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | xcloud-base-service 13 | 14 | 15 | 16 | cn.exrick 17 | xcloud-base-api 18 | 1.0-SNAPSHOT 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-service/src/main/java/cn/exrick/xcloud/base/BaseServerApplication.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.base; 2 | 3 | import cn.exrick.xcloud.common.config.Swagger2Config; 4 | import cn.exrick.xcloud.common.exception.RestCtrlExceptionHandler; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.cache.annotation.EnableCaching; 7 | import org.springframework.cloud.client.SpringCloudApplication; 8 | import org.springframework.context.annotation.ComponentScan; 9 | import org.springframework.context.annotation.Import; 10 | import org.springframework.data.jpa.repository.config.EnableJpaAuditing; 11 | 12 | /** 13 | * @author Exrickx 14 | */ 15 | @SpringCloudApplication 16 | //可按需引入全局异常拦截、Swagger2、Redis等配置类[当然推荐配置扫描包] 17 | @ComponentScan({"cn.exrick.xcloud.base", "cn.exrick.xcloud.common"}) 18 | //@Import({RestCtrlExceptionHandler.class, Swagger2Config.class}) 19 | //启用JPA审计 20 | @EnableJpaAuditing 21 | @EnableCaching 22 | public class BaseServerApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(BaseServerApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-service/src/main/java/cn/exrick/xcloud/base/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.base.controller; 2 | 3 | import cn.exrick.xcloud.base.entity.User; 4 | import cn.exrick.xcloud.base.service.UserService; 5 | import cn.exrick.xcloud.common.base.BaseXCloudController; 6 | import cn.exrick.xcloud.common.utils.ResultUtil; 7 | import cn.exrick.xcloud.common.vo.Result; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | 18 | /** 19 | * @author Exrickx 20 | */ 21 | @Slf4j 22 | @RestController 23 | @Api(description = "管理员接口") 24 | @RequestMapping("/user") 25 | public class UserController extends BaseXCloudController { 26 | 27 | @Autowired 28 | private UserService userService; 29 | 30 | @Override 31 | public UserService getService() { 32 | return userService; 33 | } 34 | 35 | @RequestMapping(value = "/getUserByUsername", method = RequestMethod.GET) 36 | @ApiOperation("通过用户名获取用户") 37 | public Result getUserByUsername(@RequestParam String username){ 38 | 39 | User u = userService.findUserByUsername(username); 40 | return new ResultUtil().setData(u); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-service/src/main/java/cn/exrick/xcloud/base/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.base.dao; 2 | 3 | import cn.exrick.xcloud.base.entity.User; 4 | import cn.exrick.xcloud.common.base.BaseXCloudDao; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author Exrickx 10 | */ 11 | public interface UserDao extends BaseXCloudDao { 12 | 13 | /** 14 | * 通过用户名获取用户 15 | * @param username 16 | * @return 17 | */ 18 | List findUserByUsername(String username); 19 | } 20 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-service/src/main/java/cn/exrick/xcloud/base/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.base.service.impl; 2 | 3 | import cn.exrick.xcloud.base.dao.UserDao; 4 | import cn.exrick.xcloud.base.entity.User; 5 | import cn.exrick.xcloud.base.service.UserService; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.cache.annotation.CacheConfig; 9 | import org.springframework.cache.annotation.Cacheable; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @author Exrickx 16 | */ 17 | @Slf4j 18 | @Service 19 | @CacheConfig(cacheNames = "user-service") 20 | public class UserServiceImpl implements UserService { 21 | 22 | @Autowired 23 | private UserDao userDao; 24 | 25 | @Override 26 | public UserDao getRepository() { 27 | return userDao; 28 | } 29 | 30 | @Override 31 | @Cacheable(key = "'user:' + #username") 32 | public User findUserByUsername(String username) { 33 | 34 | List list=userDao.findUserByUsername(username); 35 | if(list!=null&&list.size()>0){ 36 | return list.get(0); 37 | } 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # 配置文件加密 2 | jasypt: 3 | encryptor: 4 | password: xcloud 5 | 6 | server: 7 | port: 1004 8 | 9 | eureka: 10 | instance: 11 | prefer-ip-address: true 12 | ip-address: 127.0.0.1 13 | client: 14 | serviceUrl: 15 | defaultZone: http://localhost:1000/eureka/ 16 | 17 | spring: 18 | application: 19 | name: base-server 20 | # 数据源 21 | datasource: 22 | url: jdbc:mysql://127.0.0.1:3306/xcloud_base?useUnicode=true&characterEncoding=utf-8&useSSL=false 23 | username: root 24 | # Jasyp加密 可到xcloud-common服务中找到JasyptUtil生成加密结果 25 | password: ENC(hiDl0S/3fQ42A9chNzldNw==) 26 | type: com.alibaba.druid.pool.DruidDataSource 27 | driverClassName: com.mysql.jdbc.Driver 28 | # Druid StatViewServlet配置 29 | druid: 30 | stat-view-servlet: 31 | # 默认true 内置监控页面首页/druid/index.html 32 | enabled: true 33 | url-pattern: /druid/* 34 | # 允许清空统计数据 35 | reset-enable: true 36 | login-username: root 37 | login-password: ENC(hiDl0S/3fQ42A9chNzldNw==) 38 | # IP白名单 多个逗号分隔 39 | allow: 40 | # IP黑名单 41 | deny: 42 | jpa: 43 | show-sql: true 44 | # 自动生成表结构 45 | generate-ddl: true 46 | hibernate: 47 | ddl-auto: none 48 | # Redis 49 | redis: 50 | host: 127.0.0.1 51 | password: 52 | # 数据库索引 默认0 53 | database: 0 54 | port: 6379 55 | timeout: 10000 56 | 57 | 58 | # Swagger界面内容配置 59 | swagger: 60 | title: XCloud BaseServer API接口文档 61 | description: XCloud BaseServer Api Documentation 62 | version: 1.0.0 63 | termsOfServiceUrl: http://blog.exrick.cn 64 | contact: 65 | name: Exrick 66 | url: http://blog.exrick.cn 67 | email: 1012139570@qq.com 68 | 69 | 70 | # 关闭Spring Security 71 | #security: 72 | # basic: 73 | # enabled: false 74 | 75 | 76 | -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-service/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ___________ .__ __ 2 | \_ _____/__ __________|__| ____ | | __ 3 | | __)_\ \/ /\_ __ \ |/ ___\| |/ / 4 | | \> < | | \/ \ \___| < 5 | /_______ /__/\_ \ |__| |__|\___ >__|_ \ 6 | \/ \/ \/ \/ -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | # 以下配置需放在bootstrap中,因为加载顺序: bootstrap > config配置中心 > application 2 | spring: 3 | cloud: 4 | config: 5 | # 启用读取远程配置中心 6 | enabled: true 7 | discovery: 8 | # 开启通过服务来访问config-server 9 | enabled: true 10 | # 指定服务发现组件中config的serviceId 11 | service-id: config-server 12 | # 对应配置文件名规则: /{label}/{search-paths}/{name或application.name}-{profile}} 13 | name: base 14 | profile: dev 15 | # 对应分支 默认master 16 | label: master 17 | rabbitmq: 18 | host: 148.70.109.242 19 | port: 5672 20 | username: guest 21 | password: guest 22 | 23 | eureka: 24 | instance: 25 | prefer-ip-address: true 26 | ip-address: 127.0.0.1 27 | client: 28 | serviceUrl: 29 | defaultZone: http://localhost:1000/eureka/ -------------------------------------------------------------------------------- /xcloud-modules/xcloud-base/xcloud-base-service/src/main/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Exrick/x-cloud/ff2d20169ab3946c271691a5a07e71bbfb902533/xcloud-modules/xcloud-base/xcloud-base-service/src/main/resources/favicon.ico -------------------------------------------------------------------------------- /xcloud-oauth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | x-cloud 7 | cn.exrick 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | xcloud-oauth 13 | 14 | 15 | UTF-8 16 | 1.8 17 | 18 | 19 | 20 | 21 | cn.exrick 22 | xcloud-common 23 | 1.0-SNAPSHOT 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-openfeign 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-oauth2 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /xcloud-oauth/src/main/java/cn/exrick/xcloud/oauth/OAuthServerApplication.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.oauth; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 7 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 8 | import org.springframework.cloud.client.SpringCloudApplication; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | import org.springframework.context.annotation.ComponentScan; 11 | 12 | /** 13 | * @author Exrickx 14 | */ 15 | @SpringCloudApplication 16 | @EnableOAuth2Sso 17 | @EnableFeignClients 18 | @ComponentScan({"cn.exrick.xcloud.oauth", "cn.exrick.xcloud.common"}) 19 | @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) 20 | public class OAuthServerApplication { 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(OAuthServerApplication.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /xcloud-oauth/src/main/java/cn/exrick/xcloud/oauth/config/AuthorizationServerConfig.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.oauth.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.data.redis.connection.RedisConnectionFactory; 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; 10 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; 11 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 12 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; 13 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; 14 | import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; 15 | 16 | /** 17 | * @author Exrickx 18 | */ 19 | @Configuration 20 | @EnableAuthorizationServer 21 | public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { 22 | 23 | @Value("${xcloud.oauth.clientId}") 24 | private String clientId; 25 | 26 | @Value("${xcloud.oauth.secret}") 27 | private String secret; 28 | 29 | @Value("${xcloud.oauth.scope}") 30 | private String scope; 31 | 32 | @Autowired 33 | AuthenticationManager authenticationManager; 34 | 35 | @Autowired 36 | RedisConnectionFactory redisConnectionFactory; 37 | 38 | @Autowired 39 | private UserDetailsService userDetailsService; 40 | 41 | @Override 42 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 43 | 44 | //配置一个客户端 password、authorization_code认证 45 | clients.inMemory() 46 | .withClient(clientId) 47 | .secret(secret) 48 | //密码、授权码模式 49 | .authorizedGrantTypes("password", "authorization_code", "refresh_token") 50 | //此处的scopes是无用的,可以随意设置 51 | .scopes(scope); 52 | 53 | } 54 | 55 | @Override 56 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 57 | 58 | endpoints 59 | .tokenStore(new RedisTokenStore(redisConnectionFactory)) 60 | .authenticationManager(authenticationManager) 61 | .userDetailsService(userDetailsService); 62 | } 63 | 64 | @Override 65 | public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { 66 | 67 | oauthServer 68 | //允许表单认证 69 | .allowFormAuthenticationForClients() 70 | .tokenKeyAccess("permitAll()") 71 | .checkTokenAccess("isAuthenticated()");; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /xcloud-oauth/src/main/java/cn/exrick/xcloud/oauth/config/ResourceServerConfig.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.oauth.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 6 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 7 | 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | /** 11 | * @author Exrickx 12 | */ 13 | @Configuration 14 | @EnableResourceServer 15 | public class ResourceServerConfig extends ResourceServerConfigurerAdapter { 16 | 17 | @Override 18 | public void configure(HttpSecurity http) throws Exception { 19 | http 20 | .csrf().disable() 21 | .exceptionHandling() 22 | .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)) 23 | .and() 24 | .authorizeRequests() 25 | .anyRequest().authenticated() 26 | .and() 27 | .httpBasic(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /xcloud-oauth/src/main/java/cn/exrick/xcloud/oauth/config/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.oauth.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.authentication.AuthenticationManager; 6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 | import org.springframework.security.core.userdetails.User; 10 | import org.springframework.security.core.userdetails.UserDetailsService; 11 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 12 | import org.springframework.security.crypto.password.PasswordEncoder; 13 | import org.springframework.security.provisioning.InMemoryUserDetailsManager; 14 | 15 | /** 16 | * @author Exrickx 17 | */ 18 | @Configuration 19 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 20 | 21 | @Bean 22 | @Override 23 | protected UserDetailsService userDetailsService(){ 24 | InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); 25 | manager.createUser(User.withUsername("user_1").password("123456").authorities("USER").build()); 26 | manager.createUser(User.withUsername("user_2").password("123456").authorities("USER").build()); 27 | return manager; 28 | } 29 | 30 | @Override 31 | protected void configure(HttpSecurity http) throws Exception { 32 | // @formatter:off 33 | http 34 | .requestMatchers().anyRequest() 35 | .and() 36 | .authorizeRequests() 37 | .antMatchers("/oauth/*").permitAll(); 38 | // @formatter:on 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /xcloud-oauth/src/main/java/cn/exrick/xcloud/oauth/controller/OauthController.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.oauth.controller; 2 | 3 | 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.stereotype.Controller; 6 | /** 7 | * @author Exrickx 8 | */ 9 | @Controller 10 | @Slf4j 11 | public class OauthController { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /xcloud-oauth/src/main/java/cn/exrick/xcloud/oauth/fegin/UserService.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.oauth.fegin; 2 | 3 | import cn.exrick.xcloud.oauth.fegin.fallback.UserServiceImplFallback; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @author Exrickx 8 | */ 9 | @FeignClient(name = "base-server",fallback = UserServiceImplFallback.class) 10 | public interface UserService { 11 | } 12 | -------------------------------------------------------------------------------- /xcloud-oauth/src/main/java/cn/exrick/xcloud/oauth/fegin/fallback/UserServiceImplFallback.java: -------------------------------------------------------------------------------- 1 | package cn.exrick.xcloud.oauth.fegin.fallback; 2 | 3 | import cn.exrick.xcloud.oauth.fegin.UserService; 4 | 5 | /** 6 | * @author Exrickx 7 | */ 8 | public class UserServiceImplFallback implements UserService { 9 | } 10 | -------------------------------------------------------------------------------- /xcloud-oauth/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: oauth-server 4 | # Redis 5 | redis: 6 | host: 127.0.0.1 7 | password: 8 | # 数据库索引 默认0 9 | database: 0 10 | port: 6379 11 | timeout: 10000 12 | 13 | server: 14 | port: 1003 15 | 16 | eureka: 17 | instance: 18 | ip-address: 127.0.0.1 19 | prefer-ip-address: true 20 | client: 21 | serviceUrl: 22 | defaultZone: http://localhost:1000/eureka/ 23 | 24 | # OAuth配置 25 | xcloud: 26 | oauth: 27 | clientId: ENC(6+MZAAAvXC0kAtA+qgVSxA==) 28 | secret: ENC(u+7DHvCv+WmUYHDDW89GBQ==) 29 | # 无用可以随意设置 30 | scope: xcloud 31 | 32 | # Swagger界面内容配置 33 | swagger: 34 | title: XCloud OAuthServer API接口文档 35 | description: XCloud OAuthServer Api Documentation 36 | version: 1.0.0 37 | termsOfServiceUrl: http://blog.exrick.cn 38 | contact: 39 | name: Exrick 40 | url: http://blog.exrick.cn 41 | email: 1012139570@qq.com -------------------------------------------------------------------------------- /xcloud-oauth/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ___________ .__ __ 2 | \_ _____/__ __________|__| ____ | | __ 3 | | __)_\ \/ /\_ __ \ |/ ___\| |/ / 4 | | \> < | | \/ \ \___| < 5 | /_______ /__/\_ \ |__| |__|\___ >__|_ \ 6 | \/ \/ \/ \/ -------------------------------------------------------------------------------- /xcloud-oauth/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | # 以下配置需放在bootstrap中,因为加载顺序: bootstrap > config配置中心 > application 2 | spring: 3 | cloud: 4 | config: 5 | # 启用读取远程配置中心 此处已关闭 节省开发资源 建议根据你硬件配置选择是否启用xcloud-config配置中心服务 6 | enabled: false 7 | discovery: 8 | # 使用服务发现组件的xcloud-config 启用远程配置中心时记得设为true 此处关闭防止报错 9 | enabled: false 10 | # 指定服务发现组件中config的serviceId 11 | service-id: config-server 12 | # 对应配置文件名规则: /{label}/{search-paths}/{name或application.name}-{profile}} 13 | name: oauth 14 | profile: dev 15 | # 分支 16 | label: master -------------------------------------------------------------------------------- /xcloud-oauth/src/main/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Exrick/x-cloud/ff2d20169ab3946c271691a5a07e71bbfb902533/xcloud-oauth/src/main/resources/favicon.ico --------------------------------------------------------------------------------