├── .classpath ├── .gitignore ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs ├── org.eclipse.m2e.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.prefs.xml ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container ├── org.eclipse.wst.jsdt.ui.superType.name └── org.eclipse.wst.validation.prefs ├── LICENSE ├── README.md ├── doc ├── .gitignore ├── Quick_Guide_1.docx ├── Quick_Guide_2.docx ├── postman │ └── restful.json ├── readme └── sql │ └── data.sql ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── samsung │ │ └── ax │ │ └── restful │ │ ├── common │ │ ├── Constants.java │ │ └── PropertiesManager.java │ │ ├── persistence │ │ ├── BBSPersistence.java │ │ ├── NotePersistence.java │ │ ├── UserPersistence.java │ │ └── impl │ │ │ ├── BBSPersistenceImpl.java │ │ │ ├── NotePersistenceImpl.java │ │ │ └── UserPersistenceImpl.java │ │ ├── pojo │ │ ├── List.java │ │ ├── Note.java │ │ ├── Paging.java │ │ ├── Query.java │ │ └── User.java │ │ ├── resource │ │ ├── BBSResource.java │ │ ├── NoteResource.java │ │ └── UserResource.java │ │ ├── service │ │ ├── BBSService.java │ │ ├── NoteService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── BBSServiceImpl.java │ │ │ ├── NoteServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ └── validate │ │ ├── note │ │ ├── AbstractNoteValidate.java │ │ ├── MissingContent.java │ │ ├── MissingIdx.java │ │ └── MissingSubject.java │ │ └── user │ │ ├── AbstractUserValidate.java │ │ └── ValidatingName.java ├── resources │ ├── config │ │ ├── jdbc.properties │ │ └── restful.properties │ ├── log4j.xml │ ├── messages │ │ └── exceptions_en.properties │ ├── spring │ │ └── spring_ctx.xml │ └── sqlmap │ │ ├── audit.xml │ │ ├── note.xml │ │ ├── sqlMaps.xml │ │ └── user.xml └── webapp │ ├── WEB-INF │ ├── lib │ │ └── ax-restful-framework.jar │ └── web.xml │ ├── bbs │ └── upload.html │ ├── css │ └── style.css │ ├── js │ └── restful.js │ ├── note │ ├── content.html │ ├── create.html │ ├── list.html │ └── update.html │ └── user │ ├── list.html │ ├── manage.html │ ├── profile.html │ ├── signin.html │ ├── signup.html │ └── update.html └── test ├── java └── com │ └── samsung │ └── ax │ └── restful │ ├── crypt │ └── aes │ │ └── AxCryptTest.java │ └── utils │ ├── FileHelperTest.java │ ├── FormatHelperTest.java │ └── StreamHelperTest.java └── resources └── com └── samsung └── ax └── restful └── utils ├── list.json └── project.properties /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /logs/ 3 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | [github]restful 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.jdt.core.javanature 38 | org.eclipse.m2e.core.maven2Nature 39 | org.eclipse.wst.common.project.facet.core.nature 40 | org.eclipse.wst.jsdt.core.jsNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.compliance=1.7 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.source=1.7 9 | org.eclipse.objectteams.otdt.compiler.option.pure_java=enabled 10 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.prefs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Samsung Electronics Corporation 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | Apache License 8 | Version 2.0, January 2004 9 | http://www.apache.org/licenses/ 10 | 11 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 12 | 13 | 1. Definitions. 14 | 15 | "License" shall mean the terms and conditions for use, reproduction, 16 | and distribution as defined by Sections 1 through 9 of this document. 17 | 18 | "Licensor" shall mean the copyright owner or entity authorized by 19 | the copyright owner that is granting the License. 20 | 21 | "Legal Entity" shall mean the union of the acting entity and all 22 | other entities that control, are controlled by, or are under common 23 | control with that entity. For the purposes of this definition, 24 | "control" means (i) the power, direct or indirect, to cause the 25 | direction or management of such entity, whether by contract or 26 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 27 | outstanding shares, or (iii) beneficial ownership of such entity. 28 | 29 | "You" (or "Your") shall mean an individual or Legal Entity 30 | exercising permissions granted by this License. 31 | 32 | "Source" form shall mean the preferred form for making modifications, 33 | including but not limited to software source code, documentation 34 | source, and configuration files. 35 | 36 | "Object" form shall mean any form resulting from mechanical 37 | transformation or translation of a Source form, including but 38 | not limited to compiled object code, generated documentation, 39 | and conversions to other media types. 40 | 41 | "Work" shall mean the work of authorship, whether in Source or 42 | Object form, made available under the License, as indicated by a 43 | copyright notice that is included in or attached to the work 44 | (an example is provided in the Appendix below). 45 | 46 | "Derivative Works" shall mean any work, whether in Source or Object 47 | form, that is based on (or derived from) the Work and for which the 48 | editorial revisions, annotations, elaborations, or other modifications 49 | represent, as a whole, an original work of authorship. For the purposes 50 | of this License, Derivative Works shall not include works that remain 51 | separable from, or merely link (or bind by name) to the interfaces of, 52 | the Work and Derivative Works thereof. 53 | 54 | "Contribution" shall mean any work of authorship, including 55 | the original version of the Work and any modifications or additions 56 | to that Work or Derivative Works thereof, that is intentionally 57 | submitted to Licensor for inclusion in the Work by the copyright owner 58 | or by an individual or Legal Entity authorized to submit on behalf of 59 | the copyright owner. For the purposes of this definition, "submitted" 60 | means any form of electronic, verbal, or written communication sent 61 | to the Licensor or its representatives, including but not limited to 62 | communication on electronic mailing lists, source code control systems, 63 | and issue tracking systems that are managed by, or on behalf of, the 64 | Licensor for the purpose of discussing and improving the Work, but 65 | excluding communication that is conspicuously marked or otherwise 66 | designated in writing by the copyright owner as "Not a Contribution." 67 | 68 | "Contributor" shall mean Licensor and any individual or Legal Entity 69 | on behalf of whom a Contribution has been received by Licensor and 70 | subsequently incorporated within the Work. 71 | 72 | 2. Grant of Copyright License. Subject to the terms and conditions of 73 | this License, each Contributor hereby grants to You a perpetual, 74 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 75 | copyright license to reproduce, prepare Derivative Works of, 76 | publicly display, publicly perform, sublicense, and distribute the 77 | Work and such Derivative Works in Source or Object form. 78 | 79 | 3. Grant of Patent License. Subject to the terms and conditions of 80 | this License, each Contributor hereby grants to You a perpetual, 81 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 82 | (except as stated in this section) patent license to make, have made, 83 | use, offer to sell, sell, import, and otherwise transfer the Work, 84 | where such license applies only to those patent claims licensable 85 | by such Contributor that are necessarily infringed by their 86 | Contribution(s) alone or by combination of their Contribution(s) 87 | with the Work to which such Contribution(s) was submitted. If You 88 | institute patent litigation against any entity (including a 89 | cross-claim or counterclaim in a lawsuit) alleging that the Work 90 | or a Contribution incorporated within the Work constitutes direct 91 | or contributory patent infringement, then any patent licenses 92 | granted to You under this License for that Work shall terminate 93 | as of the date such litigation is filed. 94 | 95 | 4. Redistribution. You may reproduce and distribute copies of the 96 | Work or Derivative Works thereof in any medium, with or without 97 | modifications, and in Source or Object form, provided that You 98 | meet the following conditions: 99 | 100 | (a) You must give any other recipients of the Work or 101 | Derivative Works a copy of this License; and 102 | 103 | (b) You must cause any modified files to carry prominent notices 104 | stating that You changed the files; and 105 | 106 | (c) You must retain, in the Source form of any Derivative Works 107 | that You distribute, all copyright, patent, trademark, and 108 | attribution notices from the Source form of the Work, 109 | excluding those notices that do not pertain to any part of 110 | the Derivative Works; and 111 | 112 | (d) If the Work includes a "NOTICE" text file as part of its 113 | distribution, then any Derivative Works that You distribute must 114 | include a readable copy of the attribution notices contained 115 | within such NOTICE file, excluding those notices that do not 116 | pertain to any part of the Derivative Works, in at least one 117 | of the following places: within a NOTICE text file distributed 118 | as part of the Derivative Works; within the Source form or 119 | documentation, if provided along with the Derivative Works; or, 120 | within a display generated by the Derivative Works, if and 121 | wherever such third-party notices normally appear. The contents 122 | of the NOTICE file are for informational purposes only and 123 | do not modify the License. You may add Your own attribution 124 | notices within Derivative Works that You distribute, alongside 125 | or as an addendum to the NOTICE text from the Work, provided 126 | that such additional attribution notices cannot be construed 127 | as modifying the License. 128 | 129 | You may add Your own copyright statement to Your modifications and 130 | may provide additional or different license terms and conditions 131 | for use, reproduction, or distribution of Your modifications, or 132 | for any such Derivative Works as a whole, provided Your use, 133 | reproduction, and distribution of the Work otherwise complies with 134 | the conditions stated in this License. 135 | 136 | 5. Submission of Contributions. Unless You explicitly state otherwise, 137 | any Contribution intentionally submitted for inclusion in the Work 138 | by You to the Licensor shall be under the terms and conditions of 139 | this License, without any additional terms or conditions. 140 | Notwithstanding the above, nothing herein shall supersede or modify 141 | the terms of any separate license agreement you may have executed 142 | with Licensor regarding such Contributions. 143 | 144 | 6. Trademarks. This License does not grant permission to use the trade 145 | names, trademarks, service marks, or product names of the Licensor, 146 | except as required for reasonable and customary use in describing the 147 | origin of the Work and reproducing the content of the NOTICE file. 148 | 149 | 7. Disclaimer of Warranty. Unless required by applicable law or 150 | agreed to in writing, Licensor provides the Work (and each 151 | Contributor provides its Contributions) on an "AS IS" BASIS, 152 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 153 | implied, including, without limitation, any warranties or conditions 154 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 155 | PARTICULAR PURPOSE. You are solely responsible for determining the 156 | appropriateness of using or redistributing the Work and assume any 157 | risks associated with Your exercise of permissions under this License. 158 | 159 | 8. Limitation of Liability. In no event and under no legal theory, 160 | whether in tort (including negligence), contract, or otherwise, 161 | unless required by applicable law (such as deliberate and grossly 162 | negligent acts) or agreed to in writing, shall any Contributor be 163 | liable to You for damages, including any direct, indirect, special, 164 | incidental, or consequential damages of any character arising as a 165 | result of this License or out of the use or inability to use the 166 | Work (including but not limited to damages for loss of goodwill, 167 | work stoppage, computer failure or malfunction, or any and all 168 | other commercial damages or losses), even if such Contributor 169 | has been advised of the possibility of such damages. 170 | 171 | 9. Accepting Warranty or Additional Liability. While redistributing 172 | the Work or Derivative Works thereof, You may choose to offer, 173 | and charge a fee for, acceptance of support, warranty, indemnity, 174 | or other liability obligations and/or rights consistent with this 175 | License. However, in accepting such obligations, You may act only 176 | on Your own behalf and on Your sole responsibility, not on behalf 177 | of any other Contributor, and only if You agree to indemnify, 178 | defend, and hold each Contributor harmless for any liability 179 | incurred by, or claims asserted against, such Contributor by reason 180 | of your accepting any such warranty or additional liability. 181 | 182 | END OF TERMS AND CONDITIONS 183 | 184 | APPENDIX: How to apply the Apache License to your work. 185 | 186 | To apply the Apache License to your work, attach the following 187 | boilerplate notice, with the fields enclosed by brackets "{}" 188 | replaced with your own identifying information. (Don't include 189 | the brackets!) The text should be enclosed in the appropriate 190 | comment syntax for the file format. We also recommend that a 191 | file or class name and description of purpose be included on the 192 | same "printed page" as the copyright notice for easier 193 | identification within third-party archives. 194 | 195 | Copyright {yyyy} {name of copyright owner} 196 | 197 | Licensed under the Apache License, Version 2.0 (the "License"); 198 | you may not use this file except in compliance with the License. 199 | You may obtain a copy of the License at 200 | 201 | http://www.apache.org/licenses/LICENSE-2.0 202 | 203 | Unless required by applicable law or agreed to in writing, software 204 | distributed under the License is distributed on an "AS IS" BASIS, 205 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 206 | See the License for the specific language governing permissions and 207 | limitations under the License. 208 | 209 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RESTful 2 | ======= 3 | 4 | Suggesting the codes for RESTful API including filter/annotator for allowing user access and validating input data, user management, data management and some utils such as protecting data using 128/256-bit AES encryption and so on. 5 | 6 | Please take a look at [readme](/doc/readme) to see release note. 7 | 8 | ### Guide ### 9 | The followings are quick guides:
10 | [A. Preparing development environment](/doc/Quick_Guide_1.docx)
11 | [B. Quick guide how to run RESTful using this project](/doc/Quick_Guide_2.docx)
12 | C. Customizing for your project (in progress) 13 | 14 | 15 | ### Usage ### 16 | 17 | #### html #### 18 | ##### User ##### 19 | - [x] [/restful/user/signup.html](/src/main/webapp/user/signup.html "Creating new user") 20 | - [x] [/restful/user/signin.html](/src/main/webapp/user/signin.html "Signing in") 21 | - [x] [/restful/user/profile.html](/src/main/webapp/user/profile.html "Retrieving my information") 22 | - [x] [/restful/user/setting.html](/src/main/webapp/user/setting.html "Updating/Deleting user information") 23 | - [x] [/restful/user/list.html](/src/main/webapp/user/list.html "Retrieving user list") (_admin only_) 24 | 25 | ##### Note ##### 26 | - [x] [/restful/note/create.html](/src/main/webapp/note/create.html "Creating new note") 27 | - [x] [/restful/note/update.html](/src/main/webapp/note/update.html "Updating note") 28 | - [x] [/restful/note/content.html](/src/main/webapp/note/content.html "Retrieving note content") 29 | - [x] [/restful/note/list.html](/src/main/webapp/note/list.html "Retrieving note list") 30 | 31 | #### Restful #### 32 | ##### User ##### 33 | ```json 34 | // Creating a user 35 | POST /restful/api/user/signup 36 | Content-Type: application/json 37 | { 38 | "name": "axpower", 39 | "pwd": "*****", 40 | "username": "RESTful", 41 | "role": "User" 42 | } 43 | 44 | // Signing in 45 | POST /restful/api/user/signin 46 | Content-Type: application/json 47 | { 48 | "name": "axpower", 49 | "pwd": "*****" 50 | } 51 | 52 | // Signing out 53 | GET /restful/api/user/signout 54 | Content-Type: application/json 55 | 56 | // Retrieving my information 57 | GET /restful/api/user/profile 58 | Content-Type: application/json 59 | 60 | // Updating a user 61 | PUT /restful/api/user 62 | Content-Type: application/json 63 | { 64 | "name": "axpower", 65 | "username": "Web service" 66 | } 67 | 68 | // Deleting a user 69 | DELETE /restful/api/user 70 | Content-Type: application/json 71 | { 72 | "name": "axpower" 73 | } 74 | 75 | // Retrieving a user (admin only) 76 | GET /restful/api/user/ax 77 | Content-Type: application/json 78 | 79 | // Retrieving a list of user with paging and search query (admin only) 80 | GET /restful/api/user/list 81 | GET /restful/api/user/list?pn=1 82 | GET /restful/api/user/list?pn=1&q=ax 83 | Content-Type: application/json 84 | ``` 85 | 86 | ##### Note ##### 87 | ```json 88 | // Creating a note 89 | POST /restful/api/note 90 | Content-Type: application/json 91 | { 92 | "subject": "Hello", 93 | "content": "Nice to meet you!" 94 | } 95 | 96 | // Updating a note 97 | PUT /restful/api/note 98 | Content-Type: application/json 99 | { 100 | "idx": 1, 101 | "subject": "Hello", 102 | "content": "It's really nice to meet you." 103 | } 104 | 105 | // Deleting a note 106 | DELETE /restful/api/note 107 | Content-Type: application/json 108 | { 109 | "idx": 1 110 | } 111 | 112 | // Retrieving a note 113 | GET /restful/api/note/1 114 | Content-Type: application/json 115 | 116 | // Retrieving a list of note with paging and search query 117 | GET /restful/api/note/list 118 | GET /restful/api/note/list?pn=1 119 | GET /restful/api/note/list?pn=1&q=hello 120 | Content-Type: application/json 121 | ``` -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /TODO 2 | -------------------------------------------------------------------------------- /doc/Quick_Guide_1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samsung/restful/cebf532f682ae2e6e805be40f508b6029e463fe9/doc/Quick_Guide_1.docx -------------------------------------------------------------------------------- /doc/Quick_Guide_2.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samsung/restful/cebf532f682ae2e6e805be40f508b6029e463fe9/doc/Quick_Guide_2.docx -------------------------------------------------------------------------------- /doc/postman/restful.json: -------------------------------------------------------------------------------- 1 | {"id":"257d49dd-3546-1c66-267c-7918a2e60424","name":"opensource","timestamp":1411602030599,"order":["ad9f2e60-5d04-1c7a-b203-571f1a4be632","65486763-9a67-9eb3-4d64-c4a1987889a8","31d2fe5d-c7aa-8d06-7382-54a86ff7bd6c","82e3529f-1e54-16d3-8902-712354bba97a","45bb46fa-ee9b-fc20-5764-2a55869183f3","4022007b-e87f-a0b3-3ee0-7076a8004ef0","b958c987-b4ff-b703-a715-bb5faac98bea","496f0bff-f5c6-c260-08dd-7270ce90415b","47e2ee2f-45f8-2217-0322-adfdf192e899","0a3393e8-007e-d2d5-d5a8-f830ff672c89","a5513639-0ff9-01e9-8c83-32d0dc08c96a","8a54897a-947a-4e3e-bb7d-d33c5f5c5ba5","4988eeee-d27e-27df-55bb-0352f0d2e725"],"requests":[{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"0a3393e8-007e-d2d5-d5a8-f830ff672c89","name":"http://localhost:8080/restful/user","description":"","url":"http://localhost:8080/restful/user","method":"DELETE","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"name\": \"heesik.jeon\"\n}","dataMode":"raw","timestamp":0,"responses":[],"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"31d2fe5d-c7aa-8d06-7382-54a86ff7bd6c","name":"http://localhost:8080/restful/note","description":"","url":"http://localhost:8080/restful/note","method":"POST","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"subject\": \"Hello\",\n \"content\": \"Nice to meet you!\"\n}","dataMode":"raw","timestamp":0,"responses":[],"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"4022007b-e87f-a0b3-3ee0-7076a8004ef0","name":"http://localhost:8080/restful/user/list","description":"","url":"http://localhost:8080/restful/api/user/list","method":"GET","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"utterance\": \"Hello!\"\n}","dataMode":"raw","timestamp":0,"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"45bb46fa-ee9b-fc20-5764-2a55869183f3","name":"http://localhost:8080/restful/note","description":"","url":"http://localhost:8080/restful/note","method":"DELETE","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"idx\": 3\n}","dataMode":"raw","timestamp":0,"responses":[],"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"47e2ee2f-45f8-2217-0322-adfdf192e899","name":"http://localhost:8080/restful/user","description":"","url":"http://localhost:8080/restful/user","method":"PUT","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"name\": \"heesik.jeon\",\n \"username\": \"全熙植\"\n}","dataMode":"raw","timestamp":0,"responses":[],"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"496f0bff-f5c6-c260-08dd-7270ce90415b","name":"http://localhost:8080/restful/user/signup","description":"","url":"http://localhost:8080/restful/user/signup","method":"POST","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"name\": \"heesik.jeon\",\n \"pwd\": \"heesik.jeon\",\n \"username\": \"heesik.jeon\",\n \"role\": \"User\"\n}","dataMode":"raw","timestamp":0,"responses":[],"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"4988eeee-d27e-27df-55bb-0352f0d2e725","name":"http://localhost:8080/restful/user/logout","description":"","url":"http://localhost:8080/restful/user/logout","method":"GET","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"name\": \"ax\",\n \"pwd\": \"ax\"\n}","dataMode":"raw","timestamp":0,"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"65486763-9a67-9eb3-4d64-c4a1987889a8","name":"http://localhost:8080/restful/note/1","description":"","url":"http://localhost:8080/restful/note/1","method":"GET","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"name\": \"ax\",\n \"pwd\": \"ax\"\n}","dataMode":"raw","timestamp":0,"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"82e3529f-1e54-16d3-8902-712354bba97a","name":"http://localhost:8080/restful/note","description":"","url":"http://localhost:8080/restful/note","method":"PUT","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"idx\": 3,\n \"subject\": \"Hello\",\n \"content\": \"It's really nice to meet you.\"\n}\n","dataMode":"raw","timestamp":0,"responses":[],"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"8a54897a-947a-4e3e-bb7d-d33c5f5c5ba5","name":"http://localhost:8080/restful/user/login","description":"","url":"http://localhost:8080/restful/user/login","method":"POST","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"name\": \"ax\",\n \"pwd\": \"ax\"\n}","dataMode":"raw","timestamp":0,"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"a5513639-0ff9-01e9-8c83-32d0dc08c96a","name":"http://localhost:8080/restful/user/me","description":"","url":"http://localhost:8080/restful/user/me","method":"GET","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"name\": \"heesik.jeon\"\n}","dataMode":"raw","timestamp":0,"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"ad9f2e60-5d04-1c7a-b203-571f1a4be632","name":"http://localhost:8080/restful/note/list","description":"","url":"http://localhost:8080/restful/api/note/list?pn=1&q=hello","method":"GET","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"utterance\": \"Hello!\"\n}","dataMode":"raw","timestamp":0,"version":2},{"collectionId":"257d49dd-3546-1c66-267c-7918a2e60424","id":"b958c987-b4ff-b703-a715-bb5faac98bea","name":"http://localhost:8080/restful/user/ax","description":"","url":"http://localhost:8080/restful/user/ax","method":"GET","headers":"Content-Type: application/json\nwssid: IVxPf5mM7c/HsiIEuqM0cQ\n","data":"{\n \"idx\": 4\n}","dataMode":"raw","timestamp":0,"version":2}]} -------------------------------------------------------------------------------- /doc/readme: -------------------------------------------------------------------------------- 1 | #### Release v0.4.5 #### 2 | Fix count of results (note) 3 | Handle note not found 4 | 5 | #### Release v0.4.4 #### 6 | Separate framework and service 7 | 8 | #### Release v0.4.3 #### 9 | Change package name 10 | 11 | #### Release v0.4.2 #### 12 | Add collection for postman 13 | 14 | #### Release v0.4.1 #### 15 | Add list for user management 16 | 17 | #### Release v0.4.0 #### 18 | Fix count of results (user) 19 | 20 | #### Release v0.3.9 #### 21 | Add sign out after user applies to withdraw from member 22 | 23 | #### Release v0.3.8 #### 24 | Code restructuring 25 | 26 | #### Release v0.3.7 #### 27 | Optimize html, css and js for sign up, sign in, sign out and profile retrieval 28 | 29 | #### Release v0.3.6 #### 30 | Not specify the domain name of Cookie 31 | 32 | #### Release v0.3.5 #### 33 | Change url-pattern for servlet to change its' path in web.xml 34 | 35 | #### Release v0.3.4 #### 36 | Remove WSSIDContainerFilter from web.xml 37 | 38 | #### Release v0.3.3 #### 39 | Add account for handling data into MySQL 40 | 41 | #### Release v0.3.2 #### 42 | Change location of log file 43 | Fix bugs on data.sql 44 | 45 | #### Release v0.3.1 #### 46 | Add JspServlet into web.xml 47 | 48 | #### Release v0.3.0 #### 49 | Replace tabs with spaces 50 | 51 | #### Release v0.2.9 #### 52 | Add file upload/download 53 | 54 | #### Release v0.2.8 #### 55 | Add authorization to resources 56 | 57 | #### Release v0.2.7 #### 58 | Prepare authorization for note 59 | Minor update such as changing names 60 | 61 | #### Release v0.2.6 #### 62 | Add query including paging into response for page navigation 63 | 64 | #### Release v0.2.5 #### 65 | Check whether inputted ID is 3-15 characters long and contains only letters(a-z), numbers, period(.) and hyphen(-) 66 | 67 | #### Release v0.2.4 #### 68 | Check whether inputted ID is duplicated or not when registering 69 | 70 | #### Release v0.2.3 #### 71 | Add @RolesAllowed to allow/deny user access 72 | 73 | #### Release v0.2.2 #### 74 | Add role into user table 75 | 76 | #### Release v0.2.1 #### 77 | Add status into user table 78 | 79 | #### Release v0.2.0 #### 80 | Add login/logout 81 | 82 | #### Release v0.1.9 #### 83 | Add session filter/element and adjust some classes 84 | Prepare adding authentication 85 | 86 | #### Release v0.1.8 #### 87 | Add user management using sqlmap 88 | 89 | #### Release v0.1.7 #### 90 | Add util to identify user using numeral system 91 | 92 | #### Release v0.1.6 #### 93 | Prepare adding user for personalization 94 | 95 | #### Release v0.1.5 #### 96 | Add util to decompress files from a zip file 97 | 98 | #### Release v0.1.4 #### 99 | Add util to get a hashed directory 100 | 101 | #### Release v0.1.3 #### 102 | Add customized filter to issue session ID 103 | 104 | #### Release v0.1.2 #### 105 | Add util to enable json pretty print 106 | 107 | #### Release v0.1.1 #### 108 | Add util to get a file from classpath 109 | 110 | #### Release v0.1.0 #### 111 | Add @ValidatedBy to validate data from client 112 | 113 | #### Release v0.0.9 #### 114 | Prepare adding customized filter 115 | 116 | #### Release v0.0.8 #### 117 | Add search 118 | 119 | #### Release v0.0.7 #### 120 | Add CryptDataSource to use encrypted password 121 | 122 | #### Release v0.0.6 #### 123 | Add encrypt text using AES encryption algorithm 124 | 125 | #### Release v0.0.5 #### 126 | Add decrypt text using AES encryption algorithm 127 | 128 | #### Release v0.0.4 #### 129 | Add paging for list 130 | 131 | #### Release v0.0.3 #### 132 | Add note management like bbs using sqlmap 133 | 134 | #### Release v0.0.2 #### 135 | Base template including sample codes for RESTful API 136 | 137 | #### Release v0.0.1 #### 138 | Initial environment for developing RESTful API -------------------------------------------------------------------------------- /doc/sql/data.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS `data` /*!40100 DEFAULT CHARACTER SET utf8 */; 2 | USE `data`; 3 | -- MySQL dump 10.13 Distrib 5.6.13, for Win32 (x86) 4 | -- 5 | -- Host: localhost Database: data 6 | -- ------------------------------------------------------ 7 | -- Server version 5.6.16 8 | 9 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 10 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 11 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 12 | /*!40101 SET NAMES utf8 */; 13 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 14 | /*!40103 SET TIME_ZONE='+00:00' */; 15 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 16 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 17 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 18 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 19 | 20 | -- 21 | -- Table structure for table `user` 22 | -- 23 | 24 | DROP TABLE IF EXISTS `user`; 25 | /*!40101 SET @saved_cs_client = @@character_set_client */; 26 | /*!40101 SET character_set_client = utf8 */; 27 | CREATE TABLE `user` ( 28 | `idx` int(10) unsigned NOT NULL AUTO_INCREMENT, 29 | `name` varchar(15) NOT NULL, 30 | `pwd` varchar(45) DEFAULT NULL, 31 | `sid` varchar(7) DEFAULT NULL, 32 | `username` varchar(45) NOT NULL, 33 | `role` varchar(12) NOT NULL DEFAULT 'User', 34 | `status` tinyint(1) NOT NULL DEFAULT '1', 35 | `createdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 36 | `updatedate` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, 37 | PRIMARY KEY (`idx`), 38 | UNIQUE KEY `idx_UNIQUE` (`idx`), 39 | UNIQUE KEY `name_UNIQUE` (`name`), 40 | UNIQUE KEY `sid_UNIQUE` (`sid`), 41 | KEY `status` (`status`), 42 | KEY `name` (`name`) 43 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 44 | /*!40101 SET character_set_client = @saved_cs_client */; 45 | 46 | -- 47 | -- Dumping data for table `user` 48 | -- 49 | 50 | LOCK TABLES `user` WRITE; 51 | /*!40000 ALTER TABLE `user` DISABLE KEYS */; 52 | INSERT INTO `user` VALUES (1,'axpower', PASSWORD('axpower'),'1','heesik.jeon','Admin',1,'2014-10-15 00:00:00','2014-10-15 00:00:00'); 53 | /*!40000 ALTER TABLE `user` ENABLE KEYS */; 54 | UNLOCK TABLES; 55 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 56 | 57 | -- 58 | -- Table structure for table `note` 59 | -- 60 | 61 | DROP TABLE IF EXISTS `note`; 62 | /*!40101 SET @saved_cs_client = @@character_set_client */; 63 | /*!40101 SET character_set_client = utf8 */; 64 | CREATE TABLE `note` ( 65 | `idx` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 66 | `sid` varchar(7) NOT NULL, 67 | `username` varchar(45) NOT NULL, 68 | `subject` varchar(255) NOT NULL, 69 | `access` smallint(4) unsigned NOT NULL DEFAULT '0', 70 | `content` text NOT NULL, 71 | `status` tinyint(1) NOT NULL DEFAULT '1', 72 | `createdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 73 | `updatedate` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, 74 | PRIMARY KEY (`idx`), 75 | UNIQUE KEY `idx_UNIQUE` (`idx`), 76 | KEY `status` (`status`) 77 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 78 | /*!40101 SET character_set_client = @saved_cs_client */; 79 | 80 | -- 81 | -- Dumping data for table `note` 82 | -- 83 | 84 | LOCK TABLES `note` WRITE; 85 | /*!40000 ALTER TABLE `note` DISABLE KEYS */; 86 | INSERT INTO `note` VALUES (1,'1','axpower','Hello',0,'It\'s really nice to meet you.',1,'2015-03-01 00:00:00','2015-05-02 00:00:00'),(2,'1','axpower','Hello',0,'Me too.',1,'2015-03-01 00:00:00','2015-03-02 00:00:00'); 87 | /*!40000 ALTER TABLE `note` ENABLE KEYS */; 88 | UNLOCK TABLES; 89 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 90 | 91 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 92 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 93 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 94 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 95 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 96 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 97 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 98 | 99 | -- 100 | -- Dumping data for table `user` 101 | -- 102 | 103 | LOCK TABLES `mysql`.`user` WRITE; 104 | /*!40000 ALTER TABLE `mysql`.`user` DISABLE KEYS */; 105 | INSERT INTO `mysql`.`user` VALUES ('localhost','axpower',PASSWORD('axpower'),'N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','','N'); 106 | /*!40000 ALTER TABLE `mysql`.`user` ENABLE KEYS */; 107 | UNLOCK TABLES; 108 | 109 | -- 110 | -- Dumping data for table `user` 111 | -- 112 | 113 | LOCK TABLES `mysql`.`db` WRITE; 114 | /*!40000 ALTER TABLE `mysql`.`db` DISABLE KEYS */; 115 | INSERT INTO `mysql`.`db` VALUES ('localhost','data','axpower','Y','Y','Y','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); 116 | /*!40000 ALTER TABLE `mysql`.`db` ENABLE KEYS */; 117 | UNLOCK TABLES; 118 | 119 | flush privileges; 120 | 121 | -- Dump completed on 2014-10-15 00:00:00 122 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.samsung.ax 5 | restful 6 | 0.0.1-SNAPSHOT 7 | war 8 | restful 9 | Optimized codes for RESTful API 10 | 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 3.1 17 | 18 | 1.7 19 | 1.7 20 | UTF-8 21 | 22 | 23 | 24 | org.apache.maven.plugins 25 | maven-war-plugin 26 | 2.5 27 | 28 | false 29 | 30 | 31 | 32 | org.apache.maven.plugins 33 | maven-surefire-plugin 34 | 2.17 35 | 36 | true 37 | 38 | 39 | 40 | ${project.artifactId} 41 | 42 | 43 | 44 | 45 | 46 | 47 | javax.servlet 48 | servlet-api 49 | 2.5 50 | provided 51 | 52 | 53 | 54 | 55 | ax 56 | ax-restful-framework 57 | 1.0.0 58 | system 59 | ${project.basedir}/src/main/webapp/WEB-INF/lib/ax-restful-framework.jar 60 | 61 | 62 | 63 | 64 | org.springframework 65 | spring-core 66 | ${spring.version} 67 | 68 | 69 | org.springframework 70 | spring-context 71 | ${spring.version} 72 | 73 | 74 | org.springframework 75 | spring-tx 76 | ${spring.version} 77 | 78 | 79 | org.springframework 80 | spring-webmvc 81 | ${spring.version} 82 | 83 | 84 | org.springframework 85 | spring-web 86 | ${spring.version} 87 | 88 | 89 | org.springframework 90 | spring-ibatis 91 | 2.0.8 92 | 93 | 94 | org.springframework.security 95 | spring-security-core 96 | ${spring.security} 97 | 98 | 99 | org.springframework.security 100 | spring-security-acl 101 | ${spring.security} 102 | 103 | 104 | org.springframework.security 105 | spring-security-config 106 | ${spring.security} 107 | 108 | 109 | org.springframework.security 110 | spring-security-web 111 | ${spring.security} 112 | 113 | 114 | 115 | 116 | com.sun.jersey 117 | jersey-core 118 | ${jersey.version} 119 | 120 | 121 | com.sun.jersey 122 | jersey-client 123 | ${jersey.version} 124 | 125 | 126 | com.sun.jersey 127 | jersey-json 128 | ${jersey.version} 129 | 130 | 131 | com.sun.jersey 132 | jersey-servlet 133 | ${jersey.version} 134 | 135 | 136 | com.sun.jersey.contribs 137 | jersey-spring 138 | ${jersey.version} 139 | 140 | 141 | com.sun.jersey 142 | jersey-server 143 | 144 | 145 | org.springframework 146 | spring-core 147 | 148 | 149 | org.springframework 150 | spring-beans 151 | 152 | 153 | org.springframework 154 | spring-context 155 | 156 | 157 | org.springframework 158 | spring-web 159 | 160 | 161 | org.springframework 162 | spring-aop 163 | 164 | 165 | 166 | 167 | com.sun.jersey.contribs 168 | jersey-multipart 169 | 1.18.2 170 | 171 | 172 | org.codehaus.jackson 173 | jackson-core-asl 174 | 1.9.13 175 | 176 | 177 | 178 | 179 | commons-lang 180 | commons-lang 181 | 2.6 182 | 183 | 184 | commons-codec 185 | commons-codec 186 | 1.9 187 | 188 | 189 | commons-io 190 | commons-io 191 | 2.4 192 | 193 | 194 | commons-dbcp 195 | commons-dbcp 196 | 1.4 197 | 198 | 199 | commons-pool 200 | commons-pool 201 | 202 | 203 | 204 | 205 | commons-pool 206 | commons-pool 207 | 1.6 208 | 209 | 210 | commons-logging 211 | commons-logging 212 | 1.1.3 213 | 214 | 215 | log4j 216 | log4j 217 | 1.2.17 218 | 219 | 220 | xerces 221 | xercesImpl 222 | 2.11.0 223 | 224 | 225 | 226 | 227 | com.google.code.gson 228 | gson 229 | 2.3 230 | 231 | 232 | 233 | 234 | mysql 235 | mysql-connector-java 236 | 5.1.31 237 | 238 | 239 | 240 | 241 | junit 242 | junit 243 | 3.8.1 244 | test 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 4.0.6.RELEASE 253 | 3.2.5.RELEASE 254 | 255 | 256 | 1.18.1 257 | 258 | 259 | 260 | 261 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/common/Constants.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.common; 2 | 3 | /** 4 | * 5 | * @author heesik.jeon 6 | * 7 | */ 8 | 9 | public class Constants { 10 | 11 | public static final String COOKIE_USER_KEY = Constant.COOKIE_USER_KEY; 12 | public static final String COOKIE_USER_SECRET = Constant.COOKIE_USER_SECRET; 13 | 14 | public static final String COOKIE_URI = Constant.COOKIE_URI; 15 | public static final int COOKIE_MAX_AGE = Constant.COOKIE_MAX_AGE; // 6 hours 16 | public static final int COOKIE_EXPIRY = Constant.COOKIE_EXPIRY; 17 | 18 | public static final String ERR_USER_AUTHENTICATION_FAILED = Constant.ERR_USER_AUTHENTICATION_FAILED; 19 | public static final String ERR_USER_AUTHORIZATION_FAILED = Constant.ERR_USER_AUTHORIZATION_FAILED; 20 | 21 | public static final String ERR_SYSTEM_ERROR = Constant.ERR_SYSTEM_ERROR; 22 | 23 | 24 | public static final String PROPERTIES_CLASSPATH = "/config/restful.properties"; 25 | 26 | public static final String LIST_MAX_RESULTS = "maxResults"; 27 | public static final String LIST_MAX_PAGING = "maxPaging"; 28 | 29 | public static final int USER_BASE_NUMERAL_SYSTEM = 62; 30 | public static final int USER_SID_BASE_VALUE = 238328; 31 | 32 | public static final int USER_NAME_MIN_LENGTH = 3; 33 | public static final int USER_NAME_MAX_LENGTH = 15; 34 | 35 | public static final String NOTE_IDX = "idx"; 36 | public static final String NOTE_SUBJECT = "subject"; 37 | public static final String NOTE_CONTENT = "content"; 38 | 39 | public static final String FILE_BASE_PATH = "/usr/local/share/bbs/"; // TODO Need to change it to your filepath 40 | public static final int FILE_BASE_DEPTH = 2; 41 | 42 | 43 | public static final String ERR_DATA_ACCESS = "err.data.access"; 44 | 45 | public static final String ERR_USER_NAME_DUPLICATED = "err.user.name.duplicated"; 46 | public static final String ERR_USER_NAME_PATTERN = "err.user.name.pattern"; 47 | public static final String ERR_USER_NAME_LENGTH = "err.user.name.length"; 48 | 49 | public static final String ERR_USER_NOT_FOUND = "err.user.not.found"; 50 | public static final String ERR_USER_LOGIN_FAILED = "err.user.login.failed"; 51 | 52 | public static final String ERR_NOTE_NOT_FOUND = "err.note.not.found"; 53 | 54 | public static final String ERR_FILE_MISSING = "err.file.missing"; 55 | 56 | public static final String ERR_MANDATORY_MISSING = "err.mandatory.missing"; 57 | 58 | } -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/common/PropertiesManager.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.common; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.util.Properties; 6 | 7 | import org.apache.log4j.Logger; 8 | 9 | /** 10 | * 11 | * @author heesik.jeon 12 | * 13 | */ 14 | 15 | public class PropertiesManager { 16 | 17 | private static final Logger logger = Logger.getLogger(PropertiesManager.class); 18 | 19 | private Properties properties; 20 | 21 | public PropertiesManager() { 22 | 23 | logger.debug(".."); 24 | 25 | InputStream is = null; 26 | 27 | try { 28 | is = this.getClass().getResourceAsStream(Constants.PROPERTIES_CLASSPATH); 29 | 30 | properties = new Properties(); 31 | properties.load(is); 32 | } catch (IOException e) { 33 | e.printStackTrace(); 34 | } 35 | 36 | } 37 | 38 | public String getProperty(String key) { 39 | return properties.getProperty(key); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/persistence/BBSPersistence.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.persistence; 2 | 3 | /** 4 | * 5 | * @author heesik.jeon 6 | * 7 | */ 8 | 9 | public interface BBSPersistence { 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/persistence/NotePersistence.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.persistence; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.dao.DataAccessException; 6 | 7 | import com.samsung.ax.restful.pojo.Note; 8 | import com.samsung.ax.restful.pojo.Query; 9 | 10 | /** 11 | * 12 | * @author heesik.jeon 13 | * 14 | */ 15 | 16 | public interface NotePersistence { 17 | 18 | /** 19 | * @param note 20 | * @return 21 | * @throws DataAccessException 22 | */ 23 | public int create(Note note) throws DataAccessException; 24 | 25 | /** 26 | * @param idx 27 | * @return 28 | * @throws DataAccessException 29 | */ 30 | public String sid(int idx) throws DataAccessException; 31 | 32 | /** 33 | * @param note 34 | * @return 35 | * @throws DataAccessException 36 | */ 37 | public int update(Note note) throws DataAccessException; 38 | 39 | /** 40 | * @param note 41 | * @return 42 | * @throws DataAccessException 43 | */ 44 | public int delete(Note note) throws DataAccessException; 45 | 46 | /** 47 | * @param idx 48 | * @return 49 | * @throws DataAccessException 50 | */ 51 | public Note idx(int idx) throws DataAccessException; 52 | 53 | /** 54 | * @param idx 55 | * @return 56 | * @throws DataAccessException 57 | */ 58 | public int access(int idx) throws DataAccessException; 59 | 60 | /** 61 | * @param query 62 | * @return 63 | * @throws DataAccessException 64 | */ 65 | public int count(Query query) throws DataAccessException; 66 | 67 | /** 68 | * @param query 69 | * @return 70 | * @throws DataAccessException 71 | */ 72 | public List list(Query query) throws DataAccessException; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/persistence/UserPersistence.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.persistence; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.dao.DataAccessException; 6 | 7 | import com.samsung.ax.restful.pojo.Query; 8 | import com.samsung.ax.restful.pojo.User; 9 | 10 | /** 11 | * 12 | * @author heesik.jeon 13 | * 14 | */ 15 | 16 | public interface UserPersistence { 17 | 18 | /** 19 | * @param user 20 | * @return 21 | * @throws DataAccessException 22 | */ 23 | public int signup(User user) throws DataAccessException; 24 | 25 | /** 26 | * @param user 27 | * @return 28 | * @throws DataAccessException 29 | */ 30 | public int sid(User user) throws DataAccessException; 31 | 32 | /** 33 | * @param user 34 | * @return 35 | * @throws DataAccessException 36 | */ 37 | public User signin(User user) throws DataAccessException; 38 | 39 | /** 40 | * @param user 41 | * @return 42 | * @throws DataAccessException 43 | */ 44 | public int update(User user) throws DataAccessException; 45 | 46 | /** 47 | * @param user 48 | * @return 49 | * @throws DataAccessException 50 | */ 51 | public int delete(User user) throws DataAccessException; 52 | 53 | /** 54 | * @param name 55 | * @return 56 | * @throws DataAccessException 57 | */ 58 | public User name(String name) throws DataAccessException; 59 | 60 | /** 61 | * @param query 62 | * @return 63 | * @throws DataAccessException 64 | */ 65 | public int count(Query query) throws DataAccessException; 66 | 67 | /** 68 | * @param query 69 | * @return 70 | * @throws DataAccessException 71 | */ 72 | public List list(Query query) throws DataAccessException; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/persistence/impl/BBSPersistenceImpl.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.persistence.impl; 2 | 3 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 4 | 5 | import com.samsung.ax.restful.persistence.BBSPersistence; 6 | 7 | /** 8 | * 9 | * @author heesik.jeon 10 | * 11 | */ 12 | 13 | public class BBSPersistenceImpl extends SqlMapClientDaoSupport implements BBSPersistence { 14 | } -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/persistence/impl/NotePersistenceImpl.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.persistence.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.log4j.Logger; 6 | import org.springframework.dao.DataAccessException; 7 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 8 | 9 | import com.samsung.ax.restful.persistence.NotePersistence; 10 | import com.samsung.ax.restful.pojo.Note; 11 | import com.samsung.ax.restful.pojo.Paging; 12 | import com.samsung.ax.restful.pojo.Query; 13 | 14 | /** 15 | * 16 | * @author heesik.jeon 17 | * 18 | */ 19 | 20 | public class NotePersistenceImpl extends SqlMapClientDaoSupport implements NotePersistence { 21 | 22 | private static final Logger logger = Logger.getLogger(NotePersistenceImpl.class); 23 | 24 | /* 25 | * @see com.samsung.ax.restful.persistence.NotePersistence#create(com.samsung.ax.restful.pojo.Note) 26 | */ 27 | @Override 28 | public int create(Note note) throws DataAccessException { 29 | 30 | logger.debug(".."); 31 | 32 | return (int) getSqlMapClientTemplate().insert("note.create", note); 33 | 34 | } 35 | 36 | /* 37 | * @see com.samsung.ax.restful.persistence.NotePersistence#sid(int) 38 | */ 39 | @Override 40 | public String sid(int idx) throws DataAccessException { 41 | 42 | logger.debug(".."); 43 | 44 | return (String) getSqlMapClientTemplate().queryForObject("note.sid", idx); 45 | 46 | } 47 | 48 | /* 49 | * @see com.samsung.ax.restful.persistence.NotePersistence#update(com.samsung.ax.restful.pojo.Note) 50 | */ 51 | @Override 52 | public int update(Note note) throws DataAccessException { 53 | 54 | logger.debug(".."); 55 | 56 | return getSqlMapClientTemplate().update("note.update", note); 57 | 58 | } 59 | 60 | /* 61 | * @see com.samsung.ax.restful.persistence.NotePersistence#delete(com.samsung.ax.restful.pojo.Note) 62 | */ 63 | @Override 64 | public int delete(Note note) throws DataAccessException { 65 | 66 | logger.debug(".."); 67 | 68 | return getSqlMapClientTemplate().delete("note.delete", note); 69 | 70 | } 71 | 72 | /* 73 | * @see com.samsung.ax.restful.persistence.NotePersistence#idx(int) 74 | */ 75 | @Override 76 | public Note idx(int idx) throws DataAccessException { 77 | 78 | logger.debug(".."); 79 | 80 | return (Note) getSqlMapClientTemplate().queryForObject("note.idx", idx); 81 | 82 | } 83 | 84 | /* 85 | * @see com.samsung.ax.restful.persistence.NotePersistence#access(int) 86 | */ 87 | @Override 88 | public int access(int idx) throws DataAccessException { 89 | 90 | logger.debug(".."); 91 | 92 | return (int) getSqlMapClientTemplate().update("note.access", idx); 93 | 94 | } 95 | 96 | /* 97 | * @see com.samsung.ax.restful.persistence.NotePersistence#count(com.samsung.ax.restful.pojo.Query) 98 | */ 99 | @Override 100 | public int count(Query query) throws DataAccessException { 101 | 102 | logger.debug(".."); 103 | 104 | return (int) getSqlMapClientTemplate().queryForObject("note.count", query); 105 | 106 | } 107 | 108 | /* 109 | * @see com.samsung.ax.restful.persistence.NotePersistence#list(com.samsung.ax.restful.pojo.Query) 110 | */ 111 | @Override 112 | public List list(Query query) throws DataAccessException { 113 | 114 | logger.debug(".."); 115 | 116 | Paging paging = query.getPaging(); 117 | 118 | @SuppressWarnings("unchecked") 119 | List list = getSqlMapClientTemplate().queryForList("note.list", query, paging.getSkipResults(), paging.getMaxResults()); 120 | 121 | return list; 122 | 123 | } 124 | 125 | } -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/persistence/impl/UserPersistenceImpl.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.persistence.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.log4j.Logger; 6 | import org.springframework.dao.DataAccessException; 7 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; 8 | 9 | import com.samsung.ax.restful.persistence.UserPersistence; 10 | import com.samsung.ax.restful.pojo.Paging; 11 | import com.samsung.ax.restful.pojo.Query; 12 | import com.samsung.ax.restful.pojo.User; 13 | 14 | /** 15 | * 16 | * @author heesik.jeon 17 | * 18 | */ 19 | 20 | public class UserPersistenceImpl extends SqlMapClientDaoSupport implements UserPersistence { 21 | 22 | private static final Logger logger = Logger.getLogger(UserPersistenceImpl.class); 23 | 24 | /* 25 | * @see com.samsung.ax.restful.persistence.UserPersistence#signup(com.samsung.ax.restful.pojo.User) 26 | */ 27 | @Override 28 | public int signup(User user) throws DataAccessException { 29 | 30 | logger.debug(".."); 31 | 32 | return (int) getSqlMapClientTemplate().insert("user.signup", user); 33 | 34 | } 35 | 36 | /* 37 | * @see com.samsung.ax.restful.persistence.UserPersistence#sid(com.samsung.ax.restful.pojo.User) 38 | */ 39 | @Override 40 | public int sid(User user) throws DataAccessException { 41 | 42 | logger.debug(".."); 43 | 44 | return getSqlMapClientTemplate().update("user.sid", user); 45 | 46 | } 47 | 48 | /* 49 | * @see com.samsung.ax.restful.persistence.UserPersistence#signin(com.samsung.ax.restful.pojo.User) 50 | */ 51 | @Override 52 | public User signin(User user) throws DataAccessException { 53 | 54 | logger.debug(".."); 55 | 56 | return (User) getSqlMapClientTemplate().queryForObject("user.signin", user); 57 | 58 | } 59 | 60 | /* 61 | * @see com.samsung.ax.restful.persistence.UserPersistence#update(com.samsung.ax.restful.pojo.User) 62 | */ 63 | @Override 64 | public int update(User user) throws DataAccessException { 65 | 66 | logger.debug(".."); 67 | 68 | return getSqlMapClientTemplate().update("user.update", user); 69 | 70 | } 71 | 72 | /* 73 | * @see com.samsung.ax.restful.persistence.UserPersistence#delete(com.samsung.ax.restful.pojo.User) 74 | */ 75 | @Override 76 | public int delete(User user) throws DataAccessException { 77 | 78 | logger.debug(".."); 79 | 80 | return getSqlMapClientTemplate().delete("user.delete", user); 81 | 82 | } 83 | 84 | /* 85 | * @see com.samsung.ax.restful.persistence.UserPersistence#name(java.lang.String) 86 | */ 87 | @Override 88 | public User name(String name) throws DataAccessException { 89 | 90 | logger.debug(".."); 91 | 92 | return (User) getSqlMapClientTemplate().queryForObject("user.name", name); 93 | 94 | } 95 | 96 | /* 97 | * @see com.samsung.ax.restful.persistence.UserPersistence#count(com.samsung.ax.restful.pojo.Query) 98 | */ 99 | @Override 100 | public int count(Query query) throws DataAccessException { 101 | 102 | logger.debug(".."); 103 | 104 | return (int) getSqlMapClientTemplate().queryForObject("user.count", query); 105 | 106 | } 107 | 108 | /* 109 | * @see com.samsung.ax.restful.persistence.UserPersistence#list(com.samsung.ax.restful.pojo.Query) 110 | */ 111 | @Override 112 | public List list(Query query) throws DataAccessException { 113 | 114 | logger.debug(".."); 115 | 116 | Paging paging = query.getPaging(); 117 | 118 | @SuppressWarnings("unchecked") 119 | List list = getSqlMapClientTemplate().queryForList("user.list", query, paging.getSkipResults(), paging.getMaxResults()); 120 | 121 | return list; 122 | 123 | } 124 | 125 | } -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/pojo/List.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.pojo; 2 | 3 | /** 4 | * 5 | * @author heesik.jeon 6 | * 7 | */ 8 | 9 | public class List { 10 | 11 | private Query query; 12 | private Object object; 13 | 14 | public List() { 15 | } 16 | 17 | public Query getQuery() { 18 | return query; 19 | } 20 | 21 | public void setQuery(Query query) { 22 | this.query = query; 23 | } 24 | 25 | public Object getObject() { 26 | return object; 27 | } 28 | 29 | public void setObject(Object object) { 30 | this.object = object; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/pojo/Note.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.pojo; 2 | 3 | /** 4 | * 5 | * @author heesik.jeon 6 | * 7 | */ 8 | 9 | public class Note extends Audit { 10 | 11 | private int idx; 12 | 13 | private String sid; 14 | private String username; 15 | private String subject; 16 | private String content; 17 | private int access; 18 | 19 | public Note() { 20 | } 21 | 22 | public int getIdx() { 23 | return idx; 24 | } 25 | 26 | public void setIdx(int idx) { 27 | this.idx = idx; 28 | } 29 | 30 | public String getSid() { 31 | return sid; 32 | } 33 | 34 | public void setSid(String sid) { 35 | this.sid = sid; 36 | } 37 | 38 | public String getUsername() { 39 | return username; 40 | } 41 | 42 | public void setUsername(String username) { 43 | this.username = username; 44 | } 45 | 46 | public String getSubject() { 47 | return subject; 48 | } 49 | 50 | public void setSubject(String subject) { 51 | this.subject = subject; 52 | } 53 | 54 | public String getContent() { 55 | return content; 56 | } 57 | 58 | public void setContent(String content) { 59 | this.content = content; 60 | } 61 | 62 | public int getAccess() { 63 | return access; 64 | } 65 | 66 | public void setAccess(int access) { 67 | this.access = access; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/pojo/Paging.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.pojo; 2 | 3 | /** 4 | * 5 | * @author heesik.jeon 6 | * 7 | */ 8 | 9 | public class Paging { 10 | 11 | private int pn; 12 | private int maxPaging; 13 | private int maxResults; 14 | private int totalResults; 15 | 16 | public int getPn() { 17 | return pn; 18 | } 19 | 20 | public void setPn(int pn) { 21 | this.pn = pn; 22 | } 23 | 24 | public int getMaxPaging() { 25 | return maxPaging; 26 | } 27 | 28 | public void setMaxPaging(int maxPaging) { 29 | this.maxPaging = maxPaging; 30 | } 31 | 32 | public int getMaxResults() { 33 | return maxResults; 34 | } 35 | 36 | public void setMaxResults(int maxResults) { 37 | this.maxResults = maxResults; 38 | } 39 | 40 | public int getTotalResults() { 41 | return totalResults; 42 | } 43 | 44 | public void setTotalResults(int totalResults) { 45 | this.totalResults = totalResults; 46 | } 47 | 48 | public int getSkipResults() { 49 | int skipResults = pn - 1; 50 | return skipResults * getMaxResults(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/pojo/Query.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.pojo; 2 | 3 | /** 4 | * 5 | * @author heesik.jeon 6 | * 7 | */ 8 | 9 | public class Query { 10 | 11 | private String search; 12 | private Paging paging; 13 | 14 | public String getSearch() { 15 | return search; 16 | } 17 | 18 | public void setSearch(String search) { 19 | this.search = search; 20 | } 21 | 22 | public Paging getPaging() { 23 | return paging; 24 | } 25 | 26 | public void setPaging(Paging paging) { 27 | this.paging = paging; 28 | } 29 | 30 | public static Query setQuery(int pn, String search) { 31 | 32 | Query query = new Query(); 33 | 34 | Paging paging = new Paging(); 35 | 36 | paging.setPn(pn); 37 | 38 | query.setSearch(search); 39 | query.setPaging(paging); 40 | 41 | return query; 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/pojo/User.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.pojo; 2 | 3 | /** 4 | * 5 | * @author heesik.jeon 6 | * 7 | */ 8 | 9 | public class User extends Audit { 10 | 11 | private int idx; 12 | 13 | private String name; // UserId 14 | private String pwd; 15 | 16 | private String sid; 17 | private String username; 18 | private Role role; 19 | private int status; 20 | 21 | private String ip; 22 | 23 | public int getIdx() { 24 | return idx; 25 | } 26 | 27 | public void setIdx(int idx) { 28 | this.idx = idx; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String getPwd() { 40 | return pwd; 41 | } 42 | 43 | public void setPwd(String pwd) { 44 | this.pwd = pwd; 45 | } 46 | 47 | public String getSid() { 48 | return sid; 49 | } 50 | 51 | public void setSid(String sid) { 52 | this.sid = sid; 53 | } 54 | 55 | public String getUsername() { 56 | return username; 57 | } 58 | 59 | public void setUsername(String username) { 60 | this.username = username; 61 | } 62 | 63 | public Role getRole() { 64 | return role; 65 | } 66 | 67 | public void setRole(Role role) { 68 | this.role = role; 69 | } 70 | 71 | public int isStatus() { 72 | return status; 73 | } 74 | 75 | public void setStatus(int status) { 76 | this.status = status; 77 | } 78 | 79 | public String getIp() { 80 | return ip; 81 | } 82 | 83 | public void setIp(String ip) { 84 | this.ip = ip; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/resource/BBSResource.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.resource; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | 7 | import javax.ws.rs.Consumes; 8 | import javax.ws.rs.GET; 9 | import javax.ws.rs.POST; 10 | import javax.ws.rs.Path; 11 | import javax.ws.rs.PathParam; 12 | import javax.ws.rs.Produces; 13 | import javax.ws.rs.core.MediaType; 14 | import javax.ws.rs.core.Response; 15 | import javax.ws.rs.core.Response.ResponseBuilder; 16 | import javax.ws.rs.core.Response.Status; 17 | 18 | import org.apache.log4j.Logger; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.stereotype.Component; 21 | 22 | import com.samsung.ax.restful.annotation.RolesAllowed; 23 | import com.samsung.ax.restful.common.Constants; 24 | import com.samsung.ax.restful.pojo.ResponseElement; 25 | import com.samsung.ax.restful.pojo.Role; 26 | import com.samsung.ax.restful.service.BBSService; 27 | import com.samsung.ax.restful.utils.FileHelper; 28 | import com.samsung.ax.restful.utils.FormatHelper; 29 | import com.sun.jersey.core.header.FormDataContentDisposition; 30 | import com.sun.jersey.multipart.FormDataParam; 31 | 32 | /** 33 | * 34 | * @author heesik.jeon 35 | * 36 | */ 37 | 38 | @Component 39 | @Path("/bbs") 40 | @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") 41 | @Consumes(MediaType.APPLICATION_FORM_URLENCODED) 42 | public class BBSResource extends AbstractResource { 43 | 44 | private static final Logger logger = Logger.getLogger(BBSResource.class); 45 | 46 | @Autowired 47 | private BBSService service; 48 | 49 | @POST 50 | @Path("/upload") 51 | @Consumes(MediaType.MULTIPART_FORM_DATA) 52 | @RolesAllowed({Role.Admin,Role.User}) 53 | public ResponseElement upload(@FormDataParam("file") InputStream is, @FormDataParam("file") FormDataContentDisposition fdcd) { 54 | 55 | logger.debug(".."); 56 | 57 | Object object = new Object(); 58 | 59 | try { 60 | 61 | object = service.upload(getUserPrincipal(), is, fdcd.getFileName()); 62 | 63 | if (object == null) { 64 | exceptionManager.fireUserException(Constants.ERR_FILE_MISSING, null); 65 | } 66 | 67 | } catch (java.io.FileNotFoundException e) { 68 | exceptionManager.fireUserException(Constants.ERR_FILE_MISSING, null); 69 | } catch (IOException e) { 70 | exceptionManager.fireSystemException(new Exception(e)); 71 | } 72 | 73 | logger.debug(FormatHelper.printPretty(object)); 74 | 75 | return ResponseElement.newSuccessInstance(object); 76 | 77 | } 78 | 79 | @GET 80 | @Path("/download/{filename}") 81 | @Produces() 82 | @RolesAllowed({Role.Admin,Role.User}) 83 | public Response download(@PathParam("filename") String filename) { 84 | 85 | logger.debug(".."); 86 | 87 | try { 88 | 89 | String hash = FileHelper.hashdir(Constants.FILE_BASE_PATH, getUserPrincipal().getName(), Constants.FILE_BASE_DEPTH); 90 | String filepath = new StringBuffer(hash).append(filename).toString(); 91 | 92 | File file = new File(filepath); 93 | 94 | if (file.exists()) { 95 | 96 | ResponseBuilder response = Response.ok(((Object) file)); 97 | response.header("Content-Disposition", "attachment; filename="+filename); 98 | 99 | return response.build(); 100 | 101 | } 102 | 103 | } catch (Exception e) { 104 | exceptionManager.fireSystemException(new Exception(e)); 105 | } 106 | 107 | ResponseBuilder response = Response.status(Status.BAD_REQUEST); 108 | 109 | return response.build(); 110 | 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/resource/NoteResource.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.resource; 2 | 3 | import javax.ws.rs.Consumes; 4 | import javax.ws.rs.DELETE; 5 | import javax.ws.rs.DefaultValue; 6 | import javax.ws.rs.GET; 7 | import javax.ws.rs.POST; 8 | import javax.ws.rs.PUT; 9 | import javax.ws.rs.Path; 10 | import javax.ws.rs.PathParam; 11 | import javax.ws.rs.Produces; 12 | import javax.ws.rs.QueryParam; 13 | import javax.ws.rs.core.MediaType; 14 | 15 | import org.apache.commons.lang.StringUtils; 16 | import org.apache.log4j.Logger; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.dao.DataAccessException; 19 | import org.springframework.stereotype.Component; 20 | 21 | import com.samsung.ax.restful.annotation.RolesAllowed; 22 | import com.samsung.ax.restful.annotation.ValidatedBy; 23 | import com.samsung.ax.restful.common.Constants; 24 | import com.samsung.ax.restful.common.PropertiesManager; 25 | import com.samsung.ax.restful.pojo.List; 26 | import com.samsung.ax.restful.pojo.Note; 27 | import com.samsung.ax.restful.pojo.Paging; 28 | import com.samsung.ax.restful.pojo.Query; 29 | import com.samsung.ax.restful.pojo.ResponseElement; 30 | import com.samsung.ax.restful.pojo.Role; 31 | import com.samsung.ax.restful.pojo.UserPrincipal; 32 | import com.samsung.ax.restful.service.NoteService; 33 | import com.samsung.ax.restful.utils.FormatHelper; 34 | 35 | /** 36 | * 37 | * @author heesik.jeon 38 | * 39 | */ 40 | 41 | @Component 42 | @Path("/note") 43 | @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") 44 | @Consumes(MediaType.APPLICATION_FORM_URLENCODED) 45 | public class NoteResource extends AbstractResource { 46 | 47 | private static final Logger logger = Logger.getLogger(NoteResource.class); 48 | 49 | @Autowired 50 | private NoteService service; 51 | 52 | @Autowired 53 | private PropertiesManager properties; 54 | 55 | /** 56 | * @param note 57 | * @return 58 | */ 59 | @POST 60 | @Consumes(MediaType.APPLICATION_JSON) 61 | @RolesAllowed({Role.Admin,Role.User}) 62 | @ValidatedBy({"missingSubject","missingContent"}) 63 | public ResponseElement create(Note note) { 64 | 65 | logger.debug(".."); 66 | 67 | Object object = new Object(); 68 | 69 | try { 70 | 71 | UserPrincipal me = getUserPrincipal(); 72 | 73 | note.setSid(me.getSid()); 74 | note.setUsername(me.getUsername()); 75 | 76 | object = service.create(note); 77 | 78 | } catch (DataAccessException e) { 79 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 80 | } 81 | 82 | logger.debug(FormatHelper.printPretty(note)); 83 | logger.debug(FormatHelper.printPretty(object)); 84 | 85 | return ResponseElement.newSuccessInstance(object); 86 | 87 | } 88 | 89 | /** 90 | * @param note 91 | * @return 92 | */ 93 | @PUT 94 | @Consumes(MediaType.APPLICATION_JSON) 95 | @RolesAllowed({Role.Admin,Role.User}) 96 | @ValidatedBy({"missingIdx","missingSubject","missingContent"}) 97 | public ResponseElement update(Note note) { 98 | 99 | logger.debug(".."); 100 | 101 | Object object = new Object(); 102 | 103 | try { 104 | 105 | UserPrincipal me = getUserPrincipal(); 106 | String sid = service.sid(note.getIdx()); 107 | 108 | if (sid == null) { 109 | exceptionManager.fireUserException(Constants.ERR_NOTE_NOT_FOUND, new Object[] {note.getIdx()}); 110 | } else if (Role.User.equals(me.getRole()) && !StringUtils.equals(me.getSid(), sid)) { 111 | exceptionManager.fireUserException(Constants.ERR_USER_AUTHORIZATION_FAILED, new Object[] {me.getName()}); 112 | } 113 | 114 | object = service.update(note); 115 | 116 | } catch (DataAccessException e) { 117 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 118 | } 119 | 120 | logger.debug(FormatHelper.printPretty(note)); 121 | logger.debug(FormatHelper.printPretty(object)); 122 | 123 | return ResponseElement.newSuccessInstance(object); 124 | 125 | } 126 | 127 | /** 128 | * @param note 129 | * @return 130 | */ 131 | @DELETE 132 | @Consumes(MediaType.APPLICATION_JSON) 133 | @RolesAllowed({Role.Admin,Role.User}) 134 | @ValidatedBy({"missingIdx"}) 135 | public ResponseElement delete(Note note) { 136 | 137 | logger.debug(".."); 138 | 139 | Object object = new Object(); 140 | 141 | try { 142 | 143 | UserPrincipal me = getUserPrincipal(); 144 | String sid = service.sid(note.getIdx()); 145 | 146 | if (sid == null) { 147 | exceptionManager.fireUserException(Constants.ERR_NOTE_NOT_FOUND, new Object[] {note.getIdx()}); 148 | } else if (Role.User.equals(me.getRole()) && !StringUtils.equals(me.getSid(), sid)) { 149 | exceptionManager.fireUserException(Constants.ERR_USER_AUTHORIZATION_FAILED, new Object[] {me.getName()}); 150 | } 151 | 152 | object = service.delete(note); 153 | 154 | } catch (DataAccessException e) { 155 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 156 | } 157 | 158 | logger.debug(FormatHelper.printPretty(note)); 159 | logger.debug(FormatHelper.printPretty(object)); 160 | 161 | return ResponseElement.newSuccessInstance(object); 162 | 163 | } 164 | 165 | /** 166 | * @param idx 167 | * @return 168 | */ 169 | @GET 170 | @Path("/{idx}") 171 | @Consumes(MediaType.APPLICATION_JSON) 172 | public ResponseElement idx(@PathParam("idx") int idx) { 173 | 174 | logger.debug(".."); 175 | 176 | Object object = new Object(); 177 | 178 | try { 179 | 180 | service.access(idx); 181 | 182 | object = service.idx(idx); 183 | 184 | if (object == null) { 185 | exceptionManager.fireUserException(Constants.ERR_NOTE_NOT_FOUND, new Object[] {idx}); 186 | } 187 | 188 | } catch (DataAccessException e) { 189 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 190 | } 191 | 192 | logger.debug(FormatHelper.printPretty(idx)); 193 | logger.debug(FormatHelper.printPretty(object)); 194 | 195 | return ResponseElement.newSuccessInstance(object); 196 | 197 | } 198 | 199 | /** 200 | * @param pn 201 | * @param search 202 | * @return 203 | */ 204 | @GET 205 | @Path("/list") 206 | @Consumes(MediaType.APPLICATION_JSON) 207 | public ResponseElement list(@DefaultValue("1") @QueryParam("pn") int pn, @QueryParam("q") String search) { 208 | 209 | logger.debug(".."); 210 | 211 | Object object = new Object(); 212 | 213 | Query query = Query.setQuery(pn, search); 214 | 215 | try { 216 | 217 | Paging paging = query.getPaging(); 218 | 219 | paging.setMaxPaging(Integer.parseInt(properties.getProperty(Constants.LIST_MAX_PAGING))); 220 | paging.setMaxResults(Integer.parseInt(properties.getProperty(Constants.LIST_MAX_RESULTS))); 221 | paging.setTotalResults(service.count(query)); 222 | 223 | List list = new List(); 224 | 225 | list.setQuery(query); 226 | list.setObject(service.list(query)); 227 | 228 | object = list; 229 | 230 | } catch (DataAccessException e) { 231 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 232 | } 233 | 234 | logger.debug(FormatHelper.printPretty(query)); 235 | logger.debug(FormatHelper.printPretty(object)); 236 | 237 | return ResponseElement.newSuccessInstance(object); 238 | 239 | } 240 | 241 | } 242 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/resource/UserResource.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.resource; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | import javax.ws.rs.Consumes; 6 | import javax.ws.rs.DELETE; 7 | import javax.ws.rs.DefaultValue; 8 | import javax.ws.rs.GET; 9 | import javax.ws.rs.POST; 10 | import javax.ws.rs.PUT; 11 | import javax.ws.rs.Path; 12 | import javax.ws.rs.PathParam; 13 | import javax.ws.rs.Produces; 14 | import javax.ws.rs.QueryParam; 15 | import javax.ws.rs.core.Context; 16 | import javax.ws.rs.core.MediaType; 17 | 18 | import org.apache.commons.lang.StringUtils; 19 | import org.apache.log4j.Logger; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.dao.DataAccessException; 22 | import org.springframework.stereotype.Component; 23 | 24 | import com.samsung.ax.restful.annotation.RolesAllowed; 25 | import com.samsung.ax.restful.annotation.ValidatedBy; 26 | import com.samsung.ax.restful.common.Constants; 27 | import com.samsung.ax.restful.common.PropertiesManager; 28 | import com.samsung.ax.restful.crypt.AxCryptException; 29 | import com.samsung.ax.restful.pojo.List; 30 | import com.samsung.ax.restful.pojo.Paging; 31 | import com.samsung.ax.restful.pojo.Query; 32 | import com.samsung.ax.restful.pojo.ResponseElement; 33 | import com.samsung.ax.restful.pojo.Role; 34 | import com.samsung.ax.restful.pojo.User; 35 | import com.samsung.ax.restful.pojo.UserPrincipal; 36 | import com.samsung.ax.restful.service.UserService; 37 | import com.samsung.ax.restful.utils.FormatHelper; 38 | 39 | /** 40 | * 41 | * @author heesik.jeon 42 | * 43 | */ 44 | 45 | @Component 46 | @Path("/user") 47 | @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8") 48 | @Consumes(MediaType.APPLICATION_FORM_URLENCODED) 49 | public class UserResource extends AbstractResource { 50 | 51 | private static final Logger logger = Logger.getLogger(UserResource.class); 52 | 53 | @Autowired 54 | private UserService service; 55 | 56 | @Autowired 57 | private PropertiesManager properties; 58 | 59 | /** 60 | * @param request 61 | * @param response 62 | * @param user 63 | * @return 64 | */ 65 | @POST 66 | @Path("/signin") 67 | @Consumes(MediaType.APPLICATION_JSON) 68 | public ResponseElement signin(@Context HttpServletRequest request, @Context HttpServletResponse response, User user) { 69 | 70 | logger.debug(".."); 71 | 72 | try { 73 | 74 | user = service.signin(request, response, user); 75 | 76 | if (user == null) { 77 | exceptionManager.fireUserException(Constants.ERR_USER_LOGIN_FAILED, null); 78 | } 79 | 80 | } catch (DataAccessException e) { 81 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 82 | } catch (AxCryptException e) { 83 | exceptionManager.fireSystemException(new Exception(e)); 84 | } 85 | 86 | logger.debug(FormatHelper.printPretty(user)); 87 | 88 | return ResponseElement.newSuccessInstance(true); 89 | 90 | } 91 | 92 | /** 93 | * @param request 94 | * @param response 95 | * @param user 96 | * @return 97 | */ 98 | @PUT 99 | @Consumes(MediaType.APPLICATION_JSON) 100 | @RolesAllowed({Role.Admin,Role.User}) 101 | public ResponseElement update(@Context HttpServletRequest request, @Context HttpServletResponse response, User user) { 102 | 103 | logger.debug(".."); 104 | 105 | Object object = new Object(); 106 | 107 | try { 108 | 109 | UserPrincipal me = getUserPrincipal(); 110 | User target = (User) service.name(user.getName()); 111 | 112 | if (target == null) { 113 | exceptionManager.fireUserException(Constants.ERR_USER_NOT_FOUND, new Object[] {user.getName()}); 114 | } else if (Role.User.equals(me.getRole()) && !StringUtils.equals(me.getSid(), target.getSid())) { 115 | exceptionManager.fireUserException(Constants.ERR_USER_AUTHORIZATION_FAILED, new Object[] {me.getName()}); 116 | } else if (user.getRole() != null && !Role.Admin.equals(me.getRole())) { 117 | exceptionManager.fireUserException(Constants.ERR_USER_AUTHORIZATION_FAILED, new Object[] {me.getName()}); 118 | } 119 | 120 | object = service.update(user); 121 | 122 | if (StringUtils.equals(me.getSid(), target.getSid())) { 123 | if(user.getName() == null) user.setName(target.getName()); 124 | if(user.getSid() == null) user.setSid(target.getSid()); 125 | if(user.getUsername() == null) user.setUsername(target.getUsername()); 126 | if(user.getRole() == null) user.setRole(target.getRole()); 127 | service.cookie(request, response, user); 128 | } 129 | 130 | } catch (DataAccessException e) { 131 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 132 | } catch (AxCryptException e) { 133 | exceptionManager.fireSystemException(new Exception(e)); 134 | } 135 | 136 | logger.debug(FormatHelper.printPretty(user)); 137 | logger.debug(FormatHelper.printPretty(object)); 138 | 139 | return ResponseElement.newSuccessInstance(object); 140 | 141 | } 142 | 143 | /** 144 | * @param request 145 | * @param response 146 | * @param user 147 | * @return 148 | */ 149 | @DELETE 150 | @Consumes(MediaType.APPLICATION_JSON) 151 | @RolesAllowed({Role.Admin,Role.User}) 152 | public ResponseElement delete(@Context HttpServletRequest request, @Context HttpServletResponse response, User user) { 153 | 154 | logger.debug(".."); 155 | 156 | Object object = new Object(); 157 | 158 | try { 159 | 160 | UserPrincipal me = getUserPrincipal(); 161 | User target = (User) service.name(user.getName()); 162 | 163 | if (target == null) { 164 | exceptionManager.fireUserException(Constants.ERR_USER_NOT_FOUND, new Object[] {user.getName()}); 165 | } else if (Role.User.equals(me.getRole()) && !StringUtils.equals(me.getSid(), target.getSid())) { 166 | exceptionManager.fireUserException(Constants.ERR_USER_AUTHORIZATION_FAILED, new Object[] {me.getName()}); 167 | } 168 | 169 | object = service.delete(user); 170 | 171 | if (StringUtils.equals(me.getSid(), target.getSid())) { 172 | service.signout(request, response); 173 | } 174 | 175 | } catch (DataAccessException e) { 176 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 177 | } 178 | 179 | logger.debug(FormatHelper.printPretty(user)); 180 | logger.debug(FormatHelper.printPretty(object)); 181 | 182 | return ResponseElement.newSuccessInstance(object); 183 | 184 | } 185 | 186 | /** 187 | * @param user 188 | * @return 189 | */ 190 | @POST 191 | @Path("/signup") 192 | @Consumes(MediaType.APPLICATION_JSON) 193 | @ValidatedBy({"validatingName"}) 194 | public ResponseElement signup(User user) { 195 | 196 | logger.debug(".."); 197 | 198 | Object object = new Object(); 199 | 200 | try { 201 | 202 | user.setRole(Role.User); 203 | user.setIdx(service.signup(user)); 204 | user.setSid(FormatHelper.convertNumeral(Constants.USER_BASE_NUMERAL_SYSTEM, user.getIdx()+Constants.USER_SID_BASE_VALUE)); 205 | 206 | object = service.sid(user); 207 | 208 | } catch (DataAccessException e) { 209 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 210 | } 211 | 212 | logger.debug(FormatHelper.printPretty(user)); 213 | logger.debug(FormatHelper.printPretty(object)); 214 | 215 | return ResponseElement.newSuccessInstance(object); 216 | 217 | } 218 | 219 | /** 220 | * @param request 221 | * @param response 222 | * @return 223 | */ 224 | @GET 225 | @Path("/signout") 226 | @Consumes(MediaType.APPLICATION_JSON) 227 | public ResponseElement signout(@Context HttpServletRequest request, @Context HttpServletResponse response) { 228 | 229 | logger.debug(".."); 230 | 231 | try { 232 | service.signout(request, response); 233 | } catch (Exception e) { 234 | exceptionManager.fireSystemException(new Exception(e)); 235 | } 236 | 237 | return ResponseElement.newSuccessInstance(true); 238 | 239 | } 240 | 241 | /** 242 | * @return 243 | */ 244 | @GET 245 | @Path("/profile") 246 | @Consumes(MediaType.APPLICATION_JSON) 247 | @RolesAllowed({Role.Admin,Role.User}) 248 | public ResponseElement profile() { 249 | 250 | logger.debug(".."); 251 | 252 | UserPrincipal me = getUserPrincipal(); 253 | 254 | logger.debug(FormatHelper.printPretty(me)); 255 | 256 | return ResponseElement.newSuccessInstance(me); 257 | 258 | } 259 | 260 | /** 261 | * @param name 262 | * @return 263 | */ 264 | @GET 265 | @Path("/{name}") 266 | @Consumes(MediaType.APPLICATION_JSON) 267 | @RolesAllowed({Role.Admin}) 268 | public ResponseElement name(@PathParam("name") String name) { 269 | 270 | logger.debug(".."); 271 | 272 | Object object = new Object(); 273 | 274 | try { 275 | object = service.name(name); 276 | } catch (DataAccessException e) { 277 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 278 | } 279 | 280 | logger.debug(FormatHelper.printPretty(name)); 281 | logger.debug(FormatHelper.printPretty(object)); 282 | 283 | return ResponseElement.newSuccessInstance(object); 284 | 285 | } 286 | 287 | /** 288 | * @param pn 289 | * @param search 290 | * @return 291 | */ 292 | @GET 293 | @Path("/list") 294 | @Consumes(MediaType.APPLICATION_JSON) 295 | @RolesAllowed({Role.Admin}) 296 | public ResponseElement list(@DefaultValue("1") @QueryParam("pn") int pn, @QueryParam("q") String search) { 297 | 298 | logger.debug(".."); 299 | 300 | Object object = new Object(); 301 | 302 | Query query = Query.setQuery(pn, search); 303 | 304 | try { 305 | 306 | Paging paging = query.getPaging(); 307 | 308 | paging.setMaxPaging(Integer.parseInt(properties.getProperty(Constants.LIST_MAX_PAGING))); 309 | paging.setMaxResults(Integer.parseInt(properties.getProperty(Constants.LIST_MAX_RESULTS))); 310 | paging.setTotalResults(service.count(query)); 311 | 312 | List list = new List(); 313 | 314 | list.setQuery(query); 315 | list.setObject(service.list(query)); 316 | 317 | object = list; 318 | 319 | } catch (DataAccessException e) { 320 | exceptionManager.fireUserException(Constants.ERR_DATA_ACCESS, null); 321 | } 322 | 323 | logger.debug(FormatHelper.printPretty(query)); 324 | logger.debug(FormatHelper.printPretty(object)); 325 | 326 | return ResponseElement.newSuccessInstance(object); 327 | 328 | } 329 | 330 | } 331 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/service/BBSService.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.service; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | import org.springframework.dao.DataAccessException; 7 | 8 | import com.samsung.ax.restful.pojo.UserPrincipal; 9 | 10 | /** 11 | * 12 | * @author heesik.jeon 13 | * 14 | */ 15 | 16 | public interface BBSService { 17 | 18 | /** 19 | * @param user 20 | * @param is 21 | * @param filename 22 | * @return 23 | * @throws DataAccessException 24 | */ 25 | public Object upload(UserPrincipal user, InputStream is, String filename) throws IOException; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/service/NoteService.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.dao.DataAccessException; 6 | 7 | import com.samsung.ax.restful.pojo.Note; 8 | import com.samsung.ax.restful.pojo.Query; 9 | 10 | 11 | /** 12 | * 13 | * @author heesik.jeon 14 | * 15 | */ 16 | 17 | public interface NoteService { 18 | 19 | /** 20 | * @param note 21 | * @return 22 | * @throws DataAccessException 23 | */ 24 | public int create(Note note) throws DataAccessException; 25 | 26 | /** 27 | * @param idx 28 | * @return 29 | * @throws DataAccessException 30 | */ 31 | public String sid(int idx) throws DataAccessException; 32 | 33 | /** 34 | * @param note 35 | * @return 36 | * @throws DataAccessException 37 | */ 38 | public int update(Note note) throws DataAccessException; 39 | 40 | /** 41 | * @param note 42 | * @return 43 | * @throws DataAccessException 44 | */ 45 | public int delete(Note note) throws DataAccessException; 46 | 47 | /** 48 | * @param idx 49 | * @return 50 | * @throws DataAccessException 51 | */ 52 | public Note idx(int idx) throws DataAccessException; 53 | 54 | /** 55 | * @param idx 56 | * @return 57 | * @throws DataAccessException 58 | */ 59 | public int access(int idx) throws DataAccessException; 60 | 61 | /** 62 | * @param query 63 | * @return 64 | * @throws DataAccessException 65 | */ 66 | public int count(Query query) throws DataAccessException; 67 | 68 | /** 69 | * @param query 70 | * @return 71 | * @throws DataAccessException 72 | */ 73 | public List list(Query query) throws DataAccessException; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.service; 2 | 3 | import java.util.List; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | import org.springframework.dao.DataAccessException; 9 | 10 | import com.samsung.ax.restful.crypt.AxCryptException; 11 | import com.samsung.ax.restful.pojo.Query; 12 | import com.samsung.ax.restful.pojo.User; 13 | 14 | /** 15 | * 16 | * @author heesik.jeon 17 | * 18 | */ 19 | 20 | public interface UserService { 21 | 22 | /** 23 | * @param user 24 | * @return 25 | * @throws DataAccessException 26 | */ 27 | public int signup(User user) throws DataAccessException; 28 | 29 | /** 30 | * @param user 31 | * @return 32 | * @throws DataAccessException 33 | */ 34 | public int sid(User user) throws DataAccessException; 35 | 36 | /** 37 | * @param request 38 | * @param response 39 | * @param user 40 | * @return 41 | * @throws DataAccessException 42 | * @throws AxCryptException 43 | */ 44 | public User signin(HttpServletRequest request, HttpServletResponse response, User user) throws DataAccessException, AxCryptException; 45 | 46 | /** 47 | * @param request 48 | * @param response 49 | * @param user 50 | * @return 51 | * @throws AxCryptException 52 | */ 53 | public User cookie(HttpServletRequest request, HttpServletResponse response, User user) throws AxCryptException; 54 | 55 | /** 56 | * @param request 57 | * @param response 58 | */ 59 | public void signout(HttpServletRequest request, HttpServletResponse response); 60 | 61 | /** 62 | * @param user 63 | * @return 64 | * @throws DataAccessException 65 | */ 66 | public int update(User user) throws DataAccessException; 67 | 68 | /** 69 | * @param user 70 | * @return 71 | * @throws DataAccessException 72 | */ 73 | public int delete(User user) throws DataAccessException; 74 | 75 | /** 76 | * @param name 77 | * @return 78 | * @throws DataAccessException 79 | */ 80 | public User name(String name) throws DataAccessException; 81 | 82 | /** 83 | * @param query 84 | * @return 85 | * @throws DataAccessException 86 | */ 87 | public int count(Query query) throws DataAccessException; 88 | 89 | /** 90 | * @param query 91 | * @return 92 | * @throws DataAccessException 93 | */ 94 | public List list(Query query) throws DataAccessException; 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/service/impl/BBSServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.service.impl; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.OutputStream; 8 | 9 | import org.apache.log4j.Logger; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | 12 | import com.samsung.ax.restful.common.Constants; 13 | import com.samsung.ax.restful.persistence.BBSPersistence; 14 | import com.samsung.ax.restful.pojo.UserPrincipal; 15 | import com.samsung.ax.restful.service.BBSService; 16 | import com.samsung.ax.restful.utils.FileHelper; 17 | 18 | /** 19 | * 20 | * @author heesik.jeon 21 | * 22 | */ 23 | 24 | public class BBSServiceImpl implements BBSService { 25 | 26 | private static final Logger logger = Logger.getLogger(BBSServiceImpl.class); 27 | 28 | @Autowired 29 | private BBSPersistence persistence; 30 | 31 | /* 32 | * @see com.samsung.ax.restful.service.BBSService#uploadUser(com.samsung.ax.restful.pojo.UserPrincipal, java.io.InputStream, java.lang.String) 33 | */ 34 | @Override 35 | public Object upload(UserPrincipal user, InputStream is, String filename) throws IOException { 36 | 37 | logger.debug(".."); 38 | 39 | String hash = FileHelper.hashdir(Constants.FILE_BASE_PATH, user.getName(), Constants.FILE_BASE_DEPTH); 40 | 41 | File filepath = new File(hash); 42 | 43 | if (!filepath.exists()) { 44 | filepath.mkdirs(); 45 | } 46 | 47 | String file = new StringBuffer(hash).append(filename).toString(); 48 | logger.debug(file); 49 | 50 | OutputStream os = new FileOutputStream(new File(file)); 51 | 52 | int read = 0; 53 | byte[] bytes = new byte[4096]; 54 | 55 | while ((read = is.read(bytes)) != -1) { 56 | os.write(bytes, 0, read); 57 | } 58 | 59 | os.flush(); 60 | os.close(); 61 | 62 | return filename; 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/service/impl/NoteServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.log4j.Logger; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.dao.DataAccessException; 8 | 9 | import com.samsung.ax.restful.persistence.NotePersistence; 10 | import com.samsung.ax.restful.pojo.Note; 11 | import com.samsung.ax.restful.pojo.Query; 12 | import com.samsung.ax.restful.service.NoteService; 13 | 14 | /** 15 | * 16 | * @author heesik.jeon 17 | * 18 | */ 19 | 20 | public class NoteServiceImpl implements NoteService { 21 | 22 | private static final Logger logger = Logger.getLogger(NoteServiceImpl.class); 23 | 24 | @Autowired 25 | private NotePersistence persistence; 26 | 27 | /* 28 | * @see com.samsung.ax.restful.service.NoteService#create(com.samsung.ax.restful.pojo.Note) 29 | */ 30 | @Override 31 | public int create(Note note) throws DataAccessException { 32 | 33 | logger.debug(".."); 34 | 35 | return persistence.create(note); 36 | 37 | } 38 | 39 | /* 40 | * @see com.samsung.ax.restful.service.NoteService#sid(int) 41 | */ 42 | @Override 43 | public String sid(int idx) throws DataAccessException { 44 | 45 | logger.debug(".."); 46 | 47 | return persistence.sid(idx); 48 | 49 | } 50 | 51 | /* 52 | * @see com.samsung.ax.restful.service.NoteService#update(com.samsung.ax.restful.pojo.Note) 53 | */ 54 | @Override 55 | public int update(Note note) throws DataAccessException { 56 | 57 | logger.debug(".."); 58 | 59 | return persistence.update(note); 60 | 61 | } 62 | 63 | /* 64 | * @see com.samsung.ax.restful.service.NoteService#delete(com.samsung.ax.restful.pojo.Note) 65 | */ 66 | @Override 67 | public int delete(Note note) throws DataAccessException { 68 | 69 | logger.debug(".."); 70 | 71 | return persistence.delete(note); 72 | 73 | } 74 | 75 | /* 76 | * @see com.samsung.ax.restful.service.NoteService#idx(int) 77 | */ 78 | @Override 79 | public Note idx(int idx) throws DataAccessException { 80 | 81 | logger.debug(".."); 82 | 83 | return persistence.idx(idx); 84 | 85 | } 86 | 87 | /* 88 | * @see com.samsung.ax.restful.service.NoteService#access(int) 89 | */ 90 | public int access(int idx) throws DataAccessException { 91 | 92 | logger.debug(".."); 93 | 94 | return persistence.access(idx); 95 | 96 | } 97 | 98 | /* 99 | * @see com.samsung.ax.restful.service.NoteService#count(com.samsung.ax.restful.pojo.Query) 100 | */ 101 | @Override 102 | public int count(Query query) throws DataAccessException { 103 | 104 | logger.debug(".."); 105 | 106 | return persistence.count(query); 107 | 108 | } 109 | 110 | /* 111 | * @see com.samsung.ax.restful.service.NoteService#list(com.samsung.ax.restful.pojo.Query) 112 | */ 113 | @Override 114 | public List list(Query query) throws DataAccessException { 115 | 116 | logger.debug(".."); 117 | 118 | return persistence.list(query); 119 | 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.service.impl; 2 | 3 | import java.util.Calendar; 4 | import java.util.List; 5 | 6 | import javax.servlet.http.Cookie; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.apache.commons.lang.StringUtils; 11 | import org.apache.log4j.Logger; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.dao.DataAccessException; 14 | 15 | import com.samsung.ax.restful.common.Constants; 16 | import com.samsung.ax.restful.crypt.AxCryptException; 17 | import com.samsung.ax.restful.crypt.aes.AxCrypt; 18 | import com.samsung.ax.restful.persistence.UserPersistence; 19 | import com.samsung.ax.restful.pojo.Query; 20 | import com.samsung.ax.restful.pojo.User; 21 | import com.samsung.ax.restful.service.UserService; 22 | 23 | /** 24 | * 25 | * @author heesik.jeon 26 | * 27 | */ 28 | 29 | public class UserServiceImpl implements UserService { 30 | 31 | private static final Logger logger = Logger.getLogger(UserServiceImpl.class); 32 | 33 | @Autowired 34 | private UserPersistence persistence; 35 | 36 | /* 37 | * @see com.samsung.ax.restful.service.UserService#signup(com.samsung.ax.restful.pojo.User) 38 | */ 39 | @Override 40 | public int signup(User user) throws DataAccessException { 41 | 42 | logger.debug(".."); 43 | 44 | return persistence.signup(user); 45 | 46 | } 47 | 48 | /* 49 | * @see com.samsung.ax.restful.service.UserService#sid(com.samsung.ax.restful.pojo.User) 50 | */ 51 | @Override 52 | public int sid(User user) throws DataAccessException { 53 | 54 | logger.debug(".."); 55 | 56 | return persistence.sid(user); 57 | 58 | } 59 | 60 | /* 61 | * @see com.samsung.ax.restful.service.UserService#signin(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, com.samsung.ax.restful.pojo.User) 62 | */ 63 | @Override 64 | public User signin(HttpServletRequest request, HttpServletResponse response, User user) throws DataAccessException, AxCryptException { 65 | 66 | logger.debug(".."); 67 | 68 | user = persistence.signin(user); 69 | 70 | return cookie(request, response, user); 71 | 72 | } 73 | 74 | /* 75 | * @see com.samsung.ax.restful.service.UserService#cookie(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, com.samsung.ax.restful.pojo.User) 76 | */ 77 | @Override 78 | public User cookie(HttpServletRequest request, HttpServletResponse response, User user) throws AxCryptException { 79 | 80 | if (user != null) { 81 | 82 | StringBuffer Ax = new StringBuffer(); 83 | 84 | Ax.append(user.getName()).append("|"); 85 | Ax.append(user.getSid()).append("|"); 86 | Ax.append(user.getUsername()).append("|"); 87 | Ax.append(user.getRole()).append("|"); 88 | Ax.append(request.getRemoteAddr()).append("|"); 89 | 90 | Calendar c = Calendar.getInstance(); 91 | Ax.append(c.getTimeInMillis()); 92 | 93 | String crypted = AxCrypt.encrypt(Ax); 94 | 95 | logger.debug(crypted); 96 | 97 | Cookie cookie = new Cookie("Ax", crypted); 98 | 99 | // cookie.setDomain(Constant.COOKIE_DOMAIN); 100 | cookie.setMaxAge(Constants.COOKIE_MAX_AGE); 101 | cookie.setPath("/"); 102 | 103 | response.addCookie(cookie); 104 | 105 | return user; 106 | 107 | } 108 | 109 | return null; 110 | 111 | } 112 | 113 | /* 114 | * @see com.samsung.ax.restful.service.UserService#signout(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) 115 | */ 116 | @Override 117 | public void signout(HttpServletRequest request, HttpServletResponse response) { 118 | 119 | Cookie[] cookies = request.getCookies(); 120 | 121 | if (cookies != null) { 122 | 123 | for(Cookie cookie : cookies) { 124 | 125 | logger.debug(cookie.getName() + ": " + cookie.getValue()); 126 | 127 | if (StringUtils.equals(Constants.COOKIE_USER_KEY, cookie.getName())) { 128 | 129 | // cookie.setDomain(Constant.COOKIE_DOMAIN); 130 | cookie.setMaxAge(Constants.COOKIE_EXPIRY); 131 | cookie.setPath("/"); 132 | 133 | response.addCookie(cookie); 134 | 135 | break; 136 | 137 | } 138 | 139 | } 140 | 141 | } 142 | 143 | } 144 | 145 | /* 146 | * @see com.samsung.ax.restful.service.UserService#update(com.samsung.ax.restful.pojo.User) 147 | */ 148 | @Override 149 | public int update(User user) throws DataAccessException { 150 | 151 | logger.debug(".."); 152 | 153 | return persistence.update(user); 154 | 155 | } 156 | 157 | /* 158 | * @see com.samsung.ax.restful.service.UserService#delete(com.samsung.ax.restful.pojo.User) 159 | */ 160 | @Override 161 | public int delete(User user) throws DataAccessException { 162 | 163 | logger.debug(".."); 164 | 165 | return persistence.delete(user); 166 | 167 | } 168 | 169 | /* 170 | * @see com.samsung.ax.restful.service.UserService#name(java.lang.String) 171 | */ 172 | @Override 173 | public User name(String name) throws DataAccessException { 174 | 175 | logger.debug(".."); 176 | 177 | return persistence.name(name); 178 | 179 | } 180 | 181 | /* 182 | * @see com.samsung.ax.restful.service.UserService#count(com.samsung.ax.restful.pojo.Query) 183 | */ 184 | @Override 185 | public int count(Query query) throws DataAccessException { 186 | 187 | logger.debug(".."); 188 | 189 | int cnt = persistence.count(query); 190 | 191 | return cnt; 192 | 193 | } 194 | 195 | /* 196 | * @see com.samsung.ax.restful.service.UserService#list(com.samsung.ax.restful.pojo.Query) 197 | */ 198 | @Override 199 | public List list(Query query) throws DataAccessException { 200 | 201 | logger.debug(".."); 202 | 203 | return persistence.list(query); 204 | 205 | } 206 | 207 | } 208 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/validate/note/AbstractNoteValidate.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.validate.note; 2 | 3 | import java.util.List; 4 | 5 | import com.samsung.ax.restful.pojo.Note; 6 | import com.samsung.ax.restful.validate.Error; 7 | import com.samsung.ax.restful.validate.Validate; 8 | 9 | /** 10 | * 11 | * @author heesik.jeon 12 | * 13 | */ 14 | 15 | public abstract class AbstractNoteValidate implements Validate { 16 | 17 | /* 18 | * @see com.samsung.ax.restful.validate.Validate#validate(java.lang.Object, java.util.List) 19 | */ 20 | @Override 21 | public void validate(Object target, List error) { 22 | validate((Note) target, error); 23 | } 24 | 25 | public abstract void validate(Note target, List error); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/validate/note/MissingContent.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.validate.note; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.commons.lang.StringUtils; 6 | 7 | import com.samsung.ax.restful.common.Constants; 8 | import com.samsung.ax.restful.pojo.Note; 9 | import com.samsung.ax.restful.validate.Error; 10 | 11 | /** 12 | * 13 | * @author heesik.jeon 14 | * 15 | */ 16 | 17 | public class MissingContent extends AbstractNoteValidate { 18 | 19 | /* 20 | * @see com.samsung.ax.restful.validate.note.AbstractNoteValidate#validate(com.samsung.ax.restful.pojo.Note, java.util.List) 21 | */ 22 | @Override 23 | public void validate(Note target, List error) { 24 | 25 | if (StringUtils.isBlank(target.getContent())) { 26 | error.add(new Error(Constants.ERR_MANDATORY_MISSING, new Object[] {Constants.NOTE_CONTENT})); 27 | } 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/validate/note/MissingIdx.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.validate.note; 2 | 3 | import java.util.List; 4 | 5 | import com.samsung.ax.restful.common.Constants; 6 | import com.samsung.ax.restful.pojo.Note; 7 | import com.samsung.ax.restful.validate.Error; 8 | 9 | /** 10 | * 11 | * @author heesik.jeon 12 | * 13 | */ 14 | 15 | public class MissingIdx extends AbstractNoteValidate { 16 | 17 | /* 18 | * @see com.samsung.ax.restful.validate.note.AbstractNoteValidate#validate(com.samsung.ax.restful.pojo.Note, java.util.List) 19 | */ 20 | @Override 21 | public void validate(Note target, List error) { 22 | 23 | if (target.getIdx() <= 0) { 24 | error.add(new Error(Constants.ERR_MANDATORY_MISSING, new Object[] {Constants.NOTE_IDX})); 25 | } 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/validate/note/MissingSubject.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.validate.note; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.commons.lang.StringUtils; 6 | 7 | import com.samsung.ax.restful.common.Constants; 8 | import com.samsung.ax.restful.pojo.Note; 9 | import com.samsung.ax.restful.validate.Error; 10 | 11 | /** 12 | * 13 | * @author heesik.jeon 14 | * 15 | */ 16 | 17 | public class MissingSubject extends AbstractNoteValidate { 18 | 19 | /* 20 | * @see com.samsung.ax.restful.validate.note.AbstractNoteValidate#validate(com.samsung.ax.restful.pojo.Note, java.util.List) 21 | */ 22 | @Override 23 | public void validate(Note target, List error) { 24 | 25 | if (StringUtils.isBlank(target.getSubject())) { 26 | error.add(new Error(Constants.ERR_MANDATORY_MISSING, new Object[] {Constants.NOTE_SUBJECT})); 27 | } 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/validate/user/AbstractUserValidate.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.validate.user; 2 | 3 | import java.util.List; 4 | 5 | import com.samsung.ax.restful.pojo.User; 6 | import com.samsung.ax.restful.validate.Error; 7 | import com.samsung.ax.restful.validate.Validate; 8 | 9 | /** 10 | * 11 | * @author heesik.jeon 12 | * 13 | */ 14 | 15 | public abstract class AbstractUserValidate implements Validate { 16 | 17 | /* 18 | * @see com.samsung.ax.restful.validate.Validate#validate(java.lang.Object, java.util.List) 19 | */ 20 | @Override 21 | public void validate(Object target, List error) { 22 | validate((User) target, error); 23 | } 24 | 25 | /** 26 | * @param target 27 | * @param error 28 | */ 29 | public abstract void validate(User target, List error); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/samsung/ax/restful/validate/user/ValidatingName.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.validate.user; 2 | 3 | import java.util.List; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | 9 | import com.samsung.ax.restful.common.Constants; 10 | import com.samsung.ax.restful.pojo.User; 11 | import com.samsung.ax.restful.service.UserService; 12 | import com.samsung.ax.restful.validate.Error; 13 | 14 | /** 15 | * 16 | * @author heesik.jeon 17 | * 18 | */ 19 | 20 | public class ValidatingName extends AbstractUserValidate { 21 | 22 | 23 | @Autowired 24 | private UserService service; 25 | 26 | /* 27 | * @see com.samsung.ax.restful.validate.user.AbstractValidatedByUser#validate(com.samsung.ax.restful.pojo.User, java.util.List) 28 | */ 29 | @Override 30 | public void validate(User target, List error) { 31 | 32 | if (service.name(target.getName()) != null) { 33 | error.add(new Error(Constants.ERR_USER_NAME_DUPLICATED, new Object[] {target.getName()})); 34 | } else if (target.getName().length() < Constants.USER_NAME_MIN_LENGTH || target.getName().length() > Constants.USER_NAME_MAX_LENGTH) { 35 | error.add(new Error(Constants.ERR_USER_NAME_LENGTH, new Object[] {Constants.USER_NAME_MIN_LENGTH, Constants.USER_NAME_MAX_LENGTH})); 36 | } else if (!isNamePattern(target.getName())) { 37 | error.add(new Error(Constants.ERR_USER_NAME_PATTERN, null)); 38 | } 39 | 40 | } 41 | 42 | private boolean isNamePattern(String name) { 43 | 44 | String regex = "^[a-z0-9.-]{3,15}+$"; 45 | 46 | Pattern pattern = Pattern.compile(regex); 47 | 48 | Matcher matcher = pattern.matcher(name); 49 | 50 | if (matcher.find()) { 51 | return true; 52 | } else { 53 | return false; 54 | } 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/resources/config/jdbc.properties: -------------------------------------------------------------------------------- 1 | ## jdbc.properties 2 | jdbc.driver=com.mysql.jdbc.Driver 3 | jdbc.url=jdbc:mysql://127.0.0.1:3306/data?characterEncoding=utf8 4 | jdbc.username=axpower 5 | jdbc.password=5XPV/9zwujUJAnSJ7rhDJw== -------------------------------------------------------------------------------- /src/main/resources/config/restful.properties: -------------------------------------------------------------------------------- 1 | ## paging.properties 2 | maxPaging=5 3 | maxResults=10 -------------------------------------------------------------------------------- /src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/main/resources/messages/exceptions_en.properties: -------------------------------------------------------------------------------- 1 | # exception 2 | err.system.error=An internal error has occurred. Reference id: ''{0}'' 3 | 4 | err.data.access=Please check database connection 5 | 6 | err.user.name.duplicated=UserId ''{0}'' you inputted isn''t available 7 | err.user.name.length=UserId can only be {0}-{1} characters long 8 | err.user.name.pattern=UserId can contains only letters(a-z), numbers, period(.) and hyphen(-) 9 | 10 | err.user.not.found=User not found, {0}. 11 | err.user.login.failed=Invalid UserId or Password. Please try again. 12 | err.user.authentication.failed=Please sign in to continue to this page 13 | err.user.authorization.failed=UserId ''{0}'' doesn''t have permission to this page 14 | 15 | err.note.not.found=Note not found, {0}. 16 | 17 | err.file.missing=File is required 18 | 19 | # validate 20 | err.mandatory.missing=''{0}'' is required -------------------------------------------------------------------------------- /src/main/resources/spring/spring_ctx.xml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | messages.exceptions 26 | 27 | 28 | 29 | 30 | 31 | 32 | classpath:config/jdbc.properties 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/main/resources/sqlmap/audit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/resources/sqlmap/note.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | INSERT INTO 11 | note (sid, username, subject, content) 12 | VALUES ( 13 | #sid#, #username#, #subject#, #content# 14 | ) 15 | 16 | SELECT LAST_INSERT_ID() AS idx 17 | 18 | 19 | 20 | 28 | 29 | 30 | UPDATE 31 | note 32 | SET 33 | subject = #subject#, 34 | content = #content# 35 | WHERE 36 | idx = #idx# AND status = 1 37 | 38 | 39 | 40 | DELETE FROM 41 | note 42 | WHERE 43 | idx = #idx# AND status = 1 44 | 45 | 46 | 54 | 55 | 56 | UPDATE 57 | note 58 | SET 59 | access = access + 1 60 | WHERE 61 | idx = #idx# AND status = 1 62 | 63 | 64 | 77 | 78 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/main/resources/sqlmap/sqlMaps.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/resources/sqlmap/user.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | INSERT INTO 19 | user (name, pwd, sid, username, role) 20 | VALUES ( 21 | LOWER(#name#), PASSWORD(#pwd#), #sid#, #username#, #role,javaType=com.samsung.ax.restful.pojo.Role,jdbcType=VARCHAR# 22 | ) 23 | 24 | SELECT LAST_INSERT_ID() AS idx 25 | 26 | 27 | 28 | 29 | UPDATE 30 | user 31 | SET 32 | sid = #sid# 33 | WHERE 34 | idx = #idx# AND status = 1 35 | 36 | 37 | 45 | 46 | 47 | UPDATE 48 | user 49 | SET 50 | 51 | 52 | 53 | username = #username# 54 | 55 | 56 | pwd = PASSWORD(#pwd#) 57 | 58 | 59 | role = #role,javaType=com.samsung.ax.restful.pojo.Role,jdbcType=VARCHAR# 60 | 61 | 62 | 63 | WHERE 64 | name = LOWER(#name#) AND status = 1 65 | 66 | 67 | 68 | DELETE FROM 69 | user 70 | WHERE 71 | name = LOWER(#name#) AND status = 1 72 | 73 | 74 | 82 | 83 | 96 | 97 | 111 | 112 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/lib/ax-restful-framework.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samsung/restful/cebf532f682ae2e6e805be40f508b6029e463fe9/src/main/webapp/WEB-INF/lib/ax-restful-framework.jar -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | contextConfigLocation 10 | classpath:/spring/spring_ctx.xml 11 | 12 | 13 | 14 | org.springframework.web.context.ContextLoaderListener 15 | 16 | 17 | org.springframework.web.context.request.RequestContextListener 18 | 19 | 20 | 21 | jersey 22 | com.sun.jersey.spi.spring.container.servlet.SpringServlet 23 | 24 | com.sun.jersey.config.property.packages 25 | com.samsung.ax.restful.resource 26 | 27 | 28 | com.sun.jersey.api.json.POJOMappingFeature 29 | true 30 | 31 | 32 | com.sun.jersey.spi.container.ContainerRequestFilters 33 | com.samsung.ax.restful.filter.AuthenticationContainerFilter 34 | 35 | 36 | com.sun.jersey.spi.container.ResourceFilters 37 | com.samsung.ax.restful.filter.ResourceFilterFactoryImpl 38 | 39 | 1 40 | 41 | 42 | 43 | jersey 44 | /api/* 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/main/webapp/bbs/upload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 |
10 | File : 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/webapp/css/style.css: -------------------------------------------------------------------------------- 1 | @CHARSET "UTF-8"; 2 | html,body { 3 | font-size:12px; 4 | line-height:1.5; 5 | font-family:dotum,sans-serif; 6 | color:#333; 7 | } 8 | a { 9 | color:#4447c3; 10 | text-decoration:none; 11 | } -------------------------------------------------------------------------------- /src/main/webapp/js/restful.js: -------------------------------------------------------------------------------- 1 | // Implement ajax request using XMLHttpRequest 2 | var ajaxCall = (function() { 3 | 4 | return function(Method, Url, Headers, Body, successFunc, errorFunc) { 5 | 6 | var xmlHttpRequest = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsotf.XMLHTTP")); 7 | 8 | xmlHttpRequest.onreadystatechange = function() { 9 | if (xmlHttpRequest.readyState == 4 ) { 10 | var data = JSON.parse(xmlHttpRequest.responseText); 11 | if (xmlHttpRequest.status == 200) { 12 | successFunc(data); 13 | } else { 14 | errorFunc(data); 15 | } 16 | } 17 | }; 18 | 19 | xmlHttpRequest.open(Method, Url, true); 20 | xmlHttpRequest.setRequestHeader('Content-type', 'application/json;charset=utf-8'); 21 | xmlHttpRequest.setRequestHeader("Cache-Control","no-cache, must-revalidate"); 22 | xmlHttpRequest.setRequestHeader("Pragma","no-cache"); 23 | 24 | if (Method == 'GET') { 25 | xmlHttpRequest.send(); 26 | } else { 27 | xmlHttpRequest.send(JSON.stringify(Body)); 28 | } 29 | 30 | }; 31 | 32 | } 33 | 34 | )(); 35 | 36 | var JSON = JSON || {}; 37 | 38 | // Implement JSON.stringify serialization 39 | JSON.stringify = JSON.stringify || function(obj) { 40 | 41 | var t = typeof (obj); 42 | 43 | if (t != "object" || obj === null) { 44 | 45 | // Simple data type 46 | if (t == "string") { 47 | obj = '"' + obj + '"'; 48 | } 49 | 50 | return String(obj); 51 | 52 | } else { 53 | 54 | // Recurse array or object 55 | var v, json = [], arr = (obj && obj.constructor == Array); 56 | 57 | for (n in obj) { 58 | v = obj[n]; 59 | t = typeof (v); 60 | if (t == "string") { 61 | v = '"' + v + '"'; 62 | } else if (t == "object" && v !== null) { 63 | v = JSON.stringify(v); 64 | } 65 | json.push((arr ? "" : '"' + n + '":') + String(v)); 66 | } 67 | 68 | return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); 69 | 70 | } 71 | 72 | }; 73 | 74 | // Implement JSON.parse de-serialization 75 | JSON.parse = JSON.parse || function(str) { 76 | 77 | if (str === "") { 78 | str = '""'; 79 | } 80 | 81 | eval("var p=" + str + ";"); 82 | 83 | return p; 84 | 85 | }; -------------------------------------------------------------------------------- /src/main/webapp/note/content.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Note/Content 6 | 7 | 8 | 100 | 101 | 102 |

Content

103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 |
112 | 113 | -------------------------------------------------------------------------------- /src/main/webapp/note/create.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Note/Create 6 | 7 | 8 | 108 | 109 | 110 |

Create

111 |
112 | 113 | 114 | 125 | 126 | 127 | 128 | 129 |
115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 |
subject
124 |
130 |
131 | 132 | -------------------------------------------------------------------------------- /src/main/webapp/note/list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Note/List 6 | 7 | 8 | 157 | 158 | 159 |

List

160 | 161 | 162 | 163 | 164 | 165 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 |
166 | 167 | 168 |
Create
177 | 178 | 179 | -------------------------------------------------------------------------------- /src/main/webapp/note/update.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Note/Update 6 | 7 | 8 | 115 | 116 | 117 |

Update

118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 |
127 | 128 | -------------------------------------------------------------------------------- /src/main/webapp/user/list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | User/List 6 | 7 | 8 | 157 | 158 | 159 |

List

160 | 161 | 162 | 163 | 164 | 165 | 169 | 170 | 171 | 172 | 173 |
166 | 167 | 168 |
174 | 175 | -------------------------------------------------------------------------------- /src/main/webapp/user/manage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | User/Update 6 | 7 | 8 | 191 | 192 | 193 |

Management

194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 |
202 | 203 | -------------------------------------------------------------------------------- /src/main/webapp/user/profile.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | User/Profile 6 | 7 | 8 | 63 | 64 | 65 |

Profile

66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
Sign InSign UpSetting
76 | 77 | -------------------------------------------------------------------------------- /src/main/webapp/user/signin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | User/Sign In 6 | 7 | 8 | 41 | 42 | 43 |

Sign In

44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
userid
password
Sign Up
60 | 61 | -------------------------------------------------------------------------------- /src/main/webapp/user/signup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | User/Sign Up 6 | 7 | 8 | 46 | 47 | 48 |

Sign Up

49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
userid
username
password
66 | 67 | -------------------------------------------------------------------------------- /src/main/webapp/user/update.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | User/Update 6 | 7 | 8 | 121 | 122 | 123 |

Update

124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 |
133 | 134 | -------------------------------------------------------------------------------- /src/test/java/com/samsung/ax/restful/crypt/aes/AxCryptTest.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.crypt.aes; 2 | 3 | import org.apache.log4j.Level; 4 | import org.apache.log4j.Logger; 5 | 6 | import com.samsung.ax.restful.crypt.AxCryptException; 7 | import com.samsung.ax.restful.crypt.aes.AxCrypt; 8 | 9 | import junit.framework.TestCase; 10 | 11 | /** 12 | * 13 | * @author heesik.jeon 14 | * 15 | */ 16 | 17 | public class AxCryptTest extends TestCase { 18 | 19 | private Logger logger = Logger.getLogger(this.getClass()); 20 | 21 | public AxCryptTest() { 22 | logger.setLevel(Level.DEBUG); 23 | } 24 | 25 | public void testEncrypt() { 26 | 27 | try { 28 | 29 | String plain = "대한민국 Korea 韓國 ~!@#$%^&*()_+|"; 30 | String encrypted = AxCrypt.encrypt("Vvb7oruYPkOHrEwoTVnXtw==", plain); 31 | 32 | logger.debug(plain); 33 | logger.debug(encrypted); 34 | 35 | } catch (AxCryptException e) { 36 | fail(e.toString()); 37 | } 38 | 39 | } 40 | 41 | public void testDecrypt() { 42 | 43 | try { 44 | 45 | String encrypted = "yhAGrcZInqeKNvMiLiBugeIT/Sb/4ldr8YMLaL0OrRmvLc/pHJ8YZTda0R63HRyC"; 46 | String decrypted = AxCrypt.decrypt("Vvb7oruYPkOHrEwoTVnXtw==", encrypted); 47 | 48 | logger.debug(encrypted); 49 | logger.debug(decrypted); 50 | 51 | } catch (AxCryptException e) { 52 | fail(e.toString()); 53 | } 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/samsung/ax/restful/utils/FileHelperTest.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.utils; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.Reader; 6 | import java.util.Properties; 7 | 8 | import junit.framework.TestCase; 9 | 10 | import org.apache.log4j.Level; 11 | import org.apache.log4j.Logger; 12 | 13 | import com.samsung.ax.restful.common.Constants; 14 | import com.samsung.ax.restful.utils.FileHelper; 15 | 16 | /** 17 | * 18 | * @author heesik.jeon 19 | * 20 | */ 21 | 22 | public class FileHelperTest extends TestCase { 23 | 24 | private Logger logger = Logger.getLogger(this.getClass()); 25 | 26 | public FileHelperTest() { 27 | logger.setLevel(Level.DEBUG); 28 | } 29 | 30 | public void testReadProperties() throws IOException { 31 | 32 | Reader reader = null; 33 | 34 | try { 35 | 36 | reader = FileHelper.getStream("/com/samsung/ax/restful/utils/project.properties"); 37 | 38 | Properties prop = new Properties(); 39 | prop.load(reader); 40 | 41 | logger.debug(prop.get("project")); 42 | logger.debug(prop.getProperty("description")); 43 | 44 | } catch (Exception e) { 45 | fail(e.toString()); 46 | } finally { 47 | reader.close(); 48 | } 49 | 50 | } 51 | 52 | public void testReadLine() throws IOException { 53 | 54 | Reader reader = null; 55 | 56 | try { 57 | 58 | reader = FileHelper.getStream("/com/samsung/ax/restful/utils/project.properties"); 59 | 60 | BufferedReader br = new BufferedReader(reader); 61 | 62 | String line; 63 | 64 | while ((line = br.readLine()) != null) { 65 | logger.debug(line); 66 | } 67 | 68 | } catch (Exception e) { 69 | fail(e.toString()); 70 | } finally { 71 | reader.close(); 72 | } 73 | 74 | } 75 | 76 | public void testDir() { 77 | 78 | try { 79 | 80 | String input = "ax"; 81 | int depth = 2; 82 | 83 | logger.debug(FileHelper.hashdir(Constants.FILE_BASE_PATH, input, depth)); 84 | 85 | } catch (Exception e) { 86 | fail(e.toString()); 87 | } 88 | 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/com/samsung/ax/restful/utils/FormatHelperTest.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.utils; 2 | 3 | import java.io.IOException; 4 | import java.io.Reader; 5 | 6 | import junit.framework.TestCase; 7 | 8 | import org.apache.commons.io.IOUtils; 9 | import org.apache.log4j.Level; 10 | import org.apache.log4j.Logger; 11 | 12 | import com.google.gson.Gson; 13 | import com.samsung.ax.restful.pojo.Note; 14 | import com.samsung.ax.restful.utils.FileHelper; 15 | import com.samsung.ax.restful.utils.FormatHelper; 16 | 17 | /** 18 | * 19 | * @author heesik.jeon 20 | * 21 | */ 22 | 23 | public class FormatHelperTest extends TestCase { 24 | 25 | private Logger logger = Logger.getLogger(this.getClass()); 26 | 27 | public FormatHelperTest() { 28 | logger.setLevel(Level.DEBUG); 29 | } 30 | 31 | public void testPrintPretty() throws IOException { 32 | 33 | Reader reader = null; 34 | 35 | try { 36 | 37 | reader = FileHelper.getStream("/com/samsung/ax/restful/utils/list.json"); 38 | 39 | String text = IOUtils.toString(reader); 40 | 41 | Note note = new Gson().fromJson(text, Note.class); 42 | 43 | logger.debug(text); 44 | logger.debug(FormatHelper.printPretty(note)); 45 | 46 | } catch (Exception e) { 47 | fail(e.toString()); 48 | } finally { 49 | reader.close(); 50 | } 51 | 52 | } 53 | 54 | public void testNumeral() { 55 | 56 | try { 57 | 58 | int base = 16; 59 | int number = 238328; 60 | 61 | String haxa = FormatHelper.convertNumeral(base, number); 62 | long decimal = FormatHelper.invertNumeral(base, haxa); 63 | 64 | logger.debug(haxa); 65 | logger.debug(decimal); 66 | 67 | } catch (Exception e) { 68 | fail(e.toString()); 69 | } 70 | 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/com/samsung/ax/restful/utils/StreamHelperTest.java: -------------------------------------------------------------------------------- 1 | package com.samsung.ax.restful.utils; 2 | 3 | import junit.framework.TestCase; 4 | 5 | import org.apache.log4j.Level; 6 | import org.apache.log4j.Logger; 7 | 8 | /** 9 | * 10 | * @author heesik.jeon 11 | * 12 | */ 13 | 14 | public class StreamHelperTest extends TestCase { 15 | 16 | private Logger logger = Logger.getLogger(this.getClass()); 17 | 18 | public StreamHelperTest() { 19 | logger.setLevel(Level.DEBUG); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/resources/com/samsung/ax/restful/utils/list.json: -------------------------------------------------------------------------------- 1 | {"idx":1,"subject":"Hello","content":"It's really nice to meet you."} -------------------------------------------------------------------------------- /src/test/resources/com/samsung/ax/restful/utils/project.properties: -------------------------------------------------------------------------------- 1 | ## project.properties 2 | project=restful 3 | description=Suggesting standard and optimized codes for Web service to build ecosystem --------------------------------------------------------------------------------