├── .gitignore ├── .idea ├── compiler.xml ├── dictionaries │ └── .xml ├── inspectionProfiles │ └── Project_Default.xml ├── libraries │ ├── Maven__aopalliance_aopalliance_1_0.xml │ ├── Maven__ch_qos_logback_logback_classic_1_1_11.xml │ ├── Maven__ch_qos_logback_logback_core_1_1_11.xml │ ├── Maven__com_alibaba_fastjson_1_2_38.xml │ ├── Maven__com_fasterxml_classmate_1_3_4.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml │ ├── Maven__com_google_guava_guava_20_0.xml │ ├── Maven__com_jayway_jsonpath_json_path_2_2_0.xml │ ├── Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml │ ├── Maven__commons_beanutils_commons_beanutils_1_9_3.xml │ ├── Maven__commons_codec_commons_codec_1_10.xml │ ├── Maven__commons_collections_commons_collections_3_2_2.xml │ ├── Maven__commons_io_commons_io_2_5.xml │ ├── Maven__commons_lang_commons_lang_2_6.xml │ ├── Maven__io_springfox_springfox_core_2_7_0.xml │ ├── Maven__io_springfox_springfox_schema_2_7_0.xml │ ├── Maven__io_springfox_springfox_spi_2_7_0.xml │ ├── Maven__io_springfox_springfox_spring_web_2_7_0.xml │ ├── Maven__io_springfox_springfox_swagger2_2_7_0.xml │ ├── Maven__io_springfox_springfox_swagger_common_2_7_0.xml │ ├── Maven__io_springfox_springfox_swagger_ui_2_7_0.xml │ ├── Maven__io_swagger_swagger_annotations_1_5_13.xml │ ├── Maven__io_swagger_swagger_models_1_5_13.xml │ ├── Maven__javax_inject_javax_inject_1.xml │ ├── Maven__javax_validation_validation_api_1_1_0_Final.xml │ ├── Maven__junit_junit_4_12.xml │ ├── Maven__mysql_mysql_connector_java_5_1_44.xml │ ├── Maven__net_bytebuddy_byte_buddy_1_6_14.xml │ ├── Maven__net_minidev_accessors_smart_1_1.xml │ ├── Maven__net_minidev_json_smart_2_2_1.xml │ ├── Maven__org_apache_commons_commons_pool2_2_4_2.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_20.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_20.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_20.xml │ ├── Maven__org_apache_tomcat_tomcat_jdbc_8_5_20.xml │ ├── Maven__org_apache_tomcat_tomcat_juli_8_5_20.xml │ ├── Maven__org_aspectj_aspectjweaver_1_8_10.xml │ ├── Maven__org_assertj_assertj_core_2_6_0.xml │ ├── Maven__org_bouncycastle_bcpkix_jdk15on_1_56.xml │ ├── Maven__org_bouncycastle_bcprov_jdk15on_1_56.xml │ ├── Maven__org_codehaus_jackson_jackson_core_asl_1_9_13.xml │ ├── Maven__org_codehaus_jackson_jackson_mapper_asl_1_9_13.xml │ ├── Maven__org_hamcrest_hamcrest_core_1_3.xml │ ├── Maven__org_hamcrest_hamcrest_library_1_3.xml │ ├── Maven__org_hibernate_hibernate_validator_5_3_5_Final.xml │ ├── Maven__org_javassist_javassist_3_21_0_GA.xml │ ├── Maven__org_jboss_logging_jboss_logging_3_3_1_Final.xml │ ├── Maven__org_mapstruct_mapstruct_1_1_0_Final.xml │ ├── Maven__org_mockito_mockito_core_1_10_19.xml │ ├── Maven__org_objenesis_objenesis_2_5_1.xml │ ├── Maven__org_ow2_asm_asm_5_0_3.xml │ ├── Maven__org_reflections_reflections_0_9_11.xml │ ├── Maven__org_skyscreamer_jsonassert_1_4_0.xml │ ├── Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml │ ├── Maven__org_slf4j_jul_to_slf4j_1_7_25.xml │ ├── Maven__org_slf4j_log4j_over_slf4j_1_7_25.xml │ ├── Maven__org_slf4j_slf4j_api_1_7_25.xml │ ├── Maven__org_springframework_boot_spring_boot_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_actuator_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_actuator_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_aop_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_data_redis_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_jdbc_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_logging_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_security_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_test_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_tomcat_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_web_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_test_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_7_RELEASE.xml │ ├── Maven__org_springframework_cloud_spring_cloud_commons_1_2_4_RELEASE.xml │ ├── Maven__org_springframework_cloud_spring_cloud_context_1_2_4_RELEASE.xml │ ├── Maven__org_springframework_cloud_spring_cloud_security_1_2_1_RELEASE.xml │ ├── Maven__org_springframework_cloud_spring_cloud_starter_1_2_4_RELEASE.xml │ ├── Maven__org_springframework_cloud_spring_cloud_starter_oauth2_1_2_1_RELEASE.xml │ ├── Maven__org_springframework_cloud_spring_cloud_starter_security_1_2_1_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_commons_1_13_7_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_keyvalue_1_2_7_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_redis_1_8_7_RELEASE.xml │ ├── Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml │ ├── Maven__org_springframework_plugin_spring_plugin_metadata_1_2_0_RELEASE.xml │ ├── Maven__org_springframework_security_oauth_spring_security_oauth2_2_0_14_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_config_4_2_3_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_core_4_2_3_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_crypto_4_2_3_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_jwt_1_0_8_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_rsa_1_0_3_RELEASE.xml │ ├── Maven__org_springframework_security_spring_security_web_4_2_3_RELEASE.xml │ ├── Maven__org_springframework_session_spring_session_1_3_1_RELEASE.xml │ ├── Maven__org_springframework_social_spring_social_config_1_1_4_RELEASE.xml │ ├── Maven__org_springframework_social_spring_social_core_1_1_4_RELEASE.xml │ ├── Maven__org_springframework_social_spring_social_security_1_1_4_RELEASE.xml │ ├── Maven__org_springframework_social_spring_social_web_1_1_4_RELEASE.xml │ ├── Maven__org_springframework_spring_aop_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_beans_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_context_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_context_support_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_core_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_expression_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_jdbc_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_oxm_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_test_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_tx_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_web_4_3_11_RELEASE.xml │ ├── Maven__org_springframework_spring_webmvc_4_3_11_RELEASE.xml │ ├── Maven__org_yaml_snakeyaml_1_17.xml │ └── Maven__redis_clients_jedis_2_9_0.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── LICENSE ├── README.md ├── imooc-security-app ├── imooc-security-app.iml └── pom.xml ├── imooc-security-browser ├── imooc-security-browser.iml ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── imooc │ │ └── security │ │ └── browser │ │ ├── BrowserSecurityConfig.java │ │ ├── BrowserSecurityController.java │ │ ├── MyUserDetailsService.java │ │ ├── authentication │ │ ├── ImoocAuthenticationFailureHandler.java │ │ └── ImoocAuthenticationSuccessHandler.java │ │ └── support │ │ └── SimpleResponse.java │ └── resources │ └── resources │ └── imooc-signIn.html ├── imooc-security-core ├── imooc-security-core.iml ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── imooc │ └── security │ └── core │ ├── authentication │ └── mobile │ │ ├── SmsCodeAuthenticationFilter.java │ │ ├── SmsCodeAuthenticationProvider.java │ │ ├── SmsCodeAuthenticationSecurityConfig.java │ │ └── SmsCodeAuthenticationToken.java │ ├── config │ └── SecurityCoreConfig.java │ ├── properties │ ├── BrowserProperties.java │ ├── ImageCodeProperties.java │ ├── LoginType.java │ ├── SecurityConstants.java │ ├── SecurityProperties.java │ ├── SmsCodeProperties.java │ └── ValidateCodeProperties.java │ └── validate │ └── code │ ├── SmsCodeFilter.java │ ├── ValidateBeanConfig.java │ ├── ValidateCode.java │ ├── ValidateCodeController.java │ ├── ValidateCodeException.java │ ├── ValidateCodeFilter.java │ ├── ValidateCodeGenerator.java │ ├── ValidateCodeProcessor.java │ ├── ValidateCodeProcessorHolder.java │ ├── ValidateCodeType.java │ ├── image │ ├── ImageCode.java │ ├── ImageCodeGenerator.java │ └── ImageCodeProcessor.java │ ├── impl │ └── AbstractValidateCodeProcessor.java │ └── sms │ ├── DefaultSmsCodeSender.java │ ├── SmsCodeGenerator.java │ ├── SmsCodeProcessor.java │ └── SmsCodeSender.java ├── imooc-security-demo ├── imooc-security-demo.iml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── imooc │ │ │ ├── DemoApplication.java │ │ │ ├── dto │ │ │ ├── Data.java │ │ │ ├── FileInfo.java │ │ │ ├── User.java │ │ │ ├── UserJson.java │ │ │ └── UserQueryCondition.java │ │ │ ├── exception │ │ │ └── UserNotExistException.java │ │ │ ├── service │ │ │ ├── HelloService.java │ │ │ └── impl │ │ │ │ └── HelloServiceImpl.java │ │ │ ├── utils │ │ │ └── BeanUtils.java │ │ │ ├── validator │ │ │ ├── MyConstraint.java │ │ │ └── MyConstraintValidator.java │ │ │ └── web │ │ │ ├── aspect │ │ │ └── TimeAspect.java │ │ │ ├── async │ │ │ ├── AsyncController.java │ │ │ ├── DeferredResultHolder.java │ │ │ ├── MockQueue.java │ │ │ └── QueueListener.java │ │ │ ├── config │ │ │ ├── Swagger2Config.java │ │ │ └── WebConfig.java │ │ │ ├── controller │ │ │ ├── 1510457275352.txt │ │ │ ├── ControllerExceptionHandler.java │ │ │ ├── FileController.java │ │ │ ├── MyController.java │ │ │ └── UserController.java │ │ │ ├── filter │ │ │ └── TimeFilter.java │ │ │ └── interceptor │ │ │ └── TimeInterceptor.java │ └── resources │ │ ├── application.properties │ │ └── resources │ │ ├── demo-signIn.html │ │ ├── error │ │ ├── 404.html │ │ └── 500.html │ │ └── index1.html │ └── test │ └── java │ └── com │ └── imooc │ └── web │ └── controller │ └── UserControllerTest.java ├── imooc-security.iml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | imooc-security.iml 25 | imooc-security-demo.iml 26 | imooc-security-core.iml 27 | imooc-security-browser.iml 28 | imooc-security-app.iml 29 | 30 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.idea/dictionaries/.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 56 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__aopalliance_aopalliance_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__ch_qos_logback_logback_classic_1_1_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__ch_qos_logback_logback_core_1_1_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_alibaba_fastjson_1_2_38.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_classmate_1_3_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_guava_guava_20_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_jayway_jsonpath_json_path_2_2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_beanutils_commons_beanutils_1_9_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_codec_commons_codec_1_10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_collections_commons_collections_3_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_io_commons_io_2_5.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__io_springfox_springfox_core_2_7_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_schema_2_7_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_spi_2_7_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_spring_web_2_7_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_swagger2_2_7_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_swagger_common_2_7_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_swagger_ui_2_7_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_swagger_swagger_annotations_1_5_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_swagger_swagger_models_1_5_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_inject_javax_inject_1.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__junit_junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__mysql_mysql_connector_java_5_1_44.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_bytebuddy_byte_buddy_1_6_14.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_minidev_accessors_smart_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_minidev_json_smart_2_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_pool2_2_4_2.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_5_20.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_5_20.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_5_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_tomcat_jdbc_8_5_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_tomcat_juli_8_5_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_aspectj_aspectjweaver_1_8_10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_assertj_assertj_core_2_6_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bouncycastle_bcpkix_jdk15on_1_56.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_bouncycastle_bcprov_jdk15on_1_56.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_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__org_hamcrest_hamcrest_core_1_3.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_hibernate_hibernate_validator_5_3_5_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_javassist_javassist_3_21_0_GA.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_1_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_mapstruct_mapstruct_1_1_0_Final.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_objenesis_objenesis_2_5_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_ow2_asm_asm_5_0_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_reflections_reflections_0_9_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_skyscreamer_jsonassert_1_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_log4j_over_slf4j_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_1_5_7_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_actuator_1_5_7_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_5_7_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_1_5_7_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_5_7_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_5_7_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_redis_1_5_7_RELEASE.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_5_7_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_5_7_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_5_7_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_5_7_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_5_7_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_5_7_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_test_1_5_7_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_7_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_cloud_spring_cloud_commons_1_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_cloud_spring_cloud_context_1_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_cloud_spring_cloud_security_1_2_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_cloud_spring_cloud_starter_1_2_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_cloud_spring_cloud_starter_oauth2_1_2_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_cloud_spring_cloud_starter_security_1_2_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_13_7_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_data_spring_data_keyvalue_1_2_7_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_data_spring_data_redis_1_8_7_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_plugin_spring_plugin_metadata_1_2_0_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_14_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_security_spring_security_config_4_2_3_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_2_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_security_spring_security_crypto_4_2_3_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_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_security_spring_security_rsa_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_2_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_session_spring_session_1_3_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_social_spring_social_config_1_1_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_social_spring_social_core_1_1_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_social_spring_social_security_1_1_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_social_spring_social_web_1_1_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_support_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_core_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jdbc_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_oxm_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_test_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_tx_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_web_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_webmvc_4_3_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__redis_clients_jedis_2_9_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # imooc-security 2 | 根据imooc写的spring security 3 | -------------------------------------------------------------------------------- /imooc-security-app/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | imooc-security 7 | com.imooc.security 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | imooc-security-app 13 | 14 | 15 | 16 | com.imooc.security 17 | imooc-security-core 18 | ${imooc.security.version} 19 | 20 | 21 | -------------------------------------------------------------------------------- /imooc-security-browser/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | imooc-security 7 | com.imooc.security 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | imooc-security-browser 13 | 14 | 15 | 16 | com.imooc.security 17 | imooc-security-core 18 | ${imooc.security.version} 19 | 20 | 21 | org.springframework.session 22 | spring-session 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /imooc-security-browser/src/main/java/com/imooc/security/browser/BrowserSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.browser; 2 | 3 | import com.imooc.security.core.authentication.mobile.SmsCodeAuthenticationSecurityConfig; 4 | import com.imooc.security.core.properties.SecurityProperties; 5 | import com.imooc.security.core.validate.code.SmsCodeFilter; 6 | import com.imooc.security.core.validate.code.ValidateCodeFilter; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 11 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 12 | import org.springframework.security.core.userdetails.UserDetailsService; 13 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 14 | import org.springframework.security.crypto.password.PasswordEncoder; 15 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 16 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 17 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 18 | import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl; 19 | import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository; 20 | 21 | import javax.sql.DataSource; 22 | 23 | 24 | @Configuration 25 | public class BrowserSecurityConfig extends WebSecurityConfigurerAdapter { 26 | 27 | @Autowired 28 | private SecurityProperties properties; 29 | 30 | @Autowired 31 | private AuthenticationSuccessHandler imoocAuthenticationSuccessHandler; 32 | 33 | @Autowired 34 | private AuthenticationFailureHandler imoocAuthenticationFailureHandler; 35 | 36 | @Autowired 37 | private DataSource dataSource; 38 | 39 | @Autowired 40 | private UserDetailsService userDetailsService; 41 | @Autowired 42 | private SmsCodeAuthenticationSecurityConfig smsCodeAuthenticationSecurityConfig; 43 | 44 | @Bean 45 | public PasswordEncoder passwordEncoder(){ 46 | return new BCryptPasswordEncoder(); 47 | } 48 | 49 | @Bean 50 | public PersistentTokenRepository persistentTokenRepository(){ 51 | JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl(); 52 | tokenRepository.setDataSource(dataSource); 53 | // tokenRepository.setCreateTableOnStartup(true); 54 | return tokenRepository; 55 | } 56 | 57 | @Override 58 | protected void configure(HttpSecurity http) throws Exception { 59 | 60 | ValidateCodeFilter validateCodeFilter = new ValidateCodeFilter(); 61 | validateCodeFilter.setAuthenticationFailureHandler(imoocAuthenticationFailureHandler); 62 | validateCodeFilter.setSecurityProperties(properties); 63 | validateCodeFilter.afterPropertiesSet(); 64 | 65 | SmsCodeFilter smsCodeFilter = new SmsCodeFilter(); 66 | smsCodeFilter.setAuthenticationFailureHandler(imoocAuthenticationFailureHandler); 67 | smsCodeFilter.setSecurityProperties(properties); 68 | smsCodeFilter.afterPropertiesSet(); 69 | 70 | //表单登陆进行身份认证 71 | http.addFilterBefore(smsCodeFilter,UsernamePasswordAuthenticationFilter.class) 72 | .addFilterBefore(validateCodeFilter, UsernamePasswordAuthenticationFilter.class) 73 | .formLogin() 74 | .loginPage("/authentication/require") 75 | .loginProcessingUrl("/authentication/form") 76 | .successHandler(imoocAuthenticationSuccessHandler) 77 | .failureHandler(imoocAuthenticationFailureHandler) 78 | .and() 79 | .rememberMe() 80 | .tokenRepository(persistentTokenRepository()) 81 | .tokenValiditySeconds(properties.getBrowser().getRememberSeconds()) 82 | .userDetailsService(userDetailsService) 83 | .and() 84 | .authorizeRequests() 85 | .antMatchers("/authentication/require", 86 | properties.getBrowser().getLoginPage(), 87 | "/code/*","/test/*").permitAll() 88 | .anyRequest() 89 | .authenticated() 90 | .and() 91 | .csrf().disable() 92 | .apply(smsCodeAuthenticationSecurityConfig); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /imooc-security-browser/src/main/java/com/imooc/security/browser/BrowserSecurityController.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.browser; 2 | 3 | import com.imooc.security.browser.support.SimpleResponse; 4 | import com.imooc.security.core.properties.SecurityProperties; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.security.web.DefaultRedirectStrategy; 9 | import org.springframework.security.web.RedirectStrategy; 10 | import org.springframework.security.web.savedrequest.HttpSessionRequestCache; 11 | import org.springframework.security.web.savedrequest.RequestCache; 12 | import org.springframework.security.web.savedrequest.SavedRequest; 13 | import org.springframework.util.StringUtils; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.io.IOException; 20 | 21 | @RestController 22 | public class BrowserSecurityController { 23 | private Logger logger = LoggerFactory.getLogger(getClass()); 24 | 25 | private RequestCache requestCache = new HttpSessionRequestCache(); 26 | 27 | private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); 28 | 29 | @Autowired 30 | private SecurityProperties properties; 31 | 32 | /** 33 | * 当需要身份认证时跳转到这个controller 34 | * 35 | * @param request 36 | * @param response 37 | * @return 38 | */ 39 | @RequestMapping("/authentication/require") 40 | public SimpleResponse requireAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException { 41 | SavedRequest savedRequest = requestCache.getRequest(request, response); 42 | if (savedRequest != null) { 43 | String targetUrl = savedRequest.getRedirectUrl(); 44 | logger.info("引发跳转的请求是:"+targetUrl); 45 | if(StringUtils.endsWithIgnoreCase(targetUrl,".html")){ 46 | redirectStrategy.sendRedirect(request,response,properties.getBrowser().getLoginPage()); 47 | } 48 | } 49 | return new SimpleResponse("访问的服务器需要身份认证,请引导用户到登录页面"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /imooc-security-browser/src/main/java/com/imooc/security/browser/MyUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.browser; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.core.authority.AuthorityUtils; 7 | import org.springframework.security.core.userdetails.User; 8 | import org.springframework.security.core.userdetails.UserDetails; 9 | import org.springframework.security.core.userdetails.UserDetailsService; 10 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 11 | import org.springframework.security.crypto.password.PasswordEncoder; 12 | import org.springframework.stereotype.Component; 13 | 14 | @Component 15 | public class MyUserDetailsService implements UserDetailsService{ 16 | private Logger logger = LoggerFactory.getLogger(getClass()); 17 | 18 | @Autowired 19 | private PasswordEncoder passwordEncoder; 20 | 21 | @Override 22 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 23 | logger.info("登陆用户名:"+username); 24 | //根据用户名查找用户信息 25 | String password = passwordEncoder.encode("123456"); 26 | logger.info("数据库密码是:"+password); 27 | return new User(username,password, 28 | true,true,true,true, 29 | AuthorityUtils.commaSeparatedStringToAuthorityList("admin")); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /imooc-security-browser/src/main/java/com/imooc/security/browser/authentication/ImoocAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.browser.authentication; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.imooc.security.browser.support.SimpleResponse; 5 | import com.imooc.security.core.properties.LoginType; 6 | import com.imooc.security.core.properties.SecurityProperties; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.security.core.AuthenticationException; 12 | import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; 13 | import org.springframework.stereotype.Component; 14 | 15 | import javax.servlet.ServletException; 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.io.IOException; 19 | 20 | @Component("imoocAuthenticationFailureHandler") 21 | public class ImoocAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { 22 | 23 | private Logger logger = LoggerFactory.getLogger(getClass()); 24 | 25 | @Autowired 26 | private ObjectMapper objectMapper; 27 | 28 | @Autowired 29 | private SecurityProperties securityProperties; 30 | 31 | @Override 32 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException { 33 | logger.info("登录失败"); 34 | if(LoginType.JSON.equals(securityProperties.getBrowser().getLoginType())){ 35 | response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); 36 | response.setContentType("application/json;charset=UTF-8"); 37 | response.getWriter().write(objectMapper.writeValueAsString(new SimpleResponse(e.getMessage()))); 38 | }else { 39 | super.onAuthenticationFailure(request,response,e); 40 | } 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /imooc-security-browser/src/main/java/com/imooc/security/browser/authentication/ImoocAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.browser.authentication; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.imooc.security.core.properties.LoginType; 5 | import com.imooc.security.core.properties.SecurityProperties; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.core.Authentication; 10 | import org.springframework.security.web.DefaultRedirectStrategy; 11 | import org.springframework.security.web.RedirectStrategy; 12 | import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; 13 | import org.springframework.stereotype.Component; 14 | 15 | import javax.servlet.ServletException; 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.io.IOException; 19 | 20 | @Component("imoocAuthenticationSuccessHandler") 21 | public class ImoocAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { 22 | 23 | private Logger logger = LoggerFactory.getLogger(getClass()); 24 | 25 | private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); 26 | 27 | @Autowired 28 | private ObjectMapper objectMapper; 29 | 30 | @Autowired 31 | private SecurityProperties securityProperties; 32 | 33 | @Override 34 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 35 | logger.info("登录成功"); 36 | if(LoginType.JSON.equals(securityProperties.getBrowser().getLoginType())){ 37 | response.setContentType("application/json;charset=UTF-8"); 38 | response.getWriter().write(objectMapper.writeValueAsString(authentication)); 39 | }else{ 40 | // redirectStrategy.sendRedirect(request,response,"/index1.html"); 41 | super.onAuthenticationSuccess(request,response,authentication); 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /imooc-security-browser/src/main/java/com/imooc/security/browser/support/SimpleResponse.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.browser.support; 2 | 3 | public class SimpleResponse { 4 | private Object content; 5 | 6 | public SimpleResponse(Object content) { 7 | this.content = content; 8 | } 9 | 10 | public Object getContent() { 11 | return content; 12 | } 13 | 14 | public void setContent(Object content) { 15 | this.content = content; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /imooc-security-browser/src/main/resources/resources/imooc-signIn.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录 6 | 7 | 8 |

标准登录页面

9 |

表单登录

10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
用户名:
密码:
图形验证码: 23 | 24 | 25 |
记住我
34 |
35 | 36 |

短信登录

37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 50 | 51 | 52 | 53 |
手机号:
短信验证码: 46 | 47 | 发送验证码 48 |
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /imooc-security-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | imooc-security 7 | com.imooc.security 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | imooc-security-core 13 | 14 | 15 | org.springframework.cloud 16 | spring-cloud-starter-oauth2 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-data-redis 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-jdbc 25 | 26 | 27 | mysql 28 | mysql-connector-java 29 | 30 | 31 | org.springframework.social 32 | spring-social-config 33 | 34 | 35 | org.springframework.social 36 | spring-social-core 37 | 38 | 39 | org.springframework.social 40 | spring-social-security 41 | 42 | 43 | org.springframework.social 44 | spring-social-web 45 | 46 | 47 | commons-lang 48 | commons-lang 49 | 50 | 51 | commons-collections 52 | commons-collections 53 | 54 | 55 | commons-beanutils 56 | commons-beanutils 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/authentication/mobile/SmsCodeAuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.authentication.mobile; 2 | 3 | import org.springframework.security.authentication.AuthenticationServiceException; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.core.AuthenticationException; 6 | import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; 7 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | public class SmsCodeAuthenticationFilter extends AbstractAuthenticationProcessingFilter { 13 | public static final String IMOOC_FORM_MOBILE_KEY = "mobile"; 14 | private String mobileParameter = IMOOC_FORM_MOBILE_KEY; 15 | private boolean postOnly = true; 16 | 17 | public SmsCodeAuthenticationFilter() { 18 | super(new AntPathRequestMatcher("/authentication/mobile", "POST")); 19 | } 20 | 21 | public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { 22 | if(this.postOnly && !request.getMethod().equals("POST")) { 23 | throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); 24 | } else { 25 | String mobile = this.obtainMobile(request); 26 | if(mobile == null) { 27 | mobile = ""; 28 | } 29 | 30 | mobile = mobile.trim(); 31 | SmsCodeAuthenticationToken authRequest = new SmsCodeAuthenticationToken(mobile); 32 | this.setDetails(request, authRequest); 33 | return this.getAuthenticationManager().authenticate(authRequest); 34 | } 35 | } 36 | 37 | /** 38 | * 获取手机号的方法 39 | * @param request 40 | * @return 41 | */ 42 | protected String obtainMobile(HttpServletRequest request) { 43 | return request.getParameter(this.mobileParameter); 44 | } 45 | 46 | protected void setDetails(HttpServletRequest request, SmsCodeAuthenticationToken authRequest) { 47 | authRequest.setDetails(this.authenticationDetailsSource.buildDetails(request)); 48 | } 49 | 50 | public void setPostOnly(boolean postOnly) { 51 | this.postOnly = postOnly; 52 | } 53 | 54 | public String getMobileParameter() { 55 | return mobileParameter; 56 | } 57 | 58 | public void setMobileParameter(String mobileParameter) { 59 | this.mobileParameter = mobileParameter; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/authentication/mobile/SmsCodeAuthenticationProvider.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.authentication.mobile; 2 | 3 | import org.springframework.security.authentication.AuthenticationProvider; 4 | import org.springframework.security.authentication.InternalAuthenticationServiceException; 5 | import org.springframework.security.core.Authentication; 6 | import org.springframework.security.core.AuthenticationException; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | 10 | public class SmsCodeAuthenticationProvider implements AuthenticationProvider { 11 | 12 | private UserDetailsService userDetailsService; 13 | 14 | @Override 15 | public Authentication authenticate(Authentication authentication) throws AuthenticationException { 16 | SmsCodeAuthenticationToken authenticationToken = (SmsCodeAuthenticationToken) authentication; 17 | UserDetails user = userDetailsService.loadUserByUsername((String) authenticationToken.getPrincipal()); 18 | if(user==null){ 19 | throw new InternalAuthenticationServiceException("无法获取用户信息"); 20 | } 21 | SmsCodeAuthenticationToken authenticationResult = new SmsCodeAuthenticationToken(user,user.getAuthorities()); 22 | //把未认证的信息放到已认证的detail里面 23 | authenticationResult.setDetails(authenticationToken.getDetails()); 24 | 25 | return authenticationResult; 26 | } 27 | 28 | @Override 29 | public boolean supports(Class authentication) { 30 | return SmsCodeAuthenticationToken.class.isAssignableFrom(authentication); 31 | } 32 | 33 | public UserDetailsService getUserDetailsService() { 34 | return userDetailsService; 35 | } 36 | 37 | public void setUserDetailsService(UserDetailsService userDetailsService) { 38 | this.userDetailsService = userDetailsService; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/authentication/mobile/SmsCodeAuthenticationSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.authentication.mobile; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.security.authentication.AuthenticationManager; 5 | import org.springframework.security.config.annotation.SecurityConfigurerAdapter; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.core.userdetails.UserDetailsService; 8 | import org.springframework.security.web.DefaultSecurityFilterChain; 9 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 10 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 11 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 12 | import org.springframework.stereotype.Component; 13 | 14 | @Component 15 | public class SmsCodeAuthenticationSecurityConfig extends SecurityConfigurerAdapter { 16 | 17 | @Autowired 18 | private AuthenticationSuccessHandler imoocAuthenticationSuccessHandler; 19 | @Autowired 20 | private AuthenticationFailureHandler imoocAuthenticationFailureHandler; 21 | @Autowired 22 | private UserDetailsService userDetailsService; 23 | 24 | @Override 25 | public void configure(HttpSecurity http) throws Exception { 26 | SmsCodeAuthenticationFilter smsCodeAuthenticationFilter = new SmsCodeAuthenticationFilter(); 27 | smsCodeAuthenticationFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class)); 28 | smsCodeAuthenticationFilter.setAuthenticationSuccessHandler(imoocAuthenticationSuccessHandler); 29 | smsCodeAuthenticationFilter.setAuthenticationFailureHandler(imoocAuthenticationFailureHandler); 30 | 31 | SmsCodeAuthenticationProvider smsCodeAuthenticationProvider = new SmsCodeAuthenticationProvider(); 32 | smsCodeAuthenticationProvider.setUserDetailsService(userDetailsService); 33 | 34 | http.authenticationProvider(smsCodeAuthenticationProvider) 35 | .addFilterAfter(smsCodeAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/authentication/mobile/SmsCodeAuthenticationToken.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.authentication.mobile; 2 | 3 | import org.springframework.security.authentication.AbstractAuthenticationToken; 4 | import org.springframework.security.core.GrantedAuthority; 5 | 6 | import java.util.Collection; 7 | 8 | public class SmsCodeAuthenticationToken extends AbstractAuthenticationToken { 9 | private static final long serialVersionUID = 420L; 10 | private final Object principal; 11 | 12 | public SmsCodeAuthenticationToken(String mobile) { 13 | super((Collection)null); 14 | this.principal = mobile; 15 | this.setAuthenticated(false); 16 | } 17 | 18 | public SmsCodeAuthenticationToken(Object principal, Collection authorities) { 19 | super(authorities); 20 | this.principal = principal; 21 | super.setAuthenticated(true); 22 | } 23 | 24 | public Object getCredentials() { 25 | return null; 26 | } 27 | 28 | public Object getPrincipal() { 29 | return this.principal; 30 | } 31 | 32 | public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { 33 | if(isAuthenticated) { 34 | throw new IllegalArgumentException("Cannot set this token to trusted - use constructor which takes a GrantedAuthority list instead"); 35 | } else { 36 | super.setAuthenticated(false); 37 | } 38 | } 39 | 40 | public void eraseCredentials() { 41 | super.eraseCredentials(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/config/SecurityCoreConfig.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.config; 2 | 3 | import com.imooc.security.core.properties.SecurityProperties; 4 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | @EnableConfigurationProperties(SecurityProperties.class) 9 | public class SecurityCoreConfig { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/properties/BrowserProperties.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.properties; 2 | 3 | public class BrowserProperties { 4 | private String loginPage = "/imooc-signIn.html"; 5 | 6 | private LoginType loginType = LoginType.JSON; 7 | 8 | private int rememberSeconds = 3600; 9 | 10 | public String getLoginPage() { 11 | return loginPage; 12 | } 13 | 14 | public void setLoginPage(String loginPage) { 15 | this.loginPage = loginPage; 16 | } 17 | 18 | public LoginType getLoginType() { 19 | return loginType; 20 | } 21 | 22 | public void setLoginType(LoginType loginType) { 23 | this.loginType = loginType; 24 | } 25 | 26 | public int getRememberSeconds() { 27 | return rememberSeconds; 28 | } 29 | 30 | public void setRememberSeconds(int rememberSeconds) { 31 | this.rememberSeconds = rememberSeconds; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/properties/ImageCodeProperties.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.properties; 2 | 3 | public class ImageCodeProperties extends SmsCodeProperties { 4 | 5 | private int width=67; 6 | private int height=23; 7 | 8 | private String url; 9 | 10 | public ImageCodeProperties() { 11 | setLength(4); 12 | } 13 | 14 | public int getWidth() { 15 | return width; 16 | } 17 | 18 | public void setWidth(int width) { 19 | this.width = width; 20 | } 21 | 22 | public int getHeight() { 23 | return height; 24 | } 25 | 26 | public void setHeight(int height) { 27 | this.height = height; 28 | } 29 | 30 | 31 | public String getUrl() { 32 | return url; 33 | } 34 | 35 | public void setUrl(String url) { 36 | this.url = url; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/properties/LoginType.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.properties; 2 | 3 | public enum LoginType { 4 | REDIRECT, 5 | JSON 6 | } 7 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/properties/SecurityConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.imooc.security.core.properties; 5 | 6 | /** 7 | * @author zhailiang 8 | * 9 | */ 10 | public interface SecurityConstants { 11 | 12 | /** 13 | * 默认的处理验证码的url前缀 14 | */ 15 | public static final String DEFAULT_VALIDATE_CODE_URL_PREFIX = "/code"; 16 | /** 17 | * 当请求需要身份认证时,默认跳转的url 18 | * 19 | * @see SecurityController 20 | */ 21 | public static final String DEFAULT_UNAUTHENTICATION_URL = "/authentication/require"; 22 | /** 23 | * 默认的用户名密码登录请求处理url 24 | */ 25 | public static final String DEFAULT_LOGIN_PROCESSING_URL_FORM = "/authentication/form"; 26 | /** 27 | * 默认的手机验证码登录请求处理url 28 | */ 29 | public static final String DEFAULT_LOGIN_PROCESSING_URL_MOBILE = "/authentication/mobile"; 30 | /** 31 | * 默认登录页面 32 | * 33 | * @see SecurityController 34 | */ 35 | public static final String DEFAULT_LOGIN_PAGE_URL = "/imooc-signIn.html"; 36 | /** 37 | * 验证图片验证码时,http请求中默认的携带图片验证码信息的参数的名称 38 | */ 39 | public static final String DEFAULT_PARAMETER_NAME_CODE_IMAGE = "imageCode"; 40 | /** 41 | * 验证短信验证码时,http请求中默认的携带短信验证码信息的参数的名称 42 | */ 43 | public static final String DEFAULT_PARAMETER_NAME_CODE_SMS = "smsCode"; 44 | /** 45 | * 发送短信验证码 或 验证短信验证码时,传递手机号的参数的名称 46 | */ 47 | public static final String DEFAULT_PARAMETER_NAME_MOBILE = "mobile"; 48 | /** 49 | * session失效默认的跳转地址 50 | */ 51 | public static final String DEFAULT_SESSION_INVALID_URL = "/session/invalid"; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/properties/SecurityProperties.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.properties; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | @ConfigurationProperties(prefix = "imooc.security") 6 | public class SecurityProperties { 7 | 8 | private BrowserProperties browser = new BrowserProperties(); 9 | 10 | private ValidateCodeProperties code = new ValidateCodeProperties(); 11 | 12 | public BrowserProperties getBrowser() { 13 | return browser; 14 | } 15 | 16 | public void setBrowser(BrowserProperties browser) { 17 | this.browser = browser; 18 | } 19 | 20 | public ValidateCodeProperties getCode() { 21 | return code; 22 | } 23 | 24 | public void setCode(ValidateCodeProperties code) { 25 | this.code = code; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/properties/SmsCodeProperties.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.properties; 2 | 3 | public class SmsCodeProperties { 4 | 5 | private int length = 4; 6 | private int expireIn = 60; 7 | 8 | private String url; 9 | 10 | public int getLength() { 11 | return length; 12 | } 13 | 14 | public void setLength(int length) { 15 | this.length = length; 16 | } 17 | 18 | public int getExpireIn() { 19 | return expireIn; 20 | } 21 | 22 | public void setExpireIn(int expireIn) { 23 | this.expireIn = expireIn; 24 | } 25 | 26 | public String getUrl() { 27 | return url; 28 | } 29 | 30 | public void setUrl(String url) { 31 | this.url = url; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/properties/ValidateCodeProperties.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.properties; 2 | 3 | public class ValidateCodeProperties { 4 | 5 | private ImageCodeProperties image = new ImageCodeProperties(); 6 | 7 | private SmsCodeProperties sms = new SmsCodeProperties(); 8 | 9 | public ImageCodeProperties getImage() { 10 | return image; 11 | } 12 | 13 | public void setImage(ImageCodeProperties image) { 14 | this.image = image; 15 | } 16 | 17 | public SmsCodeProperties getSms() { 18 | return sms; 19 | } 20 | 21 | public void setSms(SmsCodeProperties sms) { 22 | this.sms = sms; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/SmsCodeFilter.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code; 2 | 3 | import com.imooc.security.core.properties.SecurityProperties; 4 | import org.apache.commons.lang.StringUtils; 5 | import org.springframework.beans.factory.InitializingBean; 6 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 7 | import org.springframework.social.connect.web.HttpSessionSessionStrategy; 8 | import org.springframework.social.connect.web.SessionStrategy; 9 | import org.springframework.util.AntPathMatcher; 10 | import org.springframework.web.bind.ServletRequestBindingException; 11 | import org.springframework.web.bind.ServletRequestUtils; 12 | import org.springframework.web.context.request.ServletWebRequest; 13 | import org.springframework.web.filter.OncePerRequestFilter; 14 | 15 | import javax.servlet.FilterChain; 16 | import javax.servlet.ServletException; 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.io.IOException; 20 | import java.util.HashSet; 21 | import java.util.Set; 22 | 23 | public class SmsCodeFilter extends OncePerRequestFilter implements InitializingBean{ 24 | 25 | private AuthenticationFailureHandler authenticationFailureHandler; 26 | 27 | private SessionStrategy sessionStrategy =new HttpSessionSessionStrategy(); 28 | 29 | private Set urls = new HashSet<>(); 30 | 31 | private SecurityProperties securityProperties; 32 | 33 | private AntPathMatcher antPathMatcher = new AntPathMatcher(); 34 | 35 | 36 | @Override 37 | public void afterPropertiesSet() throws ServletException { 38 | super.afterPropertiesSet(); 39 | /* String[] configUrls = StringUtils.splitByWholeSeparatorPreserveAllTokens(securityProperties.getCode().getImage().getUrl(),","); 40 | for (String configUrl : configUrls) { 41 | urls.add(configUrl); 42 | }*/ 43 | urls.add("/authentication/mobile"); 44 | } 45 | 46 | @Override 47 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { 48 | boolean action = false; 49 | for (String url : urls) { 50 | if(antPathMatcher.match(url,request.getRequestURI())){ 51 | action = true; 52 | } 53 | } 54 | if(action){ 55 | try { 56 | validate(new ServletWebRequest(request)); 57 | }catch (ValidateCodeException e){ 58 | authenticationFailureHandler.onAuthenticationFailure(request,response,e); 59 | return; 60 | } 61 | } 62 | 63 | filterChain.doFilter(request,response); 64 | } 65 | 66 | private void validate(ServletWebRequest request) throws ServletRequestBindingException { 67 | ValidateCode codeInSession = (ValidateCode) sessionStrategy.getAttribute(request,ValidateCodeController.SESSION_KEY_CODE); 68 | String codeInRequest = ServletRequestUtils.getStringParameter(request.getRequest(), "smsCode"); 69 | if(StringUtils.isBlank(codeInRequest)){ 70 | throw new ValidateCodeException("验证码不能为空"); 71 | } 72 | if(codeInSession==null){ 73 | throw new ValidateCodeException("验证码不存在"); 74 | } 75 | if(codeInSession.isExpired()){ 76 | sessionStrategy.removeAttribute(request,ValidateCodeController.SESSION_KEY_CODE); 77 | throw new ValidateCodeException("验证码过期"); 78 | } 79 | if(!StringUtils.equals(codeInSession.getCode(),codeInRequest)){ 80 | throw new ValidateCodeException("验证码不匹配"); 81 | } 82 | sessionStrategy.removeAttribute(request,ValidateCodeController.SESSION_KEY_CODE); 83 | } 84 | 85 | public AuthenticationFailureHandler getAuthenticationFailureHandler() { 86 | return authenticationFailureHandler; 87 | } 88 | 89 | public void setAuthenticationFailureHandler(AuthenticationFailureHandler authenticationFailureHandler) { 90 | this.authenticationFailureHandler = authenticationFailureHandler; 91 | } 92 | 93 | public SessionStrategy getSessionStrategy() { 94 | return sessionStrategy; 95 | } 96 | 97 | public void setSessionStrategy(SessionStrategy sessionStrategy) { 98 | this.sessionStrategy = sessionStrategy; 99 | } 100 | 101 | public Set getUrls() { 102 | return urls; 103 | } 104 | 105 | public void setUrls(Set urls) { 106 | this.urls = urls; 107 | } 108 | 109 | public SecurityProperties getSecurityProperties() { 110 | return securityProperties; 111 | } 112 | 113 | public void setSecurityProperties(SecurityProperties securityProperties) { 114 | this.securityProperties = securityProperties; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/ValidateBeanConfig.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code; 2 | 3 | import com.imooc.security.core.properties.SecurityProperties; 4 | import com.imooc.security.core.validate.code.image.ImageCodeGenerator; 5 | import com.imooc.security.core.validate.code.sms.DefaultSmsCodeSender; 6 | import com.imooc.security.core.validate.code.sms.SmsCodeSender; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | @Configuration 13 | public class ValidateBeanConfig { 14 | 15 | @Autowired 16 | private SecurityProperties securityProperties; 17 | 18 | @Bean 19 | @ConditionalOnMissingBean(name="imageCodeGenerator") 20 | public ValidateCodeGenerator imageCodeGenerator(){ 21 | ImageCodeGenerator imageCodeGenerator = new ImageCodeGenerator(); 22 | imageCodeGenerator.setSecurityProperties(securityProperties); 23 | return imageCodeGenerator; 24 | } 25 | 26 | @Bean 27 | @ConditionalOnMissingBean(SmsCodeSender.class) 28 | public SmsCodeSender smsCodeSender(){ 29 | return new DefaultSmsCodeSender(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/ValidateCode.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public class ValidateCode { 6 | private String code; 7 | private LocalDateTime expireTime; 8 | 9 | public ValidateCode( String code, int expireIn) { 10 | this.code = code; 11 | this.expireTime = LocalDateTime.now().plusSeconds(expireIn); 12 | } 13 | 14 | public ValidateCode(String code, LocalDateTime expireTime) { 15 | this.code = code; 16 | this.expireTime = expireTime; 17 | } 18 | 19 | public boolean isExpired() { 20 | return LocalDateTime.now().isAfter(expireTime); 21 | } 22 | 23 | public String getCode() { 24 | return code; 25 | } 26 | 27 | public void setCode(String code) { 28 | this.code = code; 29 | } 30 | 31 | public LocalDateTime getExpireTime() { 32 | return expireTime; 33 | } 34 | 35 | public void setExpireTime(LocalDateTime expireTime) { 36 | this.expireTime = expireTime; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/ValidateCodeController.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code; 2 | 3 | import com.imooc.security.core.properties.SecurityProperties; 4 | import com.imooc.security.core.validate.code.image.ImageCode; 5 | import com.imooc.security.core.validate.code.sms.SmsCodeSender; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.social.connect.web.HttpSessionSessionStrategy; 8 | import org.springframework.social.connect.web.SessionStrategy; 9 | import org.springframework.web.bind.ServletRequestBindingException; 10 | import org.springframework.web.bind.ServletRequestUtils; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | import org.springframework.web.context.request.ServletWebRequest; 14 | 15 | import javax.imageio.ImageIO; 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.io.IOException; 19 | 20 | @RestController 21 | public class ValidateCodeController { 22 | 23 | public static final String SESSION_KEY_IMAGE = "SESSION_KEY_IMAGE_CODE"; 24 | public static final String SESSION_KEY_CODE = "SESSION_KEY_CODE"; 25 | 26 | private SessionStrategy sessionStrategy = new HttpSessionSessionStrategy(); 27 | @Autowired 28 | private SecurityProperties securityProperties; 29 | @Autowired 30 | private ValidateCodeGenerator imageCodeGenerator; 31 | @Autowired 32 | private ValidateCodeGenerator smsCodeGenerator; 33 | @Autowired 34 | private SmsCodeSender smsCodeSender; 35 | 36 | @GetMapping("/code/image") 37 | public void createCode(HttpServletRequest request, HttpServletResponse response) throws IOException { 38 | ImageCode imageCode= (ImageCode) imageCodeGenerator.generate(new ServletWebRequest(request)); 39 | sessionStrategy.setAttribute(new ServletWebRequest(request),SESSION_KEY_IMAGE,imageCode); 40 | ImageIO.write(imageCode.getImage(),"JPEG",response.getOutputStream()); 41 | } 42 | 43 | @GetMapping("/code/sms") 44 | public void createSmsCode(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletRequestBindingException { 45 | ValidateCode smsCode= smsCodeGenerator.generate(new ServletWebRequest(request)); 46 | sessionStrategy.setAttribute(new ServletWebRequest(request),SESSION_KEY_CODE,smsCode); 47 | String mobile = ServletRequestUtils.getRequiredStringParameter(request, "mobile"); 48 | smsCodeSender.send(mobile,smsCode.getCode()); 49 | } 50 | 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/ValidateCodeException.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | 5 | public class ValidateCodeException extends AuthenticationException{ 6 | 7 | public ValidateCodeException(String msg) { 8 | super(msg); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/ValidateCodeFilter.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code; 2 | 3 | import com.imooc.security.core.properties.SecurityProperties; 4 | import com.imooc.security.core.validate.code.image.ImageCode; 5 | import org.apache.commons.lang.StringUtils; 6 | import org.springframework.beans.factory.InitializingBean; 7 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 8 | import org.springframework.social.connect.web.HttpSessionSessionStrategy; 9 | import org.springframework.social.connect.web.SessionStrategy; 10 | import org.springframework.util.AntPathMatcher; 11 | import org.springframework.web.bind.ServletRequestBindingException; 12 | import org.springframework.web.bind.ServletRequestUtils; 13 | import org.springframework.web.context.request.ServletWebRequest; 14 | import org.springframework.web.filter.OncePerRequestFilter; 15 | 16 | import javax.servlet.FilterChain; 17 | import javax.servlet.ServletException; 18 | import javax.servlet.http.HttpServletRequest; 19 | import javax.servlet.http.HttpServletResponse; 20 | import java.io.IOException; 21 | import java.util.HashSet; 22 | import java.util.Set; 23 | 24 | public class ValidateCodeFilter extends OncePerRequestFilter implements InitializingBean{ 25 | 26 | 27 | private AuthenticationFailureHandler authenticationFailureHandler; 28 | 29 | private SessionStrategy sessionStrategy =new HttpSessionSessionStrategy(); 30 | 31 | private Set urls = new HashSet<>(); 32 | 33 | private SecurityProperties securityProperties; 34 | 35 | private AntPathMatcher antPathMatcher = new AntPathMatcher(); 36 | 37 | 38 | @Override 39 | public void afterPropertiesSet() throws ServletException { 40 | super.afterPropertiesSet(); 41 | /* String[] configUrls = StringUtils.splitByWholeSeparatorPreserveAllTokens(securityProperties.getCode().getImage().getUrl(),","); 42 | for (String configUrl : configUrls) { 43 | urls.add(configUrl); 44 | }*/ 45 | urls.add("/authentication/form"); 46 | } 47 | 48 | @Override 49 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { 50 | boolean action = false; 51 | for (String url : urls) { 52 | if(antPathMatcher.match(url,request.getRequestURI())){ 53 | action = true; 54 | } 55 | } 56 | if(action){ 57 | try { 58 | validate(new ServletWebRequest(request)); 59 | }catch (ValidateCodeException e){ 60 | authenticationFailureHandler.onAuthenticationFailure(request,response,e); 61 | return; 62 | } 63 | } 64 | 65 | filterChain.doFilter(request,response); 66 | } 67 | 68 | private void validate(ServletWebRequest request) throws ServletRequestBindingException { 69 | ImageCode codeInSession = (ImageCode) sessionStrategy.getAttribute(request,ValidateCodeController.SESSION_KEY_IMAGE); 70 | String codeInRequest = ServletRequestUtils.getStringParameter(request.getRequest(), "imageCode"); 71 | if(StringUtils.isBlank(codeInRequest)){ 72 | throw new ValidateCodeException("验证码不能为空"); 73 | } 74 | if(codeInSession==null){ 75 | throw new ValidateCodeException("验证码不存在"); 76 | } 77 | if(codeInSession.isExpired()){ 78 | sessionStrategy.removeAttribute(request,ValidateCodeController.SESSION_KEY_IMAGE); 79 | throw new ValidateCodeException("验证码过期"); 80 | } 81 | if(!StringUtils.equals(codeInSession.getCode(),codeInRequest)){ 82 | throw new ValidateCodeException("验证码不匹配"); 83 | } 84 | sessionStrategy.removeAttribute(request,ValidateCodeController.SESSION_KEY_IMAGE); 85 | } 86 | 87 | public AuthenticationFailureHandler getAuthenticationFailureHandler() { 88 | return authenticationFailureHandler; 89 | } 90 | 91 | public void setAuthenticationFailureHandler(AuthenticationFailureHandler authenticationFailureHandler) { 92 | this.authenticationFailureHandler = authenticationFailureHandler; 93 | } 94 | 95 | public SessionStrategy getSessionStrategy() { 96 | return sessionStrategy; 97 | } 98 | 99 | public void setSessionStrategy(SessionStrategy sessionStrategy) { 100 | this.sessionStrategy = sessionStrategy; 101 | } 102 | 103 | public Set getUrls() { 104 | return urls; 105 | } 106 | 107 | public void setUrls(Set urls) { 108 | this.urls = urls; 109 | } 110 | 111 | public SecurityProperties getSecurityProperties() { 112 | return securityProperties; 113 | } 114 | 115 | public void setSecurityProperties(SecurityProperties securityProperties) { 116 | this.securityProperties = securityProperties; 117 | } 118 | 119 | 120 | } 121 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/ValidateCodeGenerator.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code; 2 | 3 | import org.springframework.web.context.request.ServletWebRequest; 4 | 5 | public interface ValidateCodeGenerator { 6 | ValidateCode generate(ServletWebRequest request); 7 | } 8 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/ValidateCodeProcessor.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code; 2 | 3 | import org.springframework.web.context.request.ServletWebRequest; 4 | 5 | /** 6 | * 校验码处理器,封装不同校验码的处理逻辑 7 | */ 8 | public interface ValidateCodeProcessor { 9 | /** 10 | * 验证码放入session时的前缀 11 | */ 12 | String SESSION_KEY_PREFIX = "SESSION_KEY_FOR_CODE_"; 13 | 14 | /** 15 | * 创建校验码 16 | * 17 | * @param request 18 | * @throws Exception 19 | */ 20 | void create(ServletWebRequest request) throws Exception; 21 | 22 | /** 23 | * 校验验证码 24 | * 25 | * @param servletWebRequest 26 | * @throws Exception 27 | */ 28 | void validate(ServletWebRequest servletWebRequest); 29 | } 30 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/ValidateCodeProcessorHolder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.imooc.security.core.validate.code; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.Map; 10 | 11 | /** 12 | * @author zhailiang 13 | * 14 | */ 15 | @Component 16 | public class ValidateCodeProcessorHolder { 17 | 18 | @Autowired 19 | private Map validateCodeProcessors; 20 | 21 | public ValidateCodeProcessor findValidateCodeProcessor(ValidateCodeType type) { 22 | return findValidateCodeProcessor(type.toString().toLowerCase()); 23 | } 24 | 25 | public ValidateCodeProcessor findValidateCodeProcessor(String type) { 26 | String name = type.toLowerCase() + ValidateCodeProcessor.class.getSimpleName(); 27 | ValidateCodeProcessor processor = validateCodeProcessors.get(name); 28 | if (processor == null) { 29 | throw new ValidateCodeException("验证码处理器" + name + "不存在"); 30 | } 31 | return processor; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/ValidateCodeType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.imooc.security.core.validate.code; 5 | 6 | import com.imooc.security.core.properties.SecurityConstants; 7 | 8 | /** 9 | * @author zhailiang 10 | * 11 | */ 12 | public enum ValidateCodeType { 13 | 14 | /** 15 | * 短信验证码 16 | */ 17 | SMS { 18 | @Override 19 | public String getParamNameOnValidate() { 20 | return SecurityConstants.DEFAULT_PARAMETER_NAME_CODE_SMS; 21 | } 22 | }, 23 | /** 24 | * 图片验证码 25 | */ 26 | IMAGE { 27 | @Override 28 | public String getParamNameOnValidate() { 29 | return SecurityConstants.DEFAULT_PARAMETER_NAME_CODE_IMAGE; 30 | } 31 | }; 32 | 33 | /** 34 | * 校验时从请求中获取的参数的名字 35 | * @return 36 | */ 37 | public abstract String getParamNameOnValidate(); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/image/ImageCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.imooc.security.core.validate.code.image; 5 | 6 | import com.imooc.security.core.validate.code.ValidateCode; 7 | 8 | import java.awt.image.BufferedImage; 9 | import java.time.LocalDateTime; 10 | 11 | 12 | /** 13 | * 14 | */ 15 | public class ImageCode extends ValidateCode { 16 | 17 | private BufferedImage image; 18 | 19 | public ImageCode(BufferedImage image, String code, int expireIn){ 20 | super(code, expireIn); 21 | this.image = image; 22 | } 23 | 24 | public ImageCode(BufferedImage image, String code, LocalDateTime expireTime){ 25 | super(code, expireTime); 26 | this.image = image; 27 | } 28 | 29 | public BufferedImage getImage() { 30 | return image; 31 | } 32 | 33 | public void setImage(BufferedImage image) { 34 | this.image = image; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/image/ImageCodeGenerator.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code.image; 2 | 3 | import com.imooc.security.core.properties.SecurityProperties; 4 | import com.imooc.security.core.validate.code.ValidateCodeGenerator; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.ServletRequestUtils; 7 | import org.springframework.web.context.request.ServletWebRequest; 8 | 9 | import java.awt.*; 10 | import java.awt.image.BufferedImage; 11 | import java.util.Random; 12 | 13 | /** 14 | * 15 | */ 16 | @org.springframework.stereotype.Component("imageCodeGenerator") 17 | public class ImageCodeGenerator implements ValidateCodeGenerator { 18 | 19 | /** 20 | * 系统配置 21 | */ 22 | @Autowired 23 | private SecurityProperties securityProperties; 24 | 25 | /* 26 | * (non-Javadoc) 27 | * 28 | * @see 29 | * com.imooc.security.core.validate.code.ValidateCodeGenerator#generate(org. 30 | * springframework.web.context.request.ServletWebRequest) 31 | */ 32 | @Override 33 | public ImageCode generate(ServletWebRequest request) { 34 | int width = ServletRequestUtils.getIntParameter(request.getRequest(), "width", 35 | securityProperties.getCode().getImage().getWidth()); 36 | int height = ServletRequestUtils.getIntParameter(request.getRequest(), "height", 37 | securityProperties.getCode().getImage().getHeight()); 38 | BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 39 | 40 | Graphics g = image.getGraphics(); 41 | 42 | Random random = new Random(); 43 | 44 | g.setColor(getRandColor(200, 250)); 45 | g.fillRect(0, 0, width, height); 46 | g.setFont(new Font("Times New Roman", Font.ITALIC, 20)); 47 | g.setColor(getRandColor(160, 200)); 48 | for (int i = 0; i < 155; i++) { 49 | int x = random.nextInt(width); 50 | int y = random.nextInt(height); 51 | int xl = random.nextInt(12); 52 | int yl = random.nextInt(12); 53 | g.drawLine(x, y, x + xl, y + yl); 54 | } 55 | 56 | String sRand = ""; 57 | for (int i = 0; i < securityProperties.getCode().getImage().getLength(); i++) { 58 | String rand = String.valueOf(random.nextInt(10)); 59 | sRand += rand; 60 | g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110))); 61 | g.drawString(rand, 13 * i + 6, 16); 62 | } 63 | 64 | g.dispose(); 65 | 66 | return new ImageCode(image, sRand, securityProperties.getCode().getImage().getExpireIn()); 67 | } 68 | 69 | /** 70 | * 生成随机背景条纹 71 | * 72 | * @param fc 73 | * @param bc 74 | * @return 75 | */ 76 | private Color getRandColor(int fc, int bc) { 77 | Random random = new Random(); 78 | if (fc > 255) { 79 | fc = 255; 80 | } 81 | if (bc > 255) { 82 | bc = 255; 83 | } 84 | int r = fc + random.nextInt(bc - fc); 85 | int g = fc + random.nextInt(bc - fc); 86 | int b = fc + random.nextInt(bc - fc); 87 | return new Color(r, g, b); 88 | } 89 | 90 | public SecurityProperties getSecurityProperties() { 91 | return securityProperties; 92 | } 93 | 94 | public void setSecurityProperties(SecurityProperties securityProperties) { 95 | this.securityProperties = securityProperties; 96 | } 97 | 98 | 99 | 100 | } 101 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/image/ImageCodeProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.imooc.security.core.validate.code.image; 5 | 6 | import com.imooc.security.core.validate.code.impl.AbstractValidateCodeProcessor; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.context.request.ServletWebRequest; 9 | 10 | import javax.imageio.ImageIO; 11 | 12 | /** 13 | * 图片验证码处理器 14 | * 15 | * 16 | */ 17 | @Component("imageValidateCodeProcessor") 18 | public class ImageCodeProcessor extends AbstractValidateCodeProcessor { 19 | 20 | /** 21 | * 发送图形验证码,将其写到响应中 22 | */ 23 | @Override 24 | protected void send(ServletWebRequest request, ImageCode imageCode) throws Exception { 25 | ImageIO.write(imageCode.getImage(), "JPEG", request.getResponse().getOutputStream()); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/impl/AbstractValidateCodeProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.imooc.security.core.validate.code.impl; 5 | 6 | import com.imooc.security.core.validate.code.*; 7 | import org.apache.commons.lang.StringUtils; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.social.connect.web.HttpSessionSessionStrategy; 10 | import org.springframework.social.connect.web.SessionStrategy; 11 | import org.springframework.web.bind.ServletRequestBindingException; 12 | import org.springframework.web.bind.ServletRequestUtils; 13 | import org.springframework.web.context.request.ServletWebRequest; 14 | 15 | import java.util.Map; 16 | 17 | /** 18 | * @author zhailiang 19 | * 20 | */ 21 | public abstract class AbstractValidateCodeProcessor implements ValidateCodeProcessor { 22 | 23 | /** 24 | * 操作session的工具类 25 | */ 26 | private SessionStrategy sessionStrategy = new HttpSessionSessionStrategy(); 27 | /** 28 | * 收集系统中所有的 {@link ValidateCodeGenerator} 接口的实现。 29 | */ 30 | @Autowired 31 | private Map validateCodeGenerators; 32 | 33 | /* 34 | * (non-Javadoc) 35 | * 36 | * @see 37 | * com.imooc.security.core.validate.code.ValidateCodeProcessor#create(org. 38 | * springframework.web.context.request.ServletWebRequest) 39 | */ 40 | @Override 41 | public void create(ServletWebRequest request) throws Exception { 42 | C validateCode = generate(request); 43 | save(request, validateCode); 44 | send(request, validateCode); 45 | } 46 | 47 | /** 48 | * 生成校验码 49 | * 50 | * @param request 51 | * @return 52 | */ 53 | @SuppressWarnings("unchecked") 54 | private C generate(ServletWebRequest request) { 55 | String type = getValidateCodeType(request).toString().toLowerCase(); 56 | String generatorName = type + ValidateCodeGenerator.class.getSimpleName(); 57 | ValidateCodeGenerator validateCodeGenerator = validateCodeGenerators.get(generatorName); 58 | if (validateCodeGenerator == null) { 59 | throw new ValidateCodeException("验证码生成器" + generatorName + "不存在"); 60 | } 61 | return (C) validateCodeGenerator.generate(request); 62 | } 63 | 64 | /** 65 | * 保存校验码 66 | * 67 | * @param request 68 | * @param validateCode 69 | */ 70 | private void save(ServletWebRequest request, C validateCode) { 71 | sessionStrategy.setAttribute(request, getSessionKey(request), validateCode); 72 | } 73 | 74 | /** 75 | * 构建验证码放入session时的key 76 | * 77 | * @param request 78 | * @return 79 | */ 80 | private String getSessionKey(ServletWebRequest request) { 81 | return SESSION_KEY_PREFIX + getValidateCodeType(request).toString().toUpperCase(); 82 | } 83 | 84 | /** 85 | * 发送校验码,由子类实现 86 | * 87 | * @param request 88 | * @param validateCode 89 | * @throws Exception 90 | */ 91 | protected abstract void send(ServletWebRequest request, C validateCode) throws Exception; 92 | 93 | /** 94 | * 根据请求的url获取校验码的类型 95 | * 96 | * @param request 97 | * @return 98 | */ 99 | private ValidateCodeType getValidateCodeType(ServletWebRequest request) { 100 | String type = StringUtils.substringBefore(getClass().getSimpleName(), "CodeProcessor"); 101 | return ValidateCodeType.valueOf(type.toUpperCase()); 102 | } 103 | 104 | @SuppressWarnings("unchecked") 105 | @Override 106 | public void validate(ServletWebRequest request) { 107 | 108 | ValidateCodeType processorType = getValidateCodeType(request); 109 | String sessionKey = getSessionKey(request); 110 | 111 | C codeInSession = (C) sessionStrategy.getAttribute(request, sessionKey); 112 | 113 | String codeInRequest; 114 | try { 115 | codeInRequest = ServletRequestUtils.getStringParameter(request.getRequest(), 116 | processorType.getParamNameOnValidate()); 117 | } catch (ServletRequestBindingException e) { 118 | throw new ValidateCodeException("获取验证码的值失败"); 119 | } 120 | 121 | if (StringUtils.isBlank(codeInRequest)) { 122 | throw new ValidateCodeException(processorType + "验证码的值不能为空"); 123 | } 124 | 125 | if (codeInSession == null) { 126 | throw new ValidateCodeException(processorType + "验证码不存在"); 127 | } 128 | 129 | if (codeInSession.isExpired()) { 130 | sessionStrategy.removeAttribute(request, sessionKey); 131 | throw new ValidateCodeException(processorType + "验证码已过期"); 132 | } 133 | 134 | if (!StringUtils.equals(codeInSession.getCode(), codeInRequest)) { 135 | throw new ValidateCodeException(processorType + "验证码不匹配"); 136 | } 137 | 138 | sessionStrategy.removeAttribute(request, sessionKey); 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/sms/DefaultSmsCodeSender.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code.sms; 2 | 3 | public class DefaultSmsCodeSender implements SmsCodeSender { 4 | 5 | 6 | @Override 7 | public void send(String mobile, String code) { 8 | System.out.println("向手机"+mobile+"发送短信验证码: "+code); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/sms/SmsCodeGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.imooc.security.core.validate.code.sms; 5 | 6 | import org.apache.commons.lang.RandomStringUtils; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.web.context.request.ServletWebRequest; 10 | 11 | import com.imooc.security.core.properties.SecurityProperties; 12 | import com.imooc.security.core.validate.code.ValidateCode; 13 | import com.imooc.security.core.validate.code.ValidateCodeGenerator; 14 | 15 | /** 16 | * 17 | */ 18 | @Component("smsCodeGenerator") 19 | public class SmsCodeGenerator implements ValidateCodeGenerator { 20 | 21 | @Autowired 22 | private SecurityProperties securityProperties; 23 | 24 | /* 25 | * (non-Javadoc) 26 | * 27 | * @see 28 | * com.imooc.security.core.validate.code.ValidateCodeGenerator#generate(org. 29 | * springframework.web.context.request.ServletWebRequest) 30 | */ 31 | @Override 32 | public ValidateCode generate(ServletWebRequest request) { 33 | String code = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength()); 34 | return new ValidateCode(code, securityProperties.getCode().getSms().getExpireIn()); 35 | } 36 | 37 | public SecurityProperties getSecurityProperties() { 38 | return securityProperties; 39 | } 40 | 41 | public void setSecurityProperties(SecurityProperties securityProperties) { 42 | this.securityProperties = securityProperties; 43 | } 44 | 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/sms/SmsCodeProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.imooc.security.core.validate.code.sms; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.bind.ServletRequestUtils; 9 | import org.springframework.web.context.request.ServletWebRequest; 10 | 11 | import com.imooc.security.core.properties.SecurityConstants; 12 | import com.imooc.security.core.validate.code.ValidateCode; 13 | import com.imooc.security.core.validate.code.impl.AbstractValidateCodeProcessor; 14 | 15 | /** 16 | * 短信验证码处理器 17 | * 18 | * @author zhailiang 19 | * 20 | */ 21 | @Component("smsValidateCodeProcessor") 22 | public class SmsCodeProcessor extends AbstractValidateCodeProcessor { 23 | 24 | /** 25 | * 短信验证码发送器 26 | */ 27 | @Autowired 28 | private SmsCodeSender smsCodeSender; 29 | 30 | @Override 31 | protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception { 32 | String paramName = SecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE; 33 | String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName); 34 | smsCodeSender.send(mobile, validateCode.getCode()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /imooc-security-core/src/main/java/com/imooc/security/core/validate/code/sms/SmsCodeSender.java: -------------------------------------------------------------------------------- 1 | package com.imooc.security.core.validate.code.sms; 2 | 3 | public interface SmsCodeSender { 4 | void send(String mobile,String code); 5 | } 6 | -------------------------------------------------------------------------------- /imooc-security-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | imooc-security 7 | com.imooc.security 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | imooc-security-demo 13 | 14 | 15 | 16 | com.imooc.security 17 | imooc-security-browser 18 | ${imooc.security.version} 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-test 23 | 24 | 25 | com.alibaba 26 | fastjson 27 | 1.2.38 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-aop 32 | 33 | 34 | commons-io 35 | commons-io 36 | 37 | 38 | 39 | io.springfox 40 | springfox-swagger2 41 | 2.7.0 42 | 43 | 44 | 45 | io.springfox 46 | springfox-swagger-ui 47 | 2.7.0 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-maven-plugin 57 | 1.3.3.RELEASE 58 | 59 | 60 | 61 | repackage 62 | 63 | 64 | 65 | 66 | 67 | demo 68 | 69 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.imooc; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 8 | 9 | @SpringBootApplication 10 | @RestController 11 | @EnableSwagger2() 12 | public class DemoApplication { 13 | 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(DemoApplication.class,args); 17 | } 18 | @RequestMapping("/hello") 19 | public String hello(){ 20 | return "hello spring security"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/dto/Data.java: -------------------------------------------------------------------------------- 1 | package com.imooc.dto; 2 | 3 | public class Data { 4 | private String name; 5 | private String age; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | public String getAge() { 16 | return age; 17 | } 18 | 19 | public void setAge(String age) { 20 | this.age = age; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/dto/FileInfo.java: -------------------------------------------------------------------------------- 1 | package com.imooc.dto; 2 | 3 | public class FileInfo { 4 | private String path; 5 | 6 | public FileInfo(String path) { 7 | this.path = path; 8 | } 9 | 10 | public String getPath() { 11 | return path; 12 | } 13 | 14 | public void setPath(String path) { 15 | this.path = path; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.imooc.dto; 2 | 3 | import com.fasterxml.jackson.annotation.JsonView; 4 | import com.imooc.validator.MyConstraint; 5 | import org.hibernate.validator.constraints.NotBlank; 6 | import javax.validation.constraints.Past; 7 | import java.util.Date; 8 | 9 | public class User { 10 | 11 | 12 | public interface UserSimpleView { 13 | }; 14 | 15 | public interface UserDetailView extends UserSimpleView { 16 | }; 17 | @Past(message = "生日必须是过去的时间") 18 | private Date birthday; 19 | private String id; 20 | @MyConstraint(message = "这是一个测试") 21 | private String username; 22 | @NotBlank(message = "密码不能为空") 23 | private String password; 24 | 25 | @JsonView(UserSimpleView.class) 26 | public String getUsername() { 27 | return username; 28 | } 29 | 30 | public void setUsername(String username) { 31 | this.username = username; 32 | } 33 | 34 | public String getPassword() { 35 | return password; 36 | } 37 | 38 | @JsonView(UserDetailView.class) 39 | public void setPassword(String password) { 40 | this.password = password; 41 | } 42 | 43 | public String getId() { 44 | return id; 45 | } 46 | @JsonView(UserSimpleView.class) 47 | public void setId(String id) { 48 | this.id = id; 49 | } 50 | public Date getBirthday() { 51 | return birthday; 52 | } 53 | @JsonView(UserSimpleView.class) 54 | public void setBirthday(Date birthday) { 55 | this.birthday = birthday; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/dto/UserJson.java: -------------------------------------------------------------------------------- 1 | package com.imooc.dto; 2 | 3 | public class UserJson { 4 | private Data data; 5 | 6 | public Data getData() { 7 | return data; 8 | } 9 | 10 | public void setData(Data data) { 11 | this.data = data; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/dto/UserQueryCondition.java: -------------------------------------------------------------------------------- 1 | package com.imooc.dto; 2 | 3 | import io.swagger.annotations.ApiModelProperty; 4 | 5 | public class UserQueryCondition { 6 | private String username; 7 | @ApiModelProperty(value = "用户年龄起始值") 8 | private int age; 9 | private int ageTo; 10 | private String xxx; 11 | 12 | public String getUsername() { 13 | return username; 14 | } 15 | 16 | public void setUsername(String username) { 17 | this.username = username; 18 | } 19 | 20 | public int getAge() { 21 | return age; 22 | } 23 | 24 | public void setAge(int age) { 25 | this.age = age; 26 | } 27 | 28 | public int getAgeTo() { 29 | return ageTo; 30 | } 31 | 32 | public void setAgeTo(int ageTo) { 33 | this.ageTo = ageTo; 34 | } 35 | 36 | public String getXxx() { 37 | return xxx; 38 | } 39 | 40 | public void setXxx(String xxx) { 41 | this.xxx = xxx; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/exception/UserNotExistException.java: -------------------------------------------------------------------------------- 1 | package com.imooc.exception; 2 | 3 | public class UserNotExistException extends RuntimeException { 4 | private String id; 5 | public UserNotExistException(String id){ 6 | super("user not exsit"); 7 | this.id = id; 8 | } 9 | 10 | public String getId() { 11 | return id; 12 | } 13 | 14 | public void setId(String id) { 15 | this.id = id; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/service/HelloService.java: -------------------------------------------------------------------------------- 1 | package com.imooc.service; 2 | 3 | public interface HelloService { 4 | String greeting(String name); 5 | } 6 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/service/impl/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.imooc.service.impl; 2 | 3 | import com.imooc.service.HelloService; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class HelloServiceImpl implements HelloService { 8 | 9 | @Override 10 | public String greeting(String name) { 11 | return "hello"+name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/utils/BeanUtils.java: -------------------------------------------------------------------------------- 1 | package com.imooc.utils; 2 | 3 | import java.beans.BeanInfo; 4 | import java.beans.IntrospectionException; 5 | import java.beans.Introspector; 6 | import java.beans.PropertyDescriptor; 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.lang.reflect.Method; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | 13 | public class BeanUtils { 14 | /** 15 | * bean 转化为实体 16 | * @param bean 17 | * @return 18 | */ 19 | public static Map beanToMap(Object bean){ 20 | Map map = new HashMap(); 21 | if(null == bean){ 22 | return map; 23 | } 24 | Class clazz = bean.getClass(); 25 | BeanInfo beanInfo = null; 26 | try { 27 | beanInfo = Introspector.getBeanInfo(clazz); 28 | } catch (IntrospectionException e) { 29 | e.printStackTrace(); 30 | } 31 | PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); 32 | for(PropertyDescriptor descriptor : descriptors){ 33 | String propertyName = descriptor.getName(); 34 | if(!"class".equals(propertyName)){ 35 | Method method = descriptor.getReadMethod(); 36 | Object result; 37 | try { 38 | result = method.invoke(bean); 39 | if(null != result){ 40 | map.put(propertyName, result); 41 | }else{ 42 | map.put(propertyName, ""); 43 | } 44 | } catch (IllegalArgumentException e) { 45 | e.printStackTrace(); 46 | } catch (IllegalAccessException e) { 47 | e.printStackTrace(); 48 | } catch (InvocationTargetException e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | } 53 | 54 | return map; 55 | } 56 | /** 57 | * map 转化为 bean 58 | * @param clazz 59 | * @param map 60 | * @return 61 | */ 62 | public static Object mapToBean(Class clazz,Map map){ 63 | Object object = null; 64 | try { 65 | object = clazz.newInstance(); 66 | BeanInfo beanInfo = Introspector.getBeanInfo(clazz); 67 | 68 | PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); 69 | for(PropertyDescriptor descriptor : descriptors){ 70 | String propertyName = descriptor.getName(); 71 | if(map.containsKey(propertyName)){ 72 | Object value = map.get(propertyName); 73 | Object[] args = new Object[1]; 74 | args[0] = value; 75 | descriptor.getWriteMethod().invoke(object, args); 76 | } 77 | } 78 | 79 | } catch (InstantiationException e) { 80 | e.printStackTrace(); 81 | } catch (IllegalAccessException e) { 82 | e.printStackTrace(); 83 | }catch (IntrospectionException e) { 84 | e.printStackTrace(); 85 | }catch (IllegalArgumentException e) { 86 | e.printStackTrace(); 87 | } catch (InvocationTargetException e) { 88 | e.printStackTrace(); 89 | } 90 | return object; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/validator/MyConstraint.java: -------------------------------------------------------------------------------- 1 | package com.imooc.validator; 2 | 3 | import javax.validation.Constraint; 4 | import javax.validation.Payload; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | @Target({ElementType.METHOD,ElementType.FIELD}) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Constraint(validatedBy = MyConstraintValidator.class) 13 | public @interface MyConstraint { 14 | String message() ; 15 | 16 | Class[] groups() default {}; 17 | 18 | Class[] payload() default {}; 19 | } 20 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/validator/MyConstraintValidator.java: -------------------------------------------------------------------------------- 1 | package com.imooc.validator; 2 | 3 | import com.imooc.service.HelloService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | 6 | import javax.validation.ConstraintValidator; 7 | import javax.validation.ConstraintValidatorContext; 8 | 9 | public class MyConstraintValidator implements ConstraintValidator { 10 | 11 | @Autowired 12 | private HelloService helloService; 13 | 14 | @Override 15 | public void initialize(MyConstraint constraintAnnotation) { 16 | System.out.println("my validator init"); 17 | } 18 | 19 | @Override 20 | public boolean isValid(Object value, ConstraintValidatorContext context) { 21 | helloService.greeting("tom"); 22 | System.out.println(value); 23 | return false; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/aspect/TimeAspect.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.aspect; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | import org.aspectj.lang.annotation.Around; 5 | 6 | import java.util.Date; 7 | 8 | //@Aspect 9 | //@Component 10 | public class TimeAspect { 11 | 12 | @Around("execution(* com.imooc.web.controller.UserController.*(..))") 13 | public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable { 14 | System.out.println("time aspect start!"); 15 | long start = new Date().getTime(); 16 | Object[] args = pjp.getArgs(); 17 | for (Object arg : args) { 18 | System.out.println("参数:"+arg); 19 | } 20 | Object proceed = pjp.proceed(); 21 | System.out.println("time aspect: " + (new Date().getTime()-start)); 22 | System.out.println("time aspect finish"); 23 | return proceed; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/async/AsyncController.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.async; 2 | 3 | import org.apache.commons.lang.RandomStringUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | import org.springframework.web.context.request.async.DeferredResult; 10 | 11 | @RestController 12 | public class AsyncController { 13 | private Logger logger = LoggerFactory.getLogger(getClass()); 14 | 15 | @Autowired 16 | private MockQueue mockQueue; 17 | @Autowired 18 | private DeferredResultHolder deferredResultHolder; 19 | 20 | 21 | @RequestMapping("/order") 22 | public DeferredResult order() throws Exception { 23 | logger.info("主线程开始"); 24 | String orderNumber = RandomStringUtils.randomNumeric(8); 25 | //设置订单号 26 | mockQueue.setPlaceOrder(orderNumber); 27 | DeferredResult result = new DeferredResult<>(); 28 | //订单号和返回结果绑定 29 | deferredResultHolder.getMap().put(orderNumber,result); 30 | logger.info("主线程返回"); 31 | return result; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/async/DeferredResultHolder.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.async; 2 | 3 | import org.springframework.stereotype.Component; 4 | import org.springframework.web.context.request.async.DeferredResult; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | @Component 9 | public class DeferredResultHolder { 10 | private Map> map = new HashMap<>(); 11 | 12 | public Map> getMap() { 13 | return map; 14 | } 15 | 16 | public void setMap(Map> map) { 17 | this.map = map; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/async/MockQueue.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.async; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class MockQueue { 9 | 10 | private Logger logger = LoggerFactory.getLogger(getClass()); 11 | private String placeOrder; 12 | private String completeOrder; 13 | 14 | public String getCompleteOrder() { 15 | return completeOrder; 16 | } 17 | 18 | public void setCompleteOrder(String completeOrder) { 19 | this.completeOrder = completeOrder; 20 | 21 | } 22 | 23 | public String getPlaceOrder() { 24 | return placeOrder; 25 | } 26 | 27 | public void setPlaceOrder(String placeOrder) throws Exception { 28 | new Thread(() -> { 29 | logger.info("接到下单请求" + placeOrder); 30 | try { 31 | Thread.sleep(1000); 32 | } catch (InterruptedException e) { 33 | e.printStackTrace(); 34 | } 35 | this.completeOrder = placeOrder; 36 | logger.info("下单请求处理完毕" + placeOrder); 37 | }).start(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/async/QueueListener.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.async; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.ApplicationListener; 7 | import org.springframework.context.event.ContextRefreshedEvent; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.util.StringUtils; 10 | 11 | @Component 12 | public class QueueListener implements ApplicationListener { 13 | private Logger logger = LoggerFactory.getLogger(getClass()); 14 | @Autowired 15 | private MockQueue mockQueue; 16 | @Autowired 17 | private DeferredResultHolder resultHolder; 18 | 19 | @Override 20 | public void onApplicationEvent(ContextRefreshedEvent event) { 21 | //因为容器启动的时候会扫描这个类,不新开线程会造成阻塞 22 | new Thread(()->{ 23 | while (true){ 24 | if(!StringUtils.isEmpty(mockQueue.getCompleteOrder())){//获取订单号是否存在 25 | String orderNumber = mockQueue.getCompleteOrder(); 26 | logger.info("返回订单处理结果"); 27 | //取出订单号对应的返回结果,设置新的返回结果 28 | resultHolder.getMap().get(orderNumber).setResult("place order success"); 29 | mockQueue.setCompleteOrder(null); 30 | }else{ 31 | try { 32 | Thread.sleep(100); 33 | } catch (InterruptedException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | } 38 | }).start(); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/config/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.config; 2 | 3 | 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | 13 | @Configuration 14 | public class Swagger2Config { 15 | @Bean 16 | public Docket createRestApi() { 17 | return new Docket(DocumentationType.SWAGGER_2) 18 | .apiInfo(apiInfo()) 19 | .select() 20 | .apis(RequestHandlerSelectors.basePackage("com.imooc.web.controller")) 21 | .paths(PathSelectors.any()) 22 | .build(); 23 | } 24 | 25 | private ApiInfo apiInfo() { 26 | return new ApiInfoBuilder() 27 | .title("Spring Boot中使用Swagger2构建RESTful APIs") 28 | .description("Spring Boot中使用Swagger2构建RESTful APIs") 29 | .contact("DengJia") 30 | .version("1.0") 31 | .build(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/config/WebConfig.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.config; 2 | 3 | import com.imooc.web.filter.TimeFilter; 4 | import com.imooc.web.interceptor.TimeInterceptor; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; 10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | @Configuration 16 | public class WebConfig extends WebMvcConfigurerAdapter { 17 | 18 | @Autowired 19 | private TimeInterceptor timeInterceptor; 20 | 21 | // @Override 22 | // public void addInterceptors(InterceptorRegistry registry) { 23 | // registry.addInterceptor(timeInterceptor); 24 | // } 25 | 26 | 27 | // @Bean 28 | public FilterRegistrationBean timeFilter(){ 29 | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); 30 | TimeFilter timeFilter = new TimeFilter(); 31 | filterRegistrationBean.setFilter(timeFilter); 32 | List urls = new ArrayList<>(); 33 | urls.add("/*"); 34 | filterRegistrationBean.setUrlPatterns(urls); 35 | return filterRegistrationBean; 36 | } 37 | 38 | //开启方法级验证 39 | @Bean 40 | public MethodValidationPostProcessor mvp(){ 41 | return new MethodValidationPostProcessor(); 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/controller/1510457275352.txt: -------------------------------------------------------------------------------- 1 | hello upload -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/controller/ControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.controller; 2 | 3 | import com.imooc.exception.UserNotExistException; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.web.bind.annotation.ControllerAdvice; 6 | import org.springframework.web.bind.annotation.ExceptionHandler; 7 | import org.springframework.web.bind.annotation.ResponseBody; 8 | import org.springframework.web.bind.annotation.ResponseStatus; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | @ControllerAdvice 14 | public class ControllerExceptionHandler { 15 | 16 | @ExceptionHandler(UserNotExistException.class) 17 | @ResponseBody 18 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) 19 | public Map handleUserNotExistException(UserNotExistException ex){ 20 | Map result = new HashMap<>(); 21 | result.put("id",ex.getId()); 22 | result.put("message",ex.getMessage()); 23 | return result; 24 | } 25 | 26 | @ExceptionHandler(Exception.class) 27 | @ResponseBody 28 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) 29 | public Exception handleException(Exception ex){ 30 | return ex; 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/controller/FileController.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.controller; 2 | 3 | import com.imooc.dto.FileInfo; 4 | import org.apache.commons.io.IOUtils; 5 | import org.springframework.web.bind.annotation.*; 6 | import org.springframework.web.multipart.MultipartFile; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.File; 11 | import java.io.FileInputStream; 12 | import java.io.IOException; 13 | import java.io.OutputStream; 14 | import java.util.Date; 15 | 16 | @RestController 17 | @RequestMapping("/file") 18 | public class FileController { 19 | private String folder = "D:\\IdeaWorkspace\\imooc-security\\imooc-security-demo\\src\\main\\java\\com\\imooc\\web\\controller"; 20 | 21 | @PostMapping 22 | public FileInfo upload(MultipartFile file) throws IOException { 23 | System.out.println(file.getName()); 24 | System.out.println(file.getOriginalFilename()); 25 | System.out.println(file.getSize()); 26 | String folder = "D:\\IdeaWorkspace\\imooc-security\\imooc-security-demo\\src\\main\\java\\com\\imooc\\web\\controller"; 27 | File localFile = new File(folder,new Date().getTime()+".txt"); 28 | file.transferTo(localFile); 29 | return new FileInfo(localFile.getAbsolutePath()); 30 | } 31 | 32 | @GetMapping("/{id}") 33 | public void download(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) throws Exception { 34 | try (FileInputStream inputStream = new FileInputStream(new File(folder, id + ".txt")); 35 | OutputStream outputStream = response.getOutputStream();){ 36 | response.setContentType("application/x-download"); 37 | response.addHeader("Content-Disposition","attachment;filename=test.txt"); 38 | IOUtils.copy(inputStream,outputStream); 39 | outputStream.flush(); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/controller/MyController.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.controller; 2 | 3 | import org.hibernate.validator.constraints.Length; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.validation.annotation.Validated; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | @RestController 12 | @Validated 13 | @RequestMapping("/test") 14 | public class MyController { 15 | 16 | @GetMapping("/length") 17 | public ResponseEntity testMax(@Length(min = 6, message = "字符太短") String username) { 18 | return new ResponseEntity("字符长度适合", HttpStatus.OK); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.controller; 2 | 3 | import com.fasterxml.jackson.annotation.JsonView; 4 | import com.imooc.dto.Data; 5 | import com.imooc.dto.User; 6 | import com.imooc.dto.UserJson; 7 | import com.imooc.dto.UserQueryCondition; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.apache.commons.lang.builder.ReflectionToStringBuilder; 10 | import org.apache.commons.lang.builder.ToStringStyle; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.web.PageableDefault; 13 | import org.springframework.validation.BindingResult; 14 | import org.springframework.validation.FieldError; 15 | import org.springframework.web.bind.annotation.*; 16 | 17 | import javax.validation.Valid; 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | @RestController 22 | @RequestMapping("/user") 23 | public class UserController { 24 | 25 | 26 | @PostMapping 27 | public User create(@Valid @RequestBody User user, BindingResult errors){ 28 | if(errors.hasErrors()){ 29 | errors.getAllErrors().stream().forEach(error -> System.out.println(error.getDefaultMessage())); 30 | } 31 | System.out.println(user.getId()); 32 | System.out.println(user.getPassword()); 33 | System.out.println(user.getUsername()); 34 | System.out.println(user.getBirthday()); 35 | user.setId("1"); 36 | return user; 37 | } 38 | 39 | 40 | @GetMapping() 41 | @JsonView(User.UserSimpleView.class) 42 | @ApiOperation(value = "查询用户") 43 | public List query(UserQueryCondition condition, @PageableDefault(page=2,size=20,sort="age,asc") Pageable pageable){ 44 | System.out.println(ReflectionToStringBuilder.toString(condition, ToStringStyle.MULTI_LINE_STYLE)); 45 | System.out.println(pageable.getPageSize()); 46 | System.out.println(pageable.getPageNumber()); 47 | System.out.println(pageable.getSort()); 48 | List users = new ArrayList<>(); 49 | users.add(new User()); 50 | users.add(new User()); 51 | users.add(new User()); 52 | return users; 53 | } 54 | 55 | @GetMapping("/{id}") 56 | @JsonView(User.UserDetailView.class) 57 | public User getInfo(@PathVariable String id){//把url路径中的变量传递到参数中 58 | // throw new UserNotExistException("23"); 59 | System.out.println("进入getInfo服务"); 60 | User user = new User(); 61 | user.setUsername("tom"); 62 | return user; 63 | } 64 | 65 | @PutMapping("/{id:\\d+}") 66 | public User update(@Valid @RequestBody User user, BindingResult errors){ 67 | if(errors.hasErrors()){ 68 | errors.getAllErrors().stream().forEach(error->{ 69 | FieldError fieldError = (FieldError) error; 70 | String message = fieldError.getField()+" "+error.getDefaultMessage(); 71 | System.out.println(message); 72 | }); 73 | } 74 | return user; 75 | } 76 | 77 | @PostMapping("json") 78 | public String testJson(@RequestBody UserJson userJson) throws Exception { 79 | Data data = userJson.getData(); 80 | System.out.println(data.getName()); 81 | System.out.println("111111"); 82 | return ""; 83 | } 84 | 85 | @GetMapping("length") 86 | public String testJson(@Valid String username) throws Exception { 87 | System.out.println(username); 88 | return ""; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/filter/TimeFilter.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.filter; 2 | import javax.servlet.*; 3 | import java.io.IOException; 4 | import java.util.Date; 5 | 6 | //@Component 7 | public class TimeFilter implements Filter { 8 | 9 | @Override 10 | public void init(FilterConfig filterConfig) throws ServletException { 11 | System.out.println("TimeFilter init"); 12 | } 13 | 14 | @Override 15 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { 16 | System.out.println("TimeFilter start"); 17 | long start = new Date().getTime(); 18 | filterChain.doFilter(request,response); 19 | System.out.println("time filter: " + (new Date().getTime()-start)); 20 | System.out.println("TimeFilter finish"); 21 | } 22 | 23 | @Override 24 | public void destroy() { 25 | System.out.println("TimeFilter destroy"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/java/com/imooc/web/interceptor/TimeInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.interceptor; 2 | 3 | import org.springframework.stereotype.Component; 4 | import org.springframework.web.method.HandlerMethod; 5 | import org.springframework.web.servlet.HandlerInterceptor; 6 | import org.springframework.web.servlet.ModelAndView; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.util.Date; 11 | 12 | @Component 13 | public class TimeInterceptor implements HandlerInterceptor { 14 | @Override 15 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 16 | System.out.println("preHandle"); 17 | System.out.println(((HandlerMethod) handler).getBean().getClass().getName()); 18 | System.out.println(((HandlerMethod) handler).getMethod().getName()); 19 | request.setAttribute("startTime", new Date().getTime()); 20 | return true; 21 | } 22 | 23 | @Override 24 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { 25 | System.out.println("postHandle"); 26 | long start = (long) request.getAttribute("startTime"); 27 | System.out.println("timeInterceptor 耗时:" + (new Date().getTime() - start)); 28 | } 29 | 30 | @Override 31 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) throws Exception { 32 | System.out.println("afterCompletion"); 33 | long start = (long) request.getAttribute("startTime"); 34 | System.out.println("timeInterceptor 耗时:" + (new Date().getTime() - start)); 35 | System.out.println(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/charlieDJ/imooc-security/157f902c8142456f76267bced40b63e1d64ef9b2/imooc-security-demo/src/main/resources/application.properties -------------------------------------------------------------------------------- /imooc-security-demo/src/main/resources/resources/demo-signIn.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录 6 | 7 | 8 |

Demo登录页

9 | 10 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/resources/resources/error/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 404 6 | 7 | 8 | 你所访问的页面不存在! 9 | 10 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/resources/resources/error/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 500 6 | 7 | 8 | 服务器内部错误! 9 | 10 | -------------------------------------------------------------------------------- /imooc-security-demo/src/main/resources/resources/index1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | index1 9 | 10 | -------------------------------------------------------------------------------- /imooc-security-demo/src/test/java/com/imooc/web/controller/UserControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.imooc.web.controller; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.mock.web.MockMultipartFile; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | import org.springframework.test.web.servlet.MockMvc; 12 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 13 | import org.springframework.web.context.WebApplicationContext; 14 | 15 | import java.time.LocalDateTime; 16 | import java.time.ZoneId; 17 | import java.util.Date; 18 | 19 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 20 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; 21 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 22 | 23 | @RunWith(SpringRunner.class) 24 | @SpringBootTest 25 | public class UserControllerTest { 26 | //伪造mvc环境 27 | @Autowired 28 | private WebApplicationContext wac; 29 | 30 | private MockMvc mockMvc; 31 | 32 | @Before 33 | public void setup(){ 34 | mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); 35 | } 36 | 37 | @Test 38 | public void whenQuerySuccess() throws Exception { 39 | String result = mockMvc.perform(get("/user") 40 | .param("username","jojo") 41 | .param("age","11") 42 | .param("username","16") 43 | .param("xxx","yyy") 44 | // .param("size","15") 45 | // .param("page","3") 46 | // .param("sort","age,desc") 47 | .contentType(MediaType.APPLICATION_JSON_UTF8)) 48 | .andExpect(status().isOk()) 49 | .andExpect(jsonPath("$.length()").value(3)) 50 | .andReturn().getResponse().getContentAsString(); 51 | System.out.println(result); 52 | } 53 | 54 | @Test 55 | public void whenGetInfoSuccess() throws Exception { 56 | mockMvc.perform(get("/user/1") 57 | .contentType(MediaType.APPLICATION_JSON_UTF8)) 58 | .andExpect(status().isOk()) 59 | .andExpect(jsonPath("$.username").value("tom")); 60 | } 61 | 62 | @Test 63 | public void whenCreateSuccess() throws Exception { 64 | Date date = new Date(); 65 | String content = "{\"username\":\"tom\",\"password\":null,\"birthday\":"+date.getTime()+"}"; 66 | String result = mockMvc.perform(post("/user") 67 | .contentType(MediaType.APPLICATION_JSON_UTF8) 68 | .content(content)) 69 | .andExpect(status().isOk()) 70 | .andExpect(jsonPath("$.id").value("1")) 71 | .andReturn().getResponse().getContentAsString(); 72 | System.out.println(result); 73 | } 74 | 75 | @Test 76 | public void whenUpdateSuccess() throws Exception { 77 | Date date = new Date(LocalDateTime.now().plusYears(1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); 78 | String content = "{\"username\":\"tom\",\"id\":\"1\",\"password\":null,\"birthday\":"+date.getTime()+"}"; 79 | String result = mockMvc.perform(put("/user/1") 80 | .contentType(MediaType.APPLICATION_JSON_UTF8) 81 | .content(content)) 82 | .andExpect(status().isOk()) 83 | .andExpect(jsonPath("$.id").value("1")) 84 | .andReturn().getResponse().getContentAsString(); 85 | System.out.println(result); 86 | } 87 | 88 | @Test 89 | public void whenUploadSuccess() throws Exception { 90 | String result = mockMvc.perform(fileUpload("/file") 91 | .file(new MockMultipartFile("file","test.txt","multipart/form-data","hello upload".getBytes("UTF-8")))) 92 | .andExpect(status().isOk()) 93 | .andReturn().getResponse().getContentAsString(); 94 | System.out.println(result); 95 | } 96 | 97 | @Test 98 | public void testLength() throws Exception { 99 | mockMvc.perform(get("/user/length") 100 | .param("username","才才是一个是打啊大家") 101 | .contentType(MediaType.APPLICATION_JSON_UTF8)) 102 | .andExpect(status().isOk()); 103 | 104 | } 105 | 106 | @Test 107 | public void testResolveJson() throws Exception { 108 | String content = "{\"data\":{\"username\":\"liuxing\",\"age\":\"12\"},\"metadata\":{\"full\":\"yes\"}}"; 109 | mockMvc.perform(post("/user/json") 110 | .content(content) 111 | .contentType(MediaType.APPLICATION_JSON_UTF8)) 112 | .andExpect(status().isOk()); 113 | 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /imooc-security.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.imooc.security 8 | imooc-security 9 | pom 10 | 1.0.0-SNAPSHOT 11 | 12 | imooc-security-core 13 | imooc-security-browser 14 | imooc-security-app 15 | imooc-security-demo 16 | 17 | 18 | 19 | 1.0.0-SNAPSHOT 20 | 21 | 22 | 23 | 24 | 25 | io.spring.platform 26 | platform-bom 27 | Brussels-SR5 28 | pom 29 | import 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-dependencies 34 | Dalston.SR4 35 | pom 36 | import 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-compiler-plugin 45 | 2.3.2 46 | 47 | 1.8 48 | 1.8 49 | UTF-8 50 | 51 | 52 | 53 | 54 | --------------------------------------------------------------------------------