├── .coveralls.yml ├── .idea ├── compiler.xml ├── encodings.xml ├── libraries │ ├── Maven__antlr_antlr_2_7_7.xml │ ├── Maven__aopalliance_aopalliance_1_0.xml │ ├── Maven__com_sun_jersey_contribs_jersey_spring_1_19_1.xml │ ├── Maven__com_sun_jersey_jersey_core_1_19_1.xml │ ├── Maven__com_sun_jersey_jersey_json_1_19_1.xml │ ├── Maven__com_sun_jersey_jersey_server_1_19_1.xml │ ├── Maven__com_sun_jersey_jersey_servlet_1_19_1.xml │ ├── Maven__com_sun_xml_bind_jaxb_impl_2_2_3_1.xml │ ├── Maven__commons_dbcp_commons_dbcp_1_4.xml │ ├── Maven__commons_fileupload_commons_fileupload_1_2.xml │ ├── Maven__commons_logging_commons_logging_1_2.xml │ ├── Maven__commons_pool_commons_pool_1_5_4.xml │ ├── Maven__dom4j_dom4j_1_6_1.xml │ ├── Maven__javax_activation_activation_1_1.xml │ ├── Maven__javax_servlet_javax_servlet_api_3_1_0.xml │ ├── Maven__javax_servlet_servlet_api_2_5.xml │ ├── Maven__javax_ws_rs_jsr311_api_1_1_1.xml │ ├── Maven__javax_xml_bind_jaxb_api_2_2_2.xml │ ├── Maven__javax_xml_stream_stax_api_1_0_2.xml │ ├── Maven__jstl_jstl_1_2.xml │ ├── Maven__junit_junit_4_11.xml │ ├── Maven__log4j_log4j_1_2_17.xml │ ├── Maven__mysql_mysql_connector_java_5_1_40.xml │ ├── Maven__org_codehaus_jackson_jackson_core_asl_1_9_2.xml │ ├── Maven__org_codehaus_jackson_jackson_jaxrs_1_9_2.xml │ ├── Maven__org_codehaus_jackson_jackson_mapper_asl_1_9_2.xml │ ├── Maven__org_codehaus_jackson_jackson_xc_1_9_2.xml │ ├── Maven__org_codehaus_jettison_jettison_1_1.xml │ ├── Maven__org_hamcrest_hamcrest_core_1_3.xml │ ├── Maven__org_hibernate_common_hibernate_commons_annotations_4_0_2_Final.xml │ ├── Maven__org_hibernate_hibernate_core_4_2_21_Final.xml │ ├── Maven__org_hibernate_hibernate_entitymanager_4_2_21_Final.xml │ ├── Maven__org_hibernate_javax_persistence_hibernate_jpa_2_0_api_1_0_1_Final.xml │ ├── Maven__org_hsqldb_hsqldb_2_3_2.xml │ ├── Maven__org_javassist_javassist_3_18_1_GA.xml │ ├── Maven__org_jboss_logging_jboss_logging_3_1_0_GA.xml │ ├── Maven__org_jboss_spec_javax_transaction_jboss_transaction_api_1_1_spec_1_0_1_Final.xml │ ├── Maven__org_slf4j_slf4j_api_1_7_5.xml │ ├── Maven__org_slf4j_slf4j_log4j12_1_7_5.xml │ ├── Maven__org_springframework_security_spring_security_config_4_0_4_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_core_4_0_4_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_web_4_0_4_RELEASE.xml │ ├── Maven__org_springframework_spring_aop_4_2_5_RELEASE.xml │ ├── Maven__org_springframework_spring_beans_4_2_5_RELEASE.xml │ ├── Maven__org_springframework_spring_context_4_2_5_RELEASE.xml │ ├── Maven__org_springframework_spring_core_4_2_5_RELEASE.xml │ ├── Maven__org_springframework_spring_expression_4_2_5_RELEASE.xml │ ├── Maven__org_springframework_spring_jdbc_4_2_5_RELEASE.xml │ ├── Maven__org_springframework_spring_orm_4_2_5_RELEASE.xml │ ├── Maven__org_springframework_spring_test_4_2_5_RELEASE.xml │ ├── Maven__org_springframework_spring_tx_4_2_5_RELEASE.xml │ ├── Maven__org_springframework_spring_web_4_2_5_RELEASE.xml │ └── Maven__org_springframework_spring_webmvc_4_2_5_RELEASE.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── .travis.yml ├── README.md ├── nasher.iml ├── pom.xml ├── pom.xml.versionsBackup └── src └── main ├── java └── ir │ └── mnm │ └── nasher │ ├── JsonViews.java │ ├── dao │ ├── Dao.java │ ├── DataBaseInitializer.java │ ├── JpaDao.java │ ├── accesstoken │ │ ├── AccessTokenDao.java │ │ └── JpaAccessTokenDao.java │ ├── blogpost │ │ ├── BlogPostDao.java │ │ └── JpaBlogPostDao.java │ ├── category │ │ ├── CategoryDao.java │ │ └── JpaCategoryDao.java │ └── user │ │ ├── JpaUserDao.java │ │ └── UserDao.java │ ├── entity │ ├── AccessToken.java │ ├── BlogPost.java │ ├── Category.java │ ├── Comment.java │ ├── Entity.java │ ├── Role.java │ └── User.java │ ├── rest │ ├── AuthenticationTokenProcessingFilter.java │ ├── UnauthorizedEntryPoint.java │ └── resources │ │ ├── BlogPostResource.java │ │ ├── CategoryResource.java │ │ ├── FileResource.java │ │ └── UserResource.java │ ├── service │ ├── DaoUserService.java │ └── UserService.java │ ├── transfer │ ├── TokenTransfer.java │ └── UserTransfer.java │ ├── util │ ├── dodownload.java │ └── tools.java │ └── web │ └── controller │ ├── blogs.java │ ├── categoryController.java │ └── oneController.java ├── main.iml ├── resources ├── META-INF │ └── persistence.xml ├── application.properties ├── context.xml └── log4j.properties └── webapp ├── WEB-INF ├── mvc-dispatcher-servlet.xml └── web.xml ├── admin ├── css │ └── custom.css ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff ├── index.html ├── js │ ├── app.js │ └── config.js └── partials │ ├── create.html │ ├── create_categ.html │ ├── edit.html │ ├── edit_categ.html │ ├── index.html │ ├── index_categ.html │ └── login.html ├── pages ├── category.jsp ├── index.jsp ├── one.jsp └── signup.jsp └── res ├── css ├── blog-home.css ├── blog-post.css ├── bootstrap.css └── bootstrap.min.css ├── fonts ├── glyphicons-halflings-regular.eot ├── glyphicons-halflings-regular.svg ├── glyphicons-halflings-regular.ttf ├── glyphicons-halflings-regular.woff └── glyphicons-halflings-regular.woff2 └── js ├── bootstrap.js ├── bootstrap.min.js └── jquery.js /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-pro 2 | repo_token: JLiPcnAvQM7yI6zrPJCeSHmSQ4mJ8ANqE -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__antlr_antlr_2_7_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__aopalliance_aopalliance_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_sun_jersey_contribs_jersey_spring_1_19_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_sun_jersey_jersey_core_1_19_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_sun_jersey_jersey_json_1_19_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_sun_jersey_jersey_server_1_19_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_sun_jersey_jersey_servlet_1_19_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_sun_xml_bind_jaxb_impl_2_2_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_dbcp_commons_dbcp_1_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_fileupload_commons_fileupload_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_logging_commons_logging_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_pool_commons_pool_1_5_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__dom4j_dom4j_1_6_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_activation_activation_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_servlet_javax_servlet_api_3_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_servlet_servlet_api_2_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_ws_rs_jsr311_api_1_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_xml_bind_jaxb_api_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_xml_stream_stax_api_1_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__jstl_jstl_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__junit_junit_4_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__log4j_log4j_1_2_17.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__mysql_mysql_connector_java_5_1_40.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_codehaus_jackson_jackson_core_asl_1_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_codehaus_jackson_jackson_jaxrs_1_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_codehaus_jackson_jackson_mapper_asl_1_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_codehaus_jackson_jackson_xc_1_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_codehaus_jettison_jettison_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_common_hibernate_commons_annotations_4_0_2_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_hibernate_core_4_2_21_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_hibernate_entitymanager_4_2_21_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_javax_persistence_hibernate_jpa_2_0_api_1_0_1_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hsqldb_hsqldb_2_3_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_javassist_javassist_3_18_1_GA.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_1_0_GA.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jboss_spec_javax_transaction_jboss_transaction_api_1_1_spec_1_0_1_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_7_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_security_spring_security_config_4_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_security_spring_security_core_4_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_security_spring_security_web_4_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_core_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jdbc_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_orm_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_test_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_tx_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_web_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_webmvc_4_2_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 1.8 18 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 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 | 27 | 28 | 29 | 30 | 31 | 32 | 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 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Nasher](https://github.com/mmghasemi/nasher) 2 | =========================== 3 | 4 | [![Build Status](https://travis-ci.org/ghaseminya/nasher-mvc-spring-security-blog-angular.svg?branch=master)](https://travis-ci.org/mmghasemi/nasher) 5 | [![Apache License](http://img.shields.io/badge/license-apache2-orange.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) 6 | [![Coverage Status](https://coveralls.io/repos/github/mmghasemi/nasher/badge.svg?branch=master)](https://coveralls.io/github/mmghasemi/nasher?branch=master) 7 | 8 | 9 | Nasher is a light Java blogging system 10 | 11 | Admin panel + Home pages 12 | 13 | [Demo](http://jnasher.ir) => http://jnasher.ir 14 | 15 | [Admin Demo](http://jnasher.ir/admin/index.html) username/password=mnm 16 | 17 | About 18 | ----- 19 | 20 | The projects aim is to demonstrate the Java implementation of a simple REST interface which is used by an AngularJS application. The following topics are covered: 21 | 22 | * A relational database that holds blog posts and users. 23 | * A REST service that exposes the data in the database. 24 | * Authentication and authorization against the REST service. 25 | * A Simple AngularJS application that allows users to view or edit news entries depending on their role. 26 | * A responsive design. 27 | 28 | This project is just meant to be a demonstration, therefore it is neither well documented nor well tested. Use it to learn about the technologies used, but do not use it for productive applications. 29 | 30 | Any feedback is welcome, and I will incorporate useful pull requests. 31 | 32 | Technologies 33 | ------------ 34 | 35 | * [Spring MVC](http://spring.io) 36 | * [AngularJS](http://angularjs.org/) 37 | * [Bootstrap](http://getbootstrap.com/) 38 | * [Jersey](https://jersey.java.net/) 39 | * [Spring Security](http://projects.spring.io/spring-security/) 40 | * [Hibernate](http://hibernate.org/) 41 | 42 | User Levels 43 | ------------ 44 | * User Level = {View posts, Apply new Comment} 45 | * Editor Level = {Add new Post,Edit posts,Delete posts} 46 | * Admin Level = {Manage Users, Posts, Comments, Files, Categories} 47 | 48 | Running 49 | ------- 50 | 51 | Make sure [Maven](http://maven.apache.org/) >= 2.2.1 is installed on your system. Go into the project dir and type `mvn jetty:run`, then point your browser to `http://localhost:8080`. 52 | 53 | License 54 | ------- 55 | 56 | [The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) 57 | -------------------------------------------------------------------------------- /nasher.iml: -------------------------------------------------------------------------------- 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 | 27 | 28 | 29 | 30 | 31 | 32 | 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 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | ir.mnm 4 | nasher 5 | 0.2.0-SNAPSHOT 6 | war 7 | 8 | 9 | UTF-8 10 | 11 | 4.0.4.RELEASE 12 | 4.2.5.RELEASE 13 | 1.19.1 14 | 4.2.21.Final 15 | 1.7.5 16 | 2.5 17 | 3.1 18 | 2.3.2 19 | 1.4 20 | 4.11 21 | 9.1.1.v20140108 22 | 23 | 24 | 25 | 26 | Mohammad Mahdi 27 | http://j2eedev.ir 28 | 29 | 30 | 31 | 32 | 33 | The Apache Software License, Version 2.0 34 | http://www.apache.org/licenses/LICENSE-2.0.txt 35 | repo 36 | 37 | 38 | 39 | 40 | 3.3 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.eluder.coveralls 49 | coveralls-maven-plugin 50 | 4.3.0 51 | 52 | KbKWmb7aI7SLYck3DUeoDJptcOGhgVfGc 53 | 54 | 55 | 56 | org.codehaus.mojo 57 | cobertura-maven-plugin 58 | 2.7 59 | 60 | true 61 | xml 62 | 256m 63 | 64 | true 65 | 66 | 67 | 68 | 69 | org.apache.maven.plugins 70 | maven-compiler-plugin 71 | ${maven-compiler-plugin.version} 72 | 73 | 1.6 74 | 1.6 75 | 76 | 77 | 78 | org.eclipse.jetty 79 | jetty-maven-plugin 80 | ${org.eclipse.jetty.jetty-maven-plugin.version} 81 | 82 | 83 | 84 | 85 | 86 | scm:git:https://github.com/mmghasemi/nasher.git 87 | 88 | 89 | 90 | 91 | 92 | org.springframework 93 | spring-orm 94 | ${version.org.springframework} 95 | 96 | 97 | 98 | 99 | org.springframework 100 | spring-jdbc 101 | ${version.org.springframework} 102 | 103 | 104 | 105 | org.springframework 106 | spring-tx 107 | ${version.org.springframework} 108 | 109 | 110 | 111 | com.sun.jersey.contribs 112 | jersey-spring 113 | ${version.com.sun.jersey.contribs} 114 | 115 | 116 | 117 | org.springframework 118 | spring 119 | 120 | 121 | org.springframework 122 | spring-core 123 | 124 | 125 | org.springframework 126 | spring-web 127 | 128 | 129 | org.springframework 130 | spring-webmvc 131 | 132 | 133 | org.springframework 134 | spring-beans 135 | 136 | 137 | org.springframework 138 | spring-context 139 | 140 | 141 | org.springframework 142 | spring-aop 143 | 144 | 145 | 146 | 147 | org.springframework 148 | spring-web 149 | ${version.org.springframework} 150 | 151 | 152 | com.sun.jersey 153 | jersey-json 154 | ${version.com.sun.jersey.contribs} 155 | 156 | 157 | 158 | org.hsqldb 159 | hsqldb 160 | ${org.hsqldb.version} 161 | 162 | 163 | 164 | commons-dbcp 165 | commons-dbcp 166 | ${commons-dbcp.version} 167 | 168 | 169 | 170 | org.hibernate 171 | hibernate-entitymanager 172 | ${version.org.hibernate} 173 | 174 | 175 | 176 | org.slf4j 177 | slf4j-log4j12 178 | ${org.slf4j.version} 179 | 180 | 181 | 182 | org.springframework.security 183 | spring-security-web 184 | ${version.org.springframework.security} 185 | 186 | 187 | 188 | org.springframework.security 189 | spring-security-config 190 | ${version.org.springframework.security} 191 | 192 | 193 | 194 | javax.servlet 195 | servlet-api 196 | ${javax.servlet-api.version} 197 | provided 198 | 199 | 200 | 201 | org.springframework 202 | spring-test 203 | ${version.org.springframework} 204 | test 205 | 206 | 207 | 208 | junit 209 | junit 210 | ${junit.version} 211 | test 212 | 213 | 214 | 215 | jstl 216 | jstl 217 | 1.2 218 | 219 | 220 | org.springframework 221 | spring-webmvc 222 | ${version.org.springframework} 223 | 224 | 225 | javax.servlet 226 | javax.servlet-api 227 | 3.1.0 228 | 229 | 230 | 231 | commons-fileupload 232 | commons-fileupload 233 | 1.2 234 | 235 | 236 | 237 | 238 | 239 | -------------------------------------------------------------------------------- /pom.xml.versionsBackup: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | ir.mnm 4 | nasher 5 | 0.1.0-SNAPSHOT 6 | war 7 | 8 | 9 | UTF-8 10 | 11 | 4.0.4.RELEASE 12 | 4.2.5.RELEASE 13 | 1.19.1 14 | 4.2.21.Final 15 | 1.7.5 16 | 2.5 17 | 3.1 18 | 2.3.2 19 | 1.4 20 | 4.11 21 | 9.1.1.v20140108 22 | 23 | 24 | 25 | 26 | Mohammad Mahdi 27 | http://j2eedev.ir 28 | 29 | 30 | 31 | 32 | 33 | The Apache Software License, Version 2.0 34 | http://www.apache.org/licenses/LICENSE-2.0.txt 35 | repo 36 | 37 | 38 | 39 | 40 | 3.3 41 | 42 | 43 | 44 | $\{project.artifactId}-$\{project.version}-r$\{buildNumber} 45 | 46 | 47 | org.codehaus.mojo 48 | buildnumber-maven-plugin 49 | 1.4 50 | 51 | 52 | validate 53 | 54 | create 55 | 56 | 57 | 58 | 59 | true 60 | true 61 | 62 | 63 | 64 | org.eluder.coveralls 65 | coveralls-maven-plugin 66 | 4.3.0 67 | 68 | JLiPcnAvQM7yI6zrPJCeSHmSQ4mJ8ANqE 69 | xml 70 | true 71 | 72 | 73 | 74 | org.codehaus.mojo 75 | cobertura-maven-plugin 76 | 2.7 77 | 78 | true 79 | xml 80 | 256m 81 | 82 | true 83 | 84 | 85 | 86 | 87 | org.apache.maven.plugins 88 | maven-compiler-plugin 89 | ${maven-compiler-plugin.version} 90 | 91 | 1.6 92 | 1.6 93 | 94 | 95 | 96 | org.eclipse.jetty 97 | jetty-maven-plugin 98 | ${org.eclipse.jetty.jetty-maven-plugin.version} 99 | 100 | 101 | 102 | 103 | 104 | scm:git:https://github.com/mmghasemi/nasher.git 105 | 106 | 107 | 108 | 109 | 110 | org.springframework 111 | spring-orm 112 | ${version.org.springframework} 113 | 114 | 115 | 116 | 117 | org.springframework 118 | spring-jdbc 119 | ${version.org.springframework} 120 | 121 | 122 | 123 | org.springframework 124 | spring-tx 125 | ${version.org.springframework} 126 | 127 | 128 | 129 | com.sun.jersey.contribs 130 | jersey-spring 131 | ${version.com.sun.jersey.contribs} 132 | 133 | 134 | 135 | org.springframework 136 | spring 137 | 138 | 139 | org.springframework 140 | spring-core 141 | 142 | 143 | org.springframework 144 | spring-web 145 | 146 | 147 | org.springframework 148 | spring-beans 149 | 150 | 151 | org.springframework 152 | spring-context 153 | 154 | 155 | org.springframework 156 | spring-aop 157 | 158 | 159 | 160 | 161 | 162 | com.sun.jersey 163 | jersey-json 164 | ${version.com.sun.jersey.contribs} 165 | 166 | 167 | 168 | org.hsqldb 169 | hsqldb 170 | ${org.hsqldb.version} 171 | 172 | 173 | 174 | commons-dbcp 175 | commons-dbcp 176 | ${commons-dbcp.version} 177 | 178 | 179 | 180 | org.hibernate 181 | hibernate-entitymanager 182 | ${version.org.hibernate} 183 | 184 | 185 | 186 | org.slf4j 187 | slf4j-log4j12 188 | ${org.slf4j.version} 189 | 190 | 191 | 192 | org.springframework.security 193 | spring-security-web 194 | ${version.org.springframework.security} 195 | 196 | 197 | 198 | org.springframework.security 199 | spring-security-config 200 | ${version.org.springframework.security} 201 | 202 | 203 | 204 | javax.servlet 205 | servlet-api 206 | ${javax.servlet-api.version} 207 | provided 208 | 209 | 210 | 211 | org.springframework 212 | spring-test 213 | ${version.org.springframework} 214 | test 215 | 216 | 217 | 218 | junit 219 | junit 220 | ${junit.version} 221 | test 222 | 223 | 224 | 225 | 226 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/JsonViews.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher; 2 | 3 | public class JsonViews 4 | { 5 | public static class User 6 | { 7 | } 8 | 9 | public static class Admin extends User 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/Dao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao; 2 | 3 | import ir.mnm.nasher.entity.Entity; 4 | 5 | import java.util.List; 6 | 7 | public interface Dao 8 | { 9 | List findAll(); 10 | 11 | T find(I id); 12 | 13 | T save(T entity); 14 | 15 | void delete(I id); 16 | 17 | void delete(T entity); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/DataBaseInitializer.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao; 2 | 3 | import ir.mnm.nasher.dao.blogpost.BlogPostDao; 4 | import ir.mnm.nasher.dao.category.CategoryDao; 5 | import ir.mnm.nasher.dao.user.UserDao; 6 | import ir.mnm.nasher.entity.BlogPost; 7 | import ir.mnm.nasher.entity.Category; 8 | import ir.mnm.nasher.entity.Role; 9 | import ir.mnm.nasher.entity.User; 10 | import org.springframework.security.crypto.password.PasswordEncoder; 11 | 12 | import java.util.Date; 13 | import java.util.Random; 14 | 15 | /** 16 | * Initialize the database with some test entries. 17 | * 18 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 19 | */ 20 | public class DataBaseInitializer 21 | { 22 | private BlogPostDao blogPostDao; 23 | 24 | private UserDao userDao; 25 | 26 | private PasswordEncoder passwordEncoder; 27 | 28 | private CategoryDao categoryDao; 29 | 30 | protected DataBaseInitializer() 31 | { 32 | /* Default constructor for reflection instantiation */ 33 | } 34 | 35 | public DataBaseInitializer(UserDao userDao, BlogPostDao blogPostDao, PasswordEncoder passwordEncoder,CategoryDao cad) 36 | { 37 | this.userDao = userDao; 38 | this.blogPostDao = blogPostDao; 39 | this.passwordEncoder = passwordEncoder; 40 | this.categoryDao=cad; 41 | } 42 | 43 | public void initDataBase() 44 | { 45 | User userUser = new User("user", this.passwordEncoder.encode("user")); 46 | userUser.addRole(Role.USER); 47 | this.userDao.save(userUser); 48 | 49 | User adminUser = new User("admin", this.passwordEncoder.encode("admin")); 50 | adminUser.addRole(Role.USER); 51 | adminUser.addRole(Role.ADMIN); 52 | this.userDao.save(adminUser); 53 | 54 | long timestamp = System.currentTimeMillis() - (1000 * 60 * 60 * 24); 55 | for (int i = 1; i < 8; i++) { 56 | BlogPost blogPost = new BlogPost(); 57 | blogPost.setContent("This is example content " + i); 58 | blogPost.setDate(new Date(timestamp)); 59 | int c=new Random().nextInt(3)+1; 60 | blogPost.setCategory(c); 61 | blogPost.setSign(1); 62 | blogPost.setFile(i+".jpg"); 63 | blogPost.setTitle("Blog title "+i); 64 | blogPost.setTags("jsf,j2eedev,java,spring"); 65 | this.blogPostDao.save(blogPost); 66 | timestamp += 1000 * 60 * 60; 67 | } 68 | 69 | categoryDao.save(new Category(new Long(1),"Java")); 70 | categoryDao.save(new Category(new Long(2),"Spring")); 71 | categoryDao.save(new Category(new Long(3),"JSF")); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/JpaDao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao; 2 | 3 | import ir.mnm.nasher.entity.Entity; 4 | import org.springframework.transaction.annotation.Transactional; 5 | 6 | import javax.persistence.EntityManager; 7 | import javax.persistence.PersistenceContext; 8 | import javax.persistence.TypedQuery; 9 | import javax.persistence.criteria.CriteriaBuilder; 10 | import javax.persistence.criteria.CriteriaQuery; 11 | import java.util.List; 12 | 13 | public class JpaDao implements Dao 14 | { 15 | private EntityManager entityManager; 16 | 17 | protected Class entityClass; 18 | 19 | public JpaDao(Class entityClass) 20 | { 21 | this.entityClass = entityClass; 22 | } 23 | 24 | public EntityManager getEntityManager() 25 | { 26 | return this.entityManager; 27 | } 28 | 29 | @PersistenceContext 30 | public void setEntityManager(final EntityManager entityManager) 31 | { 32 | this.entityManager = entityManager; 33 | } 34 | 35 | @Override 36 | @Transactional(readOnly = true) 37 | public List findAll() 38 | { 39 | final CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder(); 40 | final CriteriaQuery criteriaQuery = builder.createQuery(this.entityClass); 41 | 42 | criteriaQuery.from(this.entityClass); 43 | 44 | TypedQuery typedQuery = this.getEntityManager().createQuery(criteriaQuery); 45 | return typedQuery.getResultList(); 46 | } 47 | 48 | @Override 49 | @Transactional(readOnly = true) 50 | public T find(I id) 51 | { 52 | return this.getEntityManager().find(this.entityClass, id); 53 | } 54 | 55 | @Override 56 | @Transactional 57 | public T save(T entity) 58 | { 59 | return this.getEntityManager().merge(entity); 60 | } 61 | 62 | @Override 63 | @Transactional 64 | public void delete(I id) 65 | { 66 | if (id == null) { 67 | return; 68 | } 69 | 70 | T entity = this.find(id); 71 | if (entity == null) { 72 | return; 73 | } 74 | 75 | this.getEntityManager().remove(entity); 76 | } 77 | 78 | @Override 79 | @Transactional 80 | public void delete(T entity) 81 | { 82 | this.getEntityManager().remove(entity); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/accesstoken/AccessTokenDao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao.accesstoken; 2 | 3 | import ir.mnm.nasher.dao.Dao; 4 | import ir.mnm.nasher.entity.AccessToken; 5 | 6 | /** 7 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 8 | */ 9 | public interface AccessTokenDao extends Dao 10 | { 11 | AccessToken findByToken(String accessTokenString); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/accesstoken/JpaAccessTokenDao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao.accesstoken; 2 | 3 | import ir.mnm.nasher.dao.JpaDao; 4 | import ir.mnm.nasher.entity.AccessToken; 5 | import org.springframework.transaction.annotation.Transactional; 6 | 7 | import javax.persistence.NoResultException; 8 | import javax.persistence.criteria.CriteriaBuilder; 9 | import javax.persistence.criteria.CriteriaQuery; 10 | import javax.persistence.criteria.Root; 11 | 12 | /** 13 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 14 | */ 15 | public class JpaAccessTokenDao extends JpaDao implements AccessTokenDao 16 | { 17 | public JpaAccessTokenDao() 18 | { 19 | super(AccessToken.class); 20 | } 21 | 22 | @Override 23 | @Transactional(readOnly = true, noRollbackFor = NoResultException.class) 24 | public AccessToken findByToken(String accessTokenString) 25 | { 26 | CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder(); 27 | CriteriaQuery query = builder.createQuery(this.entityClass); 28 | Root root = query.from(this.entityClass); 29 | query.where(builder.equal(root.get("token"), accessTokenString)); 30 | 31 | try { 32 | return this.getEntityManager().createQuery(query).getSingleResult(); 33 | } catch (NoResultException e) { 34 | return null; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/blogpost/BlogPostDao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao.blogpost; 2 | 3 | import ir.mnm.nasher.dao.Dao; 4 | import ir.mnm.nasher.entity.BlogPost; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Definition of a Data Access Object that can perform CRUD Operations for {@link BlogPost}s. 10 | * 11 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 12 | */ 13 | public interface BlogPostDao extends Dao 14 | { 15 | List blogbycateg(int categ); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/blogpost/JpaBlogPostDao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao.blogpost; 2 | 3 | import ir.mnm.nasher.dao.JpaDao; 4 | import ir.mnm.nasher.entity.BlogPost; 5 | import org.springframework.transaction.annotation.Transactional; 6 | 7 | import javax.persistence.TypedQuery; 8 | import javax.persistence.criteria.CriteriaBuilder; 9 | import javax.persistence.criteria.CriteriaQuery; 10 | import javax.persistence.criteria.Path; 11 | import javax.persistence.criteria.Root; 12 | import java.util.List; 13 | 14 | /** 15 | * JPA Implementation of a {@link BlogPostDao}. 16 | * 17 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 18 | */ 19 | public class JpaBlogPostDao extends JpaDao implements BlogPostDao 20 | { 21 | public JpaBlogPostDao() 22 | { 23 | super(BlogPost.class); 24 | } 25 | 26 | @Override 27 | @Transactional(readOnly = true) 28 | public List findAll() 29 | { 30 | final CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder(); 31 | final CriteriaQuery criteriaQuery = builder.createQuery(BlogPost.class); 32 | 33 | Root root = criteriaQuery.from(BlogPost.class); 34 | criteriaQuery.orderBy(builder.desc(root.get("date"))); 35 | 36 | TypedQuery typedQuery = this.getEntityManager().createQuery(criteriaQuery); 37 | return typedQuery.getResultList(); 38 | } 39 | @Override 40 | @Transactional(readOnly = true) 41 | public List blogbycateg(int categ){ 42 | final CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder(); 43 | final CriteriaQuery criteriaQuery = builder.createQuery(BlogPost.class); 44 | 45 | Root root = criteriaQuery.from(BlogPost.class); 46 | Path namePath = root.get("category"); 47 | criteriaQuery.where(builder.equal(namePath, categ)); 48 | criteriaQuery.orderBy(builder.desc(root.get("date"))); 49 | 50 | TypedQuery typedQuery = this.getEntityManager().createQuery(criteriaQuery); 51 | return typedQuery.getResultList(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/category/CategoryDao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao.category; 2 | 3 | import ir.mnm.nasher.dao.Dao; 4 | import ir.mnm.nasher.entity.Category; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by mghasemy on 12/9/16. 10 | */ 11 | public interface CategoryDao extends Dao { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/category/JpaCategoryDao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao.category; 2 | 3 | import ir.mnm.nasher.dao.JpaDao; 4 | import ir.mnm.nasher.entity.Category; 5 | import org.springframework.transaction.annotation.Transactional; 6 | 7 | import javax.persistence.TypedQuery; 8 | import javax.persistence.criteria.CriteriaBuilder; 9 | import javax.persistence.criteria.CriteriaQuery; 10 | import javax.persistence.criteria.Root; 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by mghasemy on 12/9/16. 16 | */ 17 | public class JpaCategoryDao extends JpaDao implements CategoryDao{ 18 | 19 | public JpaCategoryDao() { 20 | super(Category.class); 21 | } 22 | 23 | @Override 24 | @Transactional(readOnly = true) 25 | public List findAll(){ 26 | final CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder(); 27 | final CriteriaQuery criteriaQuery = builder.createQuery(Category.class); 28 | 29 | Root root = criteriaQuery.from(Category.class); 30 | //criteriaQuery.orderBy(builder.desc(root.get("id"))); 31 | 32 | TypedQuery typedQuery = this.getEntityManager().createQuery(criteriaQuery); 33 | return typedQuery.getResultList(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/user/JpaUserDao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao.user; 2 | 3 | import ir.mnm.nasher.dao.JpaDao; 4 | import ir.mnm.nasher.entity.User; 5 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | import javax.persistence.TypedQuery; 9 | import javax.persistence.criteria.CriteriaBuilder; 10 | import javax.persistence.criteria.CriteriaQuery; 11 | import javax.persistence.criteria.Path; 12 | import javax.persistence.criteria.Root; 13 | import java.util.List; 14 | 15 | public class JpaUserDao extends JpaDao implements UserDao 16 | { 17 | public JpaUserDao() 18 | { 19 | super(User.class); 20 | } 21 | 22 | @Override 23 | @Transactional(readOnly = true) 24 | public User loadUserByUsername(String username) throws UsernameNotFoundException 25 | { 26 | User user = this.findByName(username); 27 | if (null == user) { 28 | throw new UsernameNotFoundException("The user with name " + username + " was not found"); 29 | } 30 | 31 | return user; 32 | } 33 | 34 | @Override 35 | @Transactional(readOnly = true) 36 | public User findByName(String name) 37 | { 38 | final CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder(); 39 | final CriteriaQuery criteriaQuery = builder.createQuery(this.entityClass); 40 | 41 | Root root = criteriaQuery.from(this.entityClass); 42 | Path namePath = root.get("name"); 43 | criteriaQuery.where(builder.equal(namePath, name)); 44 | 45 | TypedQuery typedQuery = this.getEntityManager().createQuery(criteriaQuery); 46 | List users = typedQuery.getResultList(); 47 | 48 | if (users.isEmpty()) { 49 | return null; 50 | } 51 | 52 | return users.iterator().next(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/dao/user/UserDao.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.dao.user; 2 | 3 | import ir.mnm.nasher.dao.Dao; 4 | import ir.mnm.nasher.entity.User; 5 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 6 | 7 | public interface UserDao extends Dao 8 | { 9 | User loadUserByUsername(String username) throws UsernameNotFoundException; 10 | 11 | User findByName(String name); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/entity/AccessToken.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | import javax.persistence.ManyToOne; 7 | import java.util.Date; 8 | 9 | /** 10 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 11 | */ 12 | @javax.persistence.Entity 13 | public class AccessToken implements Entity 14 | { 15 | @Id 16 | @GeneratedValue 17 | private Long id; 18 | 19 | @Column(nullable = false) 20 | private String token; 21 | 22 | @ManyToOne 23 | private User user; 24 | 25 | @Column 26 | private Date expiry; 27 | 28 | protected AccessToken() 29 | { 30 | /* Reflection instantiation */ 31 | } 32 | 33 | public AccessToken(User user, String token) 34 | { 35 | this.user = user; 36 | this.token = token; 37 | } 38 | 39 | public AccessToken(User user, String token, Date expiry) 40 | { 41 | this(user, token); 42 | this.expiry = expiry; 43 | } 44 | 45 | @Override 46 | public Long getId() 47 | { 48 | return this.id; 49 | } 50 | 51 | public String getToken() 52 | { 53 | return this.token; 54 | } 55 | 56 | public User getUser() 57 | { 58 | return this.user; 59 | } 60 | 61 | public Date getExpiry() 62 | { 63 | return this.expiry; 64 | } 65 | 66 | public boolean isExpired() 67 | { 68 | if (null == this.expiry) { 69 | return false; 70 | } 71 | 72 | return this.expiry.getTime() > System.currentTimeMillis(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/entity/BlogPost.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.entity; 2 | 3 | import ir.mnm.nasher.JsonViews; 4 | import org.codehaus.jackson.map.annotate.JsonView; 5 | 6 | import javax.persistence.Column; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | import java.util.Date; 10 | 11 | /** 12 | * JPA Annotated Pojo that represents a blog post. 13 | * 14 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 15 | */ 16 | @javax.persistence.Entity 17 | public class BlogPost implements Entity 18 | { 19 | @Id 20 | @GeneratedValue 21 | private Long id; 22 | 23 | @Column 24 | private Date date; 25 | 26 | @Column 27 | private String content; 28 | 29 | @Column 30 | private String title; 31 | 32 | @Column 33 | private String file; 34 | 35 | @Column 36 | private String tags; 37 | 38 | @Column 39 | private String summary; 40 | 41 | @Column 42 | private int sign; 43 | 44 | @Column 45 | private int category; 46 | 47 | public String getTitle() { 48 | return title; 49 | } 50 | 51 | public void setTitle(String title) { 52 | this.title = title; 53 | } 54 | 55 | public String getFile() { 56 | return file; 57 | } 58 | 59 | public void setFile(String file) { 60 | this.file = file; 61 | } 62 | 63 | public String getTags() { 64 | return tags; 65 | } 66 | 67 | public void setTags(String tags) { 68 | this.tags = tags; 69 | } 70 | 71 | public String getSummary() { 72 | return summary; 73 | } 74 | 75 | public void setSummary(String summary) { 76 | this.summary = summary; 77 | } 78 | 79 | public int getSign() { 80 | return sign; 81 | } 82 | 83 | public void setSign(int sign) { 84 | this.sign = sign; 85 | } 86 | 87 | public int getCategory() { 88 | return category; 89 | } 90 | 91 | public void setCategory(int category) { 92 | this.category = category; 93 | } 94 | 95 | public BlogPost() 96 | { 97 | this.date = new Date(); 98 | } 99 | 100 | @JsonView(JsonViews.Admin.class) 101 | public Long getId() 102 | { 103 | return this.id; 104 | } 105 | 106 | @JsonView(JsonViews.User.class) 107 | public Date getDate() 108 | { 109 | return this.date; 110 | } 111 | 112 | public void setDate(Date date) 113 | { 114 | this.date = date; 115 | } 116 | 117 | @JsonView(JsonViews.User.class) 118 | public String getContent() 119 | { 120 | return this.content; 121 | } 122 | 123 | public void setContent(String content) 124 | { 125 | this.content = content; 126 | } 127 | 128 | @Override 129 | public String toString() 130 | { 131 | return String.format("BlogPost[%d, %s]", this.id, this.content); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/entity/Category.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.entity; 2 | 3 | import ir.mnm.nasher.JsonViews; 4 | import org.codehaus.jackson.map.annotate.JsonView; 5 | 6 | import javax.persistence.Column; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | 10 | /** 11 | * Created by mghasemy on 12/9/16. 12 | */ 13 | @javax.persistence.Entity 14 | public class Category implements Entity { 15 | @Id 16 | @GeneratedValue 17 | private Long id; 18 | 19 | @Column 20 | public String name; 21 | 22 | @Column 23 | public int parent; 24 | 25 | @JsonView(JsonViews.User.class) 26 | public int getParent() { 27 | return parent; 28 | } 29 | 30 | public void setParent(int parent) { 31 | this.parent = parent; 32 | } 33 | 34 | public Category() { 35 | } 36 | 37 | public Category(Long id, String name) { 38 | this.id = id; 39 | this.name = name; 40 | } 41 | @JsonView(JsonViews.User.class) 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | @JsonView(JsonViews.Admin.class) 51 | public Long getId() { 52 | return id; 53 | } 54 | 55 | public void setId(Long id) { 56 | this.id = id; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/entity/Comment.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | /** 8 | * Created by mghasemy on 12/10/16. 9 | */ 10 | @javax.persistence.Entity 11 | public class Comment implements Entity { 12 | @Id 13 | @GeneratedValue 14 | private Long id; 15 | 16 | @Column 17 | private String text; 18 | 19 | @Column 20 | private Long blogid; 21 | 22 | 23 | @Override 24 | public Long getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Long id) { 29 | this.id = id; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/entity/Entity.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | public interface Entity extends Serializable 6 | { 7 | Long getId(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/entity/Role.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.entity; 2 | 3 | import org.springframework.security.core.GrantedAuthority; 4 | 5 | public enum Role implements GrantedAuthority 6 | { 7 | USER("ROLE_USER"), 8 | ADMIN("ROLE_ADMIN"); 9 | 10 | private String authority; 11 | 12 | Role(String authority) 13 | { 14 | this.authority = authority; 15 | } 16 | 17 | @Override 18 | public String getAuthority() 19 | { 20 | return this.authority; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/entity/User.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.entity; 2 | 3 | import org.springframework.security.core.GrantedAuthority; 4 | import org.springframework.security.core.userdetails.UserDetails; 5 | 6 | import javax.persistence.*; 7 | import java.util.Collection; 8 | import java.util.HashSet; 9 | import java.util.Set; 10 | 11 | @javax.persistence.Entity 12 | public class User implements Entity, UserDetails 13 | { 14 | @Id 15 | @GeneratedValue 16 | private Long id; 17 | 18 | @Column(unique = true, length = 16, nullable = false) 19 | private String name; 20 | 21 | @Column(length = 80, nullable = false) 22 | private String password; 23 | 24 | @ElementCollection(fetch = FetchType.EAGER) 25 | private Set roles = new HashSet(); 26 | 27 | protected User() 28 | { 29 | /* Reflection instantiation */ 30 | } 31 | 32 | public User(String name, String passwordHash) 33 | { 34 | this.name = name; 35 | this.password = passwordHash; 36 | } 37 | 38 | public Long getId() 39 | { 40 | return this.id; 41 | } 42 | 43 | public void setId(Long id) 44 | { 45 | this.id = id; 46 | } 47 | 48 | public String getName() 49 | { 50 | return this.name; 51 | } 52 | 53 | public void setName(String name) 54 | { 55 | this.name = name; 56 | } 57 | 58 | public Set getRoles() 59 | { 60 | return this.roles; 61 | } 62 | 63 | public void setRoles(Set roles) 64 | { 65 | this.roles = roles; 66 | } 67 | 68 | public void addRole(Role role) 69 | { 70 | this.roles.add(role); 71 | } 72 | 73 | @Override 74 | public String getPassword() 75 | { 76 | return this.password; 77 | } 78 | 79 | public void setPassword(String password) 80 | { 81 | this.password = password; 82 | } 83 | 84 | @Override 85 | public Collection getAuthorities() 86 | { 87 | return this.getRoles(); 88 | } 89 | 90 | @Override 91 | public String getUsername() 92 | { 93 | return this.name; 94 | } 95 | 96 | @Override 97 | public boolean isAccountNonExpired() 98 | { 99 | return true; 100 | } 101 | 102 | @Override 103 | public boolean isAccountNonLocked() 104 | { 105 | return true; 106 | } 107 | 108 | @Override 109 | public boolean isCredentialsNonExpired() 110 | { 111 | return true; 112 | } 113 | 114 | @Override 115 | public boolean isEnabled() 116 | { 117 | return true; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/rest/AuthenticationTokenProcessingFilter.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.rest; 2 | 3 | import ir.mnm.nasher.entity.User; 4 | import ir.mnm.nasher.service.UserService; 5 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 6 | import org.springframework.security.core.context.SecurityContextHolder; 7 | import org.springframework.web.filter.GenericFilterBean; 8 | 9 | import javax.servlet.FilterChain; 10 | import javax.servlet.ServletException; 11 | import javax.servlet.ServletRequest; 12 | import javax.servlet.ServletResponse; 13 | import javax.servlet.http.HttpServletRequest; 14 | import java.io.IOException; 15 | 16 | public class AuthenticationTokenProcessingFilter extends GenericFilterBean 17 | { 18 | private final UserService userService; 19 | 20 | public AuthenticationTokenProcessingFilter(UserService userService) 21 | { 22 | this.userService = userService; 23 | } 24 | 25 | @Override 26 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 27 | throws IOException, ServletException 28 | { 29 | HttpServletRequest httpRequest = this.getAsHttpRequest(request); 30 | 31 | String accessToken = this.extractAuthTokenFromRequest(httpRequest); 32 | if (null != accessToken) { 33 | User user = this.userService.findUserByAccessToken(accessToken); 34 | if (null != user) { 35 | UsernamePasswordAuthenticationToken authentication = 36 | new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities()); 37 | SecurityContextHolder.getContext().setAuthentication(authentication); 38 | } 39 | } 40 | 41 | chain.doFilter(request, response); 42 | } 43 | 44 | private HttpServletRequest getAsHttpRequest(ServletRequest request) 45 | { 46 | if (!(request instanceof HttpServletRequest)) { 47 | throw new RuntimeException("Expecting an HTTP request"); 48 | } 49 | 50 | return (HttpServletRequest) request; 51 | } 52 | 53 | private String extractAuthTokenFromRequest(HttpServletRequest httpRequest) 54 | { 55 | /* Get token from header */ 56 | String authToken = httpRequest.getHeader("X-Access-Token"); 57 | 58 | /* If token not found get it from request parameter */ 59 | if (authToken == null) { 60 | authToken = httpRequest.getParameter("token"); 61 | } 62 | 63 | return authToken; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/rest/UnauthorizedEntryPoint.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.rest; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | import org.springframework.security.web.AuthenticationEntryPoint; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | 11 | /** 12 | * {@link AuthenticationEntryPoint} that rejects all requests with an unauthorized error message. 13 | * 14 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 15 | */ 16 | public class UnauthorizedEntryPoint implements AuthenticationEntryPoint 17 | { 18 | @Override 19 | public void commence( 20 | HttpServletRequest request, 21 | HttpServletResponse response, 22 | AuthenticationException authException 23 | ) throws IOException, ServletException 24 | { 25 | response.sendError( 26 | HttpServletResponse.SC_UNAUTHORIZED, 27 | "Unauthorized: Authentication token was either missing or invalid." 28 | ); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/rest/resources/BlogPostResource.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.rest.resources; 2 | 3 | import ir.mnm.nasher.JsonViews; 4 | import ir.mnm.nasher.dao.blogpost.BlogPostDao; 5 | import ir.mnm.nasher.entity.BlogPost; 6 | import ir.mnm.nasher.entity.Role; 7 | import org.codehaus.jackson.map.ObjectMapper; 8 | import org.codehaus.jackson.map.ObjectWriter; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.security.core.Authentication; 13 | import org.springframework.security.core.context.SecurityContextHolder; 14 | import org.springframework.security.core.userdetails.UserDetails; 15 | import org.springframework.stereotype.Component; 16 | 17 | import javax.ws.rs.*; 18 | import javax.ws.rs.core.MediaType; 19 | import java.io.IOException; 20 | import java.util.List; 21 | 22 | @Component 23 | @Path("/blogposts") 24 | public class BlogPostResource 25 | { 26 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 27 | 28 | @Autowired 29 | private BlogPostDao blogPostDao; 30 | 31 | @Autowired 32 | private ObjectMapper mapper; 33 | 34 | @GET 35 | @Produces(MediaType.APPLICATION_JSON) 36 | public String list() throws IOException 37 | { 38 | this.logger.info("list()"); 39 | 40 | ObjectWriter viewWriter; 41 | if (this.isAdmin()) { 42 | viewWriter = this.mapper.writerWithView(JsonViews.Admin.class); 43 | } else { 44 | viewWriter = this.mapper.writerWithView(JsonViews.User.class); 45 | } 46 | List allEntries = this.blogPostDao.findAll(); 47 | 48 | return viewWriter.writeValueAsString(allEntries); 49 | } 50 | 51 | @GET 52 | @Produces(MediaType.APPLICATION_JSON) 53 | @Path("{id}") 54 | public BlogPost read(@PathParam("id") Long id) 55 | { 56 | this.logger.info("read(id)"); 57 | 58 | BlogPost blogPost = this.blogPostDao.find(id); 59 | if (blogPost == null) { 60 | throw new WebApplicationException(404); 61 | } 62 | return blogPost; 63 | } 64 | 65 | @POST 66 | @Produces(MediaType.APPLICATION_JSON) 67 | @Consumes(MediaType.APPLICATION_JSON) 68 | public BlogPost create(BlogPost blogPost) 69 | { 70 | this.logger.info("create(): " + blogPost); 71 | 72 | return this.blogPostDao.save(blogPost); 73 | } 74 | 75 | @POST 76 | @Produces(MediaType.APPLICATION_JSON) 77 | @Consumes(MediaType.APPLICATION_JSON) 78 | @Path("{id}") 79 | public BlogPost update(@PathParam("id") Long id, BlogPost blogPost) 80 | { 81 | this.logger.info("update(): " + blogPost); 82 | 83 | return this.blogPostDao.save(blogPost); 84 | } 85 | 86 | @DELETE 87 | @Produces(MediaType.APPLICATION_JSON) 88 | @Path("{id}") 89 | public void delete(@PathParam("id") Long id) 90 | { 91 | this.logger.info("delete(id)"); 92 | 93 | this.blogPostDao.delete(id); 94 | } 95 | 96 | private boolean isAdmin() 97 | { 98 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 99 | Object principal = authentication.getPrincipal(); 100 | if ((principal instanceof String) && ((String) principal).equals("anonymousUser")) { 101 | return false; 102 | } 103 | UserDetails userDetails = (UserDetails) principal; 104 | 105 | return userDetails.getAuthorities().contains(Role.ADMIN); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/rest/resources/CategoryResource.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.rest.resources; 2 | 3 | import ir.mnm.nasher.JsonViews; 4 | import ir.mnm.nasher.dao.blogpost.BlogPostDao; 5 | import ir.mnm.nasher.dao.category.CategoryDao; 6 | import ir.mnm.nasher.entity.BlogPost; 7 | import ir.mnm.nasher.entity.Category; 8 | import ir.mnm.nasher.entity.Role; 9 | import org.codehaus.jackson.map.ObjectMapper; 10 | import org.codehaus.jackson.map.ObjectWriter; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.security.core.Authentication; 15 | import org.springframework.security.core.context.SecurityContextHolder; 16 | import org.springframework.security.core.userdetails.UserDetails; 17 | import org.springframework.stereotype.Component; 18 | 19 | import javax.ws.rs.*; 20 | import javax.ws.rs.core.MediaType; 21 | import java.io.IOException; 22 | import java.util.List; 23 | 24 | /** 25 | * Created by mghasemy on 12/11/16. 26 | */ 27 | @Component 28 | @Path("/category") 29 | public class CategoryResource { 30 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 31 | 32 | @Autowired 33 | private CategoryDao categoryDao; 34 | 35 | @Autowired 36 | private ObjectMapper mapper; 37 | 38 | 39 | 40 | @GET 41 | @Produces(MediaType.APPLICATION_JSON) 42 | public String list() throws IOException 43 | { 44 | this.logger.info("list()"); 45 | 46 | ObjectWriter viewWriter; 47 | if (this.isAdmin()) { 48 | viewWriter = this.mapper.writerWithView(JsonViews.Admin.class); 49 | } else { 50 | viewWriter = this.mapper.writerWithView(JsonViews.User.class); 51 | } 52 | List allEntries = this.categoryDao.findAll(); 53 | 54 | return viewWriter.writeValueAsString(allEntries); 55 | } 56 | 57 | @GET 58 | @Produces(MediaType.APPLICATION_JSON) 59 | @Path("{id}") 60 | public Category read(@PathParam("id") Long id) 61 | { 62 | this.logger.info("read(id)"); 63 | 64 | Category categ = this.categoryDao.find(id); 65 | if (categ == null) { 66 | throw new WebApplicationException(404); 67 | } 68 | return categ; 69 | } 70 | 71 | @POST 72 | @Produces(MediaType.APPLICATION_JSON) 73 | @Consumes(MediaType.APPLICATION_JSON) 74 | public Category create(Category categ) 75 | { 76 | this.logger.info("create(): " + categ); 77 | 78 | return this.categoryDao.save(categ); 79 | } 80 | 81 | @POST 82 | @Produces(MediaType.APPLICATION_JSON) 83 | @Consumes(MediaType.APPLICATION_JSON) 84 | @Path("{id}") 85 | public Category update(@PathParam("id") Long id, Category categ) 86 | { 87 | this.logger.info("update(): " + categ); 88 | 89 | return this.categoryDao.save(categ); 90 | } 91 | 92 | @DELETE 93 | @Produces(MediaType.APPLICATION_JSON) 94 | @Path("{id}") 95 | public void delete(@PathParam("id") Long id) 96 | { 97 | this.logger.info("delete(id)"); 98 | 99 | this.categoryDao.delete(id); 100 | } 101 | private boolean isAdmin() 102 | { 103 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 104 | Object principal = authentication.getPrincipal(); 105 | if ((principal instanceof String) && ((String) principal).equals("anonymousUser")) { 106 | return false; 107 | } 108 | UserDetails userDetails = (UserDetails) principal; 109 | 110 | return userDetails.getAuthorities().contains(Role.ADMIN); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/rest/resources/FileResource.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.rest.resources; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | import org.springframework.web.multipart.MultipartFile; 11 | 12 | import javax.ws.rs.Path; 13 | 14 | /** 15 | * Created by mghasemy on 12/11/16. 16 | */ 17 | @Component 18 | @Path("/uploadfile") 19 | public class FileResource { 20 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 21 | @RequestMapping(value="/newDocument", method = RequestMethod.POST) 22 | public @ResponseBody 23 | void UploadFile(@RequestParam(value="file", required=true) MultipartFile file) { 24 | String fileName=file.getOriginalFilename(); 25 | System.out.println(fileName); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/rest/resources/UserResource.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.rest.resources; 2 | 3 | import ir.mnm.nasher.entity.AccessToken; 4 | import ir.mnm.nasher.entity.User; 5 | import ir.mnm.nasher.service.UserService; 6 | import ir.mnm.nasher.transfer.UserTransfer; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.annotation.Qualifier; 9 | import org.springframework.security.authentication.AuthenticationManager; 10 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 11 | import org.springframework.security.core.Authentication; 12 | import org.springframework.security.core.GrantedAuthority; 13 | import org.springframework.security.core.context.SecurityContextHolder; 14 | import org.springframework.security.core.userdetails.UserDetails; 15 | import org.springframework.stereotype.Component; 16 | 17 | import javax.ws.rs.*; 18 | import javax.ws.rs.core.MediaType; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | /** 23 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 24 | */ 25 | @Component 26 | @Path("/user") 27 | public class UserResource 28 | { 29 | @Autowired 30 | private UserService userService; 31 | 32 | @Autowired 33 | @Qualifier("authenticationManager") 34 | private AuthenticationManager authManager; 35 | 36 | /** 37 | * Retrieves the currently logged in user. 38 | * 39 | * @return A transfer containing the username and the roles. 40 | */ 41 | @GET 42 | @Produces(MediaType.APPLICATION_JSON) 43 | public UserTransfer getUser() 44 | { 45 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 46 | Object principal = authentication.getPrincipal(); 47 | if (!(principal instanceof UserDetails)) { 48 | throw new WebApplicationException(401); 49 | } 50 | UserDetails userDetails = (UserDetails) principal; 51 | 52 | return new UserTransfer(userDetails.getUsername(), this.createRoleMap(userDetails)); 53 | } 54 | 55 | /** 56 | * Authenticates a user and creates an access token. 57 | * 58 | * @param username The name of the user. 59 | * @param password The password of the user. 60 | * @return The generated access token. 61 | */ 62 | @Path("authenticate") 63 | @POST 64 | @Produces(MediaType.APPLICATION_JSON) 65 | public AccessToken authenticate(@FormParam("username") String username, @FormParam("password") String password) 66 | { 67 | UsernamePasswordAuthenticationToken authenticationToken = 68 | new UsernamePasswordAuthenticationToken(username, password); 69 | Authentication authentication = this.authManager.authenticate(authenticationToken); 70 | SecurityContextHolder.getContext().setAuthentication(authentication); 71 | 72 | Object principal = authentication.getPrincipal(); 73 | if (!(principal instanceof User)) { 74 | throw new WebApplicationException(401); 75 | } 76 | 77 | return this.userService.createAccessToken((User) principal); 78 | } 79 | 80 | private Map createRoleMap(UserDetails userDetails) 81 | { 82 | Map roles = new HashMap(); 83 | for (GrantedAuthority authority : userDetails.getAuthorities()) { 84 | roles.put(authority.getAuthority(), Boolean.TRUE); 85 | } 86 | 87 | return roles; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/service/DaoUserService.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.service; 2 | 3 | import ir.mnm.nasher.dao.accesstoken.AccessTokenDao; 4 | import ir.mnm.nasher.dao.user.UserDao; 5 | import ir.mnm.nasher.entity.AccessToken; 6 | import ir.mnm.nasher.entity.User; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | import java.util.UUID; 12 | 13 | /** 14 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 15 | */ 16 | public class DaoUserService implements UserService 17 | { 18 | private UserDao userDao; 19 | 20 | private AccessTokenDao accessTokenDao; 21 | 22 | protected DaoUserService() 23 | { 24 | /* Reflection instantiation */ 25 | } 26 | 27 | public DaoUserService(UserDao userDao, AccessTokenDao accessTokenDao) 28 | { 29 | this.userDao = userDao; 30 | this.accessTokenDao = accessTokenDao; 31 | } 32 | 33 | @Override 34 | @Transactional(readOnly = true) 35 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException 36 | { 37 | return this.userDao.loadUserByUsername(username); 38 | } 39 | 40 | @Override 41 | @Transactional 42 | public User findUserByAccessToken(String accessTokenString) 43 | { 44 | AccessToken accessToken = this.accessTokenDao.findByToken(accessTokenString); 45 | 46 | if (null == accessToken) { 47 | return null; 48 | } 49 | 50 | if (accessToken.isExpired()) { 51 | this.accessTokenDao.delete(accessToken); 52 | return null; 53 | } 54 | 55 | return accessToken.getUser(); 56 | } 57 | 58 | @Override 59 | @Transactional 60 | public AccessToken createAccessToken(User user) 61 | { 62 | AccessToken accessToken = new AccessToken(user, UUID.randomUUID().toString()); 63 | return this.accessTokenDao.save(accessToken); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/service/UserService.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.service; 2 | 3 | import ir.mnm.nasher.entity.AccessToken; 4 | import ir.mnm.nasher.entity.User; 5 | import org.springframework.security.core.userdetails.UserDetailsService; 6 | 7 | /** 8 | * @author Mohammad Mahdi mohammad.ghasemy@gmail.com 9 | */ 10 | public interface UserService extends UserDetailsService 11 | { 12 | User findUserByAccessToken(String accessToken); 13 | 14 | AccessToken createAccessToken(User user); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/transfer/TokenTransfer.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.transfer; 2 | 3 | public class TokenTransfer 4 | { 5 | 6 | private final String token; 7 | 8 | 9 | public TokenTransfer(String token) 10 | { 11 | this.token = token; 12 | } 13 | 14 | 15 | public String getToken() 16 | { 17 | return this.token; 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/transfer/UserTransfer.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.transfer; 2 | 3 | import java.util.Map; 4 | 5 | 6 | public class UserTransfer 7 | { 8 | 9 | private final String name; 10 | 11 | private final Map roles; 12 | 13 | 14 | public UserTransfer(String userName, Map roles) 15 | { 16 | this.name = userName; 17 | this.roles = roles; 18 | } 19 | 20 | 21 | public String getName() 22 | { 23 | return this.name; 24 | } 25 | 26 | 27 | public Map getRoles() 28 | { 29 | return this.roles; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/util/dodownload.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.util; 2 | 3 | /** 4 | * Created by mghasemy on 12/9/16. 5 | */ 6 | /* 7 | * To change this license header, choose License Headers in Project Properties. 8 | * To change this template file, choose Tools | Templates 9 | * and open the template in the editor. 10 | */ 11 | 12 | 13 | import java.io.File; 14 | import java.io.FileInputStream; 15 | import java.io.IOException; 16 | import java.io.OutputStream; 17 | import java.net.URLDecoder; 18 | import javax.servlet.ServletException; 19 | import javax.servlet.annotation.MultipartConfig; 20 | import javax.servlet.http.HttpServlet; 21 | import javax.servlet.http.HttpServletRequest; 22 | import javax.servlet.http.HttpServletResponse; 23 | 24 | /** 25 | * 26 | * @author mohammadghasemy 27 | */ 28 | @MultipartConfig 29 | public class dodownload extends HttpServlet { 30 | private static final long serialVersionUID = 1L; 31 | 32 | public void doGet(HttpServletRequest request, 33 | HttpServletResponse response) 34 | throws ServletException, IOException { 35 | 36 | try { 37 | String fid = request.getPathInfo(); 38 | 39 | if (fid == null) { 40 | 41 | response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404. 42 | return; 43 | } 44 | 45 | File file = new File("/website/nasher/data", URLDecoder.decode(fid, "UTF-8")); 46 | 47 | 48 | if (!file.canRead()) { 49 | response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404. 50 | return; 51 | } 52 | String contentType = getServletContext().getMimeType(file.getName()); 53 | 54 | // If content type is unknown, then set the default value. 55 | // For all content types, see: http://www.w3schools.com/media/media_mimeref.asp 56 | // To add new content types, add new mime-mapping entry in web.xml. 57 | if (contentType == null) { 58 | contentType = "application/octet-stream"; 59 | } 60 | response.reset(); 61 | response.setContentLength((int) file.length()); 62 | 63 | response.setContentType(contentType); 64 | response.setHeader("Content-Length", String.valueOf(file.length())); 65 | response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\""); 66 | 67 | OutputStream out = response.getOutputStream(); 68 | FileInputStream in = new FileInputStream(file); 69 | byte[] buffer = new byte[4096]; 70 | int length; 71 | while ((length = in.read(buffer)) > 0) { 72 | out.write(buffer, 0, length); 73 | } 74 | in.close(); 75 | out.flush(); 76 | String ip = request.getRemoteAddr(); 77 | String agent = request.getHeader("User-Agent"); 78 | } catch (Exception s) { 79 | s.printStackTrace(); 80 | return; 81 | }finally{ 82 | 83 | } 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/util/tools.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by mghasemy on 12/9/16. 8 | */ 9 | public class tools { 10 | public String utitle(String in){ 11 | return in.replaceAll(" ", "-"); 12 | } 13 | public List tag(String in){ 14 | if(in==null){ 15 | return null; 16 | } 17 | List res=new ArrayList(); 18 | String l[]=in.split("[,،]"); 19 | System.out.println("tags list"+l.length); 20 | for(String i:l){ 21 | res.add(i); 22 | } 23 | return res; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/web/controller/blogs.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.web.controller; 2 | 3 | import ir.mnm.nasher.dao.blogpost.BlogPostDao; 4 | import ir.mnm.nasher.dao.category.CategoryDao; 5 | import ir.mnm.nasher.entity.BlogPost; 6 | import ir.mnm.nasher.entity.Category; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.servlet.ModelAndView; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * Created by mghasemy on 12/9/16. 18 | */ 19 | @Controller 20 | public class blogs { 21 | 22 | 23 | private BlogPostDao blogPostDao; 24 | private CategoryDao categoryDao; 25 | 26 | public blogs(BlogPostDao blogPostDao, CategoryDao cd) { 27 | this.blogPostDao = blogPostDao; 28 | this.categoryDao = cd; 29 | } 30 | 31 | @RequestMapping(value = "/index", method = RequestMethod.GET) 32 | public ModelAndView listblog(){ 33 | List allEntries=null; 34 | List allcateg=null; 35 | if(null!=blogPostDao) 36 | allEntries= blogPostDao.findAll(); 37 | if(null!=categoryDao) 38 | allcateg=categoryDao.findAll(); 39 | //return back to index.jsp 40 | ModelAndView model = new ModelAndView("index"); 41 | model.addObject("categlists", allcateg); 42 | model.addObject("bloglists", allEntries); 43 | model.addObject("tools", new ir.mnm.nasher.util.tools()); 44 | return model; 45 | 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/web/controller/categoryController.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.web.controller; 2 | 3 | import ir.mnm.nasher.dao.blogpost.BlogPostDao; 4 | import ir.mnm.nasher.dao.category.CategoryDao; 5 | import ir.mnm.nasher.entity.BlogPost; 6 | import ir.mnm.nasher.entity.Category; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.servlet.ModelAndView; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created by mghasemy on 12/9/16. 17 | */ 18 | @Controller 19 | public class categoryController { 20 | private BlogPostDao blogPostDao; 21 | private CategoryDao categoryDao; 22 | 23 | public categoryController(BlogPostDao blogPostDao, CategoryDao cd) { 24 | this.blogPostDao = blogPostDao; 25 | this.categoryDao = cd; 26 | } 27 | @RequestMapping(value = "category/{title}/{categid}", method = RequestMethod.GET) 28 | public ModelAndView listblogbycateg(@PathVariable int categid,@PathVariable String title){ 29 | System.out.println(categid); 30 | 31 | List allEntries=null; 32 | List allcateg=null; 33 | if(null!=blogPostDao) 34 | allEntries= blogPostDao.blogbycateg(categid); 35 | if(null!=categoryDao) 36 | allcateg=categoryDao.findAll(); 37 | //return back to index.jsp 38 | ModelAndView model = new ModelAndView("category"); 39 | model.addObject("categlists", allcateg); 40 | model.addObject("bloglists", allEntries); 41 | model.addObject("categtitle", title); 42 | 43 | model.addObject("tools", new ir.mnm.nasher.util.tools()); 44 | return model; 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/ir/mnm/nasher/web/controller/oneController.java: -------------------------------------------------------------------------------- 1 | package ir.mnm.nasher.web.controller; 2 | 3 | import ir.mnm.nasher.dao.blogpost.BlogPostDao; 4 | import ir.mnm.nasher.dao.category.CategoryDao; 5 | import ir.mnm.nasher.entity.BlogPost; 6 | import ir.mnm.nasher.entity.Category; 7 | import org.springframework.stereotype.Controller; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.servlet.ModelAndView; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created by mghasemy on 12/10/16. 17 | */ 18 | @Controller 19 | public class oneController { 20 | private BlogPostDao blogPostDao; 21 | private CategoryDao categoryDao; 22 | 23 | public oneController(BlogPostDao blogPostDao, CategoryDao cd) { 24 | this.blogPostDao = blogPostDao; 25 | this.categoryDao = cd; 26 | } 27 | @RequestMapping(value = "one/{title}/{oneid}", method = RequestMethod.GET) 28 | public ModelAndView listblogbycateg(@PathVariable Long oneid){ 29 | BlogPost post=null; 30 | List allcateg=null; 31 | if(null!=blogPostDao) 32 | post= blogPostDao.find(oneid); 33 | if(null!=categoryDao) 34 | allcateg=categoryDao.findAll(); 35 | ModelAndView model = new ModelAndView("one"); 36 | model.addObject("categlists", allcateg); 37 | model.addObject("post", post); 38 | model.addObject("tools", new ir.mnm.nasher.util.tools()); 39 | return model; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/main.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | ir.mnm.nasher.entity.AccessToken 9 | ir.mnm.nasher.entity.BlogPost 10 | ir.mnm.nasher.entity.User 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Database variables 2 | db.username=sa 3 | db.password= 4 | db.driver=org.hsqldb.jdbcDriver 5 | db.url=jdbc:hsqldb:mem:example 6 | 7 | # Application secret used for salting 8 | app.secret=ThisIsASecretSoChangeMe 9 | -------------------------------------------------------------------------------- /src/main/resources/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 86 | 87 | 88 | 89 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | #Stdout appender 2 | log4j.appender.stdout = org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.Target = System.out 4 | log4j.appender.stdout.layout = org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %3p %c{1}.%M():%L - %m%n 6 | 7 | log4j.rootLogger = INFO, stdout -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 31 | /pages/ 32 | 33 | 34 | .jsp 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | nasher 8 | 9 | 12 | 13 | contextConfigLocation 14 | 15 | classpath:/context.xml 16 | 17 | 18 | 19 | org.springframework.web.context.ContextLoaderListener 20 | 21 | 22 | 25 | 26 | RestService 27 | com.sun.jersey.spi.spring.container.servlet.SpringServlet 28 | 29 | com.sun.jersey.config.property.packages 30 | ir.mnm.nasher.rest 31 | 32 | 33 | com.sun.jersey.api.json.POJOMappingFeature 34 | true 35 | 36 | 1 37 | 38 | 39 | RestService 40 | /rest/* 41 | 42 | 43 | 44 | 45 | 46 | mvc-dispatcher 47 | 48 | org.springframework.web.servlet.DispatcherServlet 49 | 50 | 1 51 | 52 | 53 | 54 | mvc-dispatcher 55 | *.do 56 | 57 | 60 | 61 | springSecurityFilterChain 62 | org.springframework.web.filter.DelegatingFilterProxy 63 | 64 | 65 | springSecurityFilterChain 66 | /* 67 | 68 | 69 | 70 | 71 | /index.do 72 | 73 | 74 | 75 | 76 | file io out of project 77 | data 78 | ir.mnm.nasher.util.dodownload 79 | 80 | 81 | data 82 | /data/* 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/main/webapp/admin/css/custom.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 60px; 3 | } 4 | 5 | .loader { 6 | font-size: 36px; 7 | line-height: 36px; 8 | font-weight: bold; 9 | width: 200px; 10 | height: 92px; 11 | text-align: center; 12 | position: absolute; 13 | top: 0; 14 | bottom: 0; 15 | left: 0; 16 | right: 0; 17 | margin: auto; 18 | } -------------------------------------------------------------------------------- /src/main/webapp/admin/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaseminya/nasher-mvc-spring-security-blog-angular/a2d4b0d25d663be27f2349b3fa9230506b65cfe1/src/main/webapp/admin/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/main/webapp/admin/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaseminya/nasher-mvc-spring-security-blog-angular/a2d4b0d25d663be27f2349b3fa9230506b65cfe1/src/main/webapp/admin/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/main/webapp/admin/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaseminya/nasher-mvc-spring-security-blog-angular/a2d4b0d25d663be27f2349b3fa9230506b65cfe1/src/main/webapp/admin/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/main/webapp/admin/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Nasher 5 | 6 | 7 | 8 | 13 | 14 | 15 | 16 |
17 |

Loading

18 |

19 |
20 | 21 | 53 | 54 |
55 |
{{error}}
56 |
57 |
58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/main/webapp/admin/js/app.js: -------------------------------------------------------------------------------- 1 | angular.module('exampleApp', ['ngRoute', 'ngCookies', 'exampleApp.services']) 2 | .config( 3 | [ '$routeProvider', '$locationProvider', '$httpProvider', function($routeProvider, $locationProvider, $httpProvider) { 4 | 5 | $routeProvider.when('/createCategory', { 6 | templateUrl: 'partials/create_categ.html', 7 | controller: CreateCategController 8 | }); 9 | $routeProvider.when('/editCategory/:id', { 10 | templateUrl: 'partials/edit_categ.html', 11 | controller: EditCategController 12 | }); 13 | $routeProvider.when('/createPost', { 14 | templateUrl: 'partials/create.html', 15 | controller: CreateController 16 | }); 17 | 18 | $routeProvider.when('/edit/:id', { 19 | templateUrl: 'partials/edit.html', 20 | controller: EditController 21 | }); 22 | 23 | $routeProvider.when('/login', { 24 | templateUrl: 'partials/login.html', 25 | controller: LoginController 26 | }); 27 | 28 | $routeProvider.when('/index', { 29 | templateUrl: 'partials/index.html', 30 | controller: IndexController 31 | }); 32 | $routeProvider.when('/categories', { 33 | templateUrl: 'partials/index_categ.html', 34 | controller: IndexCategController 35 | }); 36 | 37 | $locationProvider.hashPrefix('!'); 38 | 39 | /* Register error provider that shows message on failed requests or redirects to login page on 40 | * unauthenticated requests */ 41 | $httpProvider.interceptors.push(function ($q, $rootScope, $location) { 42 | return { 43 | 'responseError': function(rejection) { 44 | var status = rejection.status; 45 | var config = rejection.config; 46 | var method = config.method; 47 | var url = config.url; 48 | 49 | if (status == 401) { 50 | $location.path( "/login" ); 51 | } else { 52 | $rootScope.error = method + " on " + url + " failed with status " + status; 53 | } 54 | 55 | return $q.reject(rejection); 56 | } 57 | }; 58 | } 59 | ); 60 | 61 | /* Registers auth token interceptor, auth token is either passed by header or by query parameter 62 | * as soon as there is an authenticated user */ 63 | $httpProvider.interceptors.push(function ($q, $rootScope, $location) { 64 | return { 65 | 'request': function(config) { 66 | var isRestCall = config.url.indexOf('/rest') == 0; 67 | if (isRestCall && angular.isDefined($rootScope.accessToken)) { 68 | var accessToken = $rootScope.accessToken; 69 | if (exampleAppConfig.useAccessTokenHeader) { 70 | config.headers['X-Access-Token'] = accessToken; 71 | } else { 72 | config.url = config.url + "?token=" + accessToken; 73 | } 74 | } 75 | return config || $q.when(config); 76 | } 77 | }; 78 | } 79 | ); 80 | 81 | } ] 82 | 83 | ).run(function($rootScope, $location, $cookieStore, UserService) { 84 | 85 | /* Reset error when a new view is loaded */ 86 | $rootScope.$on('$viewContentLoaded', function() { 87 | delete $rootScope.error; 88 | }); 89 | 90 | $rootScope.hasRole = function(role) { 91 | 92 | if ($rootScope.user === undefined) { 93 | return false; 94 | } 95 | 96 | if ($rootScope.user.roles[role] === undefined) { 97 | return false; 98 | } 99 | 100 | return $rootScope.user.roles[role]; 101 | }; 102 | 103 | $rootScope.logout = function() { 104 | delete $rootScope.user; 105 | delete $rootScope.accessToken; 106 | $cookieStore.remove('accessToken'); 107 | $location.path("/login"); 108 | }; 109 | 110 | /* Try getting valid user from cookie or go to login page */ 111 | var originalPath = $location.path(); 112 | $location.path("/login"); 113 | var accessToken = $cookieStore.get('accessToken'); 114 | if (accessToken !== undefined) { 115 | $rootScope.accessToken = accessToken; 116 | UserService.get(function(user) { 117 | $rootScope.user = user; 118 | $location.path(originalPath); 119 | }); 120 | } 121 | 122 | $rootScope.initialized = true; 123 | }); 124 | 125 | 126 | function IndexController($scope, BlogPostService, CategoryService) { 127 | 128 | $scope.blogPosts = BlogPostService.query(); 129 | $scope.category = CategoryService.query(); 130 | $scope.deletePost = function (blogPost) { 131 | blogPost.$remove(function () { 132 | $scope.blogPosts = BlogPostService.query(); 133 | }); 134 | }; 135 | } 136 | function IndexCategController($scope, CategoryService) { 137 | $scope.category = CategoryService.query(); 138 | $scope.deleteCateg = function (categ) { 139 | categ.$remove(function () { 140 | $scope.category = CategoryService.query(); 141 | }); 142 | }; 143 | } 144 | 145 | 146 | function EditController($scope, $routeParams, $location, BlogPostService) { 147 | 148 | $scope.blogPost = BlogPostService.get({id: $routeParams.id}); 149 | 150 | $scope.save = function() { 151 | $scope.blogPost.$save(function () { 152 | $location.path('/index'); 153 | }); 154 | }; 155 | } 156 | function EditCategController($scope, $routeParams, $location, CategoryService) { 157 | 158 | $scope.categ = CategoryService.get({id: $routeParams.id}); 159 | 160 | $scope.save = function() { 161 | $scope.categ.$save(function () { 162 | $location.path('/categories'); 163 | }); 164 | }; 165 | } 166 | 167 | 168 | function CreateController($scope, $location, BlogPostService, CategoryService,$http) { 169 | 170 | $scope.blogPost = new BlogPostService(); 171 | $scope.category = CategoryService.query(); 172 | $scope.save = function() { 173 | $scope.blogPost.$save(function () { 174 | $location.path('/index'); 175 | }); 176 | }; 177 | 178 | }; 179 | function CreateCategController($scope, $location, CategoryService,$http) { 180 | $scope.categ = new CategoryService(); 181 | $scope.save = function() { 182 | $scope.categ.$save(function () { 183 | $location.path('/categories'); 184 | }); 185 | }; 186 | 187 | }; 188 | 189 | 190 | function LoginController($scope, $rootScope, $location, $cookieStore, UserService) { 191 | 192 | $scope.rememberMe = false; 193 | 194 | $scope.login = function() { 195 | UserService.authenticate($.param({username: $scope.username, password: $scope.password}), function(authenticationResult) { 196 | var accessToken = authenticationResult.token; 197 | $rootScope.accessToken = accessToken; 198 | if ($scope.rememberMe) { 199 | $cookieStore.put('accessToken', accessToken); 200 | } 201 | UserService.get(function(user) { 202 | $rootScope.user = user; 203 | $location.path("/index"); 204 | }); 205 | }); 206 | }; 207 | }; 208 | 209 | 210 | var services = angular.module('exampleApp.services', ['ngResource']); 211 | 212 | services.factory('UserService', function($resource) { 213 | 214 | return $resource('/rest/user/:action', {}, 215 | { 216 | authenticate: { 217 | method: 'POST', 218 | params: {'action' : 'authenticate'}, 219 | headers : {'Content-Type': 'application/x-www-form-urlencoded'} 220 | } 221 | } 222 | ); 223 | }); 224 | 225 | services.factory('BlogPostService', function ($resource) { 226 | 227 | return $resource('/rest/blogposts/:id', {id: '@id'}); 228 | }); 229 | 230 | services.factory('CategoryService', function ($resource) { 231 | 232 | return $resource('/rest/category/:id', {id: '@id'}); 233 | }); 234 | 235 | -------------------------------------------------------------------------------- /src/main/webapp/admin/js/config.js: -------------------------------------------------------------------------------- 1 | var exampleAppConfig = { 2 | /* When set to false a query parameter is used to pass on the access token. 3 | * This might be desirable if headers don't work correctly in some 4 | * environments and is still secure when using https. */ 5 | useAccessTokenHeader: true, 6 | debug: true 7 | }; -------------------------------------------------------------------------------- /src/main/webapp/admin/partials/create.html: -------------------------------------------------------------------------------- 1 | 4 | 5 |
6 |
7 | 8 |
9 | 10 |
11 |
12 |
13 | 14 |
15 | 18 |
19 |
20 |
21 | 22 |
23 | 24 | 25 |
26 |
27 |
28 | 29 |
30 | 31 | 32 |
33 |
34 |
35 | 36 |
37 | 39 |
40 |
41 |
42 | 43 |
44 | 46 |
47 |
48 | 49 |
50 |
51 | 52 |
53 |
54 |
-------------------------------------------------------------------------------- /src/main/webapp/admin/partials/create_categ.html: -------------------------------------------------------------------------------- 1 | 4 | 5 |
6 |
7 | 8 |
9 | 10 |
11 |
12 | 13 | 14 |
15 |
16 | 17 |
18 |
19 |
-------------------------------------------------------------------------------- /src/main/webapp/admin/partials/edit.html: -------------------------------------------------------------------------------- 1 | 4 | 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 |
34 | 35 |
36 | 38 |
39 |
40 |
41 | 42 |
43 | 45 |
46 |
47 |
48 |
49 | 50 |
51 |
52 |
-------------------------------------------------------------------------------- /src/main/webapp/admin/partials/edit_categ.html: -------------------------------------------------------------------------------- 1 | 4 | 5 |
6 |
7 | 8 |
9 | 10 |
11 |
12 | 13 |
14 |
15 | 16 |
17 |
18 |
-------------------------------------------------------------------------------- /src/main/webapp/admin/partials/index.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 7 | 8 |
9 |
10 |
11 | 13 | 15 |
16 |

{{blogPost.title}}

17 |

{{blogPost.content}}

18 |

{{blogPost.date | date}}

19 |

{{blogPost.category}}

20 |
21 |
22 | -------------------------------------------------------------------------------- /src/main/webapp/admin/partials/index_categ.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 7 | 8 |
9 |
10 |
11 | 13 | 15 |
16 |

{{cat.id}}

17 |

{{cat.name}}

18 | 19 |
20 |
21 | -------------------------------------------------------------------------------- /src/main/webapp/admin/partials/login.html: -------------------------------------------------------------------------------- 1 | 4 | 5 |
6 | 7 |
8 |
9 |
10 | 11 |
12 | 13 |
14 |
15 |
16 | 17 |
18 | 19 |
20 |
21 |
22 |
23 |
24 | 27 |
28 |
29 |
30 |
31 |
32 | 33 |
34 |
35 |
36 |
37 | 38 |
39 |

Login with either user:user to read entries or with admin:admin to read and edit entries.

40 |
41 | 42 |
-------------------------------------------------------------------------------- /src/main/webapp/pages/category.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Nasher Home 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 67 | 68 | 69 |
70 | 71 |
72 | 73 | 74 |
75 | 76 | 77 |

78 | JNasher- 79 | ${categtitle} 80 |

81 | 82 | 83 | 84 |

85 | ${categlists.get(entry.getCategory()-1).getName()}/Blog Post Title ${entry.getTitle()} 86 |

87 | 88 |

Posted on ${entry.getDate()}

89 |
90 |

${entry.getContent()}

91 | 92 | Read More 93 | 94 |
95 |
96 | 97 | 98 | 99 | 107 | 108 |
109 | 110 | 111 |
112 | 113 | 114 |
115 |

Blog Search

116 |
117 | 118 | 119 | 122 | 123 |
124 | 125 |
126 | 127 | 128 |
129 |

Blog Categories

130 |
131 |
132 | 138 |
139 | 140 | 141 | 142 |
143 | 144 |
145 | 146 | 147 | 148 |
149 | 150 |
151 | 152 | 153 |
154 | 155 | 156 |
157 |
158 |
159 |

Copyright © JNasher 2016

160 |
161 | 162 |
163 | 164 |
165 | 166 |
167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /src/main/webapp/pages/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Nasher Home 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 66 | 67 | 68 |
69 | 70 |
71 | 72 | 73 |
74 | 75 | 76 |

77 | JNasher Bloging system
78 | https://github.com/mmghasemi/nasher 79 |

80 | 81 | 82 | 83 | 84 |

85 | ${categlists.get(entry.getCategory()-1).getName()}/Blog Post Title ${entry.getTitle()} 86 |

87 | 88 |

Posted on ${entry.getDate()}

89 |
90 |

${entry.getContent()}

91 | 92 | Read More 93 | 94 |
95 | 96 | 97 | 98 | 99 | 107 | 108 |
109 | 110 | 111 |
112 | 113 | 114 |
115 |

Blog Search

116 |
117 | 118 | 119 | 122 | 123 |
124 | 125 |
126 | 127 | 128 |
129 |

Blog Categories

130 |
131 |
132 | 138 |
139 | 140 | 141 | 142 |
143 | 144 |
145 | 146 | 147 |
148 | 149 |
150 | 151 | 152 |
153 | 154 | 155 |
156 |
157 |
158 |

Copyright © JNasher 2016

159 |
160 | 161 |
162 | 163 |
164 | 165 |
166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /src/main/webapp/pages/one.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Blog Post - Start Bootstrap Template 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 65 | 66 | 67 |
68 | 69 |
70 | 71 | 72 |
73 | 74 | 75 | 76 | 77 |

${post.getTitle()}

78 | 79 | 80 |

81 | by jNasher 82 |

83 | 84 |
85 | 86 | 87 |

Posted on ${post.getDate()}

88 | 89 |
90 | 91 | 92 | 93 | 94 |
95 | 96 | 97 |

98 | ${post.getContent()} 99 |

100 | 101 |
102 | 103 | 104 |
105 | 106 | 107 |
108 | 109 | 110 |
111 |

Blog Search

112 |
113 | 114 | 115 | 118 | 119 |
120 | 121 |
122 | 123 | 124 |
125 |

Blog Categories

126 |
127 |
128 | 134 |
135 | 136 |
137 | 138 |
139 | 140 |
141 | 142 |
143 | 144 | 145 |
146 | 147 | 148 |
149 |
150 |
151 |

Copyright © JNasher 2016

152 |
153 |
154 | 155 |
156 | 157 |
158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /src/main/webapp/pages/signup.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Nasher Home 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 63 |
65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 78 | 79 |
User:
Password:
80 | 81 | 83 | 84 |
85 |
86 |
87 |
88 |
89 |
Sign In
90 | 91 |
92 | 93 |
94 | 95 | 96 | 97 |
98 | 99 | Invalid login or password. 100 | 101 |
102 | 103 | 104 |
105 | 106 |
107 | 108 | 109 |
110 | 111 | 112 | 113 |
114 |
115 | 118 |
119 |
120 | 121 | 122 |
123 | 124 | 125 |
126 | Login 127 | Login with Github! 128 | 129 |
130 |
131 | 132 | 133 |
134 |
135 |
136 | Don't have an account! 137 | 138 | Sign Up Here 139 | 140 |
141 |
142 |
143 |
144 | 145 | 146 | 147 |
148 |
149 |
150 | 225 |
226 | 227 | 228 | 229 | 230 | 231 | -------------------------------------------------------------------------------- /src/main/webapp/res/css/blog-home.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Start Bootstrap - Blog Home (http://startbootstrap.com/) 3 | * Copyright 2013-2016 Start Bootstrap 4 | * Licensed under MIT (https://github.com/BlackrockDigital/startbootstrap/blob/gh-pages/LICENSE) 5 | */ 6 | 7 | body { 8 | padding-top: 70px; /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */ 9 | } 10 | 11 | footer { 12 | margin: 50px 0; 13 | } -------------------------------------------------------------------------------- /src/main/webapp/res/css/blog-post.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Start Bootstrap - Blog Post (http://startbootstrap.com/) 3 | * Copyright 2013-2016 Start Bootstrap 4 | * Licensed under MIT (https://github.com/BlackrockDigital/startbootstrap/blob/gh-pages/LICENSE) 5 | */ 6 | 7 | body { 8 | padding-top: 70px; /* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */ 9 | } 10 | 11 | footer { 12 | margin: 50px 0; 13 | } -------------------------------------------------------------------------------- /src/main/webapp/res/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaseminya/nasher-mvc-spring-security-blog-angular/a2d4b0d25d663be27f2349b3fa9230506b65cfe1/src/main/webapp/res/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/main/webapp/res/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaseminya/nasher-mvc-spring-security-blog-angular/a2d4b0d25d663be27f2349b3fa9230506b65cfe1/src/main/webapp/res/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/main/webapp/res/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaseminya/nasher-mvc-spring-security-blog-angular/a2d4b0d25d663be27f2349b3fa9230506b65cfe1/src/main/webapp/res/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/main/webapp/res/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghaseminya/nasher-mvc-spring-security-blog-angular/a2d4b0d25d663be27f2349b3fa9230506b65cfe1/src/main/webapp/res/fonts/glyphicons-halflings-regular.woff2 --------------------------------------------------------------------------------