├── chapter03 ├── kaptcha │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── index.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── formlogin │ │ │ ├── FormloginApplication.java │ │ │ ├── controller │ │ │ └── MyLoginController.java │ │ │ └── config │ │ │ └── KaptchaConfig.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── formlogin │ │ └── FormloginApplicationTests.java ├── multiuser │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── index.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── formlogin │ │ │ ├── FormloginApplication.java │ │ │ ├── controller │ │ │ └── MyLoginController.java │ │ │ └── config │ │ │ ├── MyAuthenticationSuccessHandler.java │ │ │ └── MyAuthenticationFailureHandler.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── formlogin │ │ └── FormloginApplicationTests.java └── multiuser-mybatis │ └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── static │ │ │ └── index.html │ └── java │ │ └── org │ │ └── javaboy │ │ └── formlogin │ │ ├── FormloginApplication.java │ │ ├── mapper │ │ ├── UserMapper.xml │ │ ├── UserMapper2.xml │ │ ├── UserMapper.java │ │ └── UserMapper2.java │ │ ├── controller │ │ └── MyLoginController.java │ │ ├── model │ │ └── Role.java │ │ ├── service │ │ ├── MyUserDetailsService2.java │ │ └── MyUserDetailsService.java │ │ └── config │ │ ├── MyAuthenticationSuccessHandler.java │ │ └── MyAuthenticationFailureHandler.java │ └── test │ └── java │ └── org │ └── javaboy │ └── formlogin │ └── FormloginApplicationTests.java ├── chapter04 ├── json_login │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── json_login │ │ │ └── JsonLoginApplication.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── json_login │ │ └── JsonLoginApplicationTests.java ├── filter_kaptcha │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── index.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── formlogin │ │ │ ├── FormloginApplication.java │ │ │ ├── controller │ │ │ └── MyLoginController.java │ │ │ └── config │ │ │ └── KaptchaConfig.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── formlogin │ │ └── FormloginApplicationTests.java ├── ignoredrequests │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ ├── images │ │ │ │ └── bg.png │ │ │ │ └── css │ │ │ │ └── font-awesome-4.7.0 │ │ │ │ └── fonts │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ └── fontawesome-webfont.woff2 │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── ignoredrequests │ │ │ ├── IgnoredrequestsApplication.java │ │ │ └── SecurityConfig.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── ignoredrequests │ │ └── IgnoredrequestsApplicationTests.java ├── multi_users01 │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── multi_users01 │ │ │ ├── MultiUsers01Application.java │ │ │ ├── HelloController.java │ │ │ └── SecurityConfig.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── multi_users01 │ │ └── MultiUsers01ApplicationTests.java ├── multi_users02 │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── multi_users02 │ │ │ ├── MultiUsers02Application.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── multi_users02 │ │ └── MultiUsers02ApplicationTests.java ├── multi_users03 │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── multi_users03 │ │ │ ├── MultiUsers03Application.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── multi_users03 │ │ └── MultiUsers03ApplicationTests.java ├── startanalysis │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── META-INF │ │ │ │ └── spring.factories │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── startanalysis │ │ │ └── StartanalysisApplication.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── startanalysis │ │ └── StartanalysisApplicationTests.java ├── multi_filter_chain │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── multi_filter_chain │ │ │ ├── MultiFilterChainApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── multi_filter_chain │ │ └── MultiFilterChainApplicationTests.java └── objectpostprocessor │ └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── org │ │ └── javaboy │ │ └── objectpostprocessor │ │ ├── ObjectpostprocessorApplication.java │ │ └── HelloController.java │ └── test │ └── java │ └── org │ └── javaboy │ └── objectpostprocessor │ └── ObjectpostprocessorApplicationTests.java ├── chapter09 ├── csrf-1 │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── csrf1 │ │ │ ├── Csrf1Application.java │ │ │ ├── HelloController.java │ │ │ └── SecurityConfig.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── csrf1 │ │ └── Csrf1ApplicationTests.java ├── token_in_cookie │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── login.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── token_in_cookie │ │ │ ├── TokenInCookieApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── token_in_cookie │ │ └── TokenInCookieApplicationTests.java ├── csrf-2 │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── index.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── csrf2 │ │ │ └── Csrf2Application.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── csrf2 │ │ └── Csrf2ApplicationTests.java ├── receive_report │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── receive_report │ │ │ ├── ReceiveReportApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── receive_report │ │ └── ReceiveReportApplicationTests.java ├── http_response_headers │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── static │ │ │ │ ├── 01.css │ │ │ │ ├── hello.html │ │ │ │ └── 01.html │ │ │ ├── javaboy.p12 │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── http_response_headers │ │ │ └── HttpResponseHeadersApplication.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── http_response_headers │ │ └── HttpResponseHeadersApplicationTests.java ├── samesite │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── samesite │ │ │ ├── SamesiteApplication.java │ │ │ ├── HelloController.java │ │ │ └── WebMvcConfig.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── samesite │ │ └── SamesiteApplicationTests.java ├── synchronizer_token_pattern │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ ├── index.html │ │ │ │ └── index2.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── synchronizer_token_pattern │ │ │ ├── SynchronizerTokenPatternApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── synchronizer_token_pattern │ │ └── SynchronizerTokenPatternApplicationTests.java └── http │ └── src │ ├── main │ ├── resources │ │ ├── javaboy.p12 │ │ └── application.properties │ └── java │ │ └── org │ │ └── javaboy │ │ └── http │ │ ├── HttpApplication.java │ │ ├── HelloController.java │ │ ├── SecurityConfig.java │ │ └── TomcatConfig.java │ └── test │ └── java │ └── org │ └── javaboy │ └── http │ └── HttpApplicationTests.java ├── chapter06 ├── rememberme │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── rememberme │ │ │ ├── RemembermeApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── rememberme │ │ └── RemembermeApplicationTests.java └── rememberme_persistent │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── rememberme │ │ │ ├── RemembermeApplication.java │ │ │ └── HelloController.java │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── rememberme │ │ └── RemembermeApplicationTests.java │ └── security06.sql ├── chapter10 ├── http_basic │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── http_basic │ │ │ ├── HttpBasicApplication.java │ │ │ ├── HelloController.java │ │ │ └── SecurityConfig.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── http_basic │ │ └── HttpBasicApplicationTests.java └── http_digest │ └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── org │ │ └── javaboy │ │ └── http_digest │ │ ├── HttpDigestApplication.java │ │ └── HelloController.java │ └── test │ └── java │ └── org │ └── javaboy │ └── http_digest │ └── HttpDigestApplicationTests.java ├── chapter05 ├── passwordencoder │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── passwordencoder │ │ │ ├── PasswordencoderApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── passwordencoder │ │ └── PasswordencoderApplicationTests.java └── passwordencoder02 │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── passwordencoder │ │ │ ├── PasswordencoderApplication.java │ │ │ ├── mapper │ │ │ ├── UserMapper.xml │ │ │ └── UserMapper.java │ │ │ └── HelloController.java │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── passwordencoder │ │ └── PasswordencoderApplicationTests.java │ └── security05.sql ├── chapter07 ├── sessionmanager │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── sessionmanager │ │ │ ├── SessionmanagerApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── sessionmanager │ │ └── SessionmanagerApplicationTests.java └── sessionshare │ └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── org │ │ └── javaboy │ │ └── sessionshare │ │ ├── SessionshareApplication.java │ │ └── HelloController.java │ └── test │ └── java │ └── org │ └── javaboy │ └── sessionshare │ └── SessionshareApplicationTests.java ├── chapter13 ├── based_on_method │ └── src │ │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── based_on_method │ │ ├── BasedOnMethodApplication.java │ │ ├── SecurityConfig.java │ │ └── User.java ├── based_on_url │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── based_on_url │ │ │ ├── BasedOnUrlApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── based_on_url │ │ └── BasedOnUrlApplicationTests.java ├── custom_expression │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── based_on_url │ │ │ ├── BasedOnUrlApplication.java │ │ │ ├── PermissionExpression.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── based_on_url │ │ └── BasedOnUrlApplicationTests.java └── base_on_url_dy │ └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── org │ │ └── javaboy │ │ └── base_on_url_dy │ │ ├── BaseOnUrlDyApplication.java │ │ ├── mapper │ │ ├── MenuMapper.java │ │ ├── UserMapper.xml │ │ ├── UserMapper.java │ │ └── MenuMapper.xml │ │ ├── service │ │ ├── MenuService.java │ │ └── UserService.java │ │ ├── model │ │ ├── Role.java │ │ └── Menu.java │ │ └── controller │ │ └── HelloController.java │ └── test │ └── java │ └── org │ └── javaboy │ └── base_on_url_dy │ └── BaseOnUrlDyApplicationTests.java ├── chapter15 ├── oauth2_login_demo3 │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── oauth2_login_demo3 │ │ │ ├── Oauth2LoginDemo3Application.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── oauth2_login_demo3 │ │ └── Oauth2LoginDemo3ApplicationTests.java ├── oauth2 │ ├── auth_server_jwt │ │ └── src │ │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── application.properties │ │ │ │ └── jwt.jks │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── javaboy │ │ │ │ └── auth_server_jwt │ │ │ │ ├── AuthServerJwtApplication.java │ │ │ │ └── HelloController.java │ │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── auth_server_jwt │ │ │ └── AuthServerJwtApplicationTests.java │ ├── res_server_jwt │ │ └── src │ │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── javaboy │ │ │ │ └── res_server_jwt │ │ │ │ ├── ResServerJwtApplication.java │ │ │ │ ├── HelloController.java │ │ │ │ └── config │ │ │ │ └── OAuth2ResourceServerSecurityConfiguration.java │ │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── res_server_jwt │ │ │ └── ResServerJwtApplicationTests.java │ ├── auth_server │ │ └── src │ │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── javaboy │ │ │ │ └── auth_server │ │ │ │ ├── AuthServerApplication.java │ │ │ │ ├── HelloController.java │ │ │ │ └── config │ │ │ │ └── AccessTokenConfig.java │ │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── auth_server │ │ │ └── AuthServerApplicationTests.java │ ├── auth_server_redis │ │ └── src │ │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── javaboy │ │ │ │ └── auth_server_redis │ │ │ │ ├── AuthServerRedisApplication.java │ │ │ │ ├── HelloController.java │ │ │ │ └── config │ │ │ │ └── AccessTokenConfig.java │ │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── auth_server_redis │ │ │ └── AuthServerRedisApplicationTests.java │ ├── res_server │ │ └── src │ │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── javaboy │ │ │ │ └── res_server │ │ │ │ ├── ResServerApplication.java │ │ │ │ └── HelloController.java │ │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── res_server │ │ │ └── ResServerApplicationTests.java │ ├── client02 │ │ └── src │ │ │ ├── test │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── javaboy │ │ │ │ └── client02 │ │ │ │ └── Client02ApplicationTests.java │ │ │ └── main │ │ │ ├── java │ │ │ └── org │ │ │ │ └── javaboy │ │ │ │ └── client02 │ │ │ │ └── Client02Application.java │ │ │ └── resources │ │ │ └── application.yml │ ├── auth_server_jdbc │ │ └── src │ │ │ ├── test │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── javaboy │ │ │ │ └── auth_server_jdbc │ │ │ │ └── AuthServerJdbcApplicationTests.java │ │ │ └── main │ │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── oauth_client_details.sql │ │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── auth_server_jdbc │ │ │ ├── AuthServerJdbcApplication.java │ │ │ ├── HelloController.java │ │ │ └── config │ │ │ └── AccessTokenConfig.java │ └── pom.xml ├── oauth2_login_demo │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── oauth2_login_demo │ │ │ ├── Oauth2LoginDemoApplication.java │ │ │ ├── SecurityConfig.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── oauth2_login_demo │ │ └── Oauth2LoginDemoApplicationTests.java └── oauth2_login_demo2 │ └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── org │ │ └── javaboy │ │ └── oauth2_login_demo2 │ │ ├── Oauth2LoginDemo2Application.java │ │ └── HelloController.java │ └── test │ └── java │ └── org │ └── javaboy │ └── oauth2_login_demo2 │ └── Oauth2LoginDemo2ApplicationTests.java ├── chapter11 ├── cors01_corsfilter │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── 01.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── cors01 │ │ │ ├── Cors01Application.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── cors01 │ │ └── Cors01ApplicationTests.java ├── cors01_crossorigin │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── 01.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── cors01 │ │ │ ├── Cors01Application.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── cors01 │ │ └── Cors01ApplicationTests.java ├── cors02 │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ ├── index.html │ │ │ │ └── login.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── cors02 │ │ │ └── Cors02Application.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── cors02 │ │ └── Cors02ApplicationTests.java ├── cors01_addcorsmappings │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── 01.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── cors01 │ │ │ ├── Cors01Application.java │ │ │ ├── HelloController.java │ │ │ └── WebMvcConfig.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── cors01 │ │ └── Cors01ApplicationTests.java ├── cors_security │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── cors_security │ │ │ ├── CorsSecurityApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── cors_security │ │ └── CorsSecurityApplicationTests.java ├── cors_security_crossorigin │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── cors_security │ │ │ ├── CorsSecurityApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── cors_security │ │ └── CorsSecurityApplicationTests.java └── cors_security_corsfilter │ └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── org │ │ └── javaboy │ │ └── cors_security │ │ ├── CorsSecurityApplication.java │ │ └── HelloController.java │ └── test │ └── java │ └── org │ └── javaboy │ └── cors_security │ └── CorsSecurityApplicationTests.java ├── chapter02 ├── formlogin │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── index.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── formlogin │ │ │ ├── FormloginApplication.java │ │ │ ├── MyLoginController.java │ │ │ ├── MyAuthenticationSuccessHandler.java │ │ │ └── MyAuthenticationFailureHandler.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── formlogin │ │ └── FormloginApplicationTests.java ├── getloginuser │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── getloginuser │ │ │ ├── GetloginuserApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── getloginuser │ │ └── GetloginuserApplicationTests.java ├── user-in-memory │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── index.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── formlogin │ │ │ ├── FormloginApplication.java │ │ │ ├── MyLoginController.java │ │ │ ├── MyAuthenticationSuccessHandler.java │ │ │ └── MyAuthenticationFailureHandler.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── formlogin │ │ └── FormloginApplicationTests.java ├── firstdemo │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── firstdemo │ │ │ ├── FirstdemoApplication.java │ │ │ └── HelloController.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── firstdemo │ │ └── FirstdemoApplicationTests.java ├── jpa │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── static │ │ │ │ └── index.html │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── formlogin │ │ │ ├── FormloginApplication.java │ │ │ ├── mapper │ │ │ └── UserDao.java │ │ │ ├── controller │ │ │ └── MyLoginController.java │ │ │ ├── service │ │ │ └── MyUserDetailsService.java │ │ │ ├── config │ │ │ ├── MyAuthenticationSuccessHandler.java │ │ │ └── MyAuthenticationFailureHandler.java │ │ │ └── model │ │ │ └── Role.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── formlogin │ │ └── FormloginApplicationTests.java ├── mybatis │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── static │ │ │ │ └── index.html │ │ └── java │ │ │ └── org │ │ │ └── javaboy │ │ │ └── formlogin │ │ │ ├── FormloginApplication.java │ │ │ ├── mapper │ │ │ ├── UserMapper.xml │ │ │ └── UserMapper.java │ │ │ ├── controller │ │ │ └── MyLoginController.java │ │ │ ├── model │ │ │ └── Role.java │ │ │ ├── service │ │ │ └── MyUserDetailsService.java │ │ │ └── config │ │ │ ├── MyAuthenticationSuccessHandler.java │ │ │ └── MyAuthenticationFailureHandler.java │ │ └── test │ │ └── java │ │ └── org │ │ └── javaboy │ │ └── formlogin │ │ └── FormloginApplicationTests.java └── jdbcuserdetailsmanager │ └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── static │ │ │ └── index.html │ └── java │ │ └── org │ │ └── javaboy │ │ └── formlogin │ │ ├── FormloginApplication.java │ │ ├── MyLoginController.java │ │ ├── MyAuthenticationSuccessHandler.java │ │ └── MyAuthenticationFailureHandler.java │ └── test │ └── java │ └── org │ └── javaboy │ └── formlogin │ └── FormloginApplicationTests.java ├── chapter12 └── exception_translation_filter │ └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── org │ │ └── javaboy │ │ └── exception_translation_filter │ │ ├── ExceptionTranslationFilterApplication.java │ │ ├── GlobalException.java │ │ └── HelloController.java │ └── test │ └── java │ └── org │ └── javaboy │ └── exception_translation_filter │ └── ExceptionTranslationFilterApplicationTests.java ├── chapter08 └── httpfirewall │ └── src │ ├── main │ ├── resources │ │ └── application.properties │ └── java │ │ └── org │ │ └── javaboy │ │ └── httpfirewall │ │ ├── HttpfirewallApplication.java │ │ └── HelloController.java │ └── test │ └── java │ └── org │ └── javaboy │ └── httpfirewall │ └── HttpfirewallApplicationTests.java ├── README.md └── chapter14 └── acl └── src └── main ├── resources ├── application.properties ├── system_message.sql └── data.sql └── java └── org └── javaboy └── acl ├── AclApplication.java ├── mapper ├── NoticeMessageMapper.java └── NoticeMessageMapper.xml └── model └── NoticeMessage.java /chapter03/kaptcha/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /chapter03/multiuser/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /chapter04/json_login/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /chapter09/csrf-1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter04/filter_kaptcha/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /chapter06/rememberme/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter09/token_in_cookie/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /chapter10/http_basic/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter10/http_digest/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter04/ignoredrequests/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter04/multi_users01/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter04/multi_users02/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter04/multi_users03/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter04/startanalysis/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter05/passwordencoder/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter07/sessionmanager/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter13/based_on_method/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter13/based_on_url/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo3/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /chapter04/multi_filter_chain/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter09/csrf-2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 -------------------------------------------------------------------------------- /chapter11/cors01_corsfilter/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter11/cors01_crossorigin/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter11/cors02/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 -------------------------------------------------------------------------------- /chapter13/custom_expression/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter09/receive_report/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 -------------------------------------------------------------------------------- /chapter11/cors01_addcorsmappings/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jwt/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8881 -------------------------------------------------------------------------------- /chapter15/oauth2/res_server_jwt/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8882 -------------------------------------------------------------------------------- /chapter09/http_response_headers/src/main/resources/static/01.css: -------------------------------------------------------------------------------- 1 | body{ 2 | background-color: #ff0114; 3 | } -------------------------------------------------------------------------------- /chapter02/formlogin/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8881 2 | logging.level.org.springframework=debug -------------------------------------------------------------------------------- /chapter02/getloginuser/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 -------------------------------------------------------------------------------- /chapter02/user-in-memory/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 -------------------------------------------------------------------------------- /chapter11/cors_security/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 -------------------------------------------------------------------------------- /chapter04/objectpostprocessor/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 -------------------------------------------------------------------------------- /chapter07/sessionshare/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.redis.password=123 2 | spring.redis.host=127.0.0.1 3 | spring.redis.port=6379 -------------------------------------------------------------------------------- /chapter09/samesite/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.redis.password=123 2 | spring.redis.host=127.0.0.1 3 | spring.redis.port=6379 -------------------------------------------------------------------------------- /chapter11/cors_security_crossorigin/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 -------------------------------------------------------------------------------- /chapter09/synchronizer_token_pattern/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 -------------------------------------------------------------------------------- /chapter12/exception_translation_filter/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 -------------------------------------------------------------------------------- /chapter09/http/src/main/resources/javaboy.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenve/spring-security-book-samples/HEAD/chapter09/http/src/main/resources/javaboy.p12 -------------------------------------------------------------------------------- /chapter02/firstdemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 3 | spring.security.user.roles=admin,user -------------------------------------------------------------------------------- /chapter08/httpfirewall/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 3 | 4 | #server.servlet.context-path=/javaboy -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jwt/src/main/resources/jwt.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenve/spring-security-book-samples/HEAD/chapter15/oauth2/auth_server_jwt/src/main/resources/jwt.jks -------------------------------------------------------------------------------- /chapter11/cors_security_corsfilter/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 3 | 4 | spring.security.filter.order=-100 -------------------------------------------------------------------------------- /chapter09/http_response_headers/src/main/resources/javaboy.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenve/spring-security-book-samples/HEAD/chapter09/http_response_headers/src/main/resources/javaboy.p12 -------------------------------------------------------------------------------- /chapter04/ignoredrequests/src/main/resources/static/images/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenve/spring-security-book-samples/HEAD/chapter04/ignoredrequests/src/main/resources/static/images/bg.png -------------------------------------------------------------------------------- /chapter04/startanalysis/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer=org.springframework.security.config.annotation.web.configurers.CorsConfigurer -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_redis/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8881 2 | logging.level.org.springframework=debug 3 | 4 | spring.redis.host=127.0.0.1 5 | spring.redis.port=6379 6 | spring.redis.password=123 7 | -------------------------------------------------------------------------------- /chapter02/jpa/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 江南一点雨 6 | 7 | 8 |

hello 江南一点雨~

9 | 10 | -------------------------------------------------------------------------------- /chapter02/formlogin/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 江南一点雨 6 | 7 | 8 |

hello 江南一点雨~

9 | 10 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.username=root 2 | spring.datasource.password=123 3 | spring.datasource.url=jdbc:mysql:///security02?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 江南一点雨 6 | 7 | 8 |

hello 江南一点雨~

9 | 10 | -------------------------------------------------------------------------------- /chapter03/kaptcha/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 江南一点雨 6 | 7 | 8 |

hello 江南一点雨~

9 | 10 | -------------------------------------------------------------------------------- /chapter03/multiuser/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 江南一点雨 6 | 7 | 8 |

hello 江南一点雨~

9 | 10 | -------------------------------------------------------------------------------- /chapter11/cors01_corsfilter/src/main/resources/static/01.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

01.html

9 | 10 | -------------------------------------------------------------------------------- /chapter11/cors01_crossorigin/src/main/resources/static/01.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

01.html

9 | 10 | -------------------------------------------------------------------------------- /chapter02/user-in-memory/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 江南一点雨 6 | 7 | 8 |

hello 江南一点雨~

9 | 10 | -------------------------------------------------------------------------------- /chapter04/filter_kaptcha/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 江南一点雨 6 | 7 | 8 |

hello 江南一点雨~

9 | 10 | -------------------------------------------------------------------------------- /chapter11/cors01_addcorsmappings/src/main/resources/static/01.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

01.html

9 | 10 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.username=root 2 | spring.datasource.password=123 3 | spring.datasource.url=jdbc:mysql:///security02?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 江南一点雨 6 | 7 | 8 |

hello 江南一点雨~

9 | 10 | -------------------------------------------------------------------------------- /chapter05/passwordencoder02/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.username=root 2 | spring.datasource.password=123 3 | spring.datasource.url=jdbc:mysql:///security05?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.username=root 2 | spring.datasource.password=123 3 | spring.datasource.url=jdbc:mysql:///security13?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai 4 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.oauth2.client.registration.github.client-id=aa9e79846df9cbc6201f 2 | spring.security.oauth2.client.registration.github.client-secret=c324b93443594fe84d106bb32c904799e1839e6a -------------------------------------------------------------------------------- /chapter02/jdbcuserdetailsmanager/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.username=root 2 | spring.datasource.password=123 3 | spring.datasource.url=jdbc:mysql:///security?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai 4 | -------------------------------------------------------------------------------- /chapter02/jdbcuserdetailsmanager/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 江南一点雨 6 | 7 | 8 |

hello 江南一点雨~

9 | 10 | -------------------------------------------------------------------------------- /chapter06/rememberme_persistent/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql:///security06?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai 2 | spring.datasource.username=root 3 | spring.datasource.password=123 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # spring-security-book-samples 2 | 3 | 这是 **《深入浅出 Spring Security》** 一书的配套案例。 4 | 5 | 图书购买地址:[京东](https://item.jd.com/13131798.html) 6 | 7 | 关注微信公众号【江南一点雨】,回复 `ss`,获取更多 Spring Security 学习资料。 8 | 9 | ![](https://open.weixin.qq.com/qr/code?username=a_javaboy) -------------------------------------------------------------------------------- /chapter04/ignoredrequests/src/main/resources/static/css/font-awesome-4.7.0/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenve/spring-security-book-samples/HEAD/chapter04/ignoredrequests/src/main/resources/static/css/font-awesome-4.7.0/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /chapter04/ignoredrequests/src/main/resources/static/css/font-awesome-4.7.0/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenve/spring-security-book-samples/HEAD/chapter04/ignoredrequests/src/main/resources/static/css/font-awesome-4.7.0/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /chapter04/ignoredrequests/src/main/resources/static/css/font-awesome-4.7.0/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenve/spring-security-book-samples/HEAD/chapter04/ignoredrequests/src/main/resources/static/css/font-awesome-4.7.0/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /chapter04/ignoredrequests/src/main/resources/static/css/font-awesome-4.7.0/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lenve/spring-security-book-samples/HEAD/chapter04/ignoredrequests/src/main/resources/static/css/font-awesome-4.7.0/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /chapter09/http/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 3 | 4 | server.port=8444 5 | 6 | server.ssl.key-store=classpath:javaboy.p12 7 | server.ssl.key-alias=tomcathttps 8 | server.ssl.key-store-password=111111 9 | -------------------------------------------------------------------------------- /chapter14/acl/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql:///acls?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai 2 | spring.datasource.username=root 3 | spring.datasource.password=123 4 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -------------------------------------------------------------------------------- /chapter14/acl/src/main/resources/system_message.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `system_message` ( 2 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 3 | `content` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 4 | PRIMARY KEY (`id`) 5 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -------------------------------------------------------------------------------- /chapter09/http_response_headers/src/main/resources/static/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 |

hello.html

10 | 11 | -------------------------------------------------------------------------------- /chapter09/http_response_headers/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.user.name=javaboy 2 | spring.security.user.password=123 3 | 4 | logging.level.org.springframework.security=debug 5 | 6 | server.ssl.key-store=classpath:javaboy.p12 7 | server.ssl.key-alias=tomcathttps 8 | server.ssl.key-store-password=111111 -------------------------------------------------------------------------------- /chapter09/http/src/test/java/org/javaboy/http/HttpApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class HttpApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/test/java/org/javaboy/base_on_url_dy/BaseOnUrlDyApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.base_on_url_dy; 2 | 3 | import org.springframework.boot.test.context.SpringBootTest; 4 | 5 | @SpringBootTest 6 | class BaseOnUrlDyApplicationTests { 7 | 8 | // @Test 9 | void contextLoads() { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /chapter09/csrf-1/src/test/java/org/javaboy/csrf1/Csrf1ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.csrf1; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Csrf1ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/csrf-2/src/test/java/org/javaboy/csrf2/Csrf2ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.csrf2; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Csrf2ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors02/src/test/java/org/javaboy/cors02/Cors02ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors02; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Cors02ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/res_server/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | security: 3 | oauth2: 4 | resourceserver: 5 | opaque: 6 | introspection-uri: http://auth.javaboy.org:8881/oauth/check_token 7 | introspection-client-id: my_client 8 | introspection-client-secret: 123 9 | server: 10 | port: 8882 -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.security.oauth2.client.registration.github.client-id=aa9e79846df9cbc6201f 2 | spring.security.oauth2.client.registration.github.client-secret=c324b93443594fe84d106bb32c904799e1839e6a 3 | spring.security.oauth2.client.registration.github.redirect-uri=http://localhost:8080/authorization_code -------------------------------------------------------------------------------- /chapter09/samesite/src/test/java/org/javaboy/samesite/SamesiteApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.samesite; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SamesiteApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors01_corsfilter/src/test/java/org/javaboy/cors01/Cors01ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Cors01ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/formlogin/src/test/java/org/javaboy/formlogin/FormloginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FormloginApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/test/java/org/javaboy/formlogin/FormloginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FormloginApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter03/kaptcha/src/test/java/org/javaboy/formlogin/FormloginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FormloginApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter03/multiuser/src/test/java/org/javaboy/formlogin/FormloginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FormloginApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors01_addcorsmappings/src/test/java/org/javaboy/cors01/Cors01ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Cors01ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors01_crossorigin/src/test/java/org/javaboy/cors01/Cors01ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Cors01ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/user-in-memory/src/test/java/org/javaboy/formlogin/FormloginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FormloginApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/filter_kaptcha/src/test/java/org/javaboy/formlogin/FormloginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FormloginApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/json_login/src/test/java/org/javaboy/json_login/JsonLoginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.json_login; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class JsonLoginApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter10/http_basic/src/test/java/org/javaboy/http_basic/HttpBasicApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http_basic; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class HttpBasicApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/client02/src/test/java/org/javaboy/client02/Client02ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.client02; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Client02ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/test/java/org/javaboy/formlogin/FormloginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FormloginApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter13/based_on_url/src/test/java/org/javaboy/based_on_url/BasedOnUrlApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_url; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BasedOnUrlApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/res_server/src/test/java/org/javaboy/res_server/ResServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.res_server; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ResServerApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/getloginuser/src/test/java/org/javaboy/getloginuser/GetloginuserApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.getloginuser; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class GetloginuserApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/jdbcuserdetailsmanager/src/test/java/org/javaboy/formlogin/FormloginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class FormloginApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter07/sessionshare/src/test/java/org/javaboy/sessionshare/SessionshareApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.sessionshare; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SessionshareApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter13/custom_expression/src/test/java/org/javaboy/based_on_url/BasedOnUrlApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_url; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BasedOnUrlApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter14/acl/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO `acl_class` (`id`, `class`) 2 | VALUES 3 | (1,'org.javaboy.acls.model.NoticeMessage'); 4 | INSERT INTO `acl_sid` (`id`, `principal`, `sid`) 5 | VALUES 6 | (2,1,'hr'), 7 | (1,1,'manager'), 8 | (3,0,'ROLE_EDITOR'); 9 | INSERT INTO `system_message` (`id`, `content`) 10 | VALUES 11 | (1,'111'), 12 | (2,'222'), 13 | (3,'333'); -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server/src/test/java/org/javaboy/auth_server/AuthServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AuthServerApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/multi_users01/src/test/java/org/javaboy/multi_users01/MultiUsers01ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users01; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class MultiUsers01ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/multi_users02/src/test/java/org/javaboy/multi_users02/MultiUsers02ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users02; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class MultiUsers02ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/multi_users03/src/test/java/org/javaboy/multi_users03/MultiUsers03ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users03; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class MultiUsers03ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors_security/src/test/java/org/javaboy/cors_security/CorsSecurityApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors_security; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class CorsSecurityApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter07/sessionmanager/src/test/java/org/javaboy/sessionmanager/SessionmanagerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.sessionmanager; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SessionmanagerApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/receive_report/src/test/java/org/javaboy/receive_report/ReceiveReportApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.receive_report; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ReceiveReportApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/token_in_cookie/src/test/java/org/javaboy/token_in_cookie/TokenInCookieApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.token_in_cookie; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TokenInCookieApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/ignoredrequests/src/test/java/org/javaboy/ignoredrequests/IgnoredrequestsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.ignoredrequests; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class IgnoredrequestsApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors_security_corsfilter/src/test/java/org/javaboy/cors_security/CorsSecurityApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors_security; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class CorsSecurityApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors_security_crossorigin/src/test/java/org/javaboy/cors_security/CorsSecurityApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors_security; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class CorsSecurityApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/res_server_jwt/src/test/java/org/javaboy/res_server_jwt/ResServerJwtApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.res_server_jwt; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ResServerJwtApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jwt/src/test/java/org/javaboy/auth_server_jwt/AuthServerJwtApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_jwt; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AuthServerJwtApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo/src/test/java/org/javaboy/oauth2_login_demo/Oauth2LoginDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Oauth2LoginDemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/multi_filter_chain/src/test/java/org/javaboy/multi_filter_chain/MultiFilterChainApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_filter_chain; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class MultiFilterChainApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jdbc/src/test/java/org/javaboy/auth_server_jdbc/AuthServerJdbcApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_jdbc; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AuthServerJdbcApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo2/src/test/java/org/javaboy/oauth2_login_demo2/Oauth2LoginDemo2ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo2; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Oauth2LoginDemo2ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo3/src/test/java/org/javaboy/oauth2_login_demo3/Oauth2LoginDemo3ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo3; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class Oauth2LoginDemo3ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_redis/src/test/java/org/javaboy/auth_server_redis/AuthServerRedisApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_redis; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class AuthServerRedisApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/objectpostprocessor/src/test/java/org/javaboy/objectpostprocessor/ObjectpostprocessorApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.objectpostprocessor; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ObjectpostprocessorApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/http_response_headers/src/main/resources/static/01.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 |

01.html

11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /chapter09/http_response_headers/src/test/java/org/javaboy/http_response_headers/HttpResponseHeadersApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http_response_headers; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class HttpResponseHeadersApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter14/acl/src/main/java/org/javaboy/acl/AclApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.acl; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class AclApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(AclApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/http/src/main/java/org/javaboy/http/HttpApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HttpApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HttpApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/csrf-1/src/main/java/org/javaboy/csrf1/Csrf1Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.csrf1; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Csrf1Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Csrf1Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/csrf-2/src/main/java/org/javaboy/csrf2/Csrf2Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.csrf2; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Csrf2Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Csrf2Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/csrf-2/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |
9 | 10 | 11 | 12 |
13 | 14 | -------------------------------------------------------------------------------- /chapter09/synchronizer_token_pattern/src/test/java/org/javaboy/synchronizer_token_pattern/SynchronizerTokenPatternApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.synchronizer_token_pattern; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SynchronizerTokenPatternApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors02/src/main/java/org/javaboy/cors02/Cors02Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors02; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Cors02Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Cors02Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/jpa/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.username=root 2 | spring.datasource.password=123 3 | spring.datasource.url=jdbc:mysql:///security03?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai 4 | 5 | spring.jpa.database=mysql 6 | spring.jpa.database-platform=mysql 7 | spring.jpa.hibernate.ddl-auto=update 8 | spring.jpa.show-sql=true 9 | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect -------------------------------------------------------------------------------- /chapter09/synchronizer_token_pattern/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |
9 | 10 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /chapter09/synchronizer_token_pattern/src/main/resources/templates/index2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |
9 | 10 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /chapter02/jpa/src/main/java/org/javaboy/formlogin/FormloginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class FormloginApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(FormloginApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/samesite/src/main/java/org/javaboy/samesite/SamesiteApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.samesite; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SamesiteApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SamesiteApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors01_corsfilter/src/main/java/org/javaboy/cors01/Cors01Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Cors01Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Cors01Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors01_crossorigin/src/main/java/org/javaboy/cors01/Cors01Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Cors01Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Cors01Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jdbc/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8881 2 | logging.level.org.springframework=debug 3 | 4 | spring.datasource.url=jdbc:mysql:///security15?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai 5 | spring.datasource.password=123 6 | spring.datasource.username=root 7 | 8 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 9 | 10 | spring.main.allow-bean-definition-overriding=true -------------------------------------------------------------------------------- /chapter03/kaptcha/src/main/java/org/javaboy/formlogin/FormloginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class FormloginApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(FormloginApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors01_addcorsmappings/src/main/java/org/javaboy/cors01/Cors01Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Cors01Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Cors01Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/firstdemo/src/main/java/org/javaboy/firstdemo/FirstdemoApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.firstdemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class FirstdemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(FirstdemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/formlogin/src/main/java/org/javaboy/formlogin/FormloginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class FormloginApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(FormloginApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter03/multiuser/src/main/java/org/javaboy/formlogin/FormloginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class FormloginApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(FormloginApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/json_login/src/main/java/org/javaboy/json_login/JsonLoginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.json_login; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class JsonLoginApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(JsonLoginApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter10/http_basic/src/main/java/org/javaboy/http_basic/HttpBasicApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http_basic; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HttpBasicApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HttpBasicApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/client02/src/main/java/org/javaboy/client02/Client02Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.client02; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Client02Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Client02Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/user-in-memory/src/main/java/org/javaboy/formlogin/FormloginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class FormloginApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(FormloginApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/filter_kaptcha/src/main/java/org/javaboy/formlogin/FormloginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class FormloginApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(FormloginApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter06/rememberme/src/main/java/org/javaboy/rememberme/RemembermeApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.rememberme; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RemembermeApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RemembermeApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter10/http_digest/src/main/java/org/javaboy/http_digest/HttpDigestApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http_digest; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HttpDigestApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HttpDigestApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/jdbcuserdetailsmanager/src/main/java/org/javaboy/formlogin/FormloginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class FormloginApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(FormloginApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter13/based_on_url/src/main/java/org/javaboy/based_on_url/BasedOnUrlApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_url; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BasedOnUrlApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BasedOnUrlApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/res_server/src/main/java/org/javaboy/res_server/ResServerApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.res_server; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ResServerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ResServerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/getloginuser/src/main/java/org/javaboy/getloginuser/GetloginuserApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.getloginuser; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class GetloginuserApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(GetloginuserApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter06/rememberme_persistent/src/main/java/org/javaboy/rememberme/RemembermeApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.rememberme; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RemembermeApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RemembermeApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter07/sessionshare/src/main/java/org/javaboy/sessionshare/SessionshareApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.sessionshare; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SessionshareApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SessionshareApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter08/httpfirewall/src/main/java/org/javaboy/httpfirewall/HttpfirewallApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.httpfirewall; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HttpfirewallApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HttpfirewallApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter13/custom_expression/src/main/java/org/javaboy/based_on_url/BasedOnUrlApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_url; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BasedOnUrlApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BasedOnUrlApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server/src/main/java/org/javaboy/auth_server/AuthServerApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class AuthServerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(AuthServerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/multi_users01/src/main/java/org/javaboy/multi_users01/MultiUsers01Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users01; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MultiUsers01Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MultiUsers01Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/multi_users02/src/main/java/org/javaboy/multi_users02/MultiUsers02Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users02; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MultiUsers02Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MultiUsers02Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/multi_users03/src/main/java/org/javaboy/multi_users03/MultiUsers03Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users03; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MultiUsers03Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MultiUsers03Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/startanalysis/src/main/java/org/javaboy/startanalysis/StartanalysisApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.startanalysis; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class StartanalysisApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(StartanalysisApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors_security/src/main/java/org/javaboy/cors_security/CorsSecurityApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors_security; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CorsSecurityApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CorsSecurityApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/BaseOnUrlDyApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.base_on_url_dy; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BaseOnUrlDyApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BaseOnUrlDyApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.javaboy 8 | oauth2 9 | 1.0-SNAPSHOT 10 | 11 | 12 | -------------------------------------------------------------------------------- /chapter09/receive_report/src/main/java/org/javaboy/receive_report/ReceiveReportApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.receive_report; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ReceiveReportApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ReceiveReportApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter07/sessionmanager/src/main/java/org/javaboy/sessionmanager/SessionmanagerApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.sessionmanager; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SessionmanagerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SessionmanagerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/token_in_cookie/src/main/java/org/javaboy/token_in_cookie/TokenInCookieApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.token_in_cookie; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TokenInCookieApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TokenInCookieApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors_security_corsfilter/src/main/java/org/javaboy/cors_security/CorsSecurityApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors_security; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CorsSecurityApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CorsSecurityApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter11/cors_security_crossorigin/src/main/java/org/javaboy/cors_security/CorsSecurityApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors_security; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CorsSecurityApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CorsSecurityApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter13/based_on_method/src/main/java/org/javaboy/based_on_method/BasedOnMethodApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_method; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BasedOnMethodApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BasedOnMethodApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/res_server_jwt/src/main/java/org/javaboy/res_server_jwt/ResServerJwtApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.res_server_jwt; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ResServerJwtApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ResServerJwtApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/ignoredrequests/src/main/java/org/javaboy/ignoredrequests/IgnoredrequestsApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.ignoredrequests; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class IgnoredrequestsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(IgnoredrequestsApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jwt/src/main/java/org/javaboy/auth_server_jwt/AuthServerJwtApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_jwt; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class AuthServerJwtApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(AuthServerJwtApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jdbc/src/main/java/org/javaboy/auth_server_jdbc/AuthServerJdbcApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_jdbc; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class AuthServerJdbcApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(AuthServerJdbcApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo/src/main/java/org/javaboy/oauth2_login_demo/Oauth2LoginDemoApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Oauth2LoginDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Oauth2LoginDemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter04/multi_filter_chain/src/main/java/org/javaboy/multi_filter_chain/MultiFilterChainApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_filter_chain; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MultiFilterChainApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MultiFilterChainApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_redis/src/main/java/org/javaboy/auth_server_redis/AuthServerRedisApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_redis; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class AuthServerRedisApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(AuthServerRedisApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo2/src/main/java/org/javaboy/oauth2_login_demo2/Oauth2LoginDemo2Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo2; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Oauth2LoginDemo2Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Oauth2LoginDemo2Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo3/src/main/java/org/javaboy/oauth2_login_demo3/Oauth2LoginDemo3Application.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo3; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Oauth2LoginDemo3Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Oauth2LoginDemo3Application.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/java/org/javaboy/formlogin/FormloginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class FormloginApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(FormloginApplication.class, args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/FormloginApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class FormloginApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(FormloginApplication.class, args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /chapter04/objectpostprocessor/src/main/java/org/javaboy/objectpostprocessor/ObjectpostprocessorApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.objectpostprocessor; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ObjectpostprocessorApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ObjectpostprocessorApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/http_response_headers/src/main/java/org/javaboy/http_response_headers/HttpResponseHeadersApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http_response_headers; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HttpResponseHeadersApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HttpResponseHeadersApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter09/synchronizer_token_pattern/src/main/java/org/javaboy/synchronizer_token_pattern/SynchronizerTokenPatternApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.synchronizer_token_pattern; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SynchronizerTokenPatternApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SynchronizerTokenPatternApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter06/rememberme_persistent/security06.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS security06 COLLATE utf8mb4_unicode_ci; 2 | 3 | USE security06; 4 | 5 | CREATE TABLE `persistent_logins` ( 6 | `username` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, 7 | `series` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, 8 | `token` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, 9 | `last_used` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 10 | PRIMARY KEY (`series`) 11 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -------------------------------------------------------------------------------- /chapter12/exception_translation_filter/src/main/java/org/javaboy/exception_translation_filter/ExceptionTranslationFilterApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.exception_translation_filter; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ExceptionTranslationFilterApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ExceptionTranslationFilterApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chapter05/passwordencoder/src/main/java/org/javaboy/passwordencoder/PasswordencoderApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.passwordencoder; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.crypto.password.PasswordEncoder; 6 | 7 | @SpringBootApplication 8 | public class PasswordencoderApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(PasswordencoderApplication.class, args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /chapter05/passwordencoder02/src/main/java/org/javaboy/passwordencoder/PasswordencoderApplication.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.passwordencoder; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.crypto.password.PasswordEncoder; 6 | 7 | @SpringBootApplication 8 | public class PasswordencoderApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(PasswordencoderApplication.class, args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /chapter02/jpa/src/main/java/org/javaboy/formlogin/mapper/UserDao.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.mapper; 2 | 3 | import org.javaboy.formlogin.model.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | public interface UserDao extends JpaRepository { 16 | User findUserByUsername(String username); 17 | } -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/mapper/MenuMapper.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.base_on_url_dy.mapper; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | import org.javaboy.base_on_url_dy.model.Menu; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Mapper 18 | public interface MenuMapper { 19 | List getAllMenu(); 20 | } 21 | -------------------------------------------------------------------------------- /chapter05/passwordencoder02/security05.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE IF NOT EXISTS security05 COLLATE utf8mb4_unicode_ci; 2 | 3 | USE security05; 4 | 5 | DROP TABLE IF EXISTS `user`; 6 | 7 | CREATE TABLE `user` ( 8 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 9 | `username` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 10 | `password` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 11 | PRIMARY KEY (`id`) 12 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 13 | 14 | INSERT INTO `user` (`id`, `username`, `password`) 15 | VALUES (1,'javaboy','{noop}123'); 16 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/java/org/javaboy/formlogin/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 11 | -------------------------------------------------------------------------------- /chapter05/passwordencoder02/src/main/java/org/javaboy/passwordencoder/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 9 | update user set password = #{newPassword} where username=#{username}; 10 | 11 | 12 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 11 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/mapper/UserMapper2.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 8 | 11 | -------------------------------------------------------------------------------- /chapter04/startanalysis/src/test/java/org/javaboy/startanalysis/StartanalysisApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.startanalysis; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | import java.util.ArrayList; 7 | import java.util.LinkedHashMap; 8 | 9 | @SpringBootTest 10 | class StartanalysisApplicationTests { 11 | 12 | @Test 13 | void contextLoads() { 14 | ArrayList list = new ArrayList<>(1); 15 | list.add(1); 16 | list.add(1); 17 | list.add(1); 18 | System.out.println(list); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /chapter02/formlogin/src/main/java/org/javaboy/formlogin/MyLoginController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @Controller 16 | public class MyLoginController { 17 | @RequestMapping("/mylogin.html") 18 | public String mylogin() { 19 | return "mylogin"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter06/rememberme/src/main/java/org/javaboy/rememberme/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.rememberme; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter10/http_digest/src/main/java/org/javaboy/http_digest/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http_digest; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter02/user-in-memory/src/main/java/org/javaboy/formlogin/MyLoginController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @Controller 16 | public class MyLoginController { 17 | @RequestMapping("/mylogin.html") 18 | public String mylogin() { 19 | return "mylogin"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter04/multi_users01/src/main/java/org/javaboy/multi_users01/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users01; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter04/multi_users02/src/main/java/org/javaboy/multi_users02/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users02; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter04/multi_users03/src/main/java/org/javaboy/multi_users03/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users03; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter07/sessionmanager/src/main/java/org/javaboy/sessionmanager/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.sessionmanager; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter02/firstdemo/src/main/java/org/javaboy/firstdemo/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.firstdemo; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello spring security"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter10/http_basic/src/main/java/org/javaboy/http_basic/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http_basic; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello http basic"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server/src/main/java/org/javaboy/auth_server/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter02/jdbcuserdetailsmanager/src/main/java/org/javaboy/formlogin/MyLoginController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @Controller 16 | public class MyLoginController { 17 | @RequestMapping("/mylogin.html") 18 | public String mylogin() { 19 | return "mylogin"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter02/jpa/src/main/java/org/javaboy/formlogin/controller/MyLoginController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @Controller 16 | public class MyLoginController { 17 | @RequestMapping("/mylogin.html") 18 | public String mylogin() { 19 | return "mylogin"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter05/passwordencoder/src/main/java/org/javaboy/passwordencoder/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.passwordencoder; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter05/passwordencoder02/src/main/java/org/javaboy/passwordencoder/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.passwordencoder; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter09/token_in_cookie/src/main/java/org/javaboy/token_in_cookie/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.token_in_cookie; 2 | 3 | import org.springframework.web.bind.annotation.PostMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @PostMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/java/org/javaboy/formlogin/controller/MyLoginController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @Controller 16 | public class MyLoginController { 17 | @RequestMapping("/mylogin.html") 18 | public String mylogin() { 19 | return "mylogin"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter03/kaptcha/src/main/java/org/javaboy/formlogin/controller/MyLoginController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @Controller 16 | public class MyLoginController { 17 | @RequestMapping("/mylogin.html") 18 | public String mylogin() { 19 | return "mylogin"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 9 | 10 | 13 | -------------------------------------------------------------------------------- /chapter03/multiuser/src/main/java/org/javaboy/formlogin/controller/MyLoginController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @Controller 16 | public class MyLoginController { 17 | @RequestMapping("/mylogin.html") 18 | public String mylogin() { 19 | return "mylogin"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter04/objectpostprocessor/src/main/java/org/javaboy/objectpostprocessor/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.objectpostprocessor; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter05/passwordencoder/src/test/java/org/javaboy/passwordencoder/PasswordencoderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.passwordencoder; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 6 | 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | 10 | @SpringBootTest 11 | class PasswordencoderApplicationTests { 12 | 13 | @Test 14 | void contextLoads() { 15 | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); 16 | System.out.println(encoder.encode("123")); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /chapter05/passwordencoder02/src/test/java/org/javaboy/passwordencoder/PasswordencoderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.passwordencoder; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 6 | 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | 10 | @SpringBootTest 11 | class PasswordencoderApplicationTests { 12 | 13 | @Test 14 | void contextLoads() { 15 | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); 16 | System.out.println(encoder.encode("123")); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jdbc/src/main/java/org/javaboy/auth_server_jdbc/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_jdbc; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_redis/src/main/java/org/javaboy/auth_server_redis/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_redis; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/java/org/javaboy/formlogin/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.mapper; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | import org.javaboy.formlogin.model.Role; 5 | import org.javaboy.formlogin.model.User; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author 江南一点雨 11 | * @微信公众号 江南一点雨 12 | * @网站 http://www.itboyhub.com 13 | * @国际站 http://www.javaboy.org 14 | * @微信 a_java_boy 15 | * @GitHub https://github.com/lenve 16 | * @Gitee https://gitee.com/lenve 17 | */ 18 | @Mapper 19 | public interface UserMapper { 20 | List getRolesByUid(Integer id); 21 | User loadUserByUsername(String username); 22 | } 23 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/controller/MyLoginController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @Controller 16 | public class MyLoginController { 17 | @RequestMapping("/mylogin.html") 18 | public String mylogin() { 19 | return "mylogin"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter04/filter_kaptcha/src/main/java/org/javaboy/formlogin/controller/MyLoginController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @Controller 16 | public class MyLoginController { 17 | @RequestMapping("/mylogin.html") 18 | public String mylogin() { 19 | return "mylogin"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter15/oauth2/res_server_jwt/src/main/java/org/javaboy/res_server_jwt/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.res_server_jwt; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello res server"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.mapper; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | import org.javaboy.formlogin.model.Role; 5 | import org.javaboy.formlogin.model.User; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author 江南一点雨 11 | * @微信公众号 江南一点雨 12 | * @网站 http://www.itboyhub.com 13 | * @国际站 http://www.javaboy.org 14 | * @微信 a_java_boy 15 | * @GitHub https://github.com/lenve 16 | * @Gitee https://gitee.com/lenve 17 | */ 18 | @Mapper 19 | public interface UserMapper { 20 | List getRolesByUid(Integer id); 21 | User loadUserByUsername(String username); 22 | } 23 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/mapper/UserMapper2.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.mapper; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | import org.javaboy.formlogin.model.Role; 5 | import org.javaboy.formlogin.model.User; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author 江南一点雨 11 | * @微信公众号 江南一点雨 12 | * @网站 http://www.itboyhub.com 13 | * @国际站 http://www.javaboy.org 14 | * @微信 a_java_boy 15 | * @GitHub https://github.com/lenve 16 | * @Gitee https://gitee.com/lenve 17 | */ 18 | @Mapper 19 | public interface UserMapper2 { 20 | List getRolesByUid(Integer id); 21 | User loadUserByUsername(String username); 22 | } 23 | -------------------------------------------------------------------------------- /chapter04/multi_filter_chain/src/main/java/org/javaboy/multi_filter_chain/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_filter_chain; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | 5 | /** 6 | * @author 江南一点雨 7 | * @微信公众号 江南一点雨 8 | * @网站 http://www.itboyhub.com 9 | * @国际站 http://www.javaboy.org 10 | * @微信 a_java_boy 11 | * @GitHub https://github.com/lenve 12 | * @Gitee https://gitee.com/lenve 13 | */ 14 | public class HelloController { 15 | @GetMapping("/hello") 16 | public String hello() { 17 | return "hello"; 18 | } 19 | 20 | @GetMapping("/admin/hello") 21 | public String admin() { 22 | return "hello admin"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /chapter09/csrf-1/src/main/java/org/javaboy/csrf1/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.csrf1; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @author 江南一点雨 9 | * @微信公众号 江南一点雨 10 | * @网站 http://www.itboyhub.com 11 | * @国际站 http://www.javaboy.org 12 | * @微信 a_java_boy 13 | * @GitHub https://github.com/lenve 14 | * @Gitee https://gitee.com/lenve 15 | */ 16 | @RestController 17 | public class HelloController { 18 | @PostMapping("/withdraw") 19 | public void withdraw() { 20 | System.out.println("执行了一次转账操作"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /chapter07/sessionshare/src/main/java/org/javaboy/sessionshare/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.sessionshare; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import javax.servlet.http.HttpSession; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @RestController 18 | public class HelloController { 19 | @GetMapping("/") 20 | public String hello(HttpSession session) { 21 | return session.getClass().toString(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /chapter14/acl/src/main/java/org/javaboy/acl/mapper/NoticeMessageMapper.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.acl.mapper; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | import org.javaboy.acl.model.NoticeMessage; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Mapper 18 | public interface NoticeMessageMapper { 19 | List findAll(); 20 | 21 | NoticeMessage findById(Integer id); 22 | 23 | void save(NoticeMessage noticeMessage); 24 | 25 | void update(NoticeMessage noticeMessage); 26 | } 27 | -------------------------------------------------------------------------------- /chapter05/passwordencoder02/src/main/java/org/javaboy/passwordencoder/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.passwordencoder.mapper; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | import org.apache.ibatis.annotations.Param; 5 | import org.javaboy.passwordencoder.model.User; 6 | 7 | /** 8 | * @author 江南一点雨 9 | * @微信公众号 江南一点雨 10 | * @网站 http://www.itboyhub.com 11 | * @国际站 http://www.javaboy.org 12 | * @微信 a_java_boy 13 | * @GitHub https://github.com/lenve 14 | * @Gitee https://gitee.com/lenve 15 | */ 16 | @Mapper 17 | public interface UserMapper { 18 | User loadUserByUsername(String username); 19 | 20 | Integer updatePassword(@Param("username") String username, @Param("newPassword") String newPassword); 21 | } 22 | -------------------------------------------------------------------------------- /chapter06/rememberme/src/test/java/org/javaboy/rememberme/RemembermeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.rememberme; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | import java.io.UnsupportedEncodingException; 7 | import java.util.Base64; 8 | 9 | @SpringBootTest 10 | class RemembermeApplicationTests { 11 | 12 | @Test 13 | void contextLoads() throws UnsupportedEncodingException { 14 | Base64.Decoder decoder = Base64.getDecoder(); 15 | byte[] bytes = decoder.decode("amF2YWJveToxNTk4MzIyMTQ4MzA1OjQxYTMxYWFhZTg1MDg0ZjNlZDY1MWYwOTJiYjAyZTU4"); 16 | String s = new String(bytes, "UTF-8"); 17 | System.out.println("s = " + s); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.base_on_url_dy.mapper; 2 | 3 | import org.apache.ibatis.annotations.Mapper; 4 | import org.javaboy.base_on_url_dy.model.Menu; 5 | import org.javaboy.base_on_url_dy.model.Role; 6 | import org.javaboy.base_on_url_dy.model.User; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author 江南一点雨 12 | * @微信公众号 江南一点雨 13 | * @网站 http://www.itboyhub.com 14 | * @国际站 http://www.javaboy.org 15 | * @微信 a_java_boy 16 | * @GitHub https://github.com/lenve 17 | * @Gitee https://gitee.com/lenve 18 | */ 19 | @Mapper 20 | public interface UserMapper { 21 | List getUserRoleByUid(Integer uid); 22 | 23 | User loadUserByUsername(String username); 24 | } 25 | -------------------------------------------------------------------------------- /chapter06/rememberme_persistent/src/test/java/org/javaboy/rememberme/RemembermeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.rememberme; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | import java.io.UnsupportedEncodingException; 7 | import java.util.Base64; 8 | 9 | @SpringBootTest 10 | class RemembermeApplicationTests { 11 | 12 | @Test 13 | void contextLoads() throws UnsupportedEncodingException { 14 | Base64.Decoder decoder = Base64.getDecoder(); 15 | byte[] bytes = decoder.decode("amF2YWJveToxNTk4MzIyMTQ4MzA1OjQxYTMxYWFhZTg1MDg0ZjNlZDY1MWYwOTJiYjAyZTU4"); 16 | String s = new String(bytes, "UTF-8"); 17 | System.out.println("s = " + s); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /chapter09/receive_report/src/main/java/org/javaboy/receive_report/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.receive_report; 2 | 3 | import org.springframework.web.bind.annotation.RequestBody; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @author 江南一点雨 9 | * @微信公众号 江南一点雨 10 | * @网站 http://www.itboyhub.com 11 | * @国际站 http://www.javaboy.org 12 | * @微信 a_java_boy 13 | * @GitHub https://github.com/lenve 14 | * @Gitee https://gitee.com/lenve 15 | */ 16 | @RestController 17 | public class HelloController { 18 | @RequestMapping("/report") 19 | public void report(@RequestBody String report) { 20 | System.out.println("report = " + report); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /chapter11/cors01_corsfilter/src/main/java/org/javaboy/cors01/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author 江南一点雨 7 | * @微信公众号 江南一点雨 8 | * @网站 http://www.itboyhub.com 9 | * @国际站 http://www.javaboy.org 10 | * @微信 a_java_boy 11 | * @GitHub https://github.com/lenve 12 | * @Gitee https://gitee.com/lenve 13 | */ 14 | @RestController 15 | public class HelloController { 16 | @PostMapping("/post") 17 | public String post() { 18 | return "hello post"; 19 | } 20 | 21 | @PutMapping("/put") 22 | public String put() { 23 | return "hello put"; 24 | } 25 | 26 | @GetMapping("/get") 27 | public String get() { 28 | return "hello get"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jdbc/src/main/resources/oauth_client_details.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS `oauth_client_details`; 2 | CREATE TABLE `oauth_client_details` ( 3 | `client_id` varchar(48) NOT NULL, 4 | `resource_ids` varchar(256) DEFAULT NULL, 5 | `client_secret` varchar(256) DEFAULT NULL, 6 | `scope` varchar(256) DEFAULT NULL, 7 | `authorized_grant_types` varchar(256) DEFAULT NULL, 8 | `web_server_redirect_uri` varchar(256) DEFAULT NULL, 9 | `authorities` varchar(256) DEFAULT NULL, 10 | `access_token_validity` int(11) DEFAULT NULL, 11 | `refresh_token_validity` int(11) DEFAULT NULL, 12 | `additional_information` varchar(4096) DEFAULT NULL, 13 | `autoapprove` varchar(256) DEFAULT NULL, 14 | PRIMARY KEY (`client_id`) 15 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 16 | -------------------------------------------------------------------------------- /chapter11/cors_security/src/main/java/org/javaboy/cors_security/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors_security; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author 江南一点雨 7 | * @微信公众号 江南一点雨 8 | * @网站 http://www.itboyhub.com 9 | * @国际站 http://www.javaboy.org 10 | * @微信 a_java_boy 11 | * @GitHub https://github.com/lenve 12 | * @Gitee https://gitee.com/lenve 13 | */ 14 | @RestController 15 | public class HelloController { 16 | @PostMapping("/post") 17 | public String post() { 18 | return "hello post"; 19 | } 20 | 21 | @PutMapping("/put") 22 | public String put() { 23 | return "hello put"; 24 | } 25 | 26 | @GetMapping("/get") 27 | public String get() { 28 | return "hello get"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /chapter11/cors_security_corsfilter/src/main/java/org/javaboy/cors_security/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors_security; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author 江南一点雨 7 | * @微信公众号 江南一点雨 8 | * @网站 http://www.itboyhub.com 9 | * @国际站 http://www.javaboy.org 10 | * @微信 a_java_boy 11 | * @GitHub https://github.com/lenve 12 | * @Gitee https://gitee.com/lenve 13 | */ 14 | @RestController 15 | public class HelloController { 16 | @PostMapping("/post") 17 | public String post() { 18 | return "hello post"; 19 | } 20 | 21 | @PutMapping("/put") 22 | public String put() { 23 | return "hello put"; 24 | } 25 | 26 | @GetMapping("/get") 27 | public String get() { 28 | return "hello get"; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server/src/main/java/org/javaboy/auth_server/config/AccessTokenConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.oauth2.provider.token.TokenStore; 6 | import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Configuration 18 | public class AccessTokenConfig { 19 | @Bean 20 | TokenStore tokenStore() { 21 | return new InMemoryTokenStore(); 22 | } 23 | } -------------------------------------------------------------------------------- /chapter11/cors_security_crossorigin/src/main/java/org/javaboy/cors_security/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors_security; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author 江南一点雨 7 | * @微信公众号 江南一点雨 8 | * @网站 http://www.itboyhub.com 9 | * @国际站 http://www.javaboy.org 10 | * @微信 a_java_boy 11 | * @GitHub https://github.com/lenve 12 | * @Gitee https://gitee.com/lenve 13 | */ 14 | @RestController 15 | @CrossOrigin("*") 16 | public class HelloController { 17 | @PostMapping("/post") 18 | public String post() { 19 | return "hello post"; 20 | } 21 | 22 | @PutMapping("/put") 23 | public String put() { 24 | return "hello put"; 25 | } 26 | 27 | @GetMapping("/get") 28 | public String get() { 29 | return "hello get"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /chapter13/based_on_method/src/main/java/org/javaboy/based_on_method/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_method; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 5 | import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; 6 | 7 | /** 8 | * @author 江南一点雨 9 | * @微信公众号 江南一点雨 10 | * @网站 http://www.itboyhub.com 11 | * @国际站 http://www.javaboy.org 12 | * @微信 a_java_boy 13 | * @GitHub https://github.com/lenve 14 | * @Gitee https://gitee.com/lenve 15 | */ 16 | @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true) 17 | public class SecurityConfig extends GlobalMethodSecurityConfiguration { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jdbc/src/main/java/org/javaboy/auth_server_jdbc/config/AccessTokenConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_jdbc.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.oauth2.provider.token.TokenStore; 6 | import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Configuration 18 | public class AccessTokenConfig { 19 | @Bean 20 | TokenStore tokenStore() { 21 | return new InMemoryTokenStore(); 22 | } 23 | } -------------------------------------------------------------------------------- /chapter09/http/src/main/java/org/javaboy/http/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/https") 18 | public String https() { 19 | return "https"; 20 | } 21 | 22 | @GetMapping("/http") 23 | public String http() { 24 | return "http"; 25 | } 26 | 27 | @GetMapping("/hello") 28 | public String hello() { 29 | return "hello"; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/service/MenuService.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.base_on_url_dy.service; 2 | 3 | import org.javaboy.base_on_url_dy.mapper.MenuMapper; 4 | import org.javaboy.base_on_url_dy.mapper.UserMapper; 5 | import org.javaboy.base_on_url_dy.model.Menu; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author 江南一点雨 13 | * @微信公众号 江南一点雨 14 | * @网站 http://www.itboyhub.com 15 | * @国际站 http://www.javaboy.org 16 | * @微信 a_java_boy 17 | * @GitHub https://github.com/lenve 18 | * @Gitee https://gitee.com/lenve 19 | */ 20 | @Service 21 | public class MenuService { 22 | @Autowired 23 | MenuMapper menuMapper; 24 | public List getAllMenu() { 25 | return menuMapper.getAllMenu(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /chapter08/httpfirewall/src/main/java/org/javaboy/httpfirewall/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.httpfirewall; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author 江南一点雨 12 | * @微信公众号 江南一点雨 13 | * @网站 http://www.itboyhub.com 14 | * @国际站 http://www.javaboy.org 15 | * @微信 a_java_boy 16 | * @GitHub https://github.com/lenve 17 | * @Gitee https://gitee.com/lenve 18 | */ 19 | @RestController 20 | public class HelloController { 21 | @GetMapping("/get") 22 | public String get(){ 23 | return "get"; 24 | } 25 | @PostMapping("/post") 26 | public String post(){ 27 | return "post"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapter09/samesite/src/main/java/org/javaboy/samesite/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.samesite; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import javax.servlet.http.HttpSession; 8 | 9 | /** 10 | * @author 江南一点雨 11 | * @微信公众号 江南一点雨 12 | * @网站 http://www.itboyhub.com 13 | * @国际站 http://www.javaboy.org 14 | * @微信 a_java_boy 15 | * @GitHub https://github.com/lenve 16 | * @Gitee https://gitee.com/lenve 17 | */ 18 | @RestController 19 | public class HelloController { 20 | @PostMapping("/withdraw") 21 | public void withdraw() { 22 | System.out.println("执行了一次转账操作"); 23 | } 24 | 25 | @GetMapping("/hello") 26 | public void hello(HttpSession session) { 27 | System.out.println("session = " + session); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_jwt/src/main/java/org/javaboy/auth_server_jwt/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_jwt; 2 | 3 | import com.nimbusds.jose.jwk.JWKSet; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @RestController 18 | public class HelloController { 19 | @Autowired 20 | JWKSet jwkSet; 21 | @GetMapping("/hello") 22 | public String hello() { 23 | return "hello"; 24 | } 25 | @GetMapping(value = "/oauth2/keys") 26 | public String keys() { 27 | return jwkSet.toString(); 28 | } 29 | } -------------------------------------------------------------------------------- /chapter02/getloginuser/src/main/java/org/javaboy/getloginuser/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.getloginuser; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.security.core.context.SecurityContextHolder; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @RestController 18 | public class HelloController { 19 | @GetMapping("/hello") 20 | public void hello() { 21 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 22 | System.out.println("authentication.getClass() = " + authentication.getClass()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /chapter14/acl/src/main/java/org/javaboy/acl/mapper/NoticeMessageMapper.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 10 | 11 | 14 | 15 | 16 | insert into system_message (id,content) values (#{id},#{content}); 17 | 18 | 19 | 20 | update system_message set content = #{content} where id=#{id}; 21 | 22 | -------------------------------------------------------------------------------- /chapter09/token_in_cookie/src/main/resources/static/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 |
15 | 27 | 28 | -------------------------------------------------------------------------------- /chapter13/custom_expression/src/main/java/org/javaboy/based_on_url/PermissionExpression.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_url; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Component 18 | public class PermissionExpression { 19 | public boolean checkId(Authentication authentication, Integer userId) { 20 | if (authentication.isAuthenticated()) { 21 | return userId % 2 == 0; 22 | } 23 | return false; 24 | } 25 | 26 | public boolean check(HttpServletRequest req) { 27 | return "javaboy".equals(req.getParameter("username")); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapter12/exception_translation_filter/src/main/java/org/javaboy/exception_translation_filter/GlobalException.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.exception_translation_filter; 2 | 3 | import org.springframework.web.bind.annotation.ControllerAdvice; 4 | import org.springframework.web.bind.annotation.ExceptionHandler; 5 | import org.springframework.web.bind.annotation.RestControllerAdvice; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.sql.rowset.serial.SerialException; 9 | 10 | /** 11 | * @author 江南一点雨 12 | * @微信公众号 江南一点雨 13 | * @网站 http://www.itboyhub.com 14 | * @国际站 http://www.javaboy.org 15 | * @微信 a_java_boy 16 | * @GitHub https://github.com/lenve 17 | * @Gitee https://gitee.com/lenve 18 | */ 19 | @RestControllerAdvice 20 | public class GlobalException { 21 | @ExceptionHandler(ServletException.class) 22 | public void handle1(ServletException e) { 23 | System.out.println("e.getMessage() = " + e.getMessage()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/model/Role.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.base_on_url_dy.model; 2 | 3 | /** 4 | * @author 江南一点雨 5 | * @微信公众号 江南一点雨 6 | * @网站 http://www.itboyhub.com 7 | * @国际站 http://www.javaboy.org 8 | * @微信 a_java_boy 9 | * @GitHub https://github.com/lenve 10 | * @Gitee https://gitee.com/lenve 11 | */ 12 | public class Role { 13 | private Integer id; 14 | private String name; 15 | private String nameZh; 16 | 17 | public Integer getId() { 18 | return id; 19 | } 20 | 21 | public void setId(Integer id) { 22 | this.id = id; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | 33 | public String getNameZh() { 34 | return nameZh; 35 | } 36 | 37 | public void setNameZh(String nameZh) { 38 | this.nameZh = nameZh; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /chapter14/acl/src/main/java/org/javaboy/acl/model/NoticeMessage.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.acl.model; 2 | 3 | /** 4 | * @author 江南一点雨 5 | * @微信公众号 江南一点雨 6 | * @网站 http://www.itboyhub.com 7 | * @国际站 http://www.javaboy.org 8 | * @微信 a_java_boy 9 | * @GitHub https://github.com/lenve 10 | * @Gitee https://gitee.com/lenve 11 | */ 12 | public class NoticeMessage { 13 | private Integer id; 14 | private String content; 15 | 16 | @Override 17 | public String toString() { 18 | return "NoticeMessage{" + 19 | "id=" + id + 20 | ", content='" + content + '\'' + 21 | '}'; 22 | } 23 | 24 | public Integer getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Integer id) { 29 | this.id = id; 30 | } 31 | 32 | public String getContent() { 33 | return content; 34 | } 35 | 36 | public void setContent(String content) { 37 | this.content = content; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter11/cors01_addcorsmappings/src/main/java/org/javaboy/cors01/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.PostMapping; 5 | import org.springframework.web.bind.annotation.PutMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @RestController 18 | public class HelloController { 19 | @PostMapping("/post") 20 | public String post() { 21 | return "hello post"; 22 | } 23 | 24 | @PutMapping("/put") 25 | public String put() { 26 | return "hello put"; 27 | } 28 | 29 | @GetMapping("/get") 30 | public String get() { 31 | return "hello get"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /chapter13/based_on_url/src/main/java/org/javaboy/based_on_url/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_url; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/hello") 18 | public String hello() { 19 | return "hello"; 20 | } 21 | 22 | @GetMapping("/admin/hello") 23 | public String admin() { 24 | return "hello admin"; 25 | } 26 | 27 | @GetMapping("/user/hello") 28 | public String user() { 29 | return "hello user"; 30 | } 31 | 32 | @GetMapping("/getinfo") 33 | public String getInfo() { 34 | return "getinfo"; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /chapter10/http_digest/src/test/java/org/javaboy/http_digest/HttpDigestApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http_digest; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 6 | import org.springframework.security.crypto.codec.Hex; 7 | import org.springframework.security.crypto.password.MessageDigestPasswordEncoder; 8 | import org.springframework.util.DigestUtils; 9 | 10 | import java.security.MessageDigest; 11 | import java.security.NoSuchAlgorithmException; 12 | 13 | @SpringBootTest 14 | class HttpDigestApplicationTests { 15 | 16 | @Test 17 | void contextLoads() throws NoSuchAlgorithmException { 18 | String rawPassword = "javaboy:myrealm:123"; 19 | MessageDigest digest = MessageDigest.getInstance("MD5"); 20 | String s = new String(Hex.encode(digest.digest(rawPassword.getBytes()))); 21 | System.out.println(s); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /chapter11/cors01_addcorsmappings/src/main/java/org/javaboy/cors01/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * @author 江南一点雨 9 | * @微信公众号 江南一点雨 10 | * @网站 http://www.itboyhub.com 11 | * @国际站 http://www.javaboy.org 12 | * @微信 a_java_boy 13 | * @GitHub https://github.com/lenve 14 | * @Gitee https://gitee.com/lenve 15 | */ 16 | @Configuration 17 | public class WebMvcConfig implements WebMvcConfigurer { 18 | @Override 19 | public void addCorsMappings(CorsRegistry registry) { 20 | registry.addMapping("/**") 21 | .allowedMethods("*") 22 | .allowedOrigins("*") 23 | .allowedHeaders("*") 24 | .allowCredentials(false) 25 | .exposedHeaders("") 26 | .maxAge(3600); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chapter12/exception_translation_filter/src/main/java/org/javaboy/exception_translation_filter/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.exception_translation_filter; 2 | 3 | import org.springframework.security.authentication.AuthenticationServiceException; 4 | import org.springframework.security.core.AuthenticationException; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import javax.servlet.ServletException; 9 | 10 | /** 11 | * @author 江南一点雨 12 | * @微信公众号 江南一点雨 13 | * @网站 http://www.itboyhub.com 14 | * @国际站 http://www.javaboy.org 15 | * @微信 a_java_boy 16 | * @GitHub https://github.com/lenve 17 | * @Gitee https://gitee.com/lenve 18 | */ 19 | @RestController 20 | public class HelloController { 21 | @GetMapping("/hello") 22 | public String hello() throws Exception { 23 | // throw new ServletException("aaa"); 24 | return "hello"; 25 | // throw new AuthenticationServiceException("bbb"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo2/src/main/java/org/javaboy/oauth2_login_demo2/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo2; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.security.core.context.SecurityContextHolder; 5 | import org.springframework.security.oauth2.core.user.DefaultOAuth2User; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author 江南一点雨 11 | * @微信公众号 江南一点雨 12 | * @网站 http://www.itboyhub.com 13 | * @国际站 http://www.javaboy.org 14 | * @微信 a_java_boy 15 | * @GitHub https://github.com/lenve 16 | * @Gitee https://gitee.com/lenve 17 | */ 18 | @RestController 19 | public class HelloController { 20 | @GetMapping("/hello") 21 | public DefaultOAuth2User hello() { 22 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 23 | return ((DefaultOAuth2User) authentication.getPrincipal()); 24 | } 25 | } -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.base_on_url_dy.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | @RestController 16 | public class HelloController { 17 | @GetMapping("/admin/hello") 18 | public String admin() { 19 | return "hello admin"; 20 | } 21 | 22 | @GetMapping("/user/hello") 23 | public String user() { 24 | return "hello user"; 25 | } 26 | 27 | @GetMapping("/guest/hello") 28 | public String guest() { 29 | return "hello guest"; 30 | } 31 | 32 | 33 | @GetMapping("/hello") 34 | public String hello() { 35 | return "hello"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/model/Menu.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.base_on_url_dy.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author 江南一点雨 7 | * @微信公众号 江南一点雨 8 | * @网站 http://www.itboyhub.com 9 | * @国际站 http://www.javaboy.org 10 | * @微信 a_java_boy 11 | * @GitHub https://github.com/lenve 12 | * @Gitee https://gitee.com/lenve 13 | */ 14 | public class Menu { 15 | private Integer id; 16 | private String pattern; 17 | private List roles; 18 | 19 | public List getRoles() { 20 | return roles; 21 | } 22 | 23 | public void setRoles(List roles) { 24 | this.roles = roles; 25 | } 26 | 27 | public Integer getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Integer id) { 32 | this.id = id; 33 | } 34 | 35 | public String getPattern() { 36 | return pattern; 37 | } 38 | 39 | public void setPattern(String pattern) { 40 | this.pattern = pattern; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/mapper/MenuMapper.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo/src/main/java/org/javaboy/oauth2_login_demo/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo; 2 | 3 | import org.springframework.beans.factory.annotation.Configurable; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Configuration 18 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 19 | @Override 20 | protected void configure(HttpSecurity http) throws Exception { 21 | http.authorizeRequests() 22 | .anyRequest().authenticated() 23 | .and() 24 | .oauth2Login(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /chapter15/oauth2/res_server/src/main/java/org/javaboy/res_server/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.res_server; 2 | 3 | import net.minidev.json.JSONArray; 4 | import org.springframework.security.oauth2.core.DefaultOAuth2AuthenticatedPrincipal; 5 | import org.springframework.security.oauth2.core.OAuth2AccessToken; 6 | import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.security.Principal; 11 | import java.util.List; 12 | import java.util.stream.Collectors; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | @RestController 24 | public class HelloController { 25 | @GetMapping("/hello") 26 | public String hello() { 27 | return "hello res server"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapter11/cors02/src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 34 | 35 | -------------------------------------------------------------------------------- /chapter08/httpfirewall/src/test/java/org/javaboy/httpfirewall/HttpfirewallApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.httpfirewall; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | import java.util.Collections; 7 | import java.util.HashSet; 8 | 9 | @SpringBootTest 10 | class HttpfirewallApplicationTests { 11 | 12 | @Test 13 | void contextLoads() { 14 | // boolean b = containsOnlyPrintableAsciiCharacters("~"); 15 | // System.out.println(b); 16 | char c1 = '\u0020'; 17 | char c2 = '\u007e'; 18 | System.out.println((int) c1); 19 | System.out.println((int)c2); 20 | } 21 | 22 | private static boolean containsOnlyPrintableAsciiCharacters(String uri) { 23 | int length = uri.length(); 24 | for (int i = 0; i < length; i++) { 25 | System.out.println(i); 26 | char c = uri.charAt(i); 27 | if (c < '\u0020' || c > '\u007e') { 28 | return false; 29 | } 30 | } 31 | 32 | return true; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/java/org/javaboy/formlogin/model/Role.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.model; 2 | 3 | import org.springframework.security.core.GrantedAuthority; 4 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | public class Role { 16 | 17 | private Integer id; 18 | private String name; 19 | private String nameZh; 20 | 21 | public Integer getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Integer id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public String getNameZh() { 38 | return nameZh; 39 | } 40 | 41 | public void setNameZh(String nameZh) { 42 | this.nameZh = nameZh; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /chapter06/rememberme_persistent/src/main/java/org/javaboy/rememberme/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.rememberme; 2 | 3 | import org.springframework.security.core.context.SecurityContextHolder; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @author 江南一点雨 9 | * @微信公众号 江南一点雨 10 | * @网站 http://www.itboyhub.com 11 | * @国际站 http://www.javaboy.org 12 | * @微信 a_java_boy 13 | * @GitHub https://github.com/lenve 14 | * @Gitee https://gitee.com/lenve 15 | */ 16 | @RestController 17 | public class HelloController { 18 | @GetMapping("/hello") 19 | public String hello() { 20 | System.out.println("SecurityContextHolder.getContext().getAuthentication().getClass() = " + SecurityContextHolder.getContext().getAuthentication().getClass()); 21 | return "hello"; 22 | } 23 | @GetMapping("/admin") 24 | public String admin() { 25 | return "admin"; 26 | } 27 | @GetMapping("/rememberme") 28 | public String rememberme() { 29 | return "rememberme"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /chapter09/synchronizer_token_pattern/src/main/java/org/javaboy/synchronizer_token_pattern/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.synchronizer_token_pattern; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author 江南一点雨 11 | * @微信公众号 江南一点雨 12 | * @网站 http://www.itboyhub.com 13 | * @国际站 http://www.javaboy.org 14 | * @微信 a_java_boy 15 | * @GitHub https://github.com/lenve 16 | * @Gitee https://gitee.com/lenve 17 | */ 18 | @Controller 19 | public class HelloController { 20 | @PostMapping("/hello") 21 | @ResponseBody 22 | public String hello() { 23 | return "hello csrf!"; 24 | } 25 | 26 | @GetMapping("/index.html") 27 | public String index() { 28 | return "index"; 29 | } 30 | @GetMapping("/index2.html") 31 | public String index2() { 32 | return "index2"; 33 | } 34 | } -------------------------------------------------------------------------------- /chapter15/oauth2/client02/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8883 3 | spring: 4 | security: 5 | oauth2: 6 | client: 7 | registration: 8 | auth-code: 9 | provider: javaboy 10 | client-id: my_client 11 | client-secret: 123 12 | authorization-grant-type: authorization_code 13 | redirect-uri: http://client.javaboy.org:8883/login/oauth2/code/javaboy 14 | scope: read:msg 15 | client-creds: 16 | provider: javaboy 17 | client-id: my_client 18 | client-secret: 123 19 | authorization-grant-type: client_credentials 20 | scope: read:msg 21 | password: 22 | provider: javaboy 23 | client-id: my_client 24 | client-secret: 123 25 | authorization-grant-type: password 26 | scope: read:msg 27 | provider: 28 | javaboy: 29 | authorization-uri: http://auth.javaboy.org:8881/oauth/authorize 30 | token-uri: http://auth.javaboy.org:8881/oauth/token 31 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/model/Role.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.model; 2 | 3 | import org.springframework.security.core.GrantedAuthority; 4 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 5 | 6 | /** 7 | * @author 江南一点雨 8 | * @微信公众号 江南一点雨 9 | * @网站 http://www.itboyhub.com 10 | * @国际站 http://www.javaboy.org 11 | * @微信 a_java_boy 12 | * @GitHub https://github.com/lenve 13 | * @Gitee https://gitee.com/lenve 14 | */ 15 | public class Role { 16 | 17 | private Integer id; 18 | private String name; 19 | private String nameZh; 20 | 21 | public Integer getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Integer id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public String getNameZh() { 38 | return nameZh; 39 | } 40 | 41 | public void setNameZh(String nameZh) { 42 | this.nameZh = nameZh; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /chapter12/exception_translation_filter/src/test/java/org/javaboy/exception_translation_filter/ExceptionTranslationFilterApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.exception_translation_filter; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.security.web.util.ThrowableAnalyzer; 6 | 7 | import javax.servlet.ServletException; 8 | import java.io.IOException; 9 | import java.util.Arrays; 10 | 11 | @SpringBootTest 12 | class ExceptionTranslationFilterApplicationTests { 13 | 14 | @Test 15 | void contextLoads() { 16 | NullPointerException aaa = new NullPointerException("aaa"); 17 | ServletException bbb = new ServletException(aaa); 18 | IOException ccc = new IOException(bbb); 19 | ThrowableAnalyzer throwableAnalyzer = new ThrowableAnalyzer(); 20 | Throwable[] causeChain = throwableAnalyzer.determineCauseChain(ccc); 21 | for (int i = 0; i < causeChain.length; i++) { 22 | System.out.println("causeChain[i].getClass() = " + causeChain[i].getClass()); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /chapter02/firstdemo/src/test/java/org/javaboy/firstdemo/FirstdemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.firstdemo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | import java.util.Collections; 9 | import java.util.List; 10 | 11 | @SpringBootTest 12 | class FirstdemoApplicationTests { 13 | 14 | @Test 15 | void contextLoads() { 16 | List names1 = new ArrayList<>(); 17 | List names2 = new ArrayList<>(); 18 | List names3 = new ArrayList<>(); 19 | names1.add("zhangsan1"); 20 | // names1.add("zhangsan2"); 21 | // names1.add("zhangsan3"); 22 | names2.add("lisi1"); 23 | names2.add("lisi2"); 24 | names2.add("lisi3"); 25 | names3.add("wangwu1"); 26 | names3.add("wangwu2"); 27 | names3.add("wangwu3"); 28 | hello(names1); 29 | } 30 | 31 | public void hello(T... names) { 32 | for (T name : names) { 33 | System.out.println("name = " + name); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /chapter15/oauth2/auth_server_redis/src/main/java/org/javaboy/auth_server_redis/config/AccessTokenConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.auth_server_redis.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.data.redis.connection.RedisConnectionFactory; 7 | import org.springframework.security.oauth2.provider.token.TokenStore; 8 | import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; 9 | import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; 10 | 11 | /** 12 | * @author 江南一点雨 13 | * @微信公众号 江南一点雨 14 | * @网站 http://www.itboyhub.com 15 | * @国际站 http://www.javaboy.org 16 | * @微信 a_java_boy 17 | * @GitHub https://github.com/lenve 18 | * @Gitee https://gitee.com/lenve 19 | */ 20 | @Configuration 21 | public class AccessTokenConfig { 22 | @Autowired 23 | RedisConnectionFactory redisConnectionFactory; 24 | @Bean 25 | TokenStore tokenStore() { 26 | return new RedisTokenStore(redisConnectionFactory); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /chapter13/based_on_method/src/main/java/org/javaboy/based_on_method/User.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_method; 2 | 3 | /** 4 | * @author 江南一点雨 5 | * @微信公众号 江南一点雨 6 | * @网站 http://www.itboyhub.com 7 | * @国际站 http://www.javaboy.org 8 | * @微信 a_java_boy 9 | * @GitHub https://github.com/lenve 10 | * @Gitee https://gitee.com/lenve 11 | */ 12 | public class User { 13 | private Integer id; 14 | private String username; 15 | 16 | public User() { 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return "User{" + 22 | "id=" + id + 23 | ", username='" + username + '\'' + 24 | '}'; 25 | } 26 | 27 | public User(Integer id, String username) { 28 | this.id = id; 29 | this.username = username; 30 | } 31 | 32 | public Integer getId() { 33 | return id; 34 | } 35 | 36 | public void setId(Integer id) { 37 | this.id = id; 38 | } 39 | 40 | public String getUsername() { 41 | return username; 42 | } 43 | 44 | public void setUsername(String username) { 45 | this.username = username; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /chapter02/jpa/src/test/java/org/javaboy/formlogin/FormloginApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import org.javaboy.formlogin.mapper.UserDao; 4 | import org.javaboy.formlogin.model.Role; 5 | import org.javaboy.formlogin.model.User; 6 | import org.junit.jupiter.api.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | @SpringBootTest 14 | class FormloginApplicationTests { 15 | 16 | @Autowired 17 | UserDao userDao; 18 | @Test 19 | void contextLoads() { 20 | User u1 = new User(); 21 | u1.setUsername("javaboy"); 22 | u1.setPassword("{noop}123"); 23 | u1.setAccountNonExpired(true); 24 | u1.setAccountNonLocked(true); 25 | u1.setCredentialsNonExpired(true); 26 | u1.setEnabled(true); 27 | List rs1 = new ArrayList<>(); 28 | Role r1 = new Role(); 29 | r1.setName("ROLE_admin"); 30 | r1.setNameZh("管理员"); 31 | rs1.add(r1); 32 | u1.setRoles(rs1); 33 | userDao.save(u1); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chapter11/cors01_crossorigin/src/main/java/org/javaboy/cors01/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.cors01; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author 江南一点雨 7 | * @微信公众号 江南一点雨 8 | * @网站 http://www.itboyhub.com 9 | * @国际站 http://www.javaboy.org 10 | * @微信 a_java_boy 11 | * @GitHub https://github.com/lenve 12 | * @Gitee https://gitee.com/lenve 13 | */ 14 | @RestController 15 | @CrossOrigin(origins = "http://localhost:8081", allowedHeaders = "*", methods = {RequestMethod.POST}, maxAge = 60 * 30, exposedHeaders = {"Access-Control-Request-Headers","Access-Control-Request-Method"}) 16 | public class HelloController { 17 | @PostMapping("/post") 18 | public String post() { 19 | return "hello post"; 20 | } 21 | 22 | @CrossOrigin(origins = "http://localhost:8081", allowedHeaders = "*", methods = {RequestMethod.PUT,RequestMethod.OPTIONS}, maxAge = 60 * 30, exposedHeaders = {"Access-Control-Max-Age"}) 23 | @PutMapping("/put") 24 | public String put() { 25 | return "hello put"; 26 | } 27 | 28 | @GetMapping("/get") 29 | public String get() { 30 | return "hello get"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo/src/main/java/org/javaboy/oauth2_login_demo/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.security.core.GrantedAuthority; 5 | import org.springframework.security.core.context.SecurityContextHolder; 6 | import org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken; 7 | import org.springframework.security.oauth2.core.user.DefaultOAuth2User; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.Collection; 12 | 13 | /** 14 | * @author 江南一点雨 15 | * @微信公众号 江南一点雨 16 | * @网站 http://www.itboyhub.com 17 | * @国际站 http://www.javaboy.org 18 | * @微信 a_java_boy 19 | * @GitHub https://github.com/lenve 20 | * @Gitee https://gitee.com/lenve 21 | */ 22 | @RestController 23 | public class HelloController { 24 | @GetMapping("/hello") 25 | public DefaultOAuth2User hello() { 26 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 27 | return ((DefaultOAuth2User) authentication.getPrincipal()); 28 | } 29 | } -------------------------------------------------------------------------------- /chapter13/custom_expression/src/main/java/org/javaboy/based_on_url/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.based_on_url; 2 | 3 | import org.springframework.security.access.prepost.PreAuthorize; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @RestController 18 | public class HelloController { 19 | @GetMapping("/hello/{userId}") 20 | public String hello(@PathVariable Integer userId) { 21 | return "hello " + userId; 22 | } 23 | 24 | @GetMapping("/hi") 25 | public String hello2User(String username) { 26 | return "hello " + username; 27 | } 28 | 29 | @GetMapping("/admin/hello") 30 | @PreAuthorize("@has") 31 | public String admin() { 32 | return "hello admin"; 33 | } 34 | 35 | @GetMapping("/user/hello") 36 | public String user() { 37 | return "hello user"; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /chapter02/jpa/src/main/java/org/javaboy/formlogin/service/MyUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.service; 2 | 3 | import org.javaboy.formlogin.mapper.UserDao; 4 | import org.javaboy.formlogin.model.User; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.core.userdetails.UserDetails; 7 | import org.springframework.security.core.userdetails.UserDetailsService; 8 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 9 | import org.springframework.stereotype.Service; 10 | 11 | /** 12 | * @author 江南一点雨 13 | * @微信公众号 江南一点雨 14 | * @网站 http://www.itboyhub.com 15 | * @国际站 http://www.javaboy.org 16 | * @微信 a_java_boy 17 | * @GitHub https://github.com/lenve 18 | * @Gitee https://gitee.com/lenve 19 | */ 20 | @Service 21 | public class MyUserDetailsService implements UserDetailsService { 22 | @Autowired 23 | UserDao userDao; 24 | @Override 25 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 26 | User user = userDao.findUserByUsername(username); 27 | if (user == null) { 28 | throw new UsernameNotFoundException("用户不存在"); 29 | } 30 | return user; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapter15/oauth2/res_server_jwt/src/main/java/org/javaboy/res_server_jwt/config/OAuth2ResourceServerSecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.res_server_jwt.config; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | 9 | /** 10 | * @author 江南一点雨 11 | * @微信公众号 江南一点雨 12 | * @网站 http://www.itboyhub.com 13 | * @国际站 http://www.javaboy.org 14 | * @微信 a_java_boy 15 | * @GitHub https://github.com/lenve 16 | * @Gitee https://gitee.com/lenve 17 | */ 18 | @Configuration 19 | public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter { 20 | 21 | @Override 22 | protected void configure(HttpSecurity http) throws Exception { 23 | http.authorizeRequests() 24 | .anyRequest().authenticated() 25 | .and() 26 | .oauth2ResourceServer().jwt() 27 | .jwkSetUri("http://auth.javaboy.org:8881/oauth2/keys"); 28 | } 29 | } -------------------------------------------------------------------------------- /chapter09/http/src/main/java/org/javaboy/http/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 6 | 7 | /** 8 | * @author 江南一点雨 9 | * @微信公众号 江南一点雨 10 | * @网站 http://www.itboyhub.com 11 | * @国际站 http://www.javaboy.org 12 | * @微信 a_java_boy 13 | * @GitHub https://github.com/lenve 14 | * @Gitee https://gitee.com/lenve 15 | */ 16 | @Configuration 17 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 18 | @Override 19 | protected void configure(HttpSecurity http) throws Exception { 20 | http.authorizeRequests() 21 | .anyRequest().authenticated() 22 | .and() 23 | .formLogin() 24 | .and() 25 | .portMapper() 26 | .http(8080).mapsTo(8444) 27 | .and() 28 | .requiresChannel() 29 | .antMatchers("/https").requiresSecure() 30 | .antMatchers("/http").requiresInsecure() 31 | .and() 32 | .csrf().disable(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter04/ignoredrequests/src/main/java/org/javaboy/ignoredrequests/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.ignoredrequests; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Configuration 18 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 19 | @Override 20 | public void configure(WebSecurity web) throws Exception { 21 | web.ignoring().antMatchers("/login.html", "/css/**", "/js/**","/images/**"); 22 | } 23 | @Override 24 | protected void configure(HttpSecurity http) throws Exception { 25 | http.authorizeRequests() 26 | .anyRequest().authenticated() 27 | .and() 28 | .formLogin() 29 | .and() 30 | .csrf().disable(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapter03/kaptcha/src/main/java/org/javaboy/formlogin/config/KaptchaConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.google.code.kaptcha.Producer; 4 | import com.google.code.kaptcha.impl.DefaultKaptcha; 5 | import com.google.code.kaptcha.util.Config; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import java.util.Properties; 10 | 11 | /** 12 | * @author 江南一点雨 13 | * @微信公众号 江南一点雨 14 | * @网站 http://www.itboyhub.com 15 | * @国际站 http://www.javaboy.org 16 | * @微信 a_java_boy 17 | * @GitHub https://github.com/lenve 18 | * @Gitee https://gitee.com/lenve 19 | */ 20 | @Configuration 21 | public class KaptchaConfig { 22 | @Bean 23 | Producer kaptcha() { 24 | Properties properties = new Properties(); 25 | properties.setProperty("kaptcha.image.width", "150"); 26 | properties.setProperty("kaptcha.image.height", "50"); 27 | properties.setProperty("kaptcha.textproducer.char.string", "0123456789"); 28 | properties.setProperty("kaptcha.textproducer.char.length", "4"); 29 | Config config = new Config(properties); 30 | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); 31 | defaultKaptcha.setConfig(config); 32 | return defaultKaptcha; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter04/filter_kaptcha/src/main/java/org/javaboy/formlogin/config/KaptchaConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.google.code.kaptcha.Producer; 4 | import com.google.code.kaptcha.impl.DefaultKaptcha; 5 | import com.google.code.kaptcha.util.Config; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import java.util.Properties; 10 | 11 | /** 12 | * @author 江南一点雨 13 | * @微信公众号 江南一点雨 14 | * @网站 http://www.itboyhub.com 15 | * @国际站 http://www.javaboy.org 16 | * @微信 a_java_boy 17 | * @GitHub https://github.com/lenve 18 | * @Gitee https://gitee.com/lenve 19 | */ 20 | @Configuration 21 | public class KaptchaConfig { 22 | @Bean 23 | Producer kaptcha() { 24 | Properties properties = new Properties(); 25 | properties.setProperty("kaptcha.image.width", "150"); 26 | properties.setProperty("kaptcha.image.height", "50"); 27 | properties.setProperty("kaptcha.textproducer.char.string", "0123456789"); 28 | properties.setProperty("kaptcha.textproducer.char.length", "4"); 29 | Config config = new Config(properties); 30 | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); 31 | defaultKaptcha.setConfig(config); 32 | return defaultKaptcha; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/java/org/javaboy/formlogin/service/MyUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.service; 2 | 3 | import org.javaboy.formlogin.mapper.UserMapper; 4 | import org.javaboy.formlogin.model.User; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.core.userdetails.UserDetails; 7 | import org.springframework.security.core.userdetails.UserDetailsService; 8 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 9 | import org.springframework.stereotype.Service; 10 | 11 | /** 12 | * @author 江南一点雨 13 | * @微信公众号 江南一点雨 14 | * @网站 http://www.itboyhub.com 15 | * @国际站 http://www.javaboy.org 16 | * @微信 a_java_boy 17 | * @GitHub https://github.com/lenve 18 | * @Gitee https://gitee.com/lenve 19 | */ 20 | @Service 21 | public class MyUserDetailsService implements UserDetailsService { 22 | @Autowired 23 | UserMapper userMapper; 24 | @Override 25 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 26 | User user = userMapper.loadUserByUsername(username); 27 | if (user == null) { 28 | throw new UsernameNotFoundException("用户不存在"); 29 | } 30 | user.setRoles(userMapper.getRolesByUid(user.getId())); 31 | return user; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /chapter13/base_on_url_dy/src/main/java/org/javaboy/base_on_url_dy/service/UserService.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.base_on_url_dy.service; 2 | 3 | import org.javaboy.base_on_url_dy.mapper.UserMapper; 4 | import org.javaboy.base_on_url_dy.model.User; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.core.userdetails.UserDetails; 7 | import org.springframework.security.core.userdetails.UserDetailsService; 8 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 9 | import org.springframework.stereotype.Service; 10 | 11 | /** 12 | * @author 江南一点雨 13 | * @微信公众号 江南一点雨 14 | * @网站 http://www.itboyhub.com 15 | * @国际站 http://www.javaboy.org 16 | * @微信 a_java_boy 17 | * @GitHub https://github.com/lenve 18 | * @Gitee https://gitee.com/lenve 19 | */ 20 | @Service 21 | public class UserService implements UserDetailsService { 22 | @Autowired 23 | UserMapper userMapper; 24 | @Override 25 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 26 | User user = userMapper.loadUserByUsername(username); 27 | if (user == null) { 28 | throw new UsernameNotFoundException("用户不存在"); 29 | } 30 | user.setRoles(userMapper.getUserRoleByUid(user.getId())); 31 | return user; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /chapter15/oauth2_login_demo3/src/main/java/org/javaboy/oauth2_login_demo3/HelloController.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.oauth2_login_demo3; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.security.core.context.SecurityContextHolder; 5 | import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; 6 | import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient; 7 | import org.springframework.security.oauth2.core.user.DefaultOAuth2User; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | /** 13 | * @author 江南一点雨 14 | * @微信公众号 江南一点雨 15 | * @网站 http://www.itboyhub.com 16 | * @国际站 http://www.javaboy.org 17 | * @微信 a_java_boy 18 | * @GitHub https://github.com/lenve 19 | * @Gitee https://gitee.com/lenve 20 | */ 21 | @RestController 22 | public class HelloController { 23 | @GetMapping("/hello") 24 | public void hello() { 25 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 26 | Object principal = authentication.getPrincipal(); 27 | System.out.println("principal.getClass() = " + principal.getClass()); 28 | System.out.println("principal = " + principal); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /chapter09/csrf-1/src/main/java/org/javaboy/csrf1/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.csrf1; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Configuration 18 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 19 | @Override 20 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 21 | auth.inMemoryAuthentication() 22 | .withUser("javaboy") 23 | .password("{noop}123") 24 | .roles("admin"); 25 | } 26 | 27 | @Override 28 | protected void configure(HttpSecurity http) throws Exception { 29 | http.authorizeRequests() 30 | .anyRequest().authenticated() 31 | .and() 32 | .formLogin() 33 | .and() 34 | .csrf().disable(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /chapter09/http/src/main/java/org/javaboy/http/TomcatConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http; 2 | 3 | import org.apache.catalina.Context; 4 | import org.apache.catalina.connector.Connector; 5 | import org.apache.tomcat.util.descriptor.web.SecurityCollection; 6 | import org.apache.tomcat.util.descriptor.web.SecurityConstraint; 7 | import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | /** 12 | * @author 江南一点雨 13 | * @微信公众号 江南一点雨 14 | * @网站 http://www.itboyhub.com 15 | * @国际站 http://www.javaboy.org 16 | * @微信 a_java_boy 17 | * @GitHub https://github.com/lenve 18 | * @Gitee https://gitee.com/lenve 19 | */ 20 | @Configuration 21 | public class TomcatConfig { 22 | @Bean 23 | TomcatServletWebServerFactory tomcatServletWebServerFactory() { 24 | TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); 25 | factory.addAdditionalTomcatConnectors(createTomcatConnector()); 26 | return factory; 27 | } 28 | private Connector createTomcatConnector() { 29 | Connector connector = new 30 | Connector("org.apache.coyote.http11.Http11NioProtocol"); 31 | connector.setScheme("http"); 32 | connector.setPort(8080); 33 | return connector; 34 | } 35 | } -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/service/MyUserDetailsService2.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.service; 2 | 3 | import org.javaboy.formlogin.mapper.UserMapper; 4 | import org.javaboy.formlogin.mapper.UserMapper2; 5 | import org.javaboy.formlogin.model.User; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | * @author 江南一点雨 14 | * @微信公众号 江南一点雨 15 | * @网站 http://www.itboyhub.com 16 | * @国际站 http://www.javaboy.org 17 | * @微信 a_java_boy 18 | * @GitHub https://github.com/lenve 19 | * @Gitee https://gitee.com/lenve 20 | */ 21 | @Service 22 | public class MyUserDetailsService2 implements UserDetailsService { 23 | @Autowired 24 | UserMapper2 userMapper; 25 | @Override 26 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 27 | User user = userMapper.loadUserByUsername(username); 28 | if (user == null) { 29 | throw new UsernameNotFoundException("用户不存在"); 30 | } 31 | user.setRoles(userMapper.getRolesByUid(user.getId())); 32 | return user; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter11/cors02/src/main/resources/static/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 45 | 46 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/service/MyUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.service; 2 | 3 | import org.javaboy.formlogin.mapper.UserMapper; 4 | import org.javaboy.formlogin.model.User; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Primary; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | * @author 江南一点雨 14 | * @微信公众号 江南一点雨 15 | * @网站 http://www.itboyhub.com 16 | * @国际站 http://www.javaboy.org 17 | * @微信 a_java_boy 18 | * @GitHub https://github.com/lenve 19 | * @Gitee https://gitee.com/lenve 20 | */ 21 | @Service 22 | @Primary 23 | public class MyUserDetailsService implements UserDetailsService { 24 | @Autowired 25 | UserMapper userMapper; 26 | @Override 27 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 28 | User user = userMapper.loadUserByUsername(username); 29 | if (user == null) { 30 | throw new UsernameNotFoundException("用户不存在"); 31 | } 32 | user.setRoles(userMapper.getRolesByUid(user.getId())); 33 | return user; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chapter04/multi_users01/src/main/java/org/javaboy/multi_users01/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.multi_users01; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 5 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 6 | import org.springframework.security.core.userdetails.User; 7 | import org.springframework.security.provisioning.InMemoryUserDetailsManager; 8 | 9 | /** 10 | * @author 江南一点雨 11 | * @微信公众号 江南一点雨 12 | * @网站 http://www.itboyhub.com 13 | * @国际站 http://www.javaboy.org 14 | * @微信 a_java_boy 15 | * @GitHub https://github.com/lenve 16 | * @Gitee https://gitee.com/lenve 17 | */ 18 | @Configuration 19 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 20 | @Override 21 | protected void configure(HttpSecurity http) throws Exception { 22 | InMemoryUserDetailsManager users = new InMemoryUserDetailsManager(); 23 | users.createUser(User.withUsername("javaboy").password("{noop}123").roles("admin").build()); 24 | http.authorizeRequests() 25 | .anyRequest().authenticated() 26 | .and() 27 | .formLogin() 28 | .permitAll() 29 | .and() 30 | .userDetailsService(users) 31 | .csrf().disable(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /chapter02/formlogin/src/main/java/org/javaboy/formlogin/MyAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler{ 24 | @Override 25 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 200); 29 | resp.put("msg", "登录成功!"); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/user-in-memory/src/main/java/org/javaboy/formlogin/MyAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler{ 24 | @Override 25 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 200); 29 | resp.put("msg", "登录成功!"); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/jpa/src/main/java/org/javaboy/formlogin/config/MyAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler{ 24 | @Override 25 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 200); 29 | resp.put("msg", "登录成功!"); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter10/http_basic/src/main/java/org/javaboy/http_basic/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.http_basic; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Configuration 18 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 19 | @Override 20 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 21 | auth.inMemoryAuthentication() 22 | .withUser("javaboy") 23 | .password("{noop}123") 24 | .roles("admin"); 25 | } 26 | 27 | @Override 28 | protected void configure(HttpSecurity http) throws Exception { 29 | http.authorizeRequests() 30 | .anyRequest().authenticated() 31 | .and() 32 | .httpBasic() 33 | .and() 34 | .formLogin().disable() 35 | .csrf().disable(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /chapter02/jdbcuserdetailsmanager/src/main/java/org/javaboy/formlogin/MyAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler{ 24 | @Override 25 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 200); 29 | resp.put("msg", "登录成功!"); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/java/org/javaboy/formlogin/config/MyAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler{ 24 | @Override 25 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 200); 29 | resp.put("msg", "登录成功!"); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter03/multiuser/src/main/java/org/javaboy/formlogin/config/MyAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler{ 24 | @Override 25 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 200); 29 | resp.put("msg", "登录成功!"); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/config/MyAuthenticationSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler{ 24 | @Override 25 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 200); 29 | resp.put("msg", "登录成功!"); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter09/samesite/src/main/java/org/javaboy/samesite/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.samesite; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | import org.springframework.session.web.http.CookieSerializer; 8 | import org.springframework.session.web.http.DefaultCookieSerializer; 9 | 10 | /** 11 | * @author 江南一点雨 12 | * @微信公众号 江南一点雨 13 | * @网站 http://www.itboyhub.com 14 | * @国际站 http://www.javaboy.org 15 | * @微信 a_java_boy 16 | * @GitHub https://github.com/lenve 17 | * @Gitee https://gitee.com/lenve 18 | */ 19 | @Configuration 20 | public class WebMvcConfig extends WebSecurityConfigurerAdapter { 21 | 22 | @Override 23 | protected void configure(HttpSecurity http) throws Exception { 24 | http.authorizeRequests() 25 | .anyRequest().authenticated() 26 | .and() 27 | .formLogin() 28 | .and() 29 | .csrf().disable(); 30 | } 31 | 32 | @Bean 33 | public CookieSerializer httpSessionIdResolver(){ 34 | DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer(); 35 | cookieSerializer.setSameSite("strict"); 36 | return cookieSerializer; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /chapter02/formlogin/src/main/java/org/javaboy/formlogin/MyAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.AuthenticationException; 5 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler { 24 | @Override 25 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 500); 29 | resp.put("msg", "登录失败!" + exception.getMessage()); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/user-in-memory/src/main/java/org/javaboy/formlogin/MyAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.AuthenticationException; 5 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler { 24 | @Override 25 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 500); 29 | resp.put("msg", "登录失败!" + exception.getMessage()); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/jpa/src/main/java/org/javaboy/formlogin/config/MyAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.AuthenticationException; 5 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler { 24 | @Override 25 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 500); 29 | resp.put("msg", "登录失败!" + exception.getMessage()); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/jdbcuserdetailsmanager/src/main/java/org/javaboy/formlogin/MyAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.AuthenticationException; 5 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler { 24 | @Override 25 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 500); 29 | resp.put("msg", "登录失败!" + exception.getMessage()); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/mybatis/src/main/java/org/javaboy/formlogin/config/MyAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.AuthenticationException; 5 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler { 24 | @Override 25 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 500); 29 | resp.put("msg", "登录失败!" + exception.getMessage()); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter03/multiuser/src/main/java/org/javaboy/formlogin/config/MyAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.AuthenticationException; 5 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler { 24 | @Override 25 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 500); 29 | resp.put("msg", "登录失败!" + exception.getMessage()); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter02/jpa/src/main/java/org/javaboy/formlogin/model/Role.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * @author 江南一点雨 10 | * @微信公众号 江南一点雨 11 | * @网站 http://www.itboyhub.com 12 | * @国际站 http://www.javaboy.org 13 | * @微信 a_java_boy 14 | * @GitHub https://github.com/lenve 15 | * @Gitee https://gitee.com/lenve 16 | */ 17 | @Entity(name = "t_role") 18 | public class Role { 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | private Long id; 22 | private String name; 23 | private String nameZh; 24 | //省略 getter/setter 25 | 26 | @Override 27 | public String toString() { 28 | return "Role{" + 29 | "id=" + id + 30 | ", name='" + name + '\'' + 31 | ", nameZh='" + nameZh + '\'' + 32 | '}'; 33 | } 34 | 35 | public Long getId() { 36 | return id; 37 | } 38 | 39 | public void setId(Long id) { 40 | this.id = id; 41 | } 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public void setName(String name) { 48 | this.name = name; 49 | } 50 | 51 | public String getNameZh() { 52 | return nameZh; 53 | } 54 | 55 | public void setNameZh(String nameZh) { 56 | this.nameZh = nameZh; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /chapter03/multiuser-mybatis/src/main/java/org/javaboy/formlogin/config/MyAuthenticationFailureHandler.java: -------------------------------------------------------------------------------- 1 | package org.javaboy.formlogin.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.springframework.security.core.AuthenticationException; 5 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author 江南一点雨 16 | * @微信公众号 江南一点雨 17 | * @网站 http://www.itboyhub.com 18 | * @国际站 http://www.javaboy.org 19 | * @微信 a_java_boy 20 | * @GitHub https://github.com/lenve 21 | * @Gitee https://gitee.com/lenve 22 | */ 23 | public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler { 24 | @Override 25 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 26 | response.setContentType("application/json;charset=utf-8"); 27 | Map resp = new HashMap<>(); 28 | resp.put("status", 500); 29 | resp.put("msg", "登录失败!" + exception.getMessage()); 30 | ObjectMapper om = new ObjectMapper(); 31 | String s = om.writeValueAsString(resp); 32 | response.getWriter().write(s); 33 | } 34 | } 35 | --------------------------------------------------------------------------------