├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── modules.xml ├── artifacts │ ├── Unmentionable_war.xml │ └── Unmentionable_war_exploded.xml ├── typescript-compiler.xml ├── libraries │ ├── Maven__junit_junit_4_12.xml │ ├── Maven__antlr_antlr_2_7_7.xml │ ├── Maven__dom4j_dom4j_1_6_1.xml │ ├── Maven__javax_servlet_jstl_1_2.xml │ ├── Maven__org_hsqldb_hsqldb_2_3_3.xml │ ├── Maven__org_yaml_snakeyaml_1_16.xml │ ├── Maven__com_google_guava_guava_18_0.xml │ ├── Maven__xml_apis_xml_apis_1_0_b2.xml │ ├── Maven__org_objenesis_objenesis_2_1.xml │ ├── Maven__aopalliance_aopalliance_1_0.xml │ ├── Maven__org_slf4j_slf4j_api_1_7_13.xml │ ├── Maven__com_fasterxml_classmate_1_1_0.xml │ ├── Maven__net_minidev_json_smart_1_1_1.xml │ ├── Maven__com_sun_mail_javax_mail_1_5_4.xml │ ├── Maven__commons_lang_commons_lang_2_6.xml │ ├── Maven__org_jboss_jandex_1_1_0_Final.xml │ ├── Maven__javax_activation_activation_1_1.xml │ ├── Maven__org_hamcrest_hamcrest_core_1_3.xml │ ├── Maven__commons_codec_commons_codec_1_6.xml │ ├── Maven__org_slf4j_jul_to_slf4j_1_7_13.xml │ ├── Maven__org_aspectj_aspectjweaver_1_8_7.xml │ ├── Maven__ch_qos_logback_logback_core_1_1_3.xml │ ├── Maven__com_jayway_jsonpath_json_path_0_8_1.xml │ ├── Maven__org_mockito_mockito_core_1_10_19.xml │ ├── Maven__org_slf4j_jcl_over_slf4j_1_7_13.xml │ ├── Maven__org_eclipse_jdt_core_compiler_ecj_4_4_2.xml │ ├── Maven__org_hamcrest_hamcrest_library_1_3.xml │ ├── Maven__org_javassist_javassist_3_18_1_GA.xml │ ├── Maven__org_apache_tomcat_tomcat_jdbc_8_0_30.xml │ ├── Maven__org_apache_tomcat_tomcat_juli_8_0_30.xml │ ├── Maven__org_slf4j_log4j_over_slf4j_1_7_13.xml │ ├── Maven__org_bouncycastle_bcpkix_jdk15on_1_47.xml │ ├── Maven__org_bouncycastle_bcprov_jdk15on_1_47.xml │ ├── Maven__ch_qos_logback_logback_classic_1_1_3.xml │ ├── Maven__mysql_mysql_connector_java_5_1_38.xml │ ├── Maven__com_jayway_jsonpath_json_path_assert_0_8_1.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_core_2_6_4.xml │ ├── Maven__org_hibernate_hibernate_core_4_3_11_Final.xml │ ├── Maven__org_springframework_spring_tx_4_2_4_RELEASE.xml │ ├── Maven__javax_transaction_javax_transaction_api_1_2.xml │ ├── Maven__org_codehaus_jackson_jackson_core_asl_1_9_13.xml │ ├── Maven__org_jboss_logging_jboss_logging_3_3_0_Final.xml │ ├── Maven__javax_validation_validation_api_1_1_0_Final.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_el_8_0_30.xml │ ├── Maven__org_springframework_spring_aop_4_2_4_RELEASE.xml │ ├── Maven__org_springframework_spring_orm_4_2_4_RELEASE.xml │ ├── Maven__org_springframework_spring_web_4_2_4_RELEASE.xml │ ├── Maven__org_springframework_spring_core_4_2_4_RELEASE.xml │ ├── Maven__org_springframework_spring_jdbc_4_2_4_RELEASE.xml │ ├── Maven__org_springframework_spring_test_4_2_4_RELEASE.xml │ ├── Maven__org_codehaus_jackson_jackson_mapper_asl_1_9_13.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_databind_2_6_4.xml │ ├── Maven__org_springframework_spring_beans_4_2_4_RELEASE.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_core_8_0_30.xml │ ├── Maven__org_springframework_spring_webmvc_4_2_4_RELEASE.xml │ ├── Maven__org_hibernate_hibernate_validator_5_2_2_Final.xml │ ├── Maven__org_springframework_boot_spring_boot_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_spring_aspects_4_2_4_RELEASE.xml │ ├── Maven__org_springframework_spring_context_4_2_4_RELEASE.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_jasper_8_0_30.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_annotations_2_6_4.xml │ ├── Maven__org_springframework_spring_expression_4_2_4_RELEASE.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_0_30.xml │ ├── Maven__org_hibernate_hibernate_entitymanager_4_3_11_Final.xml │ ├── Maven__org_springframework_data_spring_data_jpa_1_9_2_RELEASE.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_logging_juli_8_0_30.xml │ ├── Maven__org_jboss_logging_jboss_logging_annotations_1_2_0_Beta1.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_spring_context_support_4_2_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_actuator_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_commons_1_11_2_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_jwt_1_0_3_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_web_4_0_3_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_aop_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_web_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_core_4_0_3_RELEASE.xml │ ├── Maven__org_hibernate_javax_persistence_hibernate_jpa_2_1_api_1_0_0_Final.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_jdbc_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_mail_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_test_1_3_1_RELEASE.xml │ ├── Maven__org_hibernate_common_hibernate_commons_annotations_4_0_5_Final.xml │ ├── Maven__org_springframework_security_spring_security_config_4_0_3_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_autoconfigure_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_tomcat_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_logging_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_actuator_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_data_jpa_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_security_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_security_oauth_spring_security_oauth2_2_0_8_RELEASE.xml │ └── Maven__org_springframework_boot_spring_boot_starter_validation_1_3_1_RELEASE.xml ├── misc.xml ├── compiler.xml └── uiDesigner.xml ├── .DS_Store ├── src ├── .DS_Store ├── main │ ├── .DS_Store │ ├── java │ │ ├── .DS_Store │ │ └── Unmentionable │ │ │ ├── .DS_Store │ │ │ ├── model │ │ │ ├── .DS_Store │ │ │ ├── Role.java │ │ │ ├── Group.java │ │ │ └── Account.java │ │ │ ├── settings │ │ │ ├── .DS_Store │ │ │ ├── errors │ │ │ │ ├── .DS_Store │ │ │ │ ├── InvalidRequestException.java │ │ │ │ ├── FieldErrorResource.java │ │ │ │ ├── ErrorResource.java │ │ │ │ └── MyExceptionHandler.java │ │ │ ├── security │ │ │ │ ├── .DS_Store │ │ │ │ ├── WebSecurityConfiguration.java │ │ │ │ ├── AccountAuthenticatoinProvider.java │ │ │ │ ├── CustomUserDetailsService.java │ │ │ │ └── OAuth2ServerConfiguration.java │ │ │ ├── exceptions │ │ │ │ ├── .DS_Store │ │ │ │ ├── ExceptionAttributes.java │ │ │ │ └── DefaultExceptionAttributes.java │ │ │ ├── validators │ │ │ │ ├── .DS_Store │ │ │ │ ├── UniqueUsername.java │ │ │ │ └── UniqueUsernameValidator.java │ │ │ ├── configuration │ │ │ │ ├── WebInitializer.java │ │ │ │ └── CorsFilterRequest.java │ │ │ └── email │ │ │ │ └── SmtpMailSender.java │ │ │ ├── repository │ │ │ ├── .DS_Store │ │ │ ├── GroupRepository.java │ │ │ ├── RoleRepository.java │ │ │ └── AccountRepository.java │ │ │ ├── service │ │ │ ├── RoleService.java │ │ │ ├── AccountService.java │ │ │ ├── RoleServiceBean.java │ │ │ └── AccountServiceBean.java │ │ │ ├── controller │ │ │ ├── StarterController.java │ │ │ ├── BaseController.java │ │ │ └── AuthenticationController.java │ │ │ └── Application.java │ ├── webapp │ │ ├── .DS_Store │ │ └── WEB-INF │ │ │ ├── .DS_Store │ │ │ └── jsp │ │ │ └── index.jsp │ └── resources │ │ ├── .DS_Store │ │ ├── config │ │ ├── .DS_Store │ │ └── application.properties │ │ └── data │ │ ├── .DS_Store │ │ └── hsqldb │ │ ├── data.sql │ │ └── schema.sql └── test │ ├── .DS_Store │ └── java │ ├── .DS_Store │ └── Unmentionable │ ├── .DS_Store │ ├── AbstractTest.java │ ├── AbstractControllerTest.java │ ├── controller │ └── AuthenticationControllerTest.java │ └── service │ └── AccountServiceTest.java ├── target ├── .DS_Store ├── classes │ ├── Unmentionable │ │ ├── model │ │ │ ├── Role.class │ │ │ ├── Group.class │ │ │ └── Account.class │ │ ├── Application.class │ │ ├── service │ │ │ ├── RoleService.class │ │ │ ├── AccountService.class │ │ │ ├── RoleServiceBean.class │ │ │ └── AccountServiceBean.class │ │ ├── controller │ │ │ ├── BaseController.class │ │ │ ├── StarterController.class │ │ │ └── AuthenticationController.class │ │ ├── repository │ │ │ ├── RoleRepository.class │ │ │ ├── GroupRepository.class │ │ │ └── AccountRepository.class │ │ └── settings │ │ │ ├── email │ │ │ └── SmtpMailSender.class │ │ │ ├── errors │ │ │ ├── ErrorResource.class │ │ │ ├── FieldErrorResource.class │ │ │ ├── MyExceptionHandler.class │ │ │ └── InvalidRequestException.class │ │ │ ├── validators │ │ │ ├── UniqueUsername.class │ │ │ └── UniqueUsernameValidator.class │ │ │ ├── configuration │ │ │ ├── WebInitializer.class │ │ │ └── CorsFilterRequest.class │ │ │ ├── exceptions │ │ │ ├── ExceptionAttributes.class │ │ │ └── DefaultExceptionAttributes.class │ │ │ └── security │ │ │ ├── CustomUserDetailsService.class │ │ │ ├── WebSecurityConfiguration.class │ │ │ ├── OAuth2ServerConfiguration.class │ │ │ ├── AccountAuthenticatoinProvider.class │ │ │ ├── CustomUserDetailsService$UserRepositoryUserDetails.class │ │ │ ├── OAuth2ServerConfiguration$ResourceServerConfiguration.class │ │ │ └── OAuth2ServerConfiguration$AuthorizationServerConfiguration.class │ ├── config │ │ └── application.properties │ └── data │ │ └── hsqldb │ │ ├── data.sql │ │ └── schema.sql ├── test-classes │ └── Unmentionable │ │ ├── AbstractTest.class │ │ ├── AbstractControllerTest.class │ │ ├── service │ │ └── AccountServiceTest.class │ │ └── controller │ │ └── AuthenticationControllerTest.class └── maven-status │ └── maven-compiler-plugin │ ├── testCompile │ └── default-testCompile │ │ ├── createdFiles.lst │ │ └── inputFiles.lst │ └── compile │ └── default-compile │ ├── createdFiles.lst │ └── inputFiles.lst ├── tsconfig.json ├── README.md ├── pom.xml └── Databese.sql /.idea/.name: -------------------------------------------------------------------------------- 1 | Unmentionable -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/.DS_Store -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/.DS_Store -------------------------------------------------------------------------------- /target/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/.DS_Store -------------------------------------------------------------------------------- /src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/.DS_Store -------------------------------------------------------------------------------- /src/test/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/test/.DS_Store -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/java/.DS_Store -------------------------------------------------------------------------------- /src/main/webapp/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/webapp/.DS_Store -------------------------------------------------------------------------------- /src/test/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/test/java/.DS_Store -------------------------------------------------------------------------------- /src/main/resources/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/resources/.DS_Store -------------------------------------------------------------------------------- /src/main/resources/config/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/resources/config/.DS_Store -------------------------------------------------------------------------------- /src/main/resources/data/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/resources/data/.DS_Store -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/webapp/WEB-INF/.DS_Store -------------------------------------------------------------------------------- /src/main/java/Unmentionable/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/java/Unmentionable/.DS_Store -------------------------------------------------------------------------------- /src/test/java/Unmentionable/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/test/java/Unmentionable/.DS_Store -------------------------------------------------------------------------------- /src/main/java/Unmentionable/model/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/java/Unmentionable/model/.DS_Store -------------------------------------------------------------------------------- /target/classes/Unmentionable/model/Role.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/model/Role.class -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/java/Unmentionable/settings/.DS_Store -------------------------------------------------------------------------------- /target/classes/Unmentionable/Application.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/Application.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/model/Group.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/model/Group.class -------------------------------------------------------------------------------- /src/main/java/Unmentionable/repository/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/java/Unmentionable/repository/.DS_Store -------------------------------------------------------------------------------- /target/classes/Unmentionable/model/Account.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/model/Account.class -------------------------------------------------------------------------------- /target/test-classes/Unmentionable/AbstractTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/test-classes/Unmentionable/AbstractTest.class -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/errors/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/java/Unmentionable/settings/errors/.DS_Store -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/security/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/java/Unmentionable/settings/security/.DS_Store -------------------------------------------------------------------------------- /target/classes/Unmentionable/service/RoleService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/service/RoleService.class -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/exceptions/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/java/Unmentionable/settings/exceptions/.DS_Store -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/validators/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/src/main/java/Unmentionable/settings/validators/.DS_Store -------------------------------------------------------------------------------- /target/classes/Unmentionable/service/AccountService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/service/AccountService.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/controller/BaseController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/controller/BaseController.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/repository/RoleRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/repository/RoleRepository.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/service/RoleServiceBean.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/service/RoleServiceBean.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/repository/GroupRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/repository/GroupRepository.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/service/AccountServiceBean.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/service/AccountServiceBean.class -------------------------------------------------------------------------------- /target/test-classes/Unmentionable/AbstractControllerTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/test-classes/Unmentionable/AbstractControllerTest.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/controller/StarterController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/controller/StarterController.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/repository/AccountRepository.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/repository/AccountRepository.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/email/SmtpMailSender.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/email/SmtpMailSender.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/errors/ErrorResource.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/errors/ErrorResource.class -------------------------------------------------------------------------------- /target/test-classes/Unmentionable/service/AccountServiceTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/test-classes/Unmentionable/service/AccountServiceTest.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/controller/AuthenticationController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/controller/AuthenticationController.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/errors/FieldErrorResource.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/errors/FieldErrorResource.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/errors/MyExceptionHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/errors/MyExceptionHandler.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/validators/UniqueUsername.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/validators/UniqueUsername.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/configuration/WebInitializer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/configuration/WebInitializer.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/configuration/CorsFilterRequest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/configuration/CorsFilterRequest.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/errors/InvalidRequestException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/errors/InvalidRequestException.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/exceptions/ExceptionAttributes.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/exceptions/ExceptionAttributes.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/security/CustomUserDetailsService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/security/CustomUserDetailsService.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/security/WebSecurityConfiguration.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/security/WebSecurityConfiguration.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/security/OAuth2ServerConfiguration.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/security/OAuth2ServerConfiguration.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/validators/UniqueUsernameValidator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/validators/UniqueUsernameValidator.class -------------------------------------------------------------------------------- /target/test-classes/Unmentionable/controller/AuthenticationControllerTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/test-classes/Unmentionable/controller/AuthenticationControllerTest.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/exceptions/DefaultExceptionAttributes.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/exceptions/DefaultExceptionAttributes.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/security/AccountAuthenticatoinProvider.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/security/AccountAuthenticatoinProvider.class -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/security/CustomUserDetailsService$UserRepositoryUserDetails.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/security/CustomUserDetailsService$UserRepositoryUserDetails.class -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/security/OAuth2ServerConfiguration$ResourceServerConfiguration.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/security/OAuth2ServerConfiguration$ResourceServerConfiguration.class -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | Unmentionable/AbstractTest.class 2 | Unmentionable/controller/AuthenticationControllerTest.class 3 | Unmentionable/AbstractControllerTest.class 4 | Unmentionable/service/AccountServiceTest.class 5 | -------------------------------------------------------------------------------- /target/classes/Unmentionable/settings/security/OAuth2ServerConfiguration$AuthorizationServerConfiguration.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calamus0427/Spring-Boot-OAuth2-JWT-MySQL/master/target/classes/Unmentionable/settings/security/OAuth2ServerConfiguration$AuthorizationServerConfiguration.class -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/service/RoleService.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.service; 2 | 3 | import Unmentionable.model.Role; 4 | 5 | /** 6 | * Created by christospapidas on 25012016--. 7 | */ 8 | public interface RoleService { 9 | 10 | Role findById(Long id); 11 | 12 | Role findByCode(String code); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /.idea/artifacts/Unmentionable_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/target 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "system", 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | "emitDecoratorMetadata": true, 8 | "experimentalDecorators": true, 9 | "removeComments": false, 10 | "noImplicitAny": false 11 | }, 12 | "exclude": [ 13 | "node_modules" 14 | ] 15 | } -------------------------------------------------------------------------------- /.idea/typescript-compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/service/AccountService.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.service; 2 | 3 | import Unmentionable.model.Account; 4 | 5 | import java.util.Collection; 6 | 7 | /** 8 | * Created by christospapidas on 24012016--. 9 | */ 10 | public interface AccountService { 11 | 12 | Collection findAll(); 13 | 14 | Account findByUsername(String userename); 15 | 16 | Account createNewAccount(Account account); 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/repository/GroupRepository.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.repository; 2 | 3 | import Unmentionable.model.Group; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * Gives to JPA the ability to communicate with database 9 | */ 10 | @Repository 11 | public interface GroupRepository extends JpaRepository{ 12 | // Todo add the custom search query 13 | } 14 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Users/christospapidas/Projects/Java/Unmentionable/src/test/java/Unmentionable/service/AccountServiceTest.java 2 | /Users/christospapidas/Projects/Java/Unmentionable/src/test/java/Unmentionable/AbstractTest.java 3 | /Users/christospapidas/Projects/Java/Unmentionable/src/test/java/Unmentionable/controller/AuthenticationControllerTest.java 4 | /Users/christospapidas/Projects/Java/Unmentionable/src/test/java/Unmentionable/AbstractControllerTest.java 5 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__junit_junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.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__dom4j_dom4j_1_6_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_servlet_jstl_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hsqldb_hsqldb_2_3_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/controller/StarterController.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | 7 | /** 8 | * Starter controller loads the index.jsp 9 | * to start the application correctly 10 | */ 11 | @Controller 12 | public class StarterController { 13 | 14 | @RequestMapping("/") 15 | public String loadIndex(){ 16 | return "index"; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/configuration/WebInitializer.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.configuration; 2 | 3 | import Unmentionable.Application; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.boot.context.web.SpringBootServletInitializer; 6 | 7 | public class WebInitializer extends SpringBootServletInitializer { 8 | 9 | @Override 10 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 11 | return application.sources(Application.class); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 4 | <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 5 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

Hell Unmentionable

15 | Hello 16 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_yaml_snakeyaml_1_16.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_guava_guava_18_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__xml_apis_xml_apis_1_0_b2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_objenesis_objenesis_2_1.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__org_slf4j_slf4j_api_1_7_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_classmate_1_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_minidev_json_smart_1_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_sun_mail_javax_mail_1_5_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_lang_commons_lang_2_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jboss_jandex_1_1_0_Final.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__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_codec_commons_codec_1_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_aspectj_aspectjweaver_1_8_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__ch_qos_logback_logback_core_1_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_jayway_jsonpath_json_path_0_8_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_mockito_mockito_core_1_10_19.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_eclipse_jdt_core_compiler_ecj_4_4_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.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 | -------------------------------------------------------------------------------- /src/test/java/Unmentionable/AbstractTest.java: -------------------------------------------------------------------------------- 1 | package Unmentionable; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | /** 10 | * An abstract class to run the test throw JUnit 11 | */ 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @SpringApplicationConfiguration(classes=Application.class) 14 | public abstract class AbstractTest { 15 | 16 | protected Logger logger = LoggerFactory.getLogger(this.getClass()); 17 | 18 | 19 | } -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_tomcat_jdbc_8_0_30.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_tomcat_juli_8_0_30.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_log4j_over_slf4j_1_7_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bouncycastle_bcpkix_jdk15on_1_47.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bouncycastle_bcprov_jdk15on_1_47.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__ch_qos_logback_logback_classic_1_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__mysql_mysql_connector_java_5_1_38.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/repository/RoleRepository.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.repository; 2 | 3 | import Unmentionable.model.Account; 4 | import Unmentionable.model.Role; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.data.jpa.repository.Query; 7 | import org.springframework.data.repository.query.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | /** 11 | * 12 | */ 13 | @Repository 14 | public interface RoleRepository extends JpaRepository { 15 | 16 | @Query("SELECT a FROM Role a WHERE a.code = :code") 17 | Role findByCode(@Param("code") String code); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_jayway_jsonpath_json_path_assert_0_8_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_6_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_hibernate_core_4_3_11_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_tx_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_transaction_javax_transaction_api_1_2.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_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_0_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_validation_validation_api_1_1_0_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_el_8_0_30.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_orm_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_web_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_core_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jdbc_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_test_4_2_4_RELEASE.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_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_6_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_core_8_0_30.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_webmvc_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_hibernate_validator_5_2_2_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aspects_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_jasper_8_0_30.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_6_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_0_30.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_hibernate_entitymanager_4_3_11_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_data_spring_data_jpa_1_9_2_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_logging_juli_8_0_30.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/validators/UniqueUsername.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.validators; 2 | 3 | import javax.validation.Constraint; 4 | import javax.validation.Payload; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.Target; 7 | 8 | import static java.lang.annotation.ElementType.FIELD; 9 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 10 | 11 | /** 12 | * Annotation that check the uniqueness of username 13 | */ 14 | @Target({ FIELD }) 15 | @Retention(RUNTIME) 16 | @Constraint(validatedBy = { UniqueUsernameValidator.class }) 17 | public @interface UniqueUsername { 18 | 19 | String message(); 20 | 21 | Class[] groups() default { }; 22 | 23 | Class[] payload() default { }; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jboss_logging_jboss_logging_annotations_1_2_0_Beta1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_support_4_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/errors/InvalidRequestException.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.errors; 2 | 3 | import org.springframework.validation.Errors; 4 | 5 | /** 6 | * This is an exception that let us return a json with 7 | * all the validations errors 8 | */ 9 | public class InvalidRequestException extends RuntimeException { 10 | 11 | private Errors errors; 12 | 13 | /** 14 | * Contructor that get the message and the errors object 15 | * @param message - a custom message as string 16 | * @param errors - the Errors that we have 17 | */ 18 | public InvalidRequestException(String message, Errors errors) { 19 | super(message); 20 | this.errors = errors; 21 | } 22 | 23 | public Errors getErrors() { return errors; } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_actuator_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_data_spring_data_commons_1_11_2_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_security_spring_security_jwt_1_0_3_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_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_aop_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_1_3_1_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_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_javax_persistence_hibernate_jpa_2_1_api_1_0_0_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_mail_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_1_3_1_RELEASE.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_5_Final.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_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_tomcat_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_actuator_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_jpa_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_security_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_security_oauth_spring_security_oauth2_2_0_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_validation_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/errors/FieldErrorResource.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.errors; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | /** 6 | * Get the field resources 7 | */ 8 | @JsonIgnoreProperties(ignoreUnknown = true) 9 | public class FieldErrorResource { 10 | private String resource; 11 | private String field; 12 | private String code; 13 | private String message; 14 | 15 | public String getResource() { return resource; } 16 | 17 | public void setResource(String resource) { this.resource = resource; } 18 | 19 | public String getField() { return field; } 20 | 21 | public void setField(String field) { this.field = field; } 22 | 23 | public String getCode() { return code; } 24 | 25 | public void setCode(String code) { this.code = code; } 26 | 27 | public String getMessage() { return message; } 28 | 29 | public void setMessage(String message) { this.message = message; } 30 | } -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/validators/UniqueUsernameValidator.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.validators; 2 | 3 | import Unmentionable.repository.AccountRepository; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | 6 | import javax.validation.ConstraintValidator; 7 | import javax.validation.ConstraintValidatorContext; 8 | 9 | /** 10 | * Validator of unique username 11 | */ 12 | public class UniqueUsernameValidator implements ConstraintValidator { 13 | 14 | @Autowired 15 | private AccountRepository accountRepository; 16 | 17 | @Override 18 | public void initialize(UniqueUsername constraintAnnotation) { 19 | 20 | } 21 | 22 | @Override 23 | public boolean isValid(String username, ConstraintValidatorContext context) { 24 | // If the repository is null then return null 25 | if(accountRepository == null){ 26 | return true; 27 | } 28 | // Check if the username is unique 29 | return accountRepository.findByUsername(username) == null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/errors/ErrorResource.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.errors; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Get the necessary field to print an error as json 9 | */ 10 | @JsonIgnoreProperties(ignoreUnknown = true) 11 | public class ErrorResource { 12 | private String code; 13 | private String message; 14 | private List fieldErrors; 15 | 16 | public ErrorResource() { } 17 | 18 | public ErrorResource(String code, String message) { 19 | this.code = code; 20 | this.message = message; 21 | } 22 | 23 | public String getCode() { return code; } 24 | 25 | public void setCode(String code) { this.code = code; } 26 | 27 | public String getMessage() { return message; } 28 | 29 | public void setMessage(String message) { this.message = message; } 30 | 31 | public List getFieldErrors() { return fieldErrors; } 32 | 33 | public void setFieldErrors(List fieldErrors) { 34 | this.fieldErrors = fieldErrors; 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/Unmentionable/repository/AccountRepository.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.repository; 2 | 3 | import Unmentionable.model.Account; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.query.Param; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * The AccountRepository interface is a Spring Data JPA data repository for 11 | * Account entities. The AccountRepository provides all the data access 12 | * behaviors exposed by JpaRepository and additional custom 13 | * behaviors may be defined in this interface. 14 | */ 15 | @Repository 16 | public interface AccountRepository extends JpaRepository { 17 | 18 | /** 19 | * Query for a single Account entity by username. 20 | * 21 | * @param username A String username value to query the repository. 22 | * @return An Account or null if none found. 23 | */ 24 | @Query("SELECT a FROM Account a WHERE a.username = :username") 25 | Account findByUsername(@Param("username") String username); 26 | 27 | } -------------------------------------------------------------------------------- /src/main/java/Unmentionable/model/Role.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | import javax.validation.constraints.NotNull; 6 | 7 | /** 8 | * The Role class is an entity model object. A Role describes a privilege level 9 | * within the application. A Role is used to authorize an Account to access a 10 | * set of application resources. 11 | * 12 | * @author Matt Warman 13 | */ 14 | @Entity 15 | public class Role { 16 | 17 | @Id 18 | private Long id; 19 | 20 | @NotNull 21 | private String code; 22 | 23 | @NotNull 24 | private String label; 25 | 26 | public Role() { 27 | 28 | } 29 | 30 | public Long getId() { 31 | return id; 32 | } 33 | 34 | public void setId(Long id) { 35 | this.id = id; 36 | } 37 | 38 | public String getCode() { 39 | return code; 40 | } 41 | 42 | public void setCode(String code) { 43 | this.code = code; 44 | } 45 | 46 | public String getLabel() { 47 | return label; 48 | } 49 | 50 | public void setLabel(String label) { 51 | this.label = label; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/email/SmtpMailSender.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.email; 2 | 3 | import javax.mail.MessagingException; 4 | import javax.mail.internet.MimeMessage; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.mail.javamail.JavaMailSender; 8 | import org.springframework.mail.javamail.MimeMessageHelper; 9 | import org.springframework.stereotype.Component; 10 | 11 | @Component 12 | public class SmtpMailSender { 13 | 14 | @Autowired 15 | private JavaMailSender javaMailSender; 16 | 17 | public void send(String to, String subject, String body) throws MessagingException { 18 | 19 | MimeMessage message = javaMailSender.createMimeMessage(); 20 | MimeMessageHelper helper; 21 | 22 | helper = new MimeMessageHelper(message, true); // true indicates 23 | // multipart message 24 | helper.setSubject(subject); 25 | helper.setTo(to); 26 | helper.setText(body, true); // true indicates html 27 | // continue using helper object for more functionalities like adding attachments, etc. 28 | 29 | javaMailSender.send(message); 30 | 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/service/RoleServiceBean.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.service; 2 | 3 | import Unmentionable.model.Role; 4 | import Unmentionable.repository.RoleRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Propagation; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | /** 11 | * Manage the data from database from Role table user 12 | */ 13 | @Service 14 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true) 15 | public class RoleServiceBean implements RoleService{ 16 | 17 | 18 | /** 19 | * The Spring Data repository for Account entities. 20 | */ 21 | @Autowired 22 | private RoleRepository roleRepository; 23 | 24 | /** 25 | * Get by id 26 | * @param id 27 | * @return 28 | */ 29 | @Override 30 | public Role findById(Long id) { 31 | Role role = roleRepository.findOne(id); 32 | return role; 33 | } 34 | 35 | /** 36 | * File Role by code 37 | * @param code - the code of the role 38 | * @return Role object 39 | */ 40 | @Override 41 | public Role findByCode(String code) { 42 | return roleRepository.findByCode(code); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /.idea/compiler.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 | -------------------------------------------------------------------------------- /target/classes/config/application.properties: -------------------------------------------------------------------------------- 1 | ### 2 | # The main application configuration file. 3 | # 4 | # This file is loaded automatically by Spring Boot when the application starts. 5 | ### 6 | 7 | spring.mvc.view.prefix: /WEB-INF/jsp/ 8 | spring.mvc.view.suffix: .jsp 9 | 10 | ### 11 | # Data Source Configuration 12 | ### 13 | # Hibernate 14 | spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy 15 | 16 | 17 | ### 18 | # Data Source Configuration 19 | ### 20 | # Hibernate 21 | spring.jpa.hibernate.ddl-auto = update 22 | spring.jpa.show-sql = true 23 | 24 | ### 25 | # Initialization 26 | ### 27 | spring.datasource.url=jdbc:mysql://localhost:3306/unmentionable 28 | spring.datasource.username=root 29 | spring.datasource.password=root 30 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 31 | 32 | ### 33 | # Sessions 34 | #### 35 | security.sessions=never 36 | 37 | ### 38 | # Email Properties 39 | ### 40 | spring.mail.host = smtp.gmail.com 41 | spring.mail.username = 42 | spring.mail.password = 43 | spring.mail.properties.mail.smtp.auth = true 44 | spring.mail.properties.mail.smtp.ssl.enable = true 45 | spring.mail.properties.mail.smtp.socketFactory.port = 465 46 | spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory 47 | spring.mail.properties.mail.smtp.socketFactory.fallback = false 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/resources/config/application.properties: -------------------------------------------------------------------------------- 1 | ### 2 | # The main application configuration file. 3 | # 4 | # This file is loaded automatically by Spring Boot when the application starts. 5 | ### 6 | 7 | spring.mvc.view.prefix: /WEB-INF/jsp/ 8 | spring.mvc.view.suffix: .jsp 9 | 10 | ### 11 | # Data Source Configuration 12 | ### 13 | # Hibernate 14 | spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy 15 | 16 | 17 | ### 18 | # Data Source Configuration 19 | ### 20 | # Hibernate 21 | spring.jpa.hibernate.ddl-auto = update 22 | spring.jpa.show-sql = true 23 | 24 | ### 25 | # Initialization 26 | ### 27 | spring.datasource.url=jdbc:mysql://localhost:3306/unmentionable 28 | spring.datasource.username=root 29 | spring.datasource.password=root 30 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 31 | 32 | ### 33 | # Sessions 34 | #### 35 | security.sessions=never 36 | 37 | ### 38 | # Email Properties 39 | ### 40 | spring.mail.host = smtp.gmail.com 41 | spring.mail.username = 42 | spring.mail.password = 43 | spring.mail.properties.mail.smtp.auth = true 44 | spring.mail.properties.mail.smtp.ssl.enable = true 45 | spring.mail.properties.mail.smtp.socketFactory.port = 465 46 | spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory 47 | spring.mail.properties.mail.smtp.socketFactory.fallback = false 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/exceptions/ExceptionAttributes.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.exceptions; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseBody; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.util.Map; 9 | 10 | /** 11 | * The ExceptionAttributes interface defines the behavioral contract to be 12 | * implemented by concrete ExceptionAttributes classes. 13 | * 14 | * Provides attributes which describe Exceptions and the context in which they 15 | * occurred. 16 | * 17 | * @author Matt Warman 18 | * @see DefaultExceptionAttributes 19 | * 20 | */ 21 | public interface ExceptionAttributes { 22 | 23 | /** 24 | * Returns a {@link Map} of exception attributes. The Map may be used to 25 | * display an error page or serialized into a {@link ResponseBody}. 26 | * 27 | * @param exception The Exception reported. 28 | * @param httpRequest The HttpServletRequest in which the Exception 29 | * occurred. 30 | * @param httpStatus The HttpStatus value that will be used in the 31 | * {@link HttpServletResponse}. 32 | * @return A Map of exception attributes. 33 | */ 34 | Map getExceptionAttributes(Exception exception, 35 | HttpServletRequest httpRequest, HttpStatus httpStatus); 36 | 37 | } -------------------------------------------------------------------------------- /target/classes/data/hsqldb/data.sql: -------------------------------------------------------------------------------- 1 | 2 | -- password is 'password' 3 | INSERT INTO Account (referenceId, username, password, enabled, credentialsexpired, expired, locked, version, createdBy, createdAt, updatedBy, updatedAt) VALUES ('a07bd221-3ecd-4893-a0f0-78d7c0fbf94e', 'user', '$2a$10$9/44Rne7kQqPXa0cY6NfG.3XzScMrCxFYjapoLq/wFmHz7EC9praK', true, false, false, false, 0, 'user', NOW(), NULL, NULL); 4 | -- password is 'operations' 5 | INSERT INTO Account (referenceId, username, password, enabled, credentialsexpired, expired, locked, version, createdBy, createdAt, updatedBy, updatedAt) VALUES ('7bd137c8-ab64-4a45-bf2d-d9bae3574622', 'operations', '$2a$10$CoMVfutnv1qZ.fNlHY1Na.rteiJhsDF0jB1o.76qXcfdWN6As27Zm', true, false, false, false, 0, 'user', NOW(), NULL, NULL); 6 | 7 | INSERT INTO Role (id, code, label, ordinal, effectiveAt, expiresAt, createdAt) VALUES (1, 'ROLE_USER', 'User', 0, '2015-01-01 00:00:00', NULL, NOW()); 8 | INSERT INTO Role (id, code, label, ordinal, effectiveAt, expiresAt, createdAt) VALUES (2, 'ROLE_ADMIN', 'Admin', 1, '2015-01-01 00:00:00', NULL, NOW()); 9 | INSERT INTO Role (id, code, label, ordinal, effectiveAt, expiresAt, createdAt) VALUES (3, 'ROLE_SYSADMIN', 'System Admin', 2, '2015-01-01 00:00:00', NULL, NOW()); 10 | 11 | INSERT INTO AccountRole (accountId, roleId) SELECT a.id, r.id FROM Account a, Role r WHERE a.username = 'user' and r.id = 1; 12 | INSERT INTO AccountRole (accountId, roleId) SELECT a.id, r.id FROM Account a, Role r WHERE a.username = 'operations' and r.id = 3; -------------------------------------------------------------------------------- /src/main/resources/data/hsqldb/data.sql: -------------------------------------------------------------------------------- 1 | 2 | -- password is 'password' 3 | INSERT INTO Account (referenceId, username, password, enabled, credentialsexpired, expired, locked, version, createdBy, createdAt, updatedBy, updatedAt) VALUES ('a07bd221-3ecd-4893-a0f0-78d7c0fbf94e', 'user', '$2a$10$9/44Rne7kQqPXa0cY6NfG.3XzScMrCxFYjapoLq/wFmHz7EC9praK', true, false, false, false, 0, 'user', NOW(), NULL, NULL); 4 | -- password is 'operations' 5 | INSERT INTO Account (referenceId, username, password, enabled, credentialsexpired, expired, locked, version, createdBy, createdAt, updatedBy, updatedAt) VALUES ('7bd137c8-ab64-4a45-bf2d-d9bae3574622', 'operations', '$2a$10$CoMVfutnv1qZ.fNlHY1Na.rteiJhsDF0jB1o.76qXcfdWN6As27Zm', true, false, false, false, 0, 'user', NOW(), NULL, NULL); 6 | 7 | INSERT INTO Role (id, code, label, ordinal, effectiveAt, expiresAt, createdAt) VALUES (1, 'ROLE_USER', 'User', 0, '2015-01-01 00:00:00', NULL, NOW()); 8 | INSERT INTO Role (id, code, label, ordinal, effectiveAt, expiresAt, createdAt) VALUES (2, 'ROLE_ADMIN', 'Admin', 1, '2015-01-01 00:00:00', NULL, NOW()); 9 | INSERT INTO Role (id, code, label, ordinal, effectiveAt, expiresAt, createdAt) VALUES (3, 'ROLE_SYSADMIN', 'System Admin', 2, '2015-01-01 00:00:00', NULL, NOW()); 10 | 11 | INSERT INTO AccountRole (accountId, roleId) SELECT a.id, r.id FROM Account a, Role r WHERE a.username = 'user' and r.id = 1; 12 | INSERT INTO AccountRole (accountId, roleId) SELECT a.id, r.id FROM Account a, Role r WHERE a.username = 'operations' and r.id = 3; -------------------------------------------------------------------------------- /target/classes/data/hsqldb/schema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE AccountRole IF EXISTS; 2 | DROP TABLE Account IF EXISTS; 3 | DROP TABLE Role IF EXISTS; 4 | 5 | CREATE TABLE Account ( 6 | id BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL, 7 | referenceId VARCHAR(255) NOT NULL, 8 | username VARCHAR(100) NOT NULL, 9 | password VARCHAR(200) NOT NULL, 10 | enabled BOOLEAN DEFAULT true NOT NULL, 11 | credentialsexpired BOOLEAN DEFAULT false NOT NULL, 12 | expired BOOLEAN DEFAULT false NOT NULL, 13 | locked BOOLEAN DEFAULT false NOT NULL, 14 | version INT NOT NULL, 15 | createdBy VARCHAR(100) NOT NULL, 16 | createdAt DATETIME NOT NULL, 17 | updatedBy VARCHAR(100) DEFAULT NULL, 18 | updatedAt DATETIME DEFAULT NULL, 19 | PRIMARY KEY (id), 20 | CONSTRAINT UQ_Account_ReferenceId UNIQUE (referenceId), 21 | CONSTRAINT UQ_Account_Username UNIQUE (username) 22 | ); 23 | 24 | CREATE TABLE Role ( 25 | id BIGINT NOT NULL, 26 | code VARCHAR(50) NOT NULL, 27 | label VARCHAR(100) NOT NULL, 28 | ordinal INT NOT NULL, 29 | effectiveAt DATETIME NOT NULL, 30 | expiresAt DATETIME DEFAULT NULL, 31 | createdAt DATETIME NOT NULL, 32 | PRIMARY KEY (id), 33 | CONSTRAINT UQ_Role_Code UNIQUE (code) 34 | ); 35 | 36 | CREATE TABLE AccountRole ( 37 | accountId BIGINT NOT NULL, 38 | roleId BIGINT NOT NULL, 39 | PRIMARY KEY (accountId, roleId), 40 | CONSTRAINT FK_AccountRole_AccountId FOREIGN KEY (accountId) REFERENCES Account (id), 41 | CONSTRAINT FK_AccountRole_RoleId FOREIGN KEY (roleId) REFERENCES Role (id) 42 | ); -------------------------------------------------------------------------------- /src/main/resources/data/hsqldb/schema.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE AccountRole IF EXISTS; 2 | DROP TABLE Account IF EXISTS; 3 | DROP TABLE Role IF EXISTS; 4 | 5 | CREATE TABLE Account ( 6 | id BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL, 7 | referenceId VARCHAR(255) NOT NULL, 8 | username VARCHAR(100) NOT NULL, 9 | password VARCHAR(200) NOT NULL, 10 | enabled BOOLEAN DEFAULT true NOT NULL, 11 | credentialsexpired BOOLEAN DEFAULT false NOT NULL, 12 | expired BOOLEAN DEFAULT false NOT NULL, 13 | locked BOOLEAN DEFAULT false NOT NULL, 14 | version INT NOT NULL, 15 | createdBy VARCHAR(100) NOT NULL, 16 | createdAt DATETIME NOT NULL, 17 | updatedBy VARCHAR(100) DEFAULT NULL, 18 | updatedAt DATETIME DEFAULT NULL, 19 | PRIMARY KEY (id), 20 | CONSTRAINT UQ_Account_ReferenceId UNIQUE (referenceId), 21 | CONSTRAINT UQ_Account_Username UNIQUE (username) 22 | ); 23 | 24 | CREATE TABLE Role ( 25 | id BIGINT NOT NULL, 26 | code VARCHAR(50) NOT NULL, 27 | label VARCHAR(100) NOT NULL, 28 | ordinal INT NOT NULL, 29 | effectiveAt DATETIME NOT NULL, 30 | expiresAt DATETIME DEFAULT NULL, 31 | createdAt DATETIME NOT NULL, 32 | PRIMARY KEY (id), 33 | CONSTRAINT UQ_Role_Code UNIQUE (code) 34 | ); 35 | 36 | CREATE TABLE AccountRole ( 37 | accountId BIGINT NOT NULL, 38 | roleId BIGINT NOT NULL, 39 | PRIMARY KEY (accountId, roleId), 40 | CONSTRAINT FK_AccountRole_AccountId FOREIGN KEY (accountId) REFERENCES Account (id), 41 | CONSTRAINT FK_AccountRole_RoleId FOREIGN KEY (roleId) REFERENCES Role (id) 42 | ); -------------------------------------------------------------------------------- /src/test/java/Unmentionable/AbstractControllerTest.java: -------------------------------------------------------------------------------- 1 | package Unmentionable; 2 | 3 | import Unmentionable.controller.BaseController; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.test.context.web.WebAppConfiguration; 8 | import org.springframework.test.web.servlet.MockMvc; 9 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 10 | import org.springframework.web.context.WebApplicationContext; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * Helps the controller testings 16 | */ 17 | @WebAppConfiguration 18 | public class AbstractControllerTest extends AbstractTest{ 19 | 20 | protected MockMvc mvc; 21 | 22 | @Autowired 23 | protected WebApplicationContext webApplicationContext; 24 | 25 | protected void setUp(){ 26 | mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); 27 | } 28 | 29 | protected String mapToJson(Object obj) throws JsonProcessingException { 30 | ObjectMapper objectMapper = new ObjectMapper(); 31 | return objectMapper.writeValueAsString(obj); 32 | } 33 | 34 | protected T mapFromJson(String json, Class clazz) throws IOException { 35 | ObjectMapper objectMapper = new ObjectMapper(); 36 | return objectMapper.readValue(json, clazz); 37 | } 38 | 39 | protected void setUp(BaseController controller){ 40 | mvc = MockMvcBuilders.standaloneSetup(controller).build(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/configuration/CorsFilterRequest.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.configuration; 2 | 3 | 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.servlet.*; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | 15 | @Component 16 | @Order(Ordered.HIGHEST_PRECEDENCE) 17 | public class CorsFilterRequest implements Filter { 18 | 19 | 20 | private final Logger log = LoggerFactory.getLogger(CorsFilterRequest.class); 21 | 22 | public CorsFilterRequest() { 23 | log.info("SimpleCORSFilter init"); 24 | } 25 | 26 | @Override 27 | public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { 28 | 29 | HttpServletRequest request = (HttpServletRequest) req; 30 | HttpServletResponse response = (HttpServletResponse) res; 31 | 32 | response.setHeader("Access-Control-Allow-Origin", "*"); 33 | response.setHeader("Access-Control-Allow-Methods", "POST, PUT, GET, OPTIONS, DELETE"); 34 | response.setHeader("Access-Control-Allow-Headers", "x-requested-with, Authorization, Content-Type"); 35 | response.setHeader("Access-Control-Max-Age", "3600"); 36 | if ("OPTIONS".equalsIgnoreCase(request.getMethod())) { 37 | response.setStatus(HttpServletResponse.SC_OK); 38 | } else { 39 | chain.doFilter(req, res); 40 | } 41 | } 42 | 43 | @Override 44 | public void init(FilterConfig filterConfig) { 45 | } 46 | 47 | @Override 48 | public void destroy() { 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | Unmentionable/service/AccountServiceBean.class 2 | Unmentionable/settings/security/OAuth2ServerConfiguration$ResourceServerConfiguration.class 3 | Unmentionable/controller/AuthenticationController.class 4 | Unmentionable/settings/configuration/CorsFilterRequest.class 5 | Unmentionable/controller/StarterController.class 6 | Unmentionable/settings/errors/InvalidRequestException.class 7 | Unmentionable/model/Group.class 8 | Unmentionable/repository/AccountRepository.class 9 | Unmentionable/service/RoleServiceBean.class 10 | Unmentionable/model/Role.class 11 | Unmentionable/settings/exceptions/DefaultExceptionAttributes.class 12 | Unmentionable/settings/configuration/WebInitializer.class 13 | Unmentionable/settings/security/WebSecurityConfiguration.class 14 | Unmentionable/controller/BaseController.class 15 | Unmentionable/repository/RoleRepository.class 16 | Unmentionable/repository/GroupRepository.class 17 | Unmentionable/model/Account.class 18 | Unmentionable/settings/errors/FieldErrorResource.class 19 | Unmentionable/settings/security/AccountAuthenticatoinProvider.class 20 | Unmentionable/settings/security/OAuth2ServerConfiguration$AuthorizationServerConfiguration.class 21 | Unmentionable/settings/validators/UniqueUsernameValidator.class 22 | Unmentionable/service/AccountService.class 23 | Unmentionable/settings/errors/ErrorResource.class 24 | Unmentionable/Application.class 25 | Unmentionable/settings/exceptions/ExceptionAttributes.class 26 | Unmentionable/settings/security/CustomUserDetailsService$UserRepositoryUserDetails.class 27 | Unmentionable/service/RoleService.class 28 | Unmentionable/settings/errors/MyExceptionHandler.class 29 | Unmentionable/settings/security/CustomUserDetailsService.class 30 | Unmentionable/settings/security/OAuth2ServerConfiguration.class 31 | Unmentionable/settings/validators/UniqueUsername.class 32 | Unmentionable/settings/email/SmtpMailSender.class 33 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/model/Group.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.model; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | import javax.validation.constraints.NotNull; 8 | import javax.validation.constraints.Size; 9 | 10 | /** 11 | * Group model describe the container of each post 12 | */ 13 | @Entity 14 | public class Group { 15 | 16 | @Id 17 | @GeneratedValue 18 | private Long id; 19 | 20 | @NotNull 21 | @Size(min=8, max=255, message="Group name should be between 8 and 255 characters") 22 | private String name; 23 | 24 | @Size(min=30, max=512, message="Group description should be between 20 and 512 characters") 25 | @Column(name="description", length=512) 26 | private String description; 27 | 28 | @Size(min=3, max=255, message="Group country should be between 3 and 255 characters") 29 | private String country; 30 | 31 | @Size(min=3, max=255, message="Group city should be between 3 and 255 characters") 32 | private String city; 33 | 34 | public Long getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Long id) { 39 | this.id = id; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public String getDescription() { 51 | return description; 52 | } 53 | 54 | public void setDescription(String description) { 55 | this.description = description; 56 | } 57 | 58 | public String getCountry() { 59 | return country; 60 | } 61 | 62 | public void setCountry(String country) { 63 | this.country = country; 64 | } 65 | 66 | public String getCity() { 67 | return city; 68 | } 69 | 70 | public void setCity(String city) { 71 | this.city = city; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/errors/MyExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.errors; 2 | 3 | import org.springframework.http.HttpHeaders; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.validation.FieldError; 8 | import org.springframework.web.bind.annotation.ControllerAdvice; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.context.request.WebRequest; 11 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * Exception Handle, handle the exception 18 | */ 19 | @ControllerAdvice 20 | public class MyExceptionHandler extends ResponseEntityExceptionHandler{ 21 | 22 | @ExceptionHandler({ InvalidRequestException.class }) 23 | protected ResponseEntity handleInvalidRequest(RuntimeException e, WebRequest request) { 24 | InvalidRequestException ire = (InvalidRequestException) e; 25 | List fieldErrorResources = new ArrayList<>(); 26 | 27 | List fieldErrors = ire.getErrors().getFieldErrors(); 28 | for (FieldError fieldError : fieldErrors) { 29 | FieldErrorResource fieldErrorResource = new FieldErrorResource(); 30 | fieldErrorResource.setResource(fieldError.getObjectName()); 31 | fieldErrorResource.setField(fieldError.getField()); 32 | fieldErrorResource.setCode(fieldError.getCode()); 33 | fieldErrorResource.setMessage(fieldError.getDefaultMessage()); 34 | fieldErrorResources.add(fieldErrorResource); 35 | } 36 | 37 | ErrorResource error = new ErrorResource("InvalidRequest", ire.getMessage()); 38 | error.setFieldErrors(fieldErrorResources); 39 | 40 | HttpHeaders headers = new HttpHeaders(); 41 | headers.setContentType(MediaType.APPLICATION_JSON); 42 | 43 | return handleExceptionInternal(e, error, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/security/WebSecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.security; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.authentication.AuthenticationManager; 7 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 10 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 11 | import org.springframework.security.crypto.password.PasswordEncoder; 12 | import org.springframework.security.oauth2.provider.token.TokenStore; 13 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; 14 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; 15 | 16 | @Configuration 17 | @EnableWebSecurity 18 | public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { 19 | 20 | @Autowired 21 | private CustomUserDetailsService userDetailsService; 22 | 23 | @Autowired 24 | private AccountAuthenticatoinProvider accountAuthenticationProvider; 25 | 26 | @Override 27 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 28 | auth.userDetailsService(userDetailsService); 29 | auth.authenticationProvider(accountAuthenticationProvider); 30 | } 31 | 32 | @Bean 33 | public PasswordEncoder passwordEncoder() { 34 | return new BCryptPasswordEncoder(); 35 | } 36 | 37 | @Override 38 | @Bean 39 | public AuthenticationManager authenticationManagerBean() throws Exception { 40 | return super.authenticationManagerBean(); 41 | } 42 | 43 | @Bean 44 | public JwtAccessTokenConverter jwtAccessTokenConverter() { 45 | final JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter(); 46 | jwtAccessTokenConverter.setSigningKey("ASDFASFsdfsdfsdfsfadsf234asdfasfdas"); 47 | return jwtAccessTokenConverter; 48 | } 49 | 50 | @Bean 51 | public TokenStore tokenStore() { 52 | return new JwtTokenStore(jwtAccessTokenConverter()); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/service/AccountServiceBean.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.service; 2 | 3 | import Unmentionable.model.Account; 4 | import Unmentionable.model.Role; 5 | import Unmentionable.repository.AccountRepository; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Propagation; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | import javax.persistence.EntityExistsException; 15 | import java.util.Collection; 16 | import java.util.HashSet; 17 | import java.util.Set; 18 | 19 | 20 | @Service 21 | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true) 22 | public class AccountServiceBean implements AccountService { 23 | 24 | /** 25 | * The Logger for this class. 26 | */ 27 | private Logger logger = LoggerFactory.getLogger(this.getClass()); 28 | 29 | /** 30 | * The Spring Data repository for Account entities. 31 | */ 32 | @Autowired 33 | private AccountRepository accountRepository; 34 | 35 | /** 36 | * The Spring Data repository for Role entities 37 | */ 38 | @Autowired 39 | private RoleService roleService; 40 | 41 | /** 42 | * Find and return all accounts 43 | * @return collection of all accounts 44 | */ 45 | @Override 46 | public Collection findAll() { 47 | Collection accounts = accountRepository.findAll(); 48 | return accounts; 49 | } 50 | 51 | /** 52 | * Find user by username 53 | * @param username the username of the user 54 | * @return the user account 55 | */ 56 | @Override 57 | public Account findByUsername(String username) { 58 | Account account = accountRepository.findByUsername(username); 59 | return account; 60 | } 61 | 62 | /** 63 | * Create a new user as simple user. Find the simple user role from the database 64 | * add assign to the many to many collection 65 | * @param account - new Account of user 66 | * @return - the created account 67 | */ 68 | @Override 69 | @Transactional(propagation = Propagation.REQUIRED, readOnly = false) 70 | public Account createNewAccount(Account account) { 71 | 72 | // Add the simple user role 73 | Role role = roleService.findByCode("ROLE_USER"); 74 | Set roles = new HashSet<>(); 75 | roles.add(role); 76 | 77 | // Validate the password 78 | if (account.getPassword().length() < 8){ 79 | throw new EntityExistsException("password should be greater than 8 characters"); 80 | } 81 | 82 | // Encode the password 83 | account.setPassword(new BCryptPasswordEncoder().encode(account.getPassword())); 84 | 85 | // Create the role 86 | account.setRoles(roles); 87 | return accountRepository.save(account); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/Unmentionable/controller/AuthenticationControllerTest.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.controller; 2 | 3 | import Unmentionable.AbstractControllerTest; 4 | import Unmentionable.model.Account; 5 | import Unmentionable.service.AccountService; 6 | import org.junit.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.http.HttpHeaders; 12 | import org.springframework.http.MediaType; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | import org.springframework.test.web.servlet.MvcResult; 15 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 16 | import org.springframework.transaction.annotation.Transactional; 17 | 18 | /** 19 | * Test the authentication controller 20 | */ 21 | @Transactional 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | public class AuthenticationControllerTest extends AbstractControllerTest { 24 | 25 | @Autowired 26 | private AccountService accountService; 27 | 28 | @Before 29 | public void setUp() { 30 | super.setUp(); 31 | } 32 | 33 | @Test 34 | public void testRegister() throws Exception { 35 | 36 | // Url of the request 37 | String uri = "/register"; 38 | 39 | // Create the params 40 | Account account = new Account(); 41 | account.setUsername("fofoFaasfdasdf234"); 42 | account.setPassword("asdfasdfasdf123123"); 43 | String inputJson = super.mapToJson(account); 44 | 45 | // Create the request 46 | MvcResult mvcResult = mvc.perform( 47 | MockMvcRequestBuilders.post(uri).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).content(inputJson) 48 | ).andReturn(); 49 | 50 | // Collect the data 51 | String content = mvcResult.getResponse().getContentAsString(); 52 | int status = mvcResult.getResponse().getStatus(); 53 | 54 | Assert.assertEquals("failure - expected HTTP status 201", 201, status); 55 | Assert.assertTrue("failure - expected Http response body to have a value", content.trim().length() > 0); 56 | } 57 | 58 | @Test 59 | public void testSample() throws Exception { 60 | 61 | String uri = "/api/sample"; 62 | 63 | HttpHeaders httpHeaders = new HttpHeaders(); 64 | httpHeaders.add("Authorization", "Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOlsicmVzdHNlcnZpY2UiXSwidXNlcl9uYW1lIjoicGFwaWRha29zIiwic2NvcGUiOlsicmVhZCIsIndyaXRlIl0sImV4cCI6MTQ1NjcxODIwNSwiYXV0aG9yaXRpZXMiOlsiUk9MRV9VU0VSIl0sImp0aSI6IjQ1NjczY2Y0LWYwNDYtNGQxZi04NGE5LTA1NjVmZjhhZThiNyIsImNsaWVudF9pZCI6ImNsaWVudGFwcCJ9.Au9dJencn68uCSoy7w8CrTCLoT2KTAB8gDKYrww9KxA"); 65 | 66 | MvcResult mvcResult = mvc.perform( 67 | MockMvcRequestBuilders.post(uri).headers(httpHeaders).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).content("") 68 | ).andReturn(); 69 | 70 | // Collect the data 71 | String content = mvcResult.getResponse().getContentAsString(); 72 | int status = mvcResult.getResponse().getStatus(); 73 | 74 | Assert.assertEquals("failure - expected HTTP status 201", 201, status); 75 | Assert.assertTrue("failure - expected Http response body to have a value", content.trim().length() > 0); 76 | 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/controller/BaseController.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.controller; 2 | 3 | import Unmentionable.settings.exceptions.DefaultExceptionAttributes; 4 | import Unmentionable.settings.exceptions.ExceptionAttributes; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | 11 | import javax.persistence.NoResultException; 12 | import javax.servlet.http.HttpServletRequest; 13 | import java.util.Map; 14 | 15 | /** 16 | * Base of all controllers 17 | */ 18 | public class BaseController { 19 | 20 | /** 21 | * The Logger for this class. 22 | */ 23 | protected Logger logger = LoggerFactory.getLogger(this.getClass()); 24 | 25 | /** 26 | * Handles JPA NoResultExceptions thrown from web service controller 27 | * methods. Creates a response with Exception Attributes as JSON and HTTP 28 | * status code 404, not found. 29 | * 30 | * @param noResultException A NoResultException instance. 31 | * @param request The HttpServletRequest in which the NoResultException was 32 | * raised. 33 | * @return A ResponseEntity containing the Exception Attributes in the body 34 | * and HTTP status code 404. 35 | */ 36 | @ExceptionHandler(NoResultException.class) 37 | public ResponseEntity> handleNoResultException( 38 | NoResultException noResultException, HttpServletRequest request) { 39 | 40 | logger.info("> handleNoResultException"); 41 | 42 | ExceptionAttributes exceptionAttributes = new DefaultExceptionAttributes(); 43 | 44 | Map responseBody = exceptionAttributes 45 | .getExceptionAttributes(noResultException, request, 46 | HttpStatus.NOT_FOUND); 47 | 48 | logger.info("< handleNoResultException"); 49 | return new ResponseEntity>(responseBody, 50 | HttpStatus.NOT_FOUND); 51 | } 52 | 53 | /** 54 | * Handles all Exceptions not addressed by more specific 55 | * @ExceptionHandler methods. Creates a response with the 56 | * Exception Attributes in the response body as JSON and a HTTP status code 57 | * of 500, internal server error. 58 | * 59 | * @param exception An Exception instance. 60 | * @param request The HttpServletRequest in which the Exception was raised. 61 | * @return A ResponseEntity containing the Exception Attributes in the body 62 | * and a HTTP status code 500. 63 | */ 64 | @ExceptionHandler(Exception.class) 65 | public ResponseEntity> handleException( 66 | Exception exception, HttpServletRequest request) { 67 | 68 | logger.error("> handleException"); 69 | logger.error("- Exception: ", exception); 70 | 71 | ExceptionAttributes exceptionAttributes = new DefaultExceptionAttributes(); 72 | 73 | Map responseBody = exceptionAttributes 74 | .getExceptionAttributes(exception, request, 75 | HttpStatus.INTERNAL_SERVER_ERROR); 76 | 77 | logger.error("< handleException"); 78 | return new ResponseEntity>(responseBody, 79 | HttpStatus.INTERNAL_SERVER_ERROR); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/controller/AuthenticationController.java 2 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/validators/UniqueUsername.java 3 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/controller/BaseController.java 4 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/service/RoleService.java 5 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/service/AccountServiceBean.java 6 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/email/SmtpMailSender.java 7 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/model/Group.java 8 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/service/RoleServiceBean.java 9 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/model/Account.java 10 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/security/OAuth2ServerConfiguration.java 11 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/errors/MyExceptionHandler.java 12 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/security/CustomUserDetailsService.java 13 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/configuration/WebInitializer.java 14 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/security/AccountAuthenticatoinProvider.java 15 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/controller/StarterController.java 16 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/Application.java 17 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/repository/GroupRepository.java 18 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/repository/RoleRepository.java 19 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/configuration/CorsFilterRequest.java 20 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/validators/UniqueUsernameValidator.java 21 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/service/AccountService.java 22 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/exceptions/DefaultExceptionAttributes.java 23 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/errors/InvalidRequestException.java 24 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/exceptions/ExceptionAttributes.java 25 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/model/Role.java 26 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/errors/ErrorResource.java 27 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/errors/FieldErrorResource.java 28 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/settings/security/WebSecurityConfiguration.java 29 | /Users/christospapidas/Projects/Java/Unmentionable/src/main/java/Unmentionable/repository/AccountRepository.java 30 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/Application.java: -------------------------------------------------------------------------------- 1 | package Unmentionable; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.builder.SpringApplicationBuilder; 7 | import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; 8 | import org.springframework.boot.context.embedded.FilterRegistrationBean; 9 | import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; 10 | import org.springframework.boot.context.web.SpringBootServletInitializer; 11 | import org.springframework.cache.CacheManager; 12 | import org.springframework.cache.annotation.EnableCaching; 13 | import org.springframework.cache.guava.GuavaCacheManager; 14 | import org.springframework.context.annotation.Bean; 15 | import org.springframework.context.annotation.ComponentScan; 16 | import org.springframework.context.annotation.Configuration; 17 | import org.springframework.scheduling.annotation.EnableAsync; 18 | import org.springframework.scheduling.annotation.EnableScheduling; 19 | import org.springframework.transaction.annotation.EnableTransactionManagement; 20 | import org.springframework.web.cors.CorsConfiguration; 21 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 22 | import org.springframework.web.filter.CorsFilter; 23 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 24 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 25 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 26 | 27 | import java.util.Arrays; 28 | 29 | /** 30 | * 31 | https://github.com/royclarkson/spring-rest-service-oauth 32 | curl -X POST -vu clientapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=papidakos123&username=papidakos&grant_type=password&scope=read%20write&client_secret=123456&client_id=clientapp" 33 | curl http://localhost:8080/api/sample -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOlsicmVzdHNlcnZpY2UiXSwidXNlcl9uYW1lIjoicGFwaWRha29zIiwic2NvcGUiOlsicmVhZCIsIndyaXRlIl0sImV4cCI6MTQ1Njc5NzQzNiwiYXV0aG9yaXRpZXMiOlsiUk9MRV9VU0VSIl0sImp0aSI6IjNlYjA3MjIzLWY5ZTAtNGI0NS1hYTM3LTVjOGYzZDg1YTVkNCIsImNsaWVudF9pZCI6ImNsaWVudGFwcCJ9.oD3jbGe0o69mJmPlcoc9ALsLyME8hwOkn9_5TJxt3l0" 34 | * Standard application controller 35 | */ 36 | @SpringBootApplication 37 | @EnableTransactionManagement 38 | @EnableCaching 39 | @EnableScheduling 40 | @EnableAsync 41 | public class Application extends SpringBootServletInitializer { 42 | 43 | /** 44 | * Entry point for the application. 45 | * 46 | * @param args Command line arguments. 47 | * @throws Exception Thrown when an unexpected Exception is thrown from the 48 | * application. 49 | */ 50 | public static void main(String[] args) throws Exception { 51 | SpringApplication.run(Application.class, args); 52 | } 53 | 54 | // @Override 55 | // protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 56 | // return application.sources(Application.class); 57 | // } 58 | 59 | /** 60 | * Create a CacheManager implementation class to be used by Spring where 61 | * @Cacheable annotations are applied. 62 | * 63 | * @return A CacheManager instance. 64 | */ 65 | @Bean 66 | public CacheManager cacheManager() { 67 | 68 | GuavaCacheManager cacheManager = new GuavaCacheManager("unmentionable"); 69 | 70 | return cacheManager; 71 | } 72 | 73 | 74 | } 75 | 76 | 77 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/model/Account.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.model; 2 | 3 | import Unmentionable.settings.validators.UniqueUsername; 4 | import org.hibernate.validator.constraints.NotBlank; 5 | 6 | import javax.persistence.*; 7 | import javax.validation.constraints.Min; 8 | import javax.validation.constraints.NotNull; 9 | import javax.validation.constraints.Size; 10 | import java.util.Set; 11 | 12 | /** 13 | * The Account class is an entity model object. An Account describes the 14 | * security credentials and authentication flags that permit access to 15 | * application functionality. 16 | */ 17 | @Entity 18 | public class Account { 19 | 20 | @Id 21 | @GeneratedValue 22 | private Long id; 23 | 24 | @NotNull 25 | @UniqueUsername(message="Username already exists") 26 | @Size(min = 8, max = 255, message = "Username have to be grater than 8 characters") 27 | @Column(unique = true) 28 | private String username; 29 | 30 | @NotNull 31 | @Size(min = 8, max = 255, message = "Password have to be grater than 8 characters") 32 | private String password; 33 | 34 | @NotNull 35 | private boolean enabled = true; 36 | 37 | @NotNull 38 | private boolean credentialsexpired = false; 39 | 40 | @NotNull 41 | private boolean expired = false; 42 | 43 | @NotNull 44 | private boolean locked = false; 45 | 46 | @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) 47 | @JoinTable(name = "AccountRole", joinColumns = @JoinColumn(name = "accountId", referencedColumnName = "id"), 48 | inverseJoinColumns = @JoinColumn(name = "roleId", referencedColumnName = "id")) 49 | private Set roles; 50 | 51 | public Account() { 52 | 53 | } 54 | 55 | public Account(Account account){ 56 | this.id = account.getId(); 57 | this.username = account.getUsername(); 58 | this.password = account.getPassword(); 59 | this.enabled = account.isEnabled(); 60 | this.credentialsexpired = account.isCredentialsexpired(); 61 | this.locked = account.isExpired(); 62 | this.roles = account.getRoles(); 63 | } 64 | 65 | public Long getId() { 66 | return id; 67 | } 68 | 69 | public void setId(Long id) { 70 | this.id = id; 71 | } 72 | 73 | public String getUsername() { 74 | return username; 75 | } 76 | 77 | public void setUsername(String username) { 78 | this.username = username; 79 | } 80 | 81 | public String getPassword() { 82 | return password; 83 | } 84 | 85 | public void setPassword(String password) { 86 | this.password = password; 87 | } 88 | 89 | public boolean isEnabled() { 90 | return enabled; 91 | } 92 | 93 | public void setEnabled(boolean enabled) { 94 | this.enabled = enabled; 95 | } 96 | 97 | public boolean isCredentialsexpired() { 98 | return credentialsexpired; 99 | } 100 | 101 | public void setCredentialsexpired(boolean credentialsexpired) { 102 | this.credentialsexpired = credentialsexpired; 103 | } 104 | 105 | public boolean isExpired() { 106 | return expired; 107 | } 108 | 109 | public void setExpired(boolean expired) { 110 | this.expired = expired; 111 | } 112 | 113 | public boolean isLocked() { 114 | return locked; 115 | } 116 | 117 | public void setLocked(boolean locked) { 118 | this.locked = locked; 119 | } 120 | 121 | public Set getRoles() { 122 | return roles; 123 | } 124 | 125 | public void setRoles(Set roles) { 126 | this.roles = roles; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/controller/AuthenticationController.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.controller; 2 | 3 | import Unmentionable.model.Account; 4 | import Unmentionable.service.AccountService; 5 | import Unmentionable.service.RoleService; 6 | import Unmentionable.settings.email.SmtpMailSender; 7 | import Unmentionable.settings.errors.InvalidRequestException; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.HttpStatus; 10 | import org.springframework.http.MediaType; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.security.authentication.AuthenticationManager; 13 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 14 | import org.springframework.security.core.Authentication; 15 | import org.springframework.security.core.context.SecurityContextHolder; 16 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; 17 | import org.springframework.security.web.authentication.WebAuthenticationDetails; 18 | import org.springframework.security.web.context.HttpSessionSecurityContextRepository; 19 | import org.springframework.validation.BindingResult; 20 | import org.springframework.web.bind.annotation.*; 21 | 22 | import javax.mail.MessagingException; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | import javax.validation.Valid; 26 | import java.security.Principal; 27 | 28 | /** 29 | * This controller is responsible to manage the authentication 30 | * system. Login - Register - Forgot password - Account Confirmation 31 | */ 32 | @RestController 33 | public class AuthenticationController extends BaseController{ 34 | 35 | @Autowired 36 | protected AuthenticationManager authenticationManager; 37 | 38 | @Autowired 39 | private AccountService accountService; 40 | 41 | @Autowired 42 | private SmtpMailSender smtpMailSender; 43 | 44 | @RequestMapping(value="/api/sample", method= RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) 45 | public ResponseEntity sampleGet(HttpServletResponse response){ 46 | return new ResponseEntity(accountService.findByUsername("papidakos"), HttpStatus.CREATED); 47 | } 48 | 49 | @RequestMapping(value="/api/sample", method= RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) 50 | public ResponseEntity sample(HttpServletResponse response){ 51 | return new ResponseEntity(accountService.findByUsername("papidakos"), HttpStatus.CREATED); 52 | } 53 | 54 | /** 55 | * Create a new user account 56 | * @param account user account 57 | * @return created account as json 58 | */ 59 | @RequestMapping(value="/register", method= RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) 60 | public ResponseEntity register(@Valid @RequestBody Account account, BindingResult errors){ 61 | 62 | // Check if account is unique 63 | if(errors.hasErrors()){ 64 | throw new InvalidRequestException("Username already exists", errors); 65 | } 66 | 67 | Account createdAccount = accountService.createNewAccount(account); 68 | return new ResponseEntity(createdAccount, HttpStatus.CREATED); 69 | } 70 | 71 | @RequestMapping(value="/forgot-password", method=RequestMethod.GET) 72 | public ResponseEntity forgotPassword() throws MessagingException { 73 | String response = "{success: true}"; 74 | smtpMailSender.send("cpapidas@gmail.com", "Password forgot", "Forgot password url"); 75 | return new ResponseEntity(response, HttpStatus.OK); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/security/AccountAuthenticatoinProvider.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.security; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.security.authentication.BadCredentialsException; 8 | import org.springframework.security.authentication.InsufficientAuthenticationException; 9 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 10 | import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider; 11 | import org.springframework.security.core.Authentication; 12 | import org.springframework.security.core.AuthenticationException; 13 | import org.springframework.security.core.userdetails.UserDetails; 14 | import org.springframework.security.crypto.password.PasswordEncoder; 15 | import org.springframework.security.oauth2.common.OAuth2AccessToken; 16 | import org.springframework.security.oauth2.common.exceptions.InvalidClientException; 17 | import org.springframework.security.oauth2.common.exceptions.InvalidGrantException; 18 | import org.springframework.security.oauth2.common.exceptions.InvalidRequestException; 19 | import org.springframework.security.oauth2.common.exceptions.UnsupportedGrantTypeException; 20 | import org.springframework.security.oauth2.common.util.OAuth2Utils; 21 | import org.springframework.security.oauth2.provider.ClientDetails; 22 | import org.springframework.security.oauth2.provider.TokenRequest; 23 | import org.springframework.stereotype.Component; 24 | import org.springframework.util.StringUtils; 25 | import org.springframework.web.HttpRequestMethodNotSupportedException; 26 | import org.springframework.web.bind.annotation.RequestParam; 27 | 28 | import java.security.Principal; 29 | import java.util.Collections; 30 | import java.util.Map; 31 | 32 | @Component 33 | public class AccountAuthenticatoinProvider extends AbstractUserDetailsAuthenticationProvider{ 34 | 35 | /** 36 | * The Logger for this class. 37 | */ 38 | private Logger logger = LoggerFactory.getLogger(this.getClass()); 39 | 40 | /** 41 | * A Spring Security UserDetailsService implementation based upon the 42 | * Account entity model. 43 | */ 44 | @Autowired 45 | private CustomUserDetailsService userDetailsService; 46 | 47 | /** 48 | * A PasswordEncoder instance to hash clear test password values. 49 | */ 50 | @Autowired 51 | private PasswordEncoder passwordEncoder; 52 | 53 | @Override 54 | protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken token) throws AuthenticationException { 55 | logger.debug("> additionalAuthenticationChecks"); 56 | 57 | if (token.getCredentials() == null || userDetails.getPassword() == null) { 58 | throw new BadCredentialsException("Credentials may not be null."); 59 | } 60 | 61 | if (!passwordEncoder.matches((String) token.getCredentials(), userDetails.getPassword())) { 62 | throw new BadCredentialsException("Invalid credentials."); 63 | } 64 | 65 | logger.debug("< additionalAuthenticationChecks"); 66 | } 67 | 68 | @Override 69 | protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken token) throws AuthenticationException { 70 | logger.debug("> retrieveUser"); 71 | 72 | UserDetails userDetails = userDetailsService.loadUserByUsername(username); 73 | 74 | logger.debug("< retrieveUser"); 75 | return userDetails; 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 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/security/CustomUserDetailsService.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | package Unmentionable.settings.security; 4 | 5 | import Unmentionable.model.Account; 6 | import Unmentionable.model.Role; 7 | import Unmentionable.repository.AccountRepository; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.core.GrantedAuthority; 10 | import org.springframework.security.core.authority.AuthorityUtils; 11 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 12 | import org.springframework.security.core.userdetails.User; 13 | import org.springframework.security.core.userdetails.UserDetails; 14 | import org.springframework.security.core.userdetails.UserDetailsService; 15 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 16 | import org.springframework.stereotype.Service; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Collection; 20 | import java.util.Set; 21 | 22 | @Service 23 | public class CustomUserDetailsService implements UserDetailsService { 24 | 25 | private final AccountRepository userRepository; 26 | 27 | @Autowired 28 | public CustomUserDetailsService(AccountRepository userRepository) { 29 | this.userRepository = userRepository; 30 | } 31 | 32 | @Override 33 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 34 | 35 | Account account = userRepository.findByUsername(username); 36 | 37 | if (account == null) { 38 | // Not found... 39 | throw new UsernameNotFoundException( 40 | "User " + username + " not found."); 41 | } 42 | 43 | if (account.getRoles() == null || account.getRoles().isEmpty()) { 44 | // No Roles assigned to user... 45 | throw new UsernameNotFoundException("User not authorized."); 46 | } 47 | 48 | 49 | Collection grantedAuthorities = new ArrayList(); 50 | for (Role role : account.getRoles()) { 51 | grantedAuthorities.add(new SimpleGrantedAuthority(role.getCode())); 52 | } 53 | 54 | User userDetails = new User(account.getUsername(), 55 | account.getPassword(), account.isEnabled(), 56 | !account.isExpired(), !account.isCredentialsexpired(), 57 | !account.isLocked(), grantedAuthorities); 58 | 59 | return userDetails; 60 | } 61 | 62 | private final static class UserRepositoryUserDetails extends Account implements UserDetails { 63 | 64 | private static final long serialVersionUID = 1L; 65 | 66 | 67 | 68 | private UserRepositoryUserDetails(Account user) { 69 | super(user); 70 | } 71 | 72 | @Override 73 | public Collection getAuthorities() { 74 | Collection grantedAuthorities = new ArrayList(); 75 | for (Role role : getRoles()) { 76 | grantedAuthorities.add(new SimpleGrantedAuthority(role.getCode())); 77 | } 78 | return grantedAuthorities; 79 | } 80 | 81 | @Override 82 | public String getUsername() { 83 | return getUsername(); 84 | } 85 | 86 | @Override 87 | public boolean isAccountNonExpired() { 88 | return !isExpired(); 89 | } 90 | 91 | @Override 92 | public boolean isAccountNonLocked() { 93 | return !isLocked(); 94 | } 95 | 96 | @Override 97 | public boolean isCredentialsNonExpired() { 98 | return !isCredentialsexpired(); 99 | } 100 | 101 | @Override 102 | public boolean isEnabled() { 103 | return isEnabled(); 104 | } 105 | 106 | @Override 107 | public Set getRoles() { 108 | return getRoles(); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This repository is not supported anymore :( 2 | 3 | So guys thank you very much for your help and your feedback but unfortunately, I don't have enough time to support it. Of course, you can clone it and play with it but keep in mind that this project is a little bit out of date. 4 | 5 | Thanks again :) 6 | 7 | # Full Security Login System with Spring Boot 8 | 9 | This project contains all the configuration about an authentication and authorization system. 10 | We are using spring boot framework, spring security, spring oauth token and mysql. Cause we want ours projects be scalable as 11 | they can we are using the JWT token key for authentication with oauth2, this means that we don’t need sessions and session 12 | storage system so our application will work faster and better even in cloud server without any configuration. 13 | 14 | ### Features 15 | User Auhtentication 16 | 17 | User Authorazation 18 | 19 | Account Registration 20 | 21 | Forgot Password (Not Ready yet) 22 | 23 | ### The concept of OAuth2 authentication and JWT 24 | **OAuth1** 25 | --- 26 | OAuth1 has 3 steps and one loop. Check the diagram bellow and you will understand what we define as step and loop. 27 | ![alt tag](http://s12.postimg.org/mnjxjivrx/Screen_Shot_2016_02_13_at_8_27_17_PM.png) 28 | 29 | **loop**: We can say that a loop is a request between client and server 30 | 31 | **step**: As a step we define the blocks of algorithm “mythology” 32 | 33 | In login system client and server have to follow those steps 34 | 35 | - Sent the username and password to server via post request 36 | - server will send to the client the access token 37 | - client now have to store the access token into cookies or local storage 38 | 39 | When client now want to get all products (for example) 40 | 41 | - Client should send the access token as header parameter 42 | - server parse all request the check if the header access token field is correct 43 | - then return all products 44 | 45 | **OAuth2** 46 | --- 47 | OAuth2 is more complex that OAuth, it has 3 loops and 3 steps in each loop. 48 | ![alt tag](http://s12.postimg.org/t7rb3lz6l/Screen_Shot_2016_02_13_at_8_05_56_PM.png) 49 | 50 | **In the first loop** 51 | 52 | - client send the username and the password throw get request 53 | - server return the refresh token. Refresh token is something that give the ability to user to request for re access token. The main difference 54 | between them are that the refresh token exist for a lot longer and but the access token is the only one that give to you the ability to have real 55 | access to the application. 56 | - client get the refresh token and have to store it to cookies or local storage 57 | 58 | **The second loop** 59 | 60 | - client is ready to request for an access token, so it sends to server a get request with the refresh token to get the access token. 61 | - server check for the refresh token and if this is correct then 62 | - return to client the access token 63 | 64 | **The third loop** 65 | 66 | - Now user have to send the access token via get or as header parameter 67 | - Server analyze the access token and if this is correct then 68 | - return the request to user 69 | 70 | ### Database 71 | As database we are using the **MySql**, if you want to run the project you want edit the **resource/config/application.properties** file and add your database settings. After that import the databse.sql file that exists in root directory 72 | 73 | ### How to run it 74 | - First **Download** the project 75 | - Install all **Maven Dependencies** 76 | - Edit the **resource/config/application.properties** file and add your properties (Mysql Database, Gmail - Email Sender) 77 | - After that import the **Databse.sql** file that exists in root directory 78 | - Run the project by **spring-boot:run** agian 79 | 80 | ### How to use it 81 | To run this example you must import the databse file that exists in root directory 82 | 83 | -First ask for a access token **curl -X POST -vu clientapp:123456 http://localhost:8080/oauth/token -H "Accept: application/json" -d "password=papidakos123&username=papidakos&grant_type=password&scope=read%20write&client_secret=123456&client_id=clientapp"** 84 | 85 | -Now Try with postman get data from secure api uri. **Don't forget to replace the headers token with your access token** 86 | ![alt tag](http://s23.postimg.org/xmuqxrzsb/Screen_Shot_2016_02_29_at_4_00_24_PM.png) 87 | 88 | 89 | 90 | 91 | *The project has been created with Intelli IDEA IDE* 92 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/exceptions/DefaultExceptionAttributes.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.exceptions; 2 | 3 | import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.web.context.request.RequestAttributes; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import java.util.Date; 9 | import java.util.LinkedHashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * The default implementation of {@link ExceptionAttributes}. This 14 | * implementation seeks to be similar to the {@link DefaultErrorAttributes} 15 | * class, but differs in the source of the attribute data. The 16 | * DefaultErrorAttributes class requires the exception to be thrown from the 17 | * Controller so that it may gather attribute values from 18 | * {@link RequestAttributes}. This class uses the {@link Exception}, 19 | * {@link HttpServletRequest}, and {@link HttpStatus} values. 20 | * 21 | * Provides a Map of the following attributes when they are available: 22 | *
    23 | *
  • timestamp - The time that the exception attributes were processed 24 | *
  • status - The HTTP status code in the response 25 | *
  • error - The HTTP status reason text 26 | *
  • exception - The class name of the Exception 27 | *
  • message - The Exception message 28 | *
  • path - The HTTP request servlet path when the exception was thrown 29 | *
30 | * 31 | * @author Matt Warman 32 | * @see ExceptionAttributes 33 | * 34 | */ 35 | public class DefaultExceptionAttributes implements ExceptionAttributes { 36 | 37 | /** 38 | * The timestamp attribute key. 39 | */ 40 | public static final String TIMESTAMP = "timestamp"; 41 | /** 42 | * The status attribute key. 43 | */ 44 | public static final String STATUS = "status"; 45 | /** 46 | * The error attribute key. 47 | */ 48 | public static final String ERROR = "error"; 49 | /** 50 | * The exception attribute key. 51 | */ 52 | public static final String EXCEPTION = "exception"; 53 | /** 54 | * The message attribute key. 55 | */ 56 | public static final String MESSAGE = "message"; 57 | /** 58 | * The path attribute key. 59 | */ 60 | public static final String PATH = "path"; 61 | 62 | @Override 63 | public Map getExceptionAttributes(Exception exception, 64 | HttpServletRequest httpRequest, HttpStatus httpStatus) { 65 | 66 | Map exceptionAttributes = new LinkedHashMap(); 67 | 68 | exceptionAttributes.put(TIMESTAMP, new Date()); 69 | addHttpStatus(exceptionAttributes, httpStatus); 70 | addExceptionDetail(exceptionAttributes, exception); 71 | addPath(exceptionAttributes, httpRequest); 72 | 73 | return exceptionAttributes; 74 | } 75 | 76 | /** 77 | * Adds the status and error attribute values from the {@link HttpStatus} 78 | * value. 79 | * @param exceptionAttributes The Map of exception attributes. 80 | * @param httpStatus The HttpStatus enum value. 81 | */ 82 | private void addHttpStatus(Map exceptionAttributes, 83 | HttpStatus httpStatus) { 84 | exceptionAttributes.put(STATUS, httpStatus.value()); 85 | exceptionAttributes.put(ERROR, httpStatus.getReasonPhrase()); 86 | } 87 | 88 | /** 89 | * Adds the exception and message attribute values from the 90 | * {@link Exception}. 91 | * @param exceptionAttributes The Map of exception attributes. 92 | * @param exception The Exception object. 93 | */ 94 | private void addExceptionDetail(Map exceptionAttributes, 95 | Exception exception) { 96 | exceptionAttributes.put(EXCEPTION, exception.getClass().getName()); 97 | exceptionAttributes.put(MESSAGE, exception.getMessage()); 98 | } 99 | 100 | /** 101 | * Adds the path attribute value from the {@link HttpServletRequest}. 102 | * @param exceptionAttributes The Map of exception attributes. 103 | * @param httpRequest The HttpServletRequest object. 104 | */ 105 | private void addPath(Map exceptionAttributes, 106 | HttpServletRequest httpRequest) { 107 | exceptionAttributes.put(PATH, httpRequest.getServletPath()); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/Unmentionable/settings/security/OAuth2ServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.settings.security; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Qualifier; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.http.HttpMethod; 8 | import org.springframework.security.authentication.AuthenticationManager; 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 10 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; 11 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; 12 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 13 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 14 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 15 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; 16 | import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; 17 | import org.springframework.security.oauth2.provider.token.DefaultTokenServices; 18 | import org.springframework.security.oauth2.provider.token.TokenStore; 19 | import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; 20 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; 21 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; 22 | import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; 23 | 24 | @Configuration 25 | public class OAuth2ServerConfiguration { 26 | 27 | private static final String RESOURCE_ID = "restservice"; 28 | 29 | @Configuration 30 | @EnableResourceServer 31 | protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { 32 | 33 | @Autowired 34 | private JwtAccessTokenConverter jwtAccessTokenConverter; 35 | 36 | @Autowired 37 | private TokenStore tokenStore; 38 | 39 | @Override 40 | public void configure(ResourceServerSecurityConfigurer resources) { 41 | // @formatter:off 42 | resources 43 | .resourceId(RESOURCE_ID).tokenStore(tokenStore); 44 | // @formatter:on 45 | } 46 | 47 | @Override 48 | public void configure(HttpSecurity http) throws Exception { 49 | // @formatter:off 50 | http 51 | .csrf().disable() 52 | .authorizeRequests() 53 | .antMatchers("/api/**").authenticated(); 54 | 55 | 56 | 57 | // @formatter:on 58 | } 59 | 60 | } 61 | 62 | 63 | 64 | @Configuration 65 | @EnableAuthorizationServer 66 | protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { 67 | 68 | @Autowired 69 | private JwtAccessTokenConverter jwtAccessTokenConverter; 70 | 71 | @Autowired 72 | private TokenStore tokenStore; 73 | 74 | @Autowired 75 | @Qualifier("authenticationManagerBean") 76 | private AuthenticationManager authenticationManager; 77 | 78 | @Autowired 79 | CustomUserDetailsService userDetailsService; 80 | 81 | @Override 82 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 83 | // @formatter:off 84 | endpoints 85 | .tokenStore(tokenStore) 86 | .authenticationManager(authenticationManager) 87 | .accessTokenConverter(jwtAccessTokenConverter) 88 | .userDetailsService(userDetailsService); 89 | // @formatter:on 90 | } 91 | 92 | @Override 93 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 94 | // @formatter:off 95 | clients 96 | .inMemory() 97 | .withClient("clientapp") 98 | .authorizedGrantTypes("password","refresh_token") 99 | .authorities("USER") 100 | .scopes("read", "write") 101 | .resourceIds(RESOURCE_ID) 102 | .secret("123456"); 103 | // @formatter:on 104 | } 105 | 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | Unmentionable 6 | com.papidas 7 | 1.0-SNAPSHOT 8 | war 9 | 10 | com.papidas 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 1.8 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 1.3.1.RELEASE 22 | 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-security 35 | 36 | 37 | org.springframework.security.oauth 38 | spring-security-oauth2 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-data-jpa 45 | 46 | 47 | org.hsqldb 48 | hsqldb 49 | 50 | 51 | 52 | 53 | 54 | org.springframework 55 | spring-context-support 56 | 57 | 58 | com.google.guava 59 | guava 60 | 18.0 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-actuator 67 | 68 | 69 | 70 | 71 | org.springframework.boot 72 | spring-boot-starter-test 73 | test 74 | 75 | 76 | 77 | 78 | mysql 79 | mysql-connector-java 80 | 81 | 82 | 83 | 84 | javax.servlet 85 | jstl 86 | 87 | 88 | org.springframework.boot 89 | spring-boot-starter-tomcat 90 | provided 91 | 92 | 93 | org.apache.tomcat.embed 94 | tomcat-embed-jasper 95 | provided 96 | 97 | 98 | 99 | 100 | org.springframework.boot 101 | spring-boot-starter-mail 102 | 103 | 104 | 105 | 106 | com.fasterxml.jackson.core 107 | jackson-databind 108 | 109 | 110 | com.jayway.jsonpath 111 | json-path 112 | 0.8.1 113 | test 114 | 115 | 116 | com.jayway.jsonpath 117 | json-path-assert 118 | 0.8.1 119 | test 120 | 121 | 122 | 123 | org.springframework.security 124 | spring-security-jwt 125 | true 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | org.springframework.boot 134 | spring-boot-maven-plugin 135 | 136 | 137 | org.apache.maven.plugins 138 | maven-surefire-plugin 139 | 140 | false 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /Databese.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.4.9 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Φιλοξενητής: localhost:3306 6 | -- Χρόνος δημιουργίας: 29 Φεβ 2016 στις 16:04:54 7 | -- Έκδοση διακομιστή: 5.5.42 8 | -- Έκδοση PHP: 5.6.10 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | -- 14 | -- Βάση δεδομένων: `unmentionable` 15 | -- 16 | 17 | -- -------------------------------------------------------- 18 | 19 | -- 20 | -- Δομή πίνακα για τον πίνακα `account` 21 | -- 22 | 23 | CREATE TABLE `account` ( 24 | `id` bigint(20) NOT NULL, 25 | `credentialsexpired` bit(1) NOT NULL, 26 | `enabled` bit(1) NOT NULL, 27 | `expired` bit(1) NOT NULL, 28 | `locked` bit(1) NOT NULL, 29 | `password` varchar(255) NOT NULL, 30 | `username` varchar(255) NOT NULL 31 | ) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=latin1; 32 | 33 | -- 34 | -- Άδειασμα δεδομένων του πίνακα `account` 35 | -- 36 | 37 | INSERT INTO `account` (`id`, `credentialsexpired`, `enabled`, `expired`, `locked`, `password`, `username`) VALUES 38 | (3, b'0', b'1', b'0', b'0', 'papidakos', 'cpapidas'), 39 | (5, b'0', b'1', b'0', b'0', 'b8f57d6d6ec0a60dfe2e20182d4615b12e321cad9e2979e0b9f81e0d6eda78ad9b6dcfe53e4e22d1', 'cpapidas2'), 40 | (10, b'0', b'1', b'0', b'0', '$2a$10$h6cO.XkIuJ8I1kS2ZuaW/uRbv67.0ib7xOLdyLhAdWtN5cXRXSatW', 'cdddddc'), 41 | (11, b'0', b'1', b'0', b'0', '$2a$10$gTqi4RDXj5ovC.MoFHEoEOMMhPqjcvF/R49EjxwfUme6PwXhUHMwa', 'cc'), 42 | (13, b'0', b'1', b'0', b'0', '$2a$10$nlGCcuWdRcLDVOFYzudn5.tl4bhH47mkZDB3JubzbZy6obZVxgdmy', 'cd'), 43 | (15, b'0', b'1', b'0', b'0', '$2a$10$jT/N9/TgXnbGpdH0R1lfL.VlCihlR9jY7CBESimbtyAhOAwo9bguu', 'cs'), 44 | (16, b'0', b'1', b'0', b'0', '$2a$10$wupaAG1Cu8rGI4.kapj7rebxjGKfwjBYjkWbq.F.ZQKyiegu0exrq', 'wesdfsdfsdfs'), 45 | (17, b'0', b'1', b'0', b'0', '$2a$10$QufI1ku2vBT1NBCENVAKUeHsaktKTGZPzn/I66WdcTnXqEhbqAaC6', 'yy'), 46 | (18, b'0', b'1', b'0', b'0', '$2a$10$1OOIk5weuiDjS8S9BKpP3uBohiQ/RaLJjUJfiqdn8IIumXQ6hXn3K', 'mm33'), 47 | (19, b'0', b'1', b'0', b'0', '$2a$10$AZJQX.Zppg2.5geTAnC6V.XUJt.NGtYROpxoKpOdBCHoDCtbU/cNa', 'mm33dfgdfg'), 48 | (20, b'0', b'1', b'0', b'0', '$2a$10$lWh.9oyG1fz7NaMrEd32m.hLm4ucEhQdanNO09fmVFZB1YxyRC3ua', 'wesdfsdllfsdfs'), 49 | (21, b'0', b'1', b'0', b'0', '$2a$10$3ybRtrgCf1D.01aeWwheluIaOEJ8FRw0UZ7LBG.yzvY1.2/QTCghK', 'asdfafsd234'), 50 | (22, b'0', b'1', b'0', b'0', '$2a$10$x1loX5n0.b5MHDSfLWEJduhZgNU.6aVlaxAJ57PlWs.B.FlFDhL3K', 'asdfafsd234e'), 51 | (23, b'0', b'1', b'0', b'0', '$2a$10$qSyGWdtTl2w2ubms8P2c1.PR4.QAxFuAaFMyA133XsGXJfPNXnVzi', 'sdfsdf333'), 52 | (24, b'0', b'1', b'0', b'0', '$2a$10$/Dtd5WqgGTmTGDaB8Sd6vOTdyCu4qc9G94Igukv3QONpuB.aUkBue', 'sdfsdf333s'), 53 | (25, b'0', b'1', b'0', b'0', '$2a$10$MA50o0uzuyqERecKD7Rl4uqdlNDAm1x/4nE2.1cJ1DTvsf8799i.O', 'fasdf3333'), 54 | (26, b'0', b'1', b'0', b'0', '$2a$10$KL00afcwiDbq24EBev1Lj.CG5WSgydNra3LlmRu3CWJMIlNF/TQcO', 'fasdf33332'), 55 | (27, b'0', b'1', b'0', b'0', '$2a$10$PY9L787.w5VgoO9ZH0S62OQOz31.yARV6w.F2QfiRxbPTktZ0s9oy', 'Christost22'), 56 | (28, b'0', b'1', b'0', b'0', '$2a$10$Q9XKh8cc4J7qy0cy9OSksuXhOwMgoghPof8ILZxsULuk3gsMr65gC', 'asdfasdf234'), 57 | (29, b'0', b'1', b'0', b'0', '$2a$10$q4FAN8hsZKwEGWWmKUJK4uan4hBHhq2nd.NLm.tc2qDq3COjHfkz6', 'adsfsda234'), 58 | (30, b'0', b'1', b'0', b'0', '$2a$10$oXvocLdaQVC3n4wKYEtON./1EnOn8Jk5E9XTQEYHvJEjD7uj12Pvy', 'asdfasdf1234'), 59 | (31, b'0', b'1', b'0', b'0', '$2a$10$OFLSsg0x5A36HPq3.2wEDexxPlHQzWvQGo5rmfG5P6eeORtaQ/Ubq', 'asfdasdf3433'), 60 | (32, b'0', b'1', b'0', b'0', '$2a$10$XlUPeD83cMNbnjnXnXHcxubm0n9SrBd.LsCB3wxwAge6tYhwhumZq', 'fasfafd324'), 61 | (38, b'0', b'1', b'0', b'0', '$2a$10$SdZfafMVkFopgdvi/JrBn.h1KDIt.3Dfx6lbhLWB/CiGIBNiGGg/i', 'asdfasdf2344'), 62 | (39, b'0', b'1', b'0', b'0', '$2a$10$7sibRze3x6SVstcQYXSDe.LqhE0gUHvSfDTVZKyURr9EzKykw4sry', 'dsfsdff444'), 63 | (40, b'0', b'1', b'0', b'0', '$2a$10$EglFcHZnRyzrlmvb1ldV9e89IL1IqgdLhgeG/WGAR9UeXRP0fNYnW', 'ddsdsdfffd'), 64 | (41, b'0', b'1', b'0', b'0', '$2a$10$5RcLNvOD.r03ZayV53MxVuUQYbJvDtMrRFTTUVL9G2X0S6/ZxEo3S', 'papidakos'), 65 | (42, b'0', b'1', b'0', b'0', '$2a$10$eR.90pak84ipqOq9HVEMq.VgQ8O9JOFGOYROCzNzb7hdRhI/cEmem', 'papidakos2'), 66 | (43, b'0', b'1', b'0', b'0', 'spring', 'roy'), 67 | (44, b'0', b'1', b'0', b'0', '$2a$10$FbaEGdHDEEvpPHjSZkWNyecmsL79lH8qzJKexRo5EH4shvZfd4WhG', 'papapakiki'), 68 | (45, b'0', b'1', b'0', b'0', '$2a$10$69qe1gDLxu9T2n6fIV6s3.bY.uvNBEG/GvLcw7enccZ4HFLY2sMHy', 'papapakiki1'), 69 | (46, b'0', b'1', b'0', b'0', '$2a$10$qBQBPCNXVGd5l.qZd47MKuI.M88K8WiwbigPUxpUbx1WJA5b8oK8q', 'papalolif'), 70 | (47, b'0', b'1', b'0', b'0', '$2a$10$6LZfgsqeunoY4gLc1EZbe..6q5seZrA191F6iH81EeI709Y0h.1Py', 'fafafakoko'); 71 | 72 | -- -------------------------------------------------------- 73 | 74 | -- 75 | -- Δομή πίνακα για τον πίνακα `account_role` 76 | -- 77 | 78 | CREATE TABLE `account_role` ( 79 | `account_id` bigint(20) NOT NULL, 80 | `role_id` bigint(20) NOT NULL 81 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 82 | 83 | -- 84 | -- Άδειασμα δεδομένων του πίνακα `account_role` 85 | -- 86 | 87 | INSERT INTO `account_role` (`account_id`, `role_id`) VALUES 88 | (3, 1), 89 | (5, 1), 90 | (10, 1), 91 | (11, 1), 92 | (13, 1), 93 | (15, 1), 94 | (16, 1), 95 | (17, 1), 96 | (18, 1), 97 | (19, 1), 98 | (20, 1), 99 | (21, 1), 100 | (22, 1), 101 | (23, 1), 102 | (24, 1), 103 | (25, 1), 104 | (26, 1), 105 | (27, 1), 106 | (28, 1), 107 | (29, 1), 108 | (30, 1), 109 | (31, 1), 110 | (32, 1), 111 | (38, 1), 112 | (39, 1), 113 | (40, 1), 114 | (41, 1), 115 | (42, 1), 116 | (44, 1), 117 | (45, 1), 118 | (46, 1), 119 | (47, 1); 120 | 121 | -- -------------------------------------------------------- 122 | 123 | -- 124 | -- Δομή πίνακα για τον πίνακα `role` 125 | -- 126 | 127 | CREATE TABLE `role` ( 128 | `id` bigint(20) NOT NULL, 129 | `code` varchar(255) NOT NULL, 130 | `label` varchar(255) NOT NULL 131 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 132 | 133 | -- 134 | -- Άδειασμα δεδομένων του πίνακα `role` 135 | -- 136 | 137 | INSERT INTO `role` (`id`, `code`, `label`) VALUES 138 | (1, 'ROLE_USER', 'User'); 139 | 140 | -- 141 | -- Ευρετήρια για άχρηστους πίνακες 142 | -- 143 | 144 | -- 145 | -- Ευρετήρια για πίνακα `account` 146 | -- 147 | ALTER TABLE `account` 148 | ADD PRIMARY KEY (`id`), 149 | ADD UNIQUE KEY `UK_gex1lmaqpg0ir5g1f5eftyaa1` (`username`); 150 | 151 | -- 152 | -- Ευρετήρια για πίνακα `account_role` 153 | -- 154 | ALTER TABLE `account_role` 155 | ADD PRIMARY KEY (`account_id`,`role_id`), 156 | ADD KEY `FK_p2jpuvn8yll7x96rae4hvw3sj` (`role_id`); 157 | 158 | -- 159 | -- Ευρετήρια για πίνακα `role` 160 | -- 161 | ALTER TABLE `role` 162 | ADD PRIMARY KEY (`id`); 163 | 164 | -- 165 | -- AUTO_INCREMENT για άχρηστους πίνακες 166 | -- 167 | 168 | -- 169 | -- AUTO_INCREMENT για πίνακα `account` 170 | -- 171 | ALTER TABLE `account` 172 | MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=48; 173 | -- 174 | -- Περιορισμοί για άχρηστους πίνακες 175 | -- 176 | 177 | -- 178 | -- Περιορισμοί για πίνακα `account_role` 179 | -- 180 | ALTER TABLE `account_role` 181 | ADD CONSTRAINT `FK_ibmw1g5w37bmuh5fc0db7wn10` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`), 182 | ADD CONSTRAINT `FK_p2jpuvn8yll7x96rae4hvw3sj` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`); 183 | -------------------------------------------------------------------------------- /src/test/java/Unmentionable/service/AccountServiceTest.java: -------------------------------------------------------------------------------- 1 | package Unmentionable.service; 2 | 3 | import Unmentionable.AbstractTest; 4 | import Unmentionable.model.Account; 5 | import Unmentionable.model.Role; 6 | import org.junit.After; 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.dao.DataIntegrityViolationException; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | import org.springframework.transaction.annotation.Transactional; 15 | 16 | import javax.persistence.EntityExistsException; 17 | import javax.persistence.NoResultException; 18 | import javax.validation.ConstraintViolationException; 19 | import java.util.Collection; 20 | import java.util.HashSet; 21 | import java.util.Set; 22 | 23 | /** 24 | * Tests for the account service 25 | */ 26 | @Transactional 27 | @RunWith(SpringJUnit4ClassRunner.class) 28 | public class AccountServiceTest extends AbstractTest { 29 | 30 | @Autowired 31 | private AccountService accountService; 32 | 33 | 34 | @Before 35 | public void setUp(){ 36 | // Nothing yet 37 | } 38 | 39 | @After 40 | public void tearDown(){ 41 | // Nothing yet 42 | } 43 | 44 | /** 45 | * Get all accounts from database 46 | * - The list should not be null 47 | */ 48 | @Test 49 | public void testGetAllAccounts(){ 50 | 51 | // Add 2 accounts 52 | createNewAccount("account1", "account111"); 53 | createNewAccount("account2", "account222"); 54 | 55 | // Get all accounts from database 56 | Collection accountCollection = accountService.findAll(); 57 | 58 | // Accounts should be null 59 | Assert.assertNotNull("failure - Accounts collection should not be null"); 60 | } 61 | 62 | /** 63 | * Test the account registration 64 | * - if after creation the object is null 65 | * - if after creation the id is null 66 | * - if after creation the size of table has increment by 1 row 67 | */ 68 | @Test 69 | public void testRegister(){ 70 | 71 | // Get all accounts 72 | Collection accountCollection = accountService.findAll(); 73 | 74 | // Create a new account into database and get the object back 75 | Account createdAccount = createNewAccount("SampleUsername", "123123123Password"); 76 | 77 | // Get user roles 78 | Set roles = createdAccount.getRoles(); 79 | 80 | // Object and id of the object should not be null 81 | Assert.assertNotNull("failure - the returned object should not be null", createdAccount); 82 | Assert.assertNotNull("failure - the id of returned object should not be null", createdAccount.getId()); 83 | 84 | 85 | // Role size should be equals to 1 and not be null also be ROLE_USER 86 | Assert.assertNotNull("failure - should not be null", roles.iterator().next()); 87 | Assert.assertEquals("failure - should have a role of simple user", roles.size(), 1); 88 | Assert.assertEquals("failure - should have a role of ROLE_USER as code", roles.iterator().next().getCode(), "ROLE_USER"); 89 | 90 | // Get all accounts 91 | Collection accountCollectionAfterCreation = accountService.findAll(); 92 | 93 | // Check if the table count is grater + 1 94 | Assert.assertEquals("failure - the created account is not in database", accountCollectionAfterCreation.size() - accountCollection.size(), 1); 95 | 96 | } 97 | 98 | /** 99 | * Check what happens when a user try to put the same username with someone else 100 | * - Should throw an exception 101 | * - The exception should be type of DataIntegrityViolationException 102 | * - The second createdAccount2 should be null (not created) 103 | * - The first account should be created 104 | */ 105 | @Test 106 | public void testRegisterSameUsername(){ 107 | // Create a new account into database and get the object back 108 | Account createdAccount1 = createNewAccount("SampleUsernameSame", "123123123Password"); 109 | Account createdAccount2 = null; 110 | 111 | Exception e = null; 112 | 113 | try{ 114 | // Create a new account into database and get the object back 115 | createdAccount2 = createNewAccount("SampleUsernameSame", "ThisIsAnotherPassword"); 116 | }catch (DataIntegrityViolationException nre){ 117 | e = nre; 118 | } 119 | 120 | // Check if the exception is null and if is instanceof DataIntegrityViolationException 121 | Assert.assertNotNull("failure - expect exception not be null ", e); 122 | Assert.assertTrue("failure - the username should be unique", e instanceof DataIntegrityViolationException); 123 | 124 | // The second account should not be created 125 | Assert.assertNull("The first account should NOT be created ", createdAccount2); 126 | 127 | // The first account should be successful created 128 | Assert.assertNotNull("failure - the first account should be created successfully", createdAccount1); 129 | } 130 | 131 | /** 132 | * Check if user try to create an account with invalid username 133 | * - Check the exception if null 134 | * - Check the exception if is type of ConstraintViolationException 135 | * - Check if the account created 136 | */ 137 | @Test 138 | public void testInvalidUsername(){ 139 | 140 | Account createdAccount = null; 141 | Exception e = null; 142 | 143 | try{ 144 | // Create a new account with invalid username 145 | createdAccount = createNewAccount("123456", "123123123Password"); 146 | }catch (ConstraintViolationException nre){ 147 | e = nre; 148 | } 149 | 150 | // Check if the exception is null and if is instanceof DataIntegrityViolationException 151 | Assert.assertNotNull("failure - expect exception not be null ", e); 152 | Assert.assertTrue("failure - the username should be unique", e instanceof ConstraintViolationException); 153 | 154 | // The account should be null and NOT created 155 | Assert.assertNull("The first account should NOT be created ", createdAccount); 156 | } 157 | 158 | /** 159 | * Check if user try to create an account with invalid password 160 | * - Check the exception if null 161 | * - Check the exception if is type of ConstraintViolationException 162 | * - Check if the account created 163 | */ 164 | @Test 165 | public void testInvalidPassword(){ 166 | 167 | Account createdAccount = null; 168 | Exception e = null; 169 | 170 | try{ 171 | // Create a new account with invalid username 172 | createdAccount = createNewAccount("123456999", "12345"); 173 | }catch (EntityExistsException nre){ 174 | e = nre; 175 | } 176 | 177 | // Check if the exception is null and if is instanceof EntityExistsException 178 | Assert.assertNotNull("failure - expect exception not be null ", e); 179 | Assert.assertTrue("failure - the username should be unique", e instanceof EntityExistsException); 180 | 181 | // The account should be null and NOT created 182 | Assert.assertNull("The first account should NOT be created ", createdAccount); 183 | } 184 | 185 | 186 | /** 187 | * Create a new account into database 188 | * @param username - string of user username 189 | * @param password - the account password 190 | * @return the created account object 191 | */ 192 | private Account createNewAccount(String username, String password){ 193 | 194 | // Create an account object 195 | Account account = new Account(); 196 | account.setUsername(username); 197 | account.setPassword(password); 198 | 199 | // Create a new account 200 | return accountService.createNewAccount(account); 201 | } 202 | 203 | 204 | } 205 | -------------------------------------------------------------------------------- /.idea/artifacts/Unmentionable_war_exploded.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/target/com.papidas-1.0-SNAPSHOT 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 | -------------------------------------------------------------------------------- /.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 | --------------------------------------------------------------------------------