{"id":376471,"date":"2024-05-21T06:51:55","date_gmt":"2024-05-21T06:51:55","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=376471"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=376471","title":{"rendered":"<span>\u041a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 Spring Security: \u0421\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 \u0438 \u043b\u043e\u0433\u0438\u043d \u0447\u0435\u0440\u0435\u0437 username\/password<\/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<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u0430\u043d\u0435\u043a\u0435\u0440, \u044f Fullstack-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a (Java, Angular). \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443\u0436\u0435  \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u0443\u0447\u0430\u044e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u043d\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044b. \u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Spring Security 6, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 (Google, GitHub \u0438 \u0434\u0440\u0443\u0433\u0438\u0435). \u0412 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043d\u0435\u043c\u0430\u043b\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u043d\u044b, \u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u043f\u043e \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u0435 \u044f \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u043b \u043f\u043e \u043a\u0440\u0443\u043f\u0438\u0446\u0430\u043c \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u0442\u0435\u043c, \u0447\u0442\u043e \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0443\u0437\u043d\u0430\u0442\u044c.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043f\u043e\u043d\u044f\u0442\u0438\u044f\u043c\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 \u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f\u043c\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u044d\u0442\u0443 \u0442\u0435\u043c\u0443, \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044e: \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043b\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0438\u043c\u0435\u0435\u0442 \u043b\u0438 \u043e\u043d \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0443 \u0432 \u0446\u0435\u043b\u043e\u043c. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0436\u0435 \u2014 \u044d\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u0432 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u0443\u0436\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0440\u043e\u043b\u044f\u0445 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u0445 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u043e\u0437\u0436\u0435.  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Spring Security 5.7.0 \u043a\u043b\u0430\u0441\u0441 WebSecurityConfigurerAdapter \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u043c \u0438 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432 \u0432\u0441\u0435 \u0435\u0449\u0435 \u043e\u043f\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 build.gradle(\u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 maven \u0442\u043e\u0433\u0434\u0430 pom.xml) \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"yaml\">plugins {     id 'java'     id 'org.springframework.boot' version '3.2.5'     id 'io.spring.dependency-management' version '1.1.4' }  group = 'kz.danekerscode' version = '0.0.1-SNAPSHOT'  java {     sourceCompatibility = '17' }  configurations {     compileOnly {         extendsFrom annotationProcessor     } }  repositories {     mavenCentral() }  dependencies {     implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'     implementation 'org.springframework.boot:spring-boot-starter-security'      implementation 'org.springframework.boot:spring-boot-starter-data-redis'     implementation 'org.springframework.session:spring-session-data-redis'      implementation 'org.springframework.boot:spring-boot-starter-web'     implementation 'org.springframework.boot:spring-boot-starter-data-jpa'     runtimeOnly 'org.postgresql:postgresql'      compileOnly 'org.projectlombok:lombok'     annotationProcessor 'org.projectlombok:lombok'     testImplementation 'org.springframework.boot:spring-boot-starter-test'     testImplementation 'org.springframework.security:spring-security-test'      testRuntimeOnly 'org.junit.platform:junit-platform-launcher' }  tasks.named('test') {     useJUnitPlatform() } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0432 application.yaml<\/p>\n<pre><code class=\"yaml\">spring:   application:     name: habr-spring-security-6   datasource:     url: jdbc:postgresql:\/\/localhost:5432\/habr_spring_security_6 # \u0438\u043b\u0438 \u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445     username: postgres # \u043f\u043e\u043c\u0435\u043d\u044f\u0439\u0442\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0432\u0430\u0448\u0438\u043c     password: postgres # \u044d\u0442\u043e \u0442\u043e\u0436\u0435   jpa:     open-in-view: false     hibernate:       ddl-auto: update     show-sql: true     properties:       hibernate:         enable_lazy_load_no_trans: true         format_sql: true   data:     redis:       host: localhost       port: 6379   security:     oauth2:       client:         registration:           github:             provider: github             client-id: ${GITHUB_CLIENT_ID}             client-secret: ${GITHUB_CLIENT_SECRET}             scope:               - user:email               - read:user         provider:           github:             user-name-attribute: login<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c OAuth \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0432 GitHub. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e \u044d\u0442\u043e\u0439 <a href=\"https:\/\/docs.github.com\/en\/apps\/oauth-apps\/building-oauth-apps\/creating-an-oauth-app\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>. \u0422\u0430\u043a\u0436\u0435, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e redirect-uri \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c <a href=\"http:\/\/localhost:8080\/login\/oauth2\/code\/google\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:8080\/login\/oauth2\/code\/<\/a>github  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u00a0\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 \u0431\u0430\u0437\u044b \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 UserRepository, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0449\u0438\u0439 JpaRepository..  <\/p>\n<pre><code class=\"java\">@Entity @Getter @Setter @Table(name = \"users\") public class User implements UserDetails {     @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     private Long id;     private String username;     @Enumerated(EnumType.STRING)     private AuthType authType;     private String email;     private String password;     private String role = \"ROLE_USER\"; \/\/ TODO \u0441\u043e\u0432\u0435\u0442\u0443\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Enum \u0438\u043b\u0438 \u0436\u0435 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c      @Override     public Collection&lt;? extends GrantedAuthority> getAuthorities() {         return new HashSet&lt;>(){{             add(new SimpleGrantedAuthority(role));         }};     }      @Override     public boolean isAccountNonExpired() {         return true;     }      @Override     public boolean isAccountNonLocked() {         return true;     }      @Override     public boolean isCredentialsNonExpired() {         return true;     }      @Override     public boolean isEnabled() {         return true;     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0435 \u043b\u043e\u0433\u0438\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0438\u0442\u0445\u0430\u0431\u0430, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435<\/p>\n<pre><code class=\"java\">@Component @RequiredArgsConstructor public class OAuth2AuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {      \/\/ \u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0442\u043e\u043b\u044c\u043a\u043e github api, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440,     \/\/ \u0432\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0435\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e     record EmailDetails(String email, Boolean primary, Boolean verified) {     }      private final UserRepository userRepository;     private final OAuth2AuthorizedClientService authorizedClientService;     private final RestClient restClient = RestClient.builder()             .baseUrl(\"https:\/\/api.github.com\/user\/emails\") \/\/ \u0434\u0440\u0443\u0433\u043e\u0439 url \u0435\u0441\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e             .build(); \/\/ \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 ClientRegistration      @Override     public void onAuthenticationSuccess(             HttpServletRequest request,             HttpServletResponse response,             Authentication auth     ) throws IOException {         if (auth instanceof OAuth2AuthenticationToken auth2AuthenticationToken) {             var principal = auth2AuthenticationToken.getPrincipal();             var username = principal.getName();             var email = fetchUserEmailFromGitHubApi(auth2AuthenticationToken.getAuthorizedClientRegistrationId(), username);              if (!userRepository.existsByEmail(email)) {                 var user = new User();                 user.setEmail(email);                 user.setUsername(username);                 userRepository.save(user);             }         }          super.clearAuthenticationAttributes(request);         super.getRedirectStrategy().sendRedirect(request, response, \"\/api\/v1\/user\/me\");     }      private String fetchUserEmailFromGitHubApi(String clientRegistrationId, String principalName) {         var authorizedClient = authorizedClientService.loadAuthorizedClient(clientRegistrationId, principalName);         var accessToken = authorizedClient.getAccessToken().getTokenValue();          var userEmailsResponse = restClient.get()                 .headers(headers -> headers.setBearerAuth(accessToken))                 .retrieve()                 .body(EmailDetails[].class);          if (userEmailsResponse == null) {             return \"null\";         }          var fetchedEmailDetails = Arrays.stream(userEmailsResponse)                 .filter(emailDetails -> emailDetails.verified() &amp;&amp; emailDetails.primary())                 .findFirst()                 .orElseGet(() -> null);          return fetchedEmailDetails != null ? fetchedEmailDetails.email() : \"null\";     } }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0435\u0441\u0442\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 onAuthenticationSuccess \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\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 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OAuth2 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432. \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 Spring Security \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0441\u0435\u0441\u0441\u0438\u044e \u0432 \u0440\u0435\u0434\u0438\u0441\u0435.<\/p>\n<p><strong>\u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0443.<\/strong><\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0434\u0442\u043e \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432<\/p>\n<pre><code class=\"java\">public record LoginRequest(         String email,         String password ) { }<\/code><\/pre>\n<pre><code class=\"java\">public record RegistrationRequest(         String email,         String password,         String username ) { }<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043d\u0430\u0448\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0441\u0442\u0430\u043d\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u044f\u0434\u0440\u043e \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<pre><code class=\"java\">@Service @Slf4j @RequiredArgsConstructor public class AuthService {     private final PasswordEncoder passwordEncoder;     private final UserRepository userRepository;     private final AuthenticationManager authenticationManager;     private final SecurityContextRepository securityContextRepository;      public void register(RegistrationRequest request) {         if (userRepository.existsByEmailAndAuthType(request.email(), AuthType.MANUAL)) {             throw new IllegalArgumentException(\"Email already registered\");         }          var user = new User();         user.setAuthType(AuthType.MANUAL);         user.setUsername(request.username());         user.setEmail(request.email());         user.setPassword(passwordEncoder.encode(request.password()));         userRepository.save(user);     }      public Authentication login(             LoginRequest loginRequest,             HttpServletRequest request,             HttpServletResponse response     ) {         var passwordAuthenticationToken = new UsernamePasswordAuthenticationToken(                 loginRequest.email(), loginRequest.password()         );          var auth = authenticationManager.authenticate(passwordAuthenticationToken);         var securityContext = SecurityContextHolder.createEmptyContext();         securityContext.setAuthentication(auth);         securityContextRepository.saveContext(securityContext, request, response); \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e \u0432 \u0440\u0435\u0434\u0438\u0441          log.info(\"Authenticated and created session for {}\", auth.getName());         return auth;     }  } <\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 AuthService \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 http \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<pre><code class=\"java\">@RequiredArgsConstructor @RestController @RequestMapping(\"api\/v1\/auth\") public class AuthController {      private final AuthService authService;      @GetMapping(\"me\")     Principal me(Principal principal) {         return principal;     }      @PostMapping(\"register\")     @ResponseStatus(HttpStatus.CREATED)     void register(@RequestBody RegistrationRequest request) {         authService.register(request);     }      @PostMapping(\"login\")     Object login(             @RequestBody LoginRequest loginRequest,             HttpServletRequest request,             HttpServletResponse response     ) {         return authService                 .login(loginRequest, request, response)                 .getPrincipal();     }  } <\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0442\u0440\u0438 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u0430. <\/p>\n<p><em>\/api\/v1\/auth\/me <\/em>&#8212; \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <\/p>\n<p><em>\/api\/v1\/auth\/register <\/em>&#8212; \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/p>\n<p> <em>\/api\/v1\/auth\/login<\/em> &#8212; \u041b\u043e\u0433\u0438\u043d<\/p>\n<p><strong>\u0412\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7d3\/1eb\/01c\/7d31eb01c74a75baf605bf4fdf519229.png\" alt=\"\" title=\"\" width=\"1862\" height=\"933\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7d3\/1eb\/01c\/7d31eb01c74a75baf605bf4fdf519229.png\"\/><\/figure>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c Spring \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043e \u043d\u0430 \u043f\u043e\u0440\u0442\u0435 8080. \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435  <a href=\"http:\/\/localhost:8080\/oauth2\/authorization\/github\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:8080\/oauth2\/authorization\/github<\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/795\/525\/d60\/795525d600adc3681665dc8e98750dfc.png\" width=\"1853\" height=\"983\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/795\/525\/d60\/795525d600adc3681665dc8e98750dfc.png\"\/><\/figure>\n<p>\u0417\u0430\u0442\u0435\u043c \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043c\u0438 \u043e\u0442\u043a\u0440\u043e\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043b\u043e\u0433\u0438\u043d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0430. \u041f\u043e\u0441\u043b\u0435 \u0432\u0432\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u044b \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442 api\/v1\/auth\/me. \u0412 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7a9\/35a\/179\/7a935a17910570fbbf21507076d3c9d7.png\" width=\"1122\" height=\"947\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7a9\/35a\/179\/7a935a17910570fbbf21507076d3c9d7.png\"\/><\/figure>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e <strong>\u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430.<\/strong><\/p>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/p>\n<pre><code class=\"assembly\">POST http:\/\/localhost:8080\/api\/v1\/auth\/register Content-Type: application\/json  {   \"username\": \"Daneker\" ,   \"password\": \"password\" ,   \"email\": \"daneker2005@gmail.com\" } <\/code><\/pre>\n<p>\u0412 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0443\u0441 201, \u0437\u0430\u0442\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 api\/v1\/auth\/login<\/p>\n<pre><code class=\"assembly\">POST http:\/\/localhost:8080\/api\/v1\/auth\/login Content-Type: application\/json  {   \"password\": \"password\" ,   \"email\": \"daneker2005@gmail.com\" }<\/code><\/pre>\n<p> \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0438\u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432 \u043e\u0442\u0432\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <\/p>\n<pre><code class=\"json\">{   \"id\": 12,   \"username\": \"Daneker\",   \"email\": \"daneker2005@gmail.com\",   \"authType\": \"MANUAL\",   \"role\": \"ROLE_USER\",   \"authorities\": [     {       \"authority\": \"ROLE_USER\"     }   ],   \"enabled\": true }<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/158\/502\/660\/158502660f00c45f7fe84584b23f9788.png\" alt=\"\u0422\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432 \u0440\u0435\u0434\u0438\u0441\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0432\u0435 \u0441\u0435\u0441\u0441\u0438\u0438\" title=\"\u0422\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432 \u0440\u0435\u0434\u0438\u0441\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0432\u0435 \u0441\u0435\u0441\u0441\u0438\u0438\" width=\"706\" height=\"166\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/158\/502\/660\/158502660f00c45f7fe84584b23f9788.png\"\/><\/p>\n<div><figcaption>\u0422\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432 \u0440\u0435\u0434\u0438\u0441\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0434\u0432\u0435 \u0441\u0435\u0441\u0441\u0438\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u043d\u0438\u0445 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u0422\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0443 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d \u0437\u0430 \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0432\u044f\u0437\u044c \u043e\u0442 \u0431\u043e\u043b\u0435\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u0438 \u0438\u0441\u043a\u0443\u0448\u0451\u043d\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432.  <\/p>\n<p>\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u00a0<a href=\"https:\/\/github.com\/youngAndMad\/habr-spring-security6\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>.  <\/p>\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\/815285\/\"> https:\/\/habr.com\/ru\/articles\/815285\/<\/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<p>\u041f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u0430\u043d\u0435\u043a\u0435\u0440, \u044f Fullstack-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a (Java, Angular). \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443\u0436\u0435  \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u0443\u0447\u0430\u044e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u043d\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044b. \u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Spring Security 6, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 (Google, GitHub \u0438 \u0434\u0440\u0443\u0433\u0438\u0435). \u0412 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043d\u0435\u043c\u0430\u043b\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c\u0438. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043b\u043d\u044b, \u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u043f\u043e \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u0435 \u044f \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u043b \u043f\u043e \u043a\u0440\u0443\u043f\u0438\u0446\u0430\u043c \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u0442\u0435\u043c, \u0447\u0442\u043e \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0443\u0437\u043d\u0430\u0442\u044c.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043f\u043e\u043d\u044f\u0442\u0438\u044f\u043c\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 \u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f\u043c\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u044d\u0442\u0443 \u0442\u0435\u043c\u0443, \u043a\u0440\u0430\u0442\u043a\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044e: \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043b\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0438\u043c\u0435\u0435\u0442 \u043b\u0438 \u043e\u043d \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0443 \u0432 \u0446\u0435\u043b\u043e\u043c. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0436\u0435 \u2014 \u044d\u0442\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u0432 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u0443\u0436\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0440\u043e\u043b\u044f\u0445 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0430\u0445 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u043e\u0437\u0436\u0435.  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 Spring Security 5.7.0 \u043a\u043b\u0430\u0441\u0441 WebSecurityConfigurerAdapter \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u043c \u0438 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432 \u0432\u0441\u0435 \u0435\u0449\u0435 \u043e\u043f\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 build.gradle(\u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 maven \u0442\u043e\u0433\u0434\u0430 pom.xml) \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"yaml\">plugins {     id 'java'     id 'org.springframework.boot' version '3.2.5'     id 'io.spring.dependency-management' version '1.1.4' }  group = 'kz.danekerscode' version = '0.0.1-SNAPSHOT'  java {     sourceCompatibility = '17' }  configurations {     compileOnly {         extendsFrom annotationProcessor     } }  repositories {     mavenCentral() }  dependencies {     implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'     implementation 'org.springframework.boot:spring-boot-starter-security'      implementation 'org.springframework.boot:spring-boot-starter-data-redis'     implementation 'org.springframework.session:spring-session-data-redis'      implementation 'org.springframework.boot:spring-boot-starter-web'     implementation 'org.springframework.boot:spring-boot-starter-data-jpa'     runtimeOnly 'org.postgresql:postgresql'      compileOnly 'org.projectlombok:lombok'     annotationProcessor 'org.projectlombok:lombok'     testImplementation 'org.springframework.boot:spring-boot-starter-test'     testImplementation 'org.springframework.security:spring-security-test'      testRuntimeOnly 'org.junit.platform:junit-platform-launcher' }  tasks.named('test') {     useJUnitPlatform() } <\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0432 application.yaml<\/p>\n<pre><code class=\"yaml\">spring:   application:     name: habr-spring-security-6   datasource:     url: jdbc:postgresql:\/\/localhost:5432\/habr_spring_security_6 # \u0438\u043b\u0438 \u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445     username: postgres # \u043f\u043e\u043c\u0435\u043d\u044f\u0439\u0442\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0432\u0430\u0448\u0438\u043c     password: postgres # \u044d\u0442\u043e \u0442\u043e\u0436\u0435   jpa:     open-in-view: false     hibernate:       ddl-auto: update     show-sql: true     properties:       hibernate:         enable_lazy_load_no_trans: true         format_sql: true   data:     redis:       host: localhost       port: 6379   security:     oauth2:       client:         registration:           github:             provider: github             client-id: ${GITHUB_CLIENT_ID}             client-secret: ${GITHUB_CLIENT_SECRET}             scope:               - user:email               - read:user         provider:           github:             user-name-attribute: login<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c OAuth \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0432 GitHub. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e \u044d\u0442\u043e\u0439 <a href=\"https:\/\/docs.github.com\/en\/apps\/oauth-apps\/building-oauth-apps\/creating-an-oauth-app\" rel=\"noopener noreferrer nofollow\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>. \u0422\u0430\u043a\u0436\u0435, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e redirect-uri \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c <a href=\"http:\/\/localhost:8080\/login\/oauth2\/code\/google\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:8080\/login\/oauth2\/code\/<\/a>github  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u00a0\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 \u0431\u0430\u0437\u044b \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 UserRepository, \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0449\u0438\u0439 JpaRepository..  <\/p>\n<pre><code class=\"java\">@Entity @Getter @Setter @Table(name = \"users\") public class User implements UserDetails {     @Id     @GeneratedValue(strategy = GenerationType.IDENTITY)     private Long id;     private String username;     @Enumerated(EnumType.STRING)     private AuthType authType;     private String email;     private String password;     private String role = \"ROLE_USER\"; \/\/ TODO \u0441\u043e\u0432\u0435\u0442\u0443\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Enum \u0438\u043b\u0438 \u0436\u0435 \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c      @Override     public Collection&lt;? extends GrantedAuthority> getAuthorities() {         return new HashSet&lt;>(){{             add(new SimpleGrantedAuthority(role));         }};     }      @Override     public boolean isAccountNonExpired() {         return true;     }      @Override     public boolean isAccountNonLocked() {         return true;     }      @Override     public boolean isCredentialsNonExpired() {         return true;     }      @Override     public boolean isEnabled() {         return true;     } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u0435 \u043b\u043e\u0433\u0438\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0438\u0442\u0445\u0430\u0431\u0430, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435<\/p>\n<pre><code class=\"java\">@Component @RequiredArgsConstructor public class OAuth2AuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {      \/\/ \u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0442\u043e\u043b\u044c\u043a\u043e github api, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440,     \/\/ \u0432\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0435\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e     record EmailDetails(String email, Boolean primary, Boolean verified) {     }      private final UserRepository userRepository;     private final OAuth2AuthorizedClientService authorizedClientService;     private final RestClient restClient = RestClient.builder()             .baseUrl(\"https:\/\/api.github.com\/user\/emails\") \/\/ \u0434\u0440\u0443\u0433\u043e\u0439 url \u0435\u0441\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e             .build(); \/\/ \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 ClientRegistration      @Override     public void onAuthenticationSuccess(             HttpServletRequest request,             HttpServletResponse response,             Authentication auth     ) throws IOException {         if (auth instanceof OAuth2AuthenticationToken auth2AuthenticationToken) {             var principal = auth2AuthenticationToken.getPrincipal();             var username = principal.getName();             var email = fetchUserEmailFromGitHubApi(auth2AuthenticationToken.getAuthorizedClientRegistrationId(), username);              if (!userRepository.existsByEmail(email)) {                 var user = new User();                 user.setEmail(email);                 user.setUsername(username);                 userRepository.save(user);             }         }          super.clearAuthenticationAttributes(request);         super.getRedirectStrategy().sendRedirect(request, response, \"\/api\/v1\/user\/me\");     }      private String fetchUserEmailFromGitHubApi(String clientRegistrationId, String principalName) {         var authorizedClient = authorizedClientService.loadAuthorizedClient(clientRegistrationId, principalName);         var accessToken = authorizedClient.getAccessToken().getTokenValue();          var userEmailsResponse = restClient.get()                 .headers(headers -> headers.setBearerAuth(accessToken))                 .retrieve()                 .body(EmailDetails[].class);          if (userEmailsResponse == null) {             return \"null\";         }          var fetchedEmailDetails = Arrays.stream(userEmailsResponse)                 .filter(emailDetails -> emailDetails.verified() &amp;&amp; emailDetails.primary())                 .findFirst()                 .orElseGet(() -> null);          return fetchedEmailDetails != null ? fetchedEmailDetails.email() : \"null\";     } }<\/code><\/pre>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0435\u0441\u0442\u044c \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 onAuthenticationSuccess \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\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 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OAuth2 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432. \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 Spring Security \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0441\u0435\u0441\u0441\u0438\u044e \u0432 \u0440\u0435\u0434\u0438\u0441\u0435.<\/p>\n<p><strong>\u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0445\u043e\u0434\u0443.<\/strong><\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0434\u0442\u043e \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0435\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u043e\u0432<\/p>\n<pre><code class=\"java\">public record LoginRequest(         String email,         String password ) { }<\/code><\/pre>\n<pre><code class=\"java\">public record RegistrationRequest(         String email,         String password,         String username ) { }<\/code><\/pre>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043d\u0430\u0448\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0441\u0442\u0430\u043d\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u044f \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u044f\u0434\u0440\u043e \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438.<\/p>\n<pre><code class=\"java\">@Service @Slf4j @RequiredArgsConstructor public class AuthService {     private final PasswordEncoder passwordEncoder;     private final UserRepository userRepository;     private final AuthenticationManager authenticationManager;     private final SecurityContextRepository securityContextRepository;      public void register(RegistrationRequest request) {         if (userRepository.existsByEmailAndAuthType(request.email(), AuthType.MANUAL)) {             throw new IllegalArgumentException(\"Email already registered\");         }          var user = new User();         user.setAuthType(AuthType.MANUAL);         user.setUsername(request.username());         user.setEmail(request.email());         user.setPassword(passwordEncoder.encode(request.password()));         userRepository.save(user);     }      public Authentication login(             LoginRequest loginRequest,             HttpServletRequest request,             HttpServletResponse response     ) {         var passwordAuthenticationToken = new UsernamePasswordAuthenticationToken(                 loginRequest.email(), loginRequest.password()         );          var auth = authenticationManager.authenticate(passwordAuthenticationToken);         var securityContext = SecurityContextHolder.createEmptyContext();         securityContext.setAuthentication(auth);         securityContextRepository.saveContext(securityContext, request, response); \/\/ \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0435\u0441\u0441\u0438\u044e \u0432 \u0440\u0435\u0434\u0438\u0441          log.info(\"Authenticated and created session for {}\",<\/code><\/pre>\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-376471","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376471","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=376471"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/376471\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=376471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=376471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=376471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}