diff --git a/examples/db-problems-demo/.gitignore b/examples/db-problems-demo/.gitignore deleted file mode 100644 index 549e00a2..00000000 --- a/examples/db-problems-demo/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ diff --git a/examples/db-problems-demo/pom.xml b/examples/db-problems-demo/pom.xml deleted file mode 100644 index eec2be97..00000000 --- a/examples/db-problems-demo/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.4.RELEASE - - - ru.otus - db-problems-demo - 0.0.1-SNAPSHOT - db-problems-demo - Demo project for Db usage problems - - - 11 - - - - - org.springframework.boot - spring-boot-starter-jdbc - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - - org.springframework.boot - spring-boot-starter-web - - - - org.flywaydb - flyway-core - - - - com.h2database - h2 - 1.4.200 - test - - - - org.postgresql - postgresql - 42.2.17 - - - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/examples/db-problems-demo/readme.md b/examples/db-problems-demo/readme.md deleted file mode 100644 index d70fff70..00000000 --- a/examples/db-problems-demo/readme.md +++ /dev/null @@ -1 +0,0 @@ -Проект с миграцией для демонстрации того, как выглядит джойн нескольких таблиц при связи "многие-ко-многим" \ No newline at end of file diff --git a/examples/db-problems-demo/src/main/java/db/migration/R__0002_Add_books.java b/examples/db-problems-demo/src/main/java/db/migration/R__0002_Add_books.java deleted file mode 100644 index 84e9608b..00000000 --- a/examples/db-problems-demo/src/main/java/db/migration/R__0002_Add_books.java +++ /dev/null @@ -1,60 +0,0 @@ -package db.migration; - -import org.flywaydb.core.api.migration.BaseJavaMigration; -import org.flywaydb.core.api.migration.Context; -import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import org.springframework.jdbc.datasource.SingleConnectionDataSource; - -import javax.sql.DataSource; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -@SuppressWarnings("unchecked") -public class R__0002_Add_books extends BaseJavaMigration { - - public static final int BOOKS_COUNT = 100_000; - - @Override - public void migrate(Context context) throws Exception { - DataSource ds = new SingleConnectionDataSource(context.getConnection(), true); - NamedParameterJdbcOperations jdbc = new NamedParameterJdbcTemplate(ds); - - insertBooks(jdbc); - insertBooksRelations(jdbc); - } - - private void insertBooks(NamedParameterJdbcOperations jdbc) { - List> params = new ArrayList<>(BOOKS_COUNT); - for (int i = 0; i < BOOKS_COUNT; i++) { - String bookTitle = String.format("Заголовок книги #%d", i); - String bookTextPart = String.format("Это текст книги #%d", i); - String bookText = bookTextPart.repeat( 8000 / bookTextPart.length()); - params.add(new MapSqlParameterSource("title", bookTitle) - .addValue("bookText", bookText) - .getValues() - ); - } - jdbc.batchUpdate("insert into books (title, book_text) values (:title, :bookText)", - params.toArray(new Map[0])); - } - - private void insertBooksRelations(NamedParameterJdbcOperations jdbc) { - List> paramsForAuthors = new ArrayList<>(BOOKS_COUNT); - List> paramsForGenres = new ArrayList<>(BOOKS_COUNT); - for (int i = 1; i <= BOOKS_COUNT; i++) { - for (int j = 1; j <= 3; j++) { - paramsForAuthors.add(new MapSqlParameterSource("bookId", i).addValue("authorId", j).getValues()); - paramsForGenres.add(new MapSqlParameterSource("bookId", i).addValue("genreId", j).getValues()); - } - } - jdbc.batchUpdate("insert into books_authors (book_id, author_id) values (:bookId, :authorId)", - paramsForAuthors.toArray(new Map[0])); - - jdbc.batchUpdate("insert into books_genres (book_id, genre_id) values (:bookId, :genreId)", - paramsForGenres.toArray(new Map[0])); - } - -} diff --git a/examples/db-problems-demo/src/main/java/ru/otus/dbproblemsdemo/DbProblemsDemoApplication.java b/examples/db-problems-demo/src/main/java/ru/otus/dbproblemsdemo/DbProblemsDemoApplication.java deleted file mode 100644 index ed8a5ff4..00000000 --- a/examples/db-problems-demo/src/main/java/ru/otus/dbproblemsdemo/DbProblemsDemoApplication.java +++ /dev/null @@ -1,24 +0,0 @@ -package ru.otus.dbproblemsdemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -import java.sql.SQLException; - -/* -SELECT * FROM AUTHORS; -SELECT * FROM GENRES; -SELECT * FROM BOOKS_AUTHORS ; -SELECT * FROM BOOKS_GENRES; -SELECT * FROM BOOKS; -SELECT * FROM BOOKS_ALL_INFO ; - */ - -@SpringBootApplication -public class DbProblemsDemoApplication { - - public static void main(String[] args) throws SQLException { - SpringApplication.run(DbProblemsDemoApplication.class, args); - } - -} diff --git a/examples/db-problems-demo/src/main/resources/application.yml b/examples/db-problems-demo/src/main/resources/application.yml deleted file mode 100644 index ea3a99d4..00000000 --- a/examples/db-problems-demo/src/main/resources/application.yml +++ /dev/null @@ -1,13 +0,0 @@ -spring: - datasource: - #url: jdbc:h2:mem:testdb - url: jdbc:postgresql://localhost:5432/problems - username: postgres - password: postgres - driver-class-name: org.postgresql.Driver - initialization-mode: never - h2: - console: - enabled: true - flyway: - enabled: true \ No newline at end of file diff --git a/examples/db-problems-demo/src/main/resources/db/migration/1.0/V1_1__2020_10_10_Initial_schema.sql b/examples/db-problems-demo/src/main/resources/db/migration/1.0/V1_1__2020_10_10_Initial_schema.sql deleted file mode 100644 index dda2b660..00000000 --- a/examples/db-problems-demo/src/main/resources/db/migration/1.0/V1_1__2020_10_10_Initial_schema.sql +++ /dev/null @@ -1,23 +0,0 @@ ---date: 2002-10-10 ---author: stvort - -create table authors (id bigserial, name varchar(50), primary key (id)); -create table genres (id bigserial, name varchar(50), primary key (id)); -create table books (id bigserial, title varchar(50), book_text varchar(8000), primary key (id)); -create table books_authors (book_id bigint not null references books (id) on delete cascade , author_id bigint not null references authors (id) on delete cascade); -create table books_genres (book_id bigint not null references books (id) on delete cascade , genre_id bigint not null references genres (id) on delete cascade); - - -create view books_all_info as -select b.id as "ID книги", - b.title as "Заголовок книги", - b.book_text as "Текст книги", - a.id as "ID автора", - a.name as "Имя автора", - g.id as "ID жанра", - g.name as "Название жанра" -from books b left join - books_authors ba on b.id = ba.book_id left join - books_genres bg on b.id = bg.book_id left join - authors a on ba.author_id = a.id left join - genres g on bg.genre_id = g.id; diff --git a/examples/db-problems-demo/src/main/resources/db/migration/data/R__0001_Add_catalogsl_data.sql b/examples/db-problems-demo/src/main/resources/db/migration/data/R__0001_Add_catalogsl_data.sql deleted file mode 100644 index ff10f291..00000000 --- a/examples/db-problems-demo/src/main/resources/db/migration/data/R__0001_Add_catalogsl_data.sql +++ /dev/null @@ -1,15 +0,0 @@ -insert into authors(id, name) -values (1, 'Админ Супервайзерович Рут'), - (2, 'Валентина Игоревна Априори'), - (3, 'Питуний Дельфинович Автостопов'), - (4, 'Инокентий Купертинович Жужа'); - -insert into genres(id, name) -values (1, 'Детектив'), - (2, 'Фантастика'), - (3, 'Фэнтези'), - (4, 'Техническая литература'); - - - - diff --git a/examples/hibernate-fetch-mode-demo/.gitignore b/examples/hibernate-fetch-mode-demo/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/examples/hibernate-fetch-mode-demo/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/examples/hibernate-fetch-mode-demo/pom.xml b/examples/hibernate-fetch-mode-demo/pom.xml deleted file mode 100644 index 9a767b37..00000000 --- a/examples/hibernate-fetch-mode-demo/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.1.RELEASE - - - ru.otus.example - hibernate-fetch-mode-demo - 0.0.1-SNAPSHOT - HibernateFetchModeDemo - Demo project for Spring Boot - - - 11 - 11 - 11 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.shell - spring-shell-starter - 2.0.1.RELEASE - - - - org.springframework.boot - spring-boot-devtools - runtime - - - - com.h2database - h2 - runtime - - - - org.projectlombok - lombok - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - - diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/HibernateFetchModeDemoApplication.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/HibernateFetchModeDemoApplication.java deleted file mode 100644 index a8600043..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/HibernateFetchModeDemoApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class HibernateFetchModeDemoApplication { - - public static void main(String[] args) { - SpringApplication.run(HibernateFetchModeDemoApplication.class, args); - } - -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Knowledge.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Knowledge.java deleted file mode 100644 index 0ff496a7..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Knowledge.java +++ /dev/null @@ -1,21 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.models; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.*; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@Entity -@Table(name = "knowledge") -public class Knowledge { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - @Column - private String name; -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Mentor.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Mentor.java deleted file mode 100644 index 2d25b162..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Mentor.java +++ /dev/null @@ -1,31 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.models; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; - -import javax.persistence.*; -import java.util.List; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@Entity -@Table(name = "mentors") -public class Mentor { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - @Column - private String name; - - @LazyCollection(LazyCollectionOption.FALSE) - @ManyToMany(targetEntity = Knowledge.class, cascade = CascadeType.ALL) - @JoinTable(name = "mentors_experience", - joinColumns = @JoinColumn(name = "mentor_id", referencedColumnName = "id"), - inverseJoinColumns = @JoinColumn(name = "knowledge_id", referencedColumnName = "id")) - private List experience; -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Student.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Student.java deleted file mode 100644 index 947005b5..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Student.java +++ /dev/null @@ -1,33 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.models; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; - -import javax.persistence.*; -import java.util.List; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@Entity -@Table(name = "students") -public class Student { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - @Column - private String name; - - //@BatchSize(size = 5) - @LazyCollection(LazyCollectionOption.FALSE) - @ManyToMany(targetEntity = Knowledge.class, cascade = CascadeType.ALL) - @JoinTable(name = "students_experience", - joinColumns = @JoinColumn(name = "student_id", referencedColumnName = "id"), - inverseJoinColumns = @JoinColumn(name = "knowledge_id", referencedColumnName = "id")) - private List experience; - -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Teacher.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Teacher.java deleted file mode 100644 index d033f511..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/models/Teacher.java +++ /dev/null @@ -1,34 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.models; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; - -import javax.persistence.*; -import java.util.List; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@Entity -@Table(name = "teachers") -public class Teacher { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - @Column - private String name; - - @LazyCollection(LazyCollectionOption.FALSE) - @Fetch(FetchMode.SUBSELECT) - @ManyToMany(targetEntity = Knowledge.class, cascade = CascadeType.ALL) - @JoinTable(name = "teachers_experience", - joinColumns = @JoinColumn(name = "teacher_id", referencedColumnName = "id"), - inverseJoinColumns = @JoinColumn(name = "knowledge_id", referencedColumnName = "id")) - private List experience; -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/MentorRepository.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/MentorRepository.java deleted file mode 100644 index e0aa59ee..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/MentorRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.repositories; - -import ru.otus.example.hibernate_fetch_mode_demo.models.Mentor; - -import java.util.List; - -public interface MentorRepository { - List findAll(); -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/MentorRepositoryImpl.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/MentorRepositoryImpl.java deleted file mode 100644 index d0854709..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/MentorRepositoryImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.repositories; - -import org.springframework.stereotype.Repository; -import ru.otus.example.hibernate_fetch_mode_demo.models.Mentor; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import java.util.List; - -@Repository -public class MentorRepositoryImpl implements MentorRepository { - - @PersistenceContext - private EntityManager em; - - @Override - public List findAll() { - return em.createQuery("select m from Mentor m join fetch m.experience", Mentor.class).getResultList(); - } -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/StudentRepository.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/StudentRepository.java deleted file mode 100644 index a477ddcc..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/StudentRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.repositories; - -import ru.otus.example.hibernate_fetch_mode_demo.models.Student; - -import java.util.List; - -public interface StudentRepository { - List findAll(); -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/StudentRepositoryImpl.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/StudentRepositoryImpl.java deleted file mode 100644 index d4b80e65..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/StudentRepositoryImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.repositories; - -import org.springframework.stereotype.Repository; -import ru.otus.example.hibernate_fetch_mode_demo.models.Student; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import java.util.List; - -@Repository -public class StudentRepositoryImpl implements StudentRepository { - - @PersistenceContext - private EntityManager em; - - @Override - public List findAll() { - return em.createQuery("select s from Student s", Student.class).getResultList(); - } -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/TeacherRepository.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/TeacherRepository.java deleted file mode 100644 index 9c230a3c..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/TeacherRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.repositories; - -import ru.otus.example.hibernate_fetch_mode_demo.models.Teacher; - -import java.util.List; - -public interface TeacherRepository { - List findAll(); -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/TeacherRepositoryImpl.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/TeacherRepositoryImpl.java deleted file mode 100644 index 703aab92..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/repositories/TeacherRepositoryImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.repositories; - -import org.springframework.stereotype.Repository; -import ru.otus.example.hibernate_fetch_mode_demo.models.Teacher; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import java.util.List; - -@Repository -public class TeacherRepositoryImpl implements TeacherRepository { - - @PersistenceContext - private EntityManager em; - - @Override - public List findAll() { - return em.createQuery("select t from Teacher t", Teacher.class).getResultList(); - } -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/shell/ShellCommands.java b/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/shell/ShellCommands.java deleted file mode 100644 index 5c2ba3fe..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/java/ru/otus/example/hibernate_fetch_mode_demo/shell/ShellCommands.java +++ /dev/null @@ -1,48 +0,0 @@ -package ru.otus.example.hibernate_fetch_mode_demo.shell; - -import org.springframework.shell.standard.ShellComponent; -import org.springframework.shell.standard.ShellMethod; -import ru.otus.example.hibernate_fetch_mode_demo.models.Mentor; -import ru.otus.example.hibernate_fetch_mode_demo.models.Student; -import ru.otus.example.hibernate_fetch_mode_demo.models.Teacher; -import ru.otus.example.hibernate_fetch_mode_demo.repositories.MentorRepository; -import ru.otus.example.hibernate_fetch_mode_demo.repositories.StudentRepository; -import ru.otus.example.hibernate_fetch_mode_demo.repositories.TeacherRepository; - -import java.util.stream.Collectors; - - -@ShellComponent -public class ShellCommands { - - private static final String OFFSET = "\n\n----------------------------\n\n"; - - private final StudentRepository studentRepository; - private final MentorRepository mentorRepository; - private final TeacherRepository teacherRepository; - - public ShellCommands(StudentRepository studentRepository, MentorRepository mentorRepository, TeacherRepository teacherRepository) { - this.studentRepository = studentRepository; - this.mentorRepository = mentorRepository; - this.teacherRepository = teacherRepository; - } - - - @ShellMethod(value = "Show all students", key = "find-all-students") - public String findAllStudents(){ - System.out.println(); - return OFFSET + studentRepository.findAll().stream().map(Student::toString).collect(Collectors.joining("\n")); - } - - @ShellMethod(value = "Show all mentors", key = "find-all-mentors") - public String findAllMentors(){ - System.out.println(); - return OFFSET + mentorRepository.findAll().stream().map(Mentor::toString).collect(Collectors.joining("\n")); - } - - @ShellMethod(value = "Show all teachers", key = "find-all-teachers") - public String findAllTeachers(){ - System.out.println(); - return OFFSET + teacherRepository.findAll().stream().map(Teacher::toString).collect(Collectors.joining("\n")); - } -} diff --git a/examples/hibernate-fetch-mode-demo/src/main/resources/application.yml b/examples/hibernate-fetch-mode-demo/src/main/resources/application.yml deleted file mode 100644 index d9f3dc49..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/resources/application.yml +++ /dev/null @@ -1,15 +0,0 @@ -spring: - datasource: - url: jdbc:h2:mem:testdb - initialization-mode: always - - jpa: - generate-ddl: false - hibernate: - ddl-auto: none - - show-sql: true - properties: - hibernate: - #format_sql: true - diff --git a/examples/hibernate-fetch-mode-demo/src/main/resources/data.sql b/examples/hibernate-fetch-mode-demo/src/main/resources/data.sql deleted file mode 100644 index d6cdac2d..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/resources/data.sql +++ /dev/null @@ -1,9 +0,0 @@ -INSERT INTO knowledge (name) VALUES ('Spring Core'), ('Spring Data'), ('Spring MVC'), ('Spring Batch'), ('Spring Integration'), ('Spring WebFlux'); - -INSERT INTO students (name) VALUES ('Student #01'), ('Student #02'), ('Student #03'), ('Student #04'), ('Student #05'), ('Student #06'), ('Student #07'), ('Student #08'), ('Student #09'); -INSERT INTO mentors (name) VALUES ('Mentor #01'), ('Mentor #02'), ('Mentor #03'), ('Mentor #04'), ('Mentor #05'), ('Mentor #06'), ('Mentor #07'), ('Mentor #08'), ('Mentor #09'); -INSERT INTO teachers (name) VALUES ('Teacher #01'), ('Teacher #02'), ('Teacher #03'), ('Teacher #04'), ('Teacher #05'), ('Teacher #06'), ('Teacher #07'), ('Teacher #08'), ('Teacher #09'); - -INSERT INTO students_experience (student_id, knowledge_id) VALUES (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (2, 5); -INSERT INTO mentors_experience (mentor_id, knowledge_id) VALUES (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6); -INSERT INTO teachers_experience (teacher_id, knowledge_id) VALUES(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6); \ No newline at end of file diff --git a/examples/hibernate-fetch-mode-demo/src/main/resources/schema.sql b/examples/hibernate-fetch-mode-demo/src/main/resources/schema.sql deleted file mode 100644 index 0b366451..00000000 --- a/examples/hibernate-fetch-mode-demo/src/main/resources/schema.sql +++ /dev/null @@ -1,48 +0,0 @@ -DROP TABLE IF EXISTS students_experience; -DROP TABLE IF EXISTS mentors_experience; -DROP TABLE IF EXISTS teachers_experience; -DROP TABLE IF EXISTS students; -DROP TABLE IF EXISTS mentors; -DROP TABLE IF EXISTS teachers; -DROP TABLE IF EXISTS knowledge; - -CREATE TABLE knowledge ( - id BIGINT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) -); - -CREATE TABLE students ( - id BIGINT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) -); - -CREATE TABLE mentors ( - id BIGINT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) -); - -CREATE TABLE teachers ( - id BIGINT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) -); - -CREATE TABLE students_experience ( - student_id BIGINT, - knowledge_id BIGINT, - FOREIGN KEY(student_id) REFERENCES students(id) ON DELETE CASCADE, - FOREIGN KEY(knowledge_id) REFERENCES knowledge(id) ON DELETE CASCADE -); - -CREATE TABLE mentors_experience ( - mentor_id BIGINT, - knowledge_id BIGINT, - FOREIGN KEY(mentor_id) REFERENCES mentors(id) ON DELETE CASCADE, - FOREIGN KEY(knowledge_id) REFERENCES knowledge(id) ON DELETE CASCADE -); - -CREATE TABLE teachers_experience ( - teacher_id BIGINT, - knowledge_id BIGINT, - FOREIGN KEY(teacher_id) REFERENCES teachers(id) ON DELETE CASCADE, - FOREIGN KEY(knowledge_id) REFERENCES knowledge(id) ON DELETE CASCADE -); \ No newline at end of file diff --git a/examples/keycloak-example/docker-compose.yml b/examples/keycloak-example/docker-compose.yml deleted file mode 100644 index 9505b43a..00000000 --- a/examples/keycloak-example/docker-compose.yml +++ /dev/null @@ -1,21 +0,0 @@ -version: "3" -services: - keycloak-container: - image: quay.io/keycloak/keycloak:11.0.0 - - command: - - -Djboss.socket.binding.port-offset=2 - - restart: always - - environment: - KEYCLOAK_USER: admin - KEYCLOAK_PASSWORD: admin - KEYCLOAK_IMPORT: /tmp/realm.json - - ports: - - 8082:8082 - - volumes: - - ./realm.json:/tmp/realm.json diff --git a/examples/keycloak-example/realm.json b/examples/keycloak-example/realm.json deleted file mode 100644 index 625251bd..00000000 --- a/examples/keycloak-example/realm.json +++ /dev/null @@ -1,1692 +0,0 @@ -{ - "id" : "KCExample", - "realm" : "KCExample", - "notBefore" : 0, - "revokeRefreshToken" : false, - "refreshTokenMaxReuse" : 0, - "accessTokenLifespan" : 300, - "accessTokenLifespanForImplicitFlow" : 900, - "ssoSessionIdleTimeout" : 1800, - "ssoSessionMaxLifespan" : 36000, - "ssoSessionIdleTimeoutRememberMe" : 0, - "ssoSessionMaxLifespanRememberMe" : 0, - "offlineSessionIdleTimeout" : 2592000, - "offlineSessionMaxLifespanEnabled" : false, - "offlineSessionMaxLifespan" : 5184000, - "clientSessionIdleTimeout" : 0, - "clientSessionMaxLifespan" : 0, - "clientOfflineSessionIdleTimeout" : 0, - "clientOfflineSessionMaxLifespan" : 0, - "accessCodeLifespan" : 60, - "accessCodeLifespanUserAction" : 300, - "accessCodeLifespanLogin" : 1800, - "actionTokenGeneratedByAdminLifespan" : 43200, - "actionTokenGeneratedByUserLifespan" : 300, - "enabled" : true, - "sslRequired" : "external", - "registrationAllowed" : false, - "registrationEmailAsUsername" : false, - "rememberMe" : false, - "verifyEmail" : false, - "loginWithEmailAllowed" : true, - "duplicateEmailsAllowed" : false, - "resetPasswordAllowed" : false, - "editUsernameAllowed" : false, - "bruteForceProtected" : false, - "permanentLockout" : false, - "maxFailureWaitSeconds" : 900, - "minimumQuickLoginWaitSeconds" : 60, - "waitIncrementSeconds" : 60, - "quickLoginCheckMilliSeconds" : 1000, - "maxDeltaTimeSeconds" : 43200, - "failureFactor" : 30, - "roles" : { - "realm" : [ { - "id" : "dc431c2f-2ff1-453f-8f77-8b375552f8aa", - "name" : "user", - "composite" : false, - "clientRole" : false, - "containerId" : "KCExample", - "attributes" : { } - }, { - "id" : "90579424-f687-4e47-bd7d-ce1ae4ea3257", - "name" : "uma_authorization", - "description" : "${role_uma_authorization}", - "composite" : false, - "clientRole" : false, - "containerId" : "KCExample", - "attributes" : { } - }, { - "id" : "247d2ebb-bf4c-4b59-ad79-604fdf72a8c0", - "name" : "offline_access", - "description" : "${role_offline-access}", - "composite" : false, - "clientRole" : false, - "containerId" : "KCExample", - "attributes" : { } - } ], - "client" : { - "realm-management" : [ { - "id" : "04d457b1-285a-47b5-a117-82603c852899", - "name" : "create-client", - "description" : "${role_create-client}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "0b7c28b2-49a9-40a2-ba7a-87b5b0ebfb6e", - "name" : "manage-clients", - "description" : "${role_manage-clients}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "b5291577-1052-4616-94de-e5ad768bc0b5", - "name" : "query-groups", - "description" : "${role_query-groups}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "62fe4970-3c8a-4037-a939-918821062df7", - "name" : "view-users", - "description" : "${role_view-users}", - "composite" : true, - "composites" : { - "client" : { - "realm-management" : [ "query-groups", "query-users" ] - } - }, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "642cd9b0-5eaf-413f-b5d8-5795023b3cb5", - "name" : "view-identity-providers", - "description" : "${role_view-identity-providers}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "b477f7dd-29be-412b-962a-b2932f7d72f8", - "name" : "realm-admin", - "description" : "${role_realm-admin}", - "composite" : true, - "composites" : { - "client" : { - "realm-management" : [ "create-client", "manage-clients", "query-groups", "view-users", "view-identity-providers", "manage-users", "manage-identity-providers", "view-clients", "view-realm", "view-events", "impersonation", "view-authorization", "query-users", "query-clients", "manage-events", "manage-authorization", "query-realms", "manage-realm" ] - } - }, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "59fb9863-1795-43eb-85a1-5b3b0d2f6133", - "name" : "manage-users", - "description" : "${role_manage-users}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "38ea0fa9-184c-403d-8e21-59c668315e09", - "name" : "view-clients", - "description" : "${role_view-clients}", - "composite" : true, - "composites" : { - "client" : { - "realm-management" : [ "query-clients" ] - } - }, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "11916f78-81c5-40c2-9f3b-778cf93c8ef7", - "name" : "manage-identity-providers", - "description" : "${role_manage-identity-providers}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "60b36880-6f90-4446-b880-4f0be7a10942", - "name" : "view-realm", - "description" : "${role_view-realm}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "8c3dfe0c-1c45-47ef-a530-84b943649ea6", - "name" : "view-events", - "description" : "${role_view-events}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "7f9fe27c-4b31-4ec2-ba12-d1c9e6a8751a", - "name" : "impersonation", - "description" : "${role_impersonation}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "4a219fa4-8d8c-4fe4-82a2-0a956db02f18", - "name" : "view-authorization", - "description" : "${role_view-authorization}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "100102c6-f673-4769-98ab-8a723ab730a6", - "name" : "query-users", - "description" : "${role_query-users}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "fbfdb2ab-bdb8-4f92-908a-245a3d9c74af", - "name" : "query-clients", - "description" : "${role_query-clients}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "64940b10-d875-4e7d-a9f8-cec1d953b4d8", - "name" : "manage-events", - "description" : "${role_manage-events}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "0b238a2a-4ed0-4d5e-8d56-af41bca5029d", - "name" : "manage-authorization", - "description" : "${role_manage-authorization}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "5248baa5-0043-44f8-9dbc-fe2e4d993ff9", - "name" : "query-realms", - "description" : "${role_query-realms}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - }, { - "id" : "c70404e9-1a03-4cc4-937c-4486b2ff9a58", - "name" : "manage-realm", - "description" : "${role_manage-realm}", - "composite" : false, - "clientRole" : true, - "containerId" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "attributes" : { } - } ], - "resource-app" : [ ], - "security-admin-console" : [ ], - "admin-cli" : [ ], - "account-console" : [ ], - "broker" : [ { - "id" : "33d04ec1-c850-42be-b3a2-b47b0c4eaa02", - "name" : "read-token", - "description" : "${role_read-token}", - "composite" : false, - "clientRole" : true, - "containerId" : "2e02a9cf-6856-4e30-88cf-dada0c3a3ca6", - "attributes" : { } - } ], - "account" : [ { - "id" : "01c1cde3-229a-480e-b75b-e5e588d4e0ca", - "name" : "manage-account", - "description" : "${role_manage-account}", - "composite" : true, - "composites" : { - "client" : { - "account" : [ "manage-account-links" ] - } - }, - "clientRole" : true, - "containerId" : "e45dba14-f168-4710-a71d-3ab3097d621b", - "attributes" : { } - }, { - "id" : "a76cb432-93ae-482d-a4f4-c19efce9ce0d", - "name" : "manage-account-links", - "description" : "${role_manage-account-links}", - "composite" : false, - "clientRole" : true, - "containerId" : "e45dba14-f168-4710-a71d-3ab3097d621b", - "attributes" : { } - }, { - "id" : "bfeec309-6ec9-4470-a404-aaad72e5a50c", - "name" : "view-profile", - "description" : "${role_view-profile}", - "composite" : false, - "clientRole" : true, - "containerId" : "e45dba14-f168-4710-a71d-3ab3097d621b", - "attributes" : { } - }, { - "id" : "43280d4b-4cfc-4326-983b-86e894f03b1c", - "name" : "manage-consent", - "description" : "${role_manage-consent}", - "composite" : true, - "composites" : { - "client" : { - "account" : [ "view-consent" ] - } - }, - "clientRole" : true, - "containerId" : "e45dba14-f168-4710-a71d-3ab3097d621b", - "attributes" : { } - }, { - "id" : "adc0fb95-8570-4d8e-926c-f54ab8c8b2a3", - "name" : "view-consent", - "description" : "${role_view-consent}", - "composite" : false, - "clientRole" : true, - "containerId" : "e45dba14-f168-4710-a71d-3ab3097d621b", - "attributes" : { } - }, { - "id" : "7cbe85fb-ef71-4d04-b288-559cf50012c8", - "name" : "view-applications", - "description" : "${role_view-applications}", - "composite" : false, - "clientRole" : true, - "containerId" : "e45dba14-f168-4710-a71d-3ab3097d621b", - "attributes" : { } - } ] - } - }, - "groups" : [ ], - "defaultRoles" : [ "offline_access", "uma_authorization" ], - "requiredCredentials" : [ "password" ], - "otpPolicyType" : "totp", - "otpPolicyAlgorithm" : "HmacSHA1", - "otpPolicyInitialCounter" : 0, - "otpPolicyDigits" : 6, - "otpPolicyLookAheadWindow" : 1, - "otpPolicyPeriod" : 30, - "otpSupportedApplications" : [ "FreeOTP", "Google Authenticator" ], - "webAuthnPolicyRpEntityName" : "keycloak", - "webAuthnPolicySignatureAlgorithms" : [ "ES256" ], - "webAuthnPolicyRpId" : "", - "webAuthnPolicyAttestationConveyancePreference" : "not specified", - "webAuthnPolicyAuthenticatorAttachment" : "not specified", - "webAuthnPolicyRequireResidentKey" : "not specified", - "webAuthnPolicyUserVerificationRequirement" : "not specified", - "webAuthnPolicyCreateTimeout" : 0, - "webAuthnPolicyAvoidSameAuthenticatorRegister" : false, - "webAuthnPolicyAcceptableAaguids" : [ ], - "webAuthnPolicyPasswordlessRpEntityName" : "keycloak", - "webAuthnPolicyPasswordlessSignatureAlgorithms" : [ "ES256" ], - "webAuthnPolicyPasswordlessRpId" : "", - "webAuthnPolicyPasswordlessAttestationConveyancePreference" : "not specified", - "webAuthnPolicyPasswordlessAuthenticatorAttachment" : "not specified", - "webAuthnPolicyPasswordlessRequireResidentKey" : "not specified", - "webAuthnPolicyPasswordlessUserVerificationRequirement" : "not specified", - "webAuthnPolicyPasswordlessCreateTimeout" : 0, - "webAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister" : false, - "webAuthnPolicyPasswordlessAcceptableAaguids" : [ ], - "users" : [ { - "id" : "4fdbd7bb-9899-43bd-8c66-611efc5562c8", - "createdTimestamp" : 1597775215644, - "username" : "user", - "enabled" : true, - "totp" : false, - "emailVerified" : false, - "credentials" : [ { - "id" : "2b6b083b-4fb8-4b65-8dd3-b904b9af3376", - "type" : "password", - "createdDate" : 1597775229838, - "secretData" : "{\"value\":\"oTlEJ/Apanqv2TLqvx7iGnewAWICgcO7dTyvXCTi1Pz39LhdsysXx2gHsdD/a3yp/NxZvlNAWsi/q9CPKPC94w==\",\"salt\":\"Ztv01bri1iuicpob2BnE/w==\"}", - "credentialData" : "{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\"}" - } ], - "disableableCredentialTypes" : [ ], - "requiredActions" : [ ], - "realmRoles" : [ "user", "uma_authorization", "offline_access" ], - "clientRoles" : { - "account" : [ "manage-account", "view-profile" ] - }, - "notBefore" : 0, - "groups" : [ ] - } ], - "scopeMappings" : [ { - "clientScope" : "offline_access", - "roles" : [ "offline_access" ] - } ], - "clientScopeMappings" : { - "account" : [ { - "client" : "account-console", - "roles" : [ "manage-account" ] - } ] - }, - "clients" : [ { - "id" : "e45dba14-f168-4710-a71d-3ab3097d621b", - "clientId" : "account", - "name" : "${client_account}", - "rootUrl" : "${authBaseUrl}", - "baseUrl" : "/realms/KCExample/account/", - "surrogateAuthRequired" : false, - "enabled" : true, - "alwaysDisplayInConsole" : false, - "clientAuthenticatorType" : "client-secret", - "secret" : "5f5174ef-70e3-4f67-99de-b13c758c6199", - "defaultRoles" : [ "manage-account", "view-profile" ], - "redirectUris" : [ "/realms/KCExample/account/*" ], - "webOrigins" : [ ], - "notBefore" : 0, - "bearerOnly" : false, - "consentRequired" : false, - "standardFlowEnabled" : true, - "implicitFlowEnabled" : false, - "directAccessGrantsEnabled" : false, - "serviceAccountsEnabled" : false, - "publicClient" : false, - "frontchannelLogout" : false, - "protocol" : "openid-connect", - "attributes" : { }, - "authenticationFlowBindingOverrides" : { }, - "fullScopeAllowed" : false, - "nodeReRegistrationTimeout" : 0, - "defaultClientScopes" : [ "web-origins", "role_list", "profile", "roles", "email" ], - "optionalClientScopes" : [ "address", "phone", "offline_access", "microprofile-jwt" ] - }, { - "id" : "89156bcf-86e2-4153-beab-c8688f10084e", - "clientId" : "account-console", - "name" : "${client_account-console}", - "rootUrl" : "${authBaseUrl}", - "baseUrl" : "/realms/KCExample/account/", - "surrogateAuthRequired" : false, - "enabled" : true, - "alwaysDisplayInConsole" : false, - "clientAuthenticatorType" : "client-secret", - "secret" : "d612a775-3fec-43e1-9f20-975444ecc9d2", - "redirectUris" : [ "/realms/KCExample/account/*" ], - "webOrigins" : [ ], - "notBefore" : 0, - "bearerOnly" : false, - "consentRequired" : false, - "standardFlowEnabled" : true, - "implicitFlowEnabled" : false, - "directAccessGrantsEnabled" : false, - "serviceAccountsEnabled" : false, - "publicClient" : true, - "frontchannelLogout" : false, - "protocol" : "openid-connect", - "attributes" : { - "pkce.code.challenge.method" : "S256" - }, - "authenticationFlowBindingOverrides" : { }, - "fullScopeAllowed" : false, - "nodeReRegistrationTimeout" : 0, - "protocolMappers" : [ { - "id" : "4eb74ba0-3bf4-4f21-a31f-2db09c1031c0", - "name" : "audience resolve", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-audience-resolve-mapper", - "consentRequired" : false, - "config" : { } - } ], - "defaultClientScopes" : [ "web-origins", "role_list", "profile", "roles", "email" ], - "optionalClientScopes" : [ "address", "phone", "offline_access", "microprofile-jwt" ] - }, { - "id" : "84c9ccf4-e524-4156-8397-d2dfc45094f2", - "clientId" : "admin-cli", - "name" : "${client_admin-cli}", - "surrogateAuthRequired" : false, - "enabled" : true, - "alwaysDisplayInConsole" : false, - "clientAuthenticatorType" : "client-secret", - "secret" : "23c7b85b-5505-4c63-8da5-ac6eb09e542f", - "redirectUris" : [ ], - "webOrigins" : [ ], - "notBefore" : 0, - "bearerOnly" : false, - "consentRequired" : false, - "standardFlowEnabled" : false, - "implicitFlowEnabled" : false, - "directAccessGrantsEnabled" : true, - "serviceAccountsEnabled" : false, - "publicClient" : true, - "frontchannelLogout" : false, - "protocol" : "openid-connect", - "attributes" : { }, - "authenticationFlowBindingOverrides" : { }, - "fullScopeAllowed" : false, - "nodeReRegistrationTimeout" : 0, - "defaultClientScopes" : [ "web-origins", "role_list", "profile", "roles", "email" ], - "optionalClientScopes" : [ "address", "phone", "offline_access", "microprofile-jwt" ] - }, { - "id" : "2e02a9cf-6856-4e30-88cf-dada0c3a3ca6", - "clientId" : "broker", - "name" : "${client_broker}", - "surrogateAuthRequired" : false, - "enabled" : true, - "alwaysDisplayInConsole" : false, - "clientAuthenticatorType" : "client-secret", - "secret" : "2e5b3528-9e3d-4ada-9e2e-d784110f4d2e", - "redirectUris" : [ ], - "webOrigins" : [ ], - "notBefore" : 0, - "bearerOnly" : false, - "consentRequired" : false, - "standardFlowEnabled" : true, - "implicitFlowEnabled" : false, - "directAccessGrantsEnabled" : false, - "serviceAccountsEnabled" : false, - "publicClient" : false, - "frontchannelLogout" : false, - "protocol" : "openid-connect", - "attributes" : { }, - "authenticationFlowBindingOverrides" : { }, - "fullScopeAllowed" : false, - "nodeReRegistrationTimeout" : 0, - "defaultClientScopes" : [ "web-origins", "role_list", "profile", "roles", "email" ], - "optionalClientScopes" : [ "address", "phone", "offline_access", "microprofile-jwt" ] - }, { - "id" : "b07799b6-1af2-4250-84b9-1d01b965ff37", - "clientId" : "realm-management", - "name" : "${client_realm-management}", - "surrogateAuthRequired" : false, - "enabled" : true, - "alwaysDisplayInConsole" : false, - "clientAuthenticatorType" : "client-secret", - "secret" : "6013cf10-5cd5-4806-8be3-8fd31b0da0bd", - "redirectUris" : [ ], - "webOrigins" : [ ], - "notBefore" : 0, - "bearerOnly" : true, - "consentRequired" : false, - "standardFlowEnabled" : true, - "implicitFlowEnabled" : false, - "directAccessGrantsEnabled" : false, - "serviceAccountsEnabled" : false, - "publicClient" : false, - "frontchannelLogout" : false, - "protocol" : "openid-connect", - "attributes" : { }, - "authenticationFlowBindingOverrides" : { }, - "fullScopeAllowed" : false, - "nodeReRegistrationTimeout" : 0, - "defaultClientScopes" : [ "web-origins", "role_list", "profile", "roles", "email" ], - "optionalClientScopes" : [ "address", "phone", "offline_access", "microprofile-jwt" ] - }, { - "id" : "2d6c11c7-cca3-4c6a-8f6b-a02b1a75d85c", - "clientId" : "resource-app", - "surrogateAuthRequired" : false, - "enabled" : true, - "alwaysDisplayInConsole" : false, - "clientAuthenticatorType" : "client-secret", - "secret" : "0cd95dfa-71f4-4e72-beb5-7d69d0ae628f", - "redirectUris" : [ "http://localhost:8080/*" ], - "webOrigins" : [ ], - "notBefore" : 0, - "bearerOnly" : false, - "consentRequired" : false, - "standardFlowEnabled" : true, - "implicitFlowEnabled" : false, - "directAccessGrantsEnabled" : true, - "serviceAccountsEnabled" : false, - "publicClient" : true, - "frontchannelLogout" : false, - "protocol" : "openid-connect", - "attributes" : { - "saml.assertion.signature" : "false", - "saml.force.post.binding" : "false", - "saml.multivalued.roles" : "false", - "saml.encrypt" : "false", - "saml.server.signature" : "false", - "saml.server.signature.keyinfo.ext" : "false", - "exclude.session.state.from.auth.response" : "false", - "saml_force_name_id_format" : "false", - "saml.client.signature" : "false", - "tls.client.certificate.bound.access.tokens" : "false", - "saml.authnstatement" : "false", - "display.on.consent.screen" : "false", - "saml.onetimeuse.condition" : "false" - }, - "authenticationFlowBindingOverrides" : { }, - "fullScopeAllowed" : true, - "nodeReRegistrationTimeout" : -1, - "defaultClientScopes" : [ "web-origins", "role_list", "profile", "roles", "email" ], - "optionalClientScopes" : [ "address", "phone", "offline_access", "microprofile-jwt" ] - }, { - "id" : "3f0a2630-2356-4d18-a279-7ff9e9d2158e", - "clientId" : "security-admin-console", - "name" : "${client_security-admin-console}", - "rootUrl" : "${authAdminUrl}", - "baseUrl" : "/admin/KCExample/console/", - "surrogateAuthRequired" : false, - "enabled" : true, - "alwaysDisplayInConsole" : false, - "clientAuthenticatorType" : "client-secret", - "secret" : "a6608280-5182-4c80-9b28-4b1cb05caa77", - "redirectUris" : [ "/admin/KCExample/console/*" ], - "webOrigins" : [ "+" ], - "notBefore" : 0, - "bearerOnly" : false, - "consentRequired" : false, - "standardFlowEnabled" : true, - "implicitFlowEnabled" : false, - "directAccessGrantsEnabled" : false, - "serviceAccountsEnabled" : false, - "publicClient" : true, - "frontchannelLogout" : false, - "protocol" : "openid-connect", - "attributes" : { - "pkce.code.challenge.method" : "S256" - }, - "authenticationFlowBindingOverrides" : { }, - "fullScopeAllowed" : false, - "nodeReRegistrationTimeout" : 0, - "protocolMappers" : [ { - "id" : "1b258cdf-4d76-4f7d-bbdd-4e074b99fc7d", - "name" : "locale", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "locale", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "locale", - "jsonType.label" : "String" - } - } ], - "defaultClientScopes" : [ "web-origins", "role_list", "profile", "roles", "email" ], - "optionalClientScopes" : [ "address", "phone", "offline_access", "microprofile-jwt" ] - } ], - "clientScopes" : [ { - "id" : "945e9419-a2ab-4ee5-bb61-830bf356255f", - "name" : "address", - "description" : "OpenID Connect built-in scope: address", - "protocol" : "openid-connect", - "attributes" : { - "include.in.token.scope" : "true", - "display.on.consent.screen" : "true", - "consent.screen.text" : "${addressScopeConsentText}" - }, - "protocolMappers" : [ { - "id" : "f5100b8d-8533-4a3a-838a-eedd22597a17", - "name" : "address", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-address-mapper", - "consentRequired" : false, - "config" : { - "user.attribute.formatted" : "formatted", - "user.attribute.country" : "country", - "user.attribute.postal_code" : "postal_code", - "userinfo.token.claim" : "true", - "user.attribute.street" : "street", - "id.token.claim" : "true", - "user.attribute.region" : "region", - "access.token.claim" : "true", - "user.attribute.locality" : "locality" - } - } ] - }, { - "id" : "874895f7-1d55-4d3a-be38-36d212365ca2", - "name" : "email", - "description" : "OpenID Connect built-in scope: email", - "protocol" : "openid-connect", - "attributes" : { - "include.in.token.scope" : "true", - "display.on.consent.screen" : "true", - "consent.screen.text" : "${emailScopeConsentText}" - }, - "protocolMappers" : [ { - "id" : "7a425203-06ca-49a8-a566-7f553365dba2", - "name" : "email", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-property-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "email", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "email", - "jsonType.label" : "String" - } - }, { - "id" : "c5bb2c35-5dd3-4ef0-830c-2bba5a46d7ff", - "name" : "email verified", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-property-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "emailVerified", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "email_verified", - "jsonType.label" : "boolean" - } - } ] - }, { - "id" : "58971c82-d63b-44c9-a2d6-53a0bb62a0ec", - "name" : "microprofile-jwt", - "description" : "Microprofile - JWT built-in scope", - "protocol" : "openid-connect", - "attributes" : { - "include.in.token.scope" : "true", - "display.on.consent.screen" : "false" - }, - "protocolMappers" : [ { - "id" : "541902b2-3f06-4fa9-b2ca-0c12c6ea5b18", - "name" : "upn", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-property-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "username", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "upn", - "jsonType.label" : "String" - } - }, { - "id" : "c8c6881e-e208-4530-9f44-432995c8f5a3", - "name" : "groups", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-realm-role-mapper", - "consentRequired" : false, - "config" : { - "multivalued" : "true", - "user.attribute" : "foo", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "groups", - "jsonType.label" : "String" - } - } ] - }, { - "id" : "15f527b5-0273-4826-a501-785c6d5a2d14", - "name" : "offline_access", - "description" : "OpenID Connect built-in scope: offline_access", - "protocol" : "openid-connect", - "attributes" : { - "consent.screen.text" : "${offlineAccessScopeConsentText}", - "display.on.consent.screen" : "true" - } - }, { - "id" : "f52e19e8-73da-460d-b987-26503519c3e7", - "name" : "phone", - "description" : "OpenID Connect built-in scope: phone", - "protocol" : "openid-connect", - "attributes" : { - "include.in.token.scope" : "true", - "display.on.consent.screen" : "true", - "consent.screen.text" : "${phoneScopeConsentText}" - }, - "protocolMappers" : [ { - "id" : "5158c1b1-b655-4c32-9a59-94b79a2b69f8", - "name" : "phone number", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "phoneNumber", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "phone_number", - "jsonType.label" : "String" - } - }, { - "id" : "1508019a-dd2b-442c-adf4-786360437c5c", - "name" : "phone number verified", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "phoneNumberVerified", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "phone_number_verified", - "jsonType.label" : "boolean" - } - } ] - }, { - "id" : "097c4ff4-76ed-4acb-9aae-b967c6c37862", - "name" : "profile", - "description" : "OpenID Connect built-in scope: profile", - "protocol" : "openid-connect", - "attributes" : { - "include.in.token.scope" : "true", - "display.on.consent.screen" : "true", - "consent.screen.text" : "${profileScopeConsentText}" - }, - "protocolMappers" : [ { - "id" : "e25b30f8-b925-4630-9902-537e8f6bed7d", - "name" : "updated at", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "updatedAt", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "updated_at", - "jsonType.label" : "String" - } - }, { - "id" : "9646891f-a605-405a-b266-4ea8b2811baa", - "name" : "website", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "website", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "website", - "jsonType.label" : "String" - } - }, { - "id" : "70cc3e36-ee1c-45ea-b77a-8d58be37c8ce", - "name" : "nickname", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "nickname", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "nickname", - "jsonType.label" : "String" - } - }, { - "id" : "7fda7133-2676-4d80-bc11-f7d3ee3293e1", - "name" : "locale", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "locale", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "locale", - "jsonType.label" : "String" - } - }, { - "id" : "7a509dfa-bcdd-49bf-ad4c-770d1bd82eba", - "name" : "family name", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-property-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "lastName", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "family_name", - "jsonType.label" : "String" - } - }, { - "id" : "88df15f0-7f95-41c2-bb3c-2d6ac0f11182", - "name" : "username", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-property-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "username", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "preferred_username", - "jsonType.label" : "String" - } - }, { - "id" : "28c32597-30fe-4510-8f28-7d85c8be4d3f", - "name" : "gender", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "gender", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "gender", - "jsonType.label" : "String" - } - }, { - "id" : "637379c0-0937-42df-8f24-642b83339d20", - "name" : "picture", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "picture", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "picture", - "jsonType.label" : "String" - } - }, { - "id" : "645ebb06-0bb6-493a-b96f-5ae45a346157", - "name" : "birthdate", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "birthdate", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "birthdate", - "jsonType.label" : "String" - } - }, { - "id" : "d0715878-42f6-4e47-b665-c3a62f1cb889", - "name" : "profile", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "profile", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "profile", - "jsonType.label" : "String" - } - }, { - "id" : "ed8fe48f-06c1-45a2-bf83-e8a297b5b200", - "name" : "given name", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-property-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "firstName", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "given_name", - "jsonType.label" : "String" - } - }, { - "id" : "9593fe2d-6c0d-4b13-8c72-d7078875d097", - "name" : "full name", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-full-name-mapper", - "consentRequired" : false, - "config" : { - "id.token.claim" : "true", - "access.token.claim" : "true", - "userinfo.token.claim" : "true" - } - }, { - "id" : "2ad79d8e-297f-4260-8591-95fb53b2ae0c", - "name" : "middle name", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "middleName", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "middle_name", - "jsonType.label" : "String" - } - }, { - "id" : "5ab24791-1d01-45dc-a421-aa86cd2424a7", - "name" : "zoneinfo", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-attribute-mapper", - "consentRequired" : false, - "config" : { - "userinfo.token.claim" : "true", - "user.attribute" : "zoneinfo", - "id.token.claim" : "true", - "access.token.claim" : "true", - "claim.name" : "zoneinfo", - "jsonType.label" : "String" - } - } ] - }, { - "id" : "f813f7b5-849b-4108-9dd2-6005e462ce43", - "name" : "role_list", - "description" : "SAML role list", - "protocol" : "saml", - "attributes" : { - "consent.screen.text" : "${samlRoleListScopeConsentText}", - "display.on.consent.screen" : "true" - }, - "protocolMappers" : [ { - "id" : "6aaf363b-b068-4add-ad36-70c2f55f8e45", - "name" : "role list", - "protocol" : "saml", - "protocolMapper" : "saml-role-list-mapper", - "consentRequired" : false, - "config" : { - "single" : "false", - "attribute.nameformat" : "Basic", - "attribute.name" : "Role" - } - } ] - }, { - "id" : "d486248b-7c68-444a-9623-af2a9059fda3", - "name" : "roles", - "description" : "OpenID Connect scope for add user roles to the access token", - "protocol" : "openid-connect", - "attributes" : { - "include.in.token.scope" : "false", - "display.on.consent.screen" : "true", - "consent.screen.text" : "${rolesScopeConsentText}" - }, - "protocolMappers" : [ { - "id" : "2b1cf97e-832e-499c-befa-55914aa9982c", - "name" : "client roles", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-client-role-mapper", - "consentRequired" : false, - "config" : { - "user.attribute" : "foo", - "access.token.claim" : "true", - "claim.name" : "resource_access.${client_id}.roles", - "jsonType.label" : "String", - "multivalued" : "true" - } - }, { - "id" : "cb823520-7944-485a-aa5e-499153f0c4d1", - "name" : "audience resolve", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-audience-resolve-mapper", - "consentRequired" : false, - "config" : { } - }, { - "id" : "6ca65b32-0960-4590-b621-29434e0b36e9", - "name" : "realm roles", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-usermodel-realm-role-mapper", - "consentRequired" : false, - "config" : { - "user.attribute" : "foo", - "access.token.claim" : "true", - "claim.name" : "realm_access.roles", - "jsonType.label" : "String", - "multivalued" : "true" - } - } ] - }, { - "id" : "73caf3fc-87b0-4d36-b6ea-e1d31b7abf33", - "name" : "web-origins", - "description" : "OpenID Connect scope for add allowed web origins to the access token", - "protocol" : "openid-connect", - "attributes" : { - "include.in.token.scope" : "false", - "display.on.consent.screen" : "false", - "consent.screen.text" : "" - }, - "protocolMappers" : [ { - "id" : "e46e624a-8524-4304-b00b-ab96b0862dd0", - "name" : "allowed web origins", - "protocol" : "openid-connect", - "protocolMapper" : "oidc-allowed-origins-mapper", - "consentRequired" : false, - "config" : { } - } ] - } ], - "defaultDefaultClientScopes" : [ "role_list", "profile", "email", "roles", "web-origins" ], - "defaultOptionalClientScopes" : [ "offline_access", "address", "phone", "microprofile-jwt" ], - "browserSecurityHeaders" : { - "contentSecurityPolicyReportOnly" : "", - "xContentTypeOptions" : "nosniff", - "xRobotsTag" : "none", - "xFrameOptions" : "SAMEORIGIN", - "contentSecurityPolicy" : "frame-src 'self'; frame-ancestors 'self'; object-src 'none';", - "xXSSProtection" : "1; mode=block", - "strictTransportSecurity" : "max-age=31536000; includeSubDomains" - }, - "smtpServer" : { }, - "eventsEnabled" : false, - "eventsListeners" : [ "jboss-logging" ], - "enabledEventTypes" : [ ], - "adminEventsEnabled" : false, - "adminEventsDetailsEnabled" : false, - "components" : { - "org.keycloak.services.clientregistration.policy.ClientRegistrationPolicy" : [ { - "id" : "ec2ac426-940b-4af6-a3f3-bd1f77e21ec1", - "name" : "Max Clients Limit", - "providerId" : "max-clients", - "subType" : "anonymous", - "subComponents" : { }, - "config" : { - "max-clients" : [ "200" ] - } - }, { - "id" : "e5949af8-9f97-41ea-bf2d-832ff6c94ef3", - "name" : "Allowed Protocol Mapper Types", - "providerId" : "allowed-protocol-mappers", - "subType" : "authenticated", - "subComponents" : { }, - "config" : { - "allowed-protocol-mapper-types" : [ "oidc-usermodel-attribute-mapper", "oidc-sha256-pairwise-sub-mapper", "oidc-full-name-mapper", "oidc-usermodel-property-mapper", "saml-user-property-mapper", "saml-user-attribute-mapper", "saml-role-list-mapper", "oidc-address-mapper" ] - } - }, { - "id" : "e57f1213-9e0c-4f7a-bd98-dfb25c4a9613", - "name" : "Consent Required", - "providerId" : "consent-required", - "subType" : "anonymous", - "subComponents" : { }, - "config" : { } - }, { - "id" : "779333b3-18fe-4cad-8bcc-2f4d98b727ba", - "name" : "Allowed Client Scopes", - "providerId" : "allowed-client-templates", - "subType" : "anonymous", - "subComponents" : { }, - "config" : { - "allow-default-scopes" : [ "true" ] - } - }, { - "id" : "083a188a-9ec8-48b2-83f6-810afffa4bed", - "name" : "Trusted Hosts", - "providerId" : "trusted-hosts", - "subType" : "anonymous", - "subComponents" : { }, - "config" : { - "host-sending-registration-request-must-match" : [ "true" ], - "client-uris-must-match" : [ "true" ] - } - }, { - "id" : "d0e390c5-4b25-44ad-9498-536eef2e1a0f", - "name" : "Allowed Client Scopes", - "providerId" : "allowed-client-templates", - "subType" : "authenticated", - "subComponents" : { }, - "config" : { - "allow-default-scopes" : [ "true" ] - } - }, { - "id" : "86ac02cb-dc12-48e4-b196-5f6973e15803", - "name" : "Allowed Protocol Mapper Types", - "providerId" : "allowed-protocol-mappers", - "subType" : "anonymous", - "subComponents" : { }, - "config" : { - "allowed-protocol-mapper-types" : [ "oidc-address-mapper", "oidc-usermodel-property-mapper", "saml-user-property-mapper", "saml-user-attribute-mapper", "oidc-sha256-pairwise-sub-mapper", "saml-role-list-mapper", "oidc-usermodel-attribute-mapper", "oidc-full-name-mapper" ] - } - }, { - "id" : "0205f3ef-680d-4b34-9857-8b10d09dab2f", - "name" : "Full Scope Disabled", - "providerId" : "scope", - "subType" : "anonymous", - "subComponents" : { }, - "config" : { } - } ], - "org.keycloak.keys.KeyProvider" : [ { - "id" : "5d16d23c-79c7-463f-9bbf-8bb5da2df6e9", - "name" : "rsa-generated", - "providerId" : "rsa-generated", - "subComponents" : { }, - "config" : { - "privateKey" : [ "MIIEpQIBAAKCAQEAou/9jwRyZEBlGvxZgAUkxJsJb7mFB+3EiIXGBnc2RNxuf2E90u0sumDVzjksJXKM+ZeaZcNvbinegyWqPU4uT3XX+eWFHpFCR60Ch4ry31/Fu8p+biKlLZX3K8MHC9H7ZKkMjKWC9gIK1p4CXLhplwxLpQb6LKvTVCxSZKPoK8jfGIHiJDCE1X4Z4uCPrl60Xg9zlhsFi/JAHtNIne8yDZSw+tEdCYoEtvOJngg8rVbiuPVjAVgKeiTwb7NEAX9xoF02J2cwla45qoGww8Ilwb+c2s01Q7KTMqTy3s1xqH0tl1BrNnhWQWWXQUWgu5VUnpfM+2WuGKxzARdudxIIoQIDAQABAoIBAGT4vjPzuIPh2AX6HeiUx21C+n0PBZ6dPO6xn77//1R7Gcq8Uxi0O8SgH771dSMbsrs1tMudah9luOui2rW1DkPVrmrBTlZcBCvwziF6/PlqG1o9qU3NEHmIdqza5jHwBY8ip5E9PEQBjf/j2WjmKyEc0H/LLBuku4htEv4lCMqgaOJI8gUTUQ0Pg5kotutdI8twDmyIRdDPO3s7xA+9LuMNXHEDRSH3vGbmTXjaD4N3xMzoFk7KvYN4OR73io9FusaIyC46gvUCq5xg4aTuhgfXPrVIvLtMcCy0apOpPNEKdqvQ1lfzwTGcJoujFYKNjQ0WNop/GRqq0C4Jbw4amAECgYEA49ycZb1TuDcYTyEicMRw9bCuJg7rRbSVvBrT30TsUGL/4Gy+VI0SRSk6uTQAQXw7jE4cg8jAJT+KV+VH2mDPOHSOQcbkpTaVt5iySrJ3/a7JifSLoy3PckMD5Vb4Fx8gapWWrQzSMQpFc1O5klJnKerzKLc50zslc+eC9Xs4NUECgYEAtw7t1gX++1mKwd7+qSjS2oDNqlxgMFZn95XlB6klFG60KIqyUkB3bkYHZw7krG8OCSPFTgq6wFVzpLe5aFYvyPGXztV4soTCymAlTSHpIoS6xJoAR6k4yfRb9z9iH957UO6uBheVNQwT1C27DBZSXqZ8fCwU/Rz6VkocvscoG2ECgYEAjopCF+7wwUtN3KpIpixs0XUd69bnXKqUBKDvqzqtbbgQgy7jfXbmV/drsdGS22RAyAtRESty75opC8T1RunKl3FqUEGAZM2ZqMlPtySfpUVC9BbTh1ev7rV3aW8XMTeairJbGJPtpRncykE01BDSUkmUpQLBnJ7iVfgcVz4mskECgYEAr4lFT8IYK/ZFNHsdQCDBcH2quf4yzqdMswGtyZbM07cEUwwMywq+e6PzXUPOy/sCPolqndd0FRLb/cufowlicRIaPGA/iQ/9qgpgOoKWCF+2qOfz9MO0jRQhTAofkefJ4GW/wl/C2EdojEH95y1Qdyq2nGu5BK5Q74XJ4rcfIoECgYEAmOlFl1ZXeXN6wACDWOmZJ3u+mbqKJ8IcWs7OFM8q1uJ2eyZwRR4VlRWEE5DX8izieH+E6xw05L1rRAvtkUOq7MZE1DYR4blyTySU27PJEHTrSmnJNGzkCYLkaikCmEwUfxmItP8l020fT69v2oCz3Cz63EUs4/UV4jnD3VzmWMg=" ], - "certificate" : [ "MIICoTCCAYkCBgF0AtGwrzANBgkqhkiG9w0BAQsFADAUMRIwEAYDVQQDDAlLQ0V4YW1wbGUwHhcNMjAwODE4MTgyMzUwWhcNMzAwODE4MTgyNTMwWjAUMRIwEAYDVQQDDAlLQ0V4YW1wbGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCi7/2PBHJkQGUa/FmABSTEmwlvuYUH7cSIhcYGdzZE3G5/YT3S7Sy6YNXOOSwlcoz5l5plw29uKd6DJao9Ti5Pddf55YUekUJHrQKHivLfX8W7yn5uIqUtlfcrwwcL0ftkqQyMpYL2AgrWngJcuGmXDEulBvosq9NULFJko+gryN8YgeIkMITVfhni4I+uXrReD3OWGwWL8kAe00id7zINlLD60R0JigS284meCDytVuK49WMBWAp6JPBvs0QBf3GgXTYnZzCVrjmqgbDDwiXBv5zazTVDspMypPLezXGofS2XUGs2eFZBZZdBRaC7lVSel8z7Za4YrHMBF253EgihAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAEHUceOFVUbK/L2ULqRK/cjAXWgpHRv22IYEXTjvK9AYdRZX8S49EFp5FCGk8bvc0CewUZcQnDRpmF5KwNu3XRUkVrPDyRBES2AhizG20lX8F7fVfXiChlE1WGPBUaUN5t+9IJhHbXSQ7TyylKWMtLdYyzXW0467gEeXzyng0mI+synh1v5H5G6F2VcTUDjIC8a/3RITrUuCWwXsGa7MMSlwWf574lrvxyp+FgfpOXtZzPeKHQc/XNPaEAngDhICFfoIw4F0/WTXmeXGXIyZqFpQImccs6rJUmhcT6aPi1XUqMYkidpbsWFkWfPCi12149y+6MBUPRKGqIHbObM5dG8=" ], - "priority" : [ "100" ] - } - }, { - "id" : "2f182934-4fe6-4e53-b095-5e83e7faa8d6", - "name" : "hmac-generated", - "providerId" : "hmac-generated", - "subComponents" : { }, - "config" : { - "kid" : [ "fe4350c9-950f-43ff-8fd2-da6de380a9d4" ], - "secret" : [ "1xrYFB_VUS2bEYAg-m4fZdokpbccITRwqhwoM4HLr0qDxU7g1ODofDHbCCT5jzC3MAhfDfV2uXZm9rpIxOjm8Q" ], - "priority" : [ "100" ], - "algorithm" : [ "HS256" ] - } - }, { - "id" : "ce512173-984a-4894-8cc1-0c2f6bb8c2d4", - "name" : "aes-generated", - "providerId" : "aes-generated", - "subComponents" : { }, - "config" : { - "kid" : [ "2f6fb75c-aa96-4cb4-9174-c8e7108deac3" ], - "secret" : [ "tS1ULzgUF9-74ojI_E2Cng" ], - "priority" : [ "100" ] - } - } ] - }, - "internationalizationEnabled" : false, - "supportedLocales" : [ ], - "authenticationFlows" : [ { - "id" : "dfd2f528-4b75-4a3d-9586-157376d5a9cb", - "alias" : "Account verification options", - "description" : "Method with which to verity the existing account", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "idp-email-verification", - "requirement" : "ALTERNATIVE", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "ALTERNATIVE", - "priority" : 20, - "flowAlias" : "Verify Existing Account by Re-authentication", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "85ba93a4-a5aa-4315-8bc5-cc9b77bd0f2e", - "alias" : "Authentication Options", - "description" : "Authentication options.", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "basic-auth", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "basic-auth-otp", - "requirement" : "DISABLED", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "auth-spnego", - "requirement" : "DISABLED", - "priority" : 30, - "userSetupAllowed" : false, - "autheticatorFlow" : false - } ] - }, { - "id" : "5bcc8efb-3878-4105-b9e4-18d70f7f14d2", - "alias" : "Browser - Conditional OTP", - "description" : "Flow to determine if the OTP is required for the authentication", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "conditional-user-configured", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "auth-otp-form", - "requirement" : "REQUIRED", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - } ] - }, { - "id" : "9f668eff-6e32-4958-b62d-fdc5827a7e91", - "alias" : "Direct Grant - Conditional OTP", - "description" : "Flow to determine if the OTP is required for the authentication", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "conditional-user-configured", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "direct-grant-validate-otp", - "requirement" : "REQUIRED", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - } ] - }, { - "id" : "f62fe642-6108-4454-837e-7f332cfa95b7", - "alias" : "First broker login - Conditional OTP", - "description" : "Flow to determine if the OTP is required for the authentication", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "conditional-user-configured", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "auth-otp-form", - "requirement" : "REQUIRED", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - } ] - }, { - "id" : "a0cd15fc-5bcb-4fed-aea8-13ba2db99140", - "alias" : "Handle Existing Account", - "description" : "Handle what to do if there is existing account with same email/username like authenticated identity provider", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "idp-confirm-link", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "REQUIRED", - "priority" : 20, - "flowAlias" : "Account verification options", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "07160955-87aa-4382-a147-2060f4c4809f", - "alias" : "Reset - Conditional OTP", - "description" : "Flow to determine if the OTP should be reset or not. Set to REQUIRED to force.", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "conditional-user-configured", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "reset-otp", - "requirement" : "REQUIRED", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - } ] - }, { - "id" : "3cab948d-5721-42f9-b17d-9066ed5b8211", - "alias" : "User creation or linking", - "description" : "Flow for the existing/non-existing user alternatives", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticatorConfig" : "create unique user config", - "authenticator" : "idp-create-user-if-unique", - "requirement" : "ALTERNATIVE", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "ALTERNATIVE", - "priority" : 20, - "flowAlias" : "Handle Existing Account", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "af7039f6-e8d4-489c-a209-eba0326b332d", - "alias" : "Verify Existing Account by Re-authentication", - "description" : "Reauthentication of existing account", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "idp-username-password-form", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "CONDITIONAL", - "priority" : 20, - "flowAlias" : "First broker login - Conditional OTP", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "8cb99efb-d70f-486a-8b74-b95b75bd79cd", - "alias" : "browser", - "description" : "browser based authentication", - "providerId" : "basic-flow", - "topLevel" : true, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "auth-cookie", - "requirement" : "ALTERNATIVE", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "auth-spnego", - "requirement" : "DISABLED", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "identity-provider-redirector", - "requirement" : "ALTERNATIVE", - "priority" : 25, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "ALTERNATIVE", - "priority" : 30, - "flowAlias" : "forms", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "616d3123-07cb-4888-86c7-8b024240a48a", - "alias" : "clients", - "description" : "Base authentication for clients", - "providerId" : "client-flow", - "topLevel" : true, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "client-secret", - "requirement" : "ALTERNATIVE", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "client-jwt", - "requirement" : "ALTERNATIVE", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "client-secret-jwt", - "requirement" : "ALTERNATIVE", - "priority" : 30, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "client-x509", - "requirement" : "ALTERNATIVE", - "priority" : 40, - "userSetupAllowed" : false, - "autheticatorFlow" : false - } ] - }, { - "id" : "0516d6fa-e1e3-41fc-8424-92a5c5b15478", - "alias" : "direct grant", - "description" : "OpenID Connect Resource Owner Grant", - "providerId" : "basic-flow", - "topLevel" : true, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "direct-grant-validate-username", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "direct-grant-validate-password", - "requirement" : "REQUIRED", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "CONDITIONAL", - "priority" : 30, - "flowAlias" : "Direct Grant - Conditional OTP", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "da35f65f-eb9d-402e-8c18-05122c748852", - "alias" : "docker auth", - "description" : "Used by Docker clients to authenticate against the IDP", - "providerId" : "basic-flow", - "topLevel" : true, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "docker-http-basic-authenticator", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - } ] - }, { - "id" : "19c7586a-b27a-4849-bfa9-1d6ad49237d5", - "alias" : "first broker login", - "description" : "Actions taken after first broker login with identity provider account, which is not yet linked to any Keycloak account", - "providerId" : "basic-flow", - "topLevel" : true, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticatorConfig" : "review profile config", - "authenticator" : "idp-review-profile", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "REQUIRED", - "priority" : 20, - "flowAlias" : "User creation or linking", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "72291173-9cde-4c48-8730-736f1f7a2138", - "alias" : "forms", - "description" : "Username, password, otp and other auth forms.", - "providerId" : "basic-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "auth-username-password-form", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "CONDITIONAL", - "priority" : 20, - "flowAlias" : "Browser - Conditional OTP", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "4cb6c342-bc21-46e5-aac4-beaacbbc543a", - "alias" : "http challenge", - "description" : "An authentication flow based on challenge-response HTTP Authentication Schemes", - "providerId" : "basic-flow", - "topLevel" : true, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "no-cookie-redirect", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "REQUIRED", - "priority" : 20, - "flowAlias" : "Authentication Options", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "e2cbdfb6-6697-4b4c-9df1-1c00633152a2", - "alias" : "registration", - "description" : "registration flow", - "providerId" : "basic-flow", - "topLevel" : true, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "registration-page-form", - "requirement" : "REQUIRED", - "priority" : 10, - "flowAlias" : "registration form", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "d9eaa5b8-1a2c-48e0-9195-14651b201a57", - "alias" : "registration form", - "description" : "registration form", - "providerId" : "form-flow", - "topLevel" : false, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "registration-user-creation", - "requirement" : "REQUIRED", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "registration-profile-action", - "requirement" : "REQUIRED", - "priority" : 40, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "registration-password-action", - "requirement" : "REQUIRED", - "priority" : 50, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "registration-recaptcha-action", - "requirement" : "DISABLED", - "priority" : 60, - "userSetupAllowed" : false, - "autheticatorFlow" : false - } ] - }, { - "id" : "e9682c13-6f5b-4b8d-ba7a-2f08e46dc6f8", - "alias" : "reset credentials", - "description" : "Reset credentials for a user if they forgot their password or something", - "providerId" : "basic-flow", - "topLevel" : true, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "reset-credentials-choose-user", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "reset-credential-email", - "requirement" : "REQUIRED", - "priority" : 20, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "authenticator" : "reset-password", - "requirement" : "REQUIRED", - "priority" : 30, - "userSetupAllowed" : false, - "autheticatorFlow" : false - }, { - "requirement" : "CONDITIONAL", - "priority" : 40, - "flowAlias" : "Reset - Conditional OTP", - "userSetupAllowed" : false, - "autheticatorFlow" : true - } ] - }, { - "id" : "3aa3d718-420f-46a0-9219-9a7ae939e847", - "alias" : "saml ecp", - "description" : "SAML ECP Profile Authentication Flow", - "providerId" : "basic-flow", - "topLevel" : true, - "builtIn" : true, - "authenticationExecutions" : [ { - "authenticator" : "http-basic-authenticator", - "requirement" : "REQUIRED", - "priority" : 10, - "userSetupAllowed" : false, - "autheticatorFlow" : false - } ] - } ], - "authenticatorConfig" : [ { - "id" : "0bcfb3fc-2a12-40d3-835c-a93c2e43864f", - "alias" : "create unique user config", - "config" : { - "require.password.update.after.registration" : "false" - } - }, { - "id" : "b29dc357-e0f4-4e00-b6f2-8cd7cfbf4661", - "alias" : "review profile config", - "config" : { - "update.profile.on.first.login" : "missing" - } - } ], - "requiredActions" : [ { - "alias" : "CONFIGURE_TOTP", - "name" : "Configure OTP", - "providerId" : "CONFIGURE_TOTP", - "enabled" : true, - "defaultAction" : false, - "priority" : 10, - "config" : { } - }, { - "alias" : "terms_and_conditions", - "name" : "Terms and Conditions", - "providerId" : "terms_and_conditions", - "enabled" : false, - "defaultAction" : false, - "priority" : 20, - "config" : { } - }, { - "alias" : "UPDATE_PASSWORD", - "name" : "Update Password", - "providerId" : "UPDATE_PASSWORD", - "enabled" : true, - "defaultAction" : false, - "priority" : 30, - "config" : { } - }, { - "alias" : "UPDATE_PROFILE", - "name" : "Update Profile", - "providerId" : "UPDATE_PROFILE", - "enabled" : true, - "defaultAction" : false, - "priority" : 40, - "config" : { } - }, { - "alias" : "VERIFY_EMAIL", - "name" : "Verify Email", - "providerId" : "VERIFY_EMAIL", - "enabled" : true, - "defaultAction" : false, - "priority" : 50, - "config" : { } - }, { - "alias" : "update_user_locale", - "name" : "Update User Locale", - "providerId" : "update_user_locale", - "enabled" : true, - "defaultAction" : false, - "priority" : 1000, - "config" : { } - } ], - "browserFlow" : "browser", - "registrationFlow" : "registration", - "directGrantFlow" : "direct grant", - "resetCredentialsFlow" : "reset credentials", - "clientAuthenticationFlow" : "clients", - "dockerAuthenticationFlow" : "docker auth", - "attributes" : { }, - "keycloakVersion" : "11.0.0", - "userManagedAccessAllowed" : false -} \ No newline at end of file diff --git a/examples/keycloak-example/resource-app/pom.xml b/examples/keycloak-example/resource-app/pom.xml deleted file mode 100644 index de722c2b..00000000 --- a/examples/keycloak-example/resource-app/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.3.RELEASE - - - ru.otus - resource-app - 0.0.1-SNAPSHOT - resource-app - KeyCloack resource app example - - - 11 - 11 - 11 - - - - - - org.keycloak.bom - keycloak-adapter-bom - 11.0.0 - pom - import - - - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-security - - - - org.keycloak - keycloak-spring-boot-starter - - - - org.projectlombok - lombok - true - - - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/examples/keycloak-example/resource-app/src/main/java/ru/otus/resourceapp/ResourceAppApplication.java b/examples/keycloak-example/resource-app/src/main/java/ru/otus/resourceapp/ResourceAppApplication.java deleted file mode 100644 index 2144c9b0..00000000 --- a/examples/keycloak-example/resource-app/src/main/java/ru/otus/resourceapp/ResourceAppApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package ru.otus.resourceapp; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -//https://www.baeldung.com/spring-boot-keycloak -//https://www.baeldung.com/keycloak-custom-user-attributes -//https://github.com/keycloak/keycloak-quickstarts/tree/latest/app-authz-springboot -@SpringBootApplication -public class ResourceAppApplication { - - public static void main(String[] args) { - SpringApplication.run(ResourceAppApplication.class, args); - } - -} diff --git a/examples/keycloak-example/resource-app/src/main/java/ru/otus/resourceapp/config/SecurityConfig.java b/examples/keycloak-example/resource-app/src/main/java/ru/otus/resourceapp/config/SecurityConfig.java deleted file mode 100644 index 8389bca7..00000000 --- a/examples/keycloak-example/resource-app/src/main/java/ru/otus/resourceapp/config/SecurityConfig.java +++ /dev/null @@ -1,51 +0,0 @@ -package ru.otus.resourceapp.config; - -import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver; -import org.keycloak.adapters.springsecurity.KeycloakSecurityComponents; -import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper; -import org.springframework.security.core.session.SessionRegistryImpl; -import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy; -import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; - -@Configuration -@EnableWebSecurity -@ComponentScan(basePackageClasses = KeycloakSecurityComponents.class) -class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter { - - @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - var keycloakAuthenticationProvider = keycloakAuthenticationProvider(); - keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper()); - auth.authenticationProvider(keycloakAuthenticationProvider); - } - - @Bean - public KeycloakSpringBootConfigResolver keycloakConfigResolver() { - return new KeycloakSpringBootConfigResolver(); - } - - @Bean - @Override - protected SessionAuthenticationStrategy sessionAuthenticationStrategy() { - return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl()); - } - - @Override - protected void configure(HttpSecurity http) throws Exception { - super.configure(http); - http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .authorizeRequests() - .antMatchers("/secret*").hasRole("user") - .anyRequest().permitAll(); - } -} \ No newline at end of file diff --git a/examples/keycloak-example/resource-app/src/main/java/ru/otus/resourceapp/controllers/CommonController.java b/examples/keycloak-example/resource-app/src/main/java/ru/otus/resourceapp/controllers/CommonController.java deleted file mode 100644 index e86dbed5..00000000 --- a/examples/keycloak-example/resource-app/src/main/java/ru/otus/resourceapp/controllers/CommonController.java +++ /dev/null @@ -1,28 +0,0 @@ -package ru.otus.resourceapp.controllers; - -import org.keycloak.KeycloakPrincipal; -import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.security.Principal; - -@RestController -public class CommonController { - - @GetMapping(path = "/") - public String commonData() { - return "Абсолютно свободные данные"; - } - - @SuppressWarnings("rawtypes") - @GetMapping(path = "/secret") - public String secretData(Principal principal) { - var authenticationToken = (KeycloakAuthenticationToken) principal; - var kp = (KeycloakPrincipal) authenticationToken.getPrincipal(); - var token = kp.getKeycloakSecurityContext().getToken(); - - return "Жутко секретные данные для пользователя: " + token.getPreferredUsername() + - ", \n остальные данные: " + token.getOtherClaims(); - } -} diff --git a/examples/keycloak-example/resource-app/src/main/resources/application.yml b/examples/keycloak-example/resource-app/src/main/resources/application.yml deleted file mode 100644 index 81f405a1..00000000 --- a/examples/keycloak-example/resource-app/src/main/resources/application.yml +++ /dev/null @@ -1,5 +0,0 @@ -keycloak: - auth-server-url: http://localhost:8082/auth - realm: KCExample - resource: resource-app - public-client: true diff --git a/examples/mongo-db-demo/.gitignore b/examples/mongo-db-demo/.gitignore deleted file mode 100644 index 153c9335..00000000 --- a/examples/mongo-db-demo/.gitignore +++ /dev/null @@ -1,29 +0,0 @@ -HELP.md -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -/build/ - -### VS Code ### -.vscode/ diff --git a/examples/mongo-db-demo/README.md b/examples/mongo-db-demo/README.md deleted file mode 100644 index 84065306..00000000 --- a/examples/mongo-db-demo/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Пример работы с MongoDB - -В примере демонстрируется: -* *два подхода к хранению вложенных сущностей* -* *инициализация базы данными с помощью инструмента миграций Mongock* -* *использование AbstractMongoEventListener для выполнения каскадных операций* -* *работа с массивами с помощью агрегаций и Criteria api* diff --git a/examples/mongo-db-demo/pom.xml b/examples/mongo-db-demo/pom.xml deleted file mode 100644 index 9c301b94..00000000 --- a/examples/mongo-db-demo/pom.xml +++ /dev/null @@ -1,121 +0,0 @@ - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.2.6.RELEASE - - - - ru.otus.example - mongo-db-demo - 0.0.1-SNAPSHOT - mongo-db-demo - Demo project for MongoDB - - - 11 - 11 - 11 - 3.2.8 - - - - - - org.springframework.boot - spring-boot-starter-data-mongodb - - - - - org.projectlombok - lombok - true - - - - com.github.cloudyrock.mongock - mongock-spring - ${mongock.version} - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - org.junit.jupiter - junit-jupiter-api - ${junit-jupiter.version} - test - - - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter.version} - test - - - - org.junit.jupiter - junit-jupiter-params - ${junit-jupiter.version} - test - - - - org.mockito - mockito-core - ${mockito.version} - test - - - - org.mockito - mockito-junit-jupiter - ${mockito.version} - test - - - - org.assertj - assertj-core - ${assertj.version} - test - - - - de.flapdoodle.embed - de.flapdoodle.embed.mongo - test - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - - diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/MongoDbDemoApplication.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/MongoDbDemoApplication.java deleted file mode 100644 index 04cf8c9d..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/MongoDbDemoApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package ru.otus.example.mongodbdemo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; - -@SpringBootApplication -@EnableConfigurationProperties -public class MongoDbDemoApplication { - - public static void main(String[] args) { - SpringApplication.run(MongoDbDemoApplication.class, args); - } - -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/changelogs/InitMongoDBDataChangeLog.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/changelogs/InitMongoDBDataChangeLog.java deleted file mode 100644 index c71c7515..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/changelogs/InitMongoDBDataChangeLog.java +++ /dev/null @@ -1,41 +0,0 @@ -package ru.otus.example.mongodbdemo.changelogs; - -import com.github.cloudyrock.mongock.ChangeLog; -import com.github.cloudyrock.mongock.ChangeSet; -import com.mongodb.client.MongoDatabase; -import lombok.val; -import org.springframework.data.mongodb.core.MongoTemplate; -import ru.otus.example.mongodbdemo.model.Knowledge; -import ru.otus.example.mongodbdemo.model.Student; -import ru.otus.example.mongodbdemo.model.Teacher; - -@ChangeLog(order = "001") -public class InitMongoDBDataChangeLog { - - private Knowledge springDataKnowledge; - private Knowledge mongockKnowledge; - private Knowledge aggregationApiKnowledge; - - @ChangeSet(order = "000", id = "dropDB", author = "stvort", runAlways = true) - public void dropDB(MongoDatabase database){ - database.drop(); - } - - @ChangeSet(order = "001", id = "initKnowledges", author = "stvort", runAlways = true) - public void initKnowledges(MongoTemplate template){ - springDataKnowledge = template.save(new Knowledge("Spring Data")); - mongockKnowledge = template.save(new Knowledge("Mongock")); - aggregationApiKnowledge = template.save(new Knowledge("AggregationApi")); - } - - @ChangeSet(order = "002", id = "initStudents", author = "stvort", runAlways = true) - public void initStudents(MongoTemplate template){ - template.save(new Student("Student #1", springDataKnowledge, mongockKnowledge)); - } - - @ChangeSet(order = "003", id = "Teacher", author = "stvort", runAlways = true) - public void initTeachers(MongoTemplate template){ - val teacher = new Teacher("Teacher #1", springDataKnowledge, mongockKnowledge, aggregationApiKnowledge); - template.save(teacher); - } -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/config/ApplicationConfig.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/config/ApplicationConfig.java deleted file mode 100644 index 77f7b6b8..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/config/ApplicationConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -package ru.otus.example.mongodbdemo.config; - -import com.github.cloudyrock.mongock.Mongock; -import com.github.cloudyrock.mongock.SpringMongockBuilder; -import com.mongodb.MongoClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class ApplicationConfig { - - private static final String CHANGELOGS_PACKAGE = "ru.otus.example.mongodbdemo.changelogs"; - - @Bean - public Mongock mongock(MongoProps mongoProps, MongoClient mongoClient) { - return new SpringMongockBuilder(mongoClient, mongoProps.getDatabase(), CHANGELOGS_PACKAGE) - .build(); - } -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/config/MongoProps.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/config/MongoProps.java deleted file mode 100644 index ce0c6d17..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/config/MongoProps.java +++ /dev/null @@ -1,14 +0,0 @@ -package ru.otus.example.mongodbdemo.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@Data -@Component -@ConfigurationProperties("spring.data.mongodb") -public class MongoProps { - private int port; - private String database; - private String uri; -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/events/MongoKnowledgeCascadeDeleteEventsListener.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/events/MongoKnowledgeCascadeDeleteEventsListener.java deleted file mode 100644 index 08f6c601..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/events/MongoKnowledgeCascadeDeleteEventsListener.java +++ /dev/null @@ -1,24 +0,0 @@ -package ru.otus.example.mongodbdemo.events; - -import lombok.RequiredArgsConstructor; -import lombok.val; -import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener; -import org.springframework.data.mongodb.core.mapping.event.AfterDeleteEvent; -import org.springframework.stereotype.Component; -import ru.otus.example.mongodbdemo.model.Knowledge; -import ru.otus.example.mongodbdemo.repositories.StudentRepository; - -@Component -@RequiredArgsConstructor -public class MongoKnowledgeCascadeDeleteEventsListener extends AbstractMongoEventListener { - - private final StudentRepository studentRepository; - - @Override - public void onAfterDelete(AfterDeleteEvent event) { - super.onAfterDelete(event); - val source = event.getSource(); - val id = source.get("_id").toString(); - studentRepository.removeExperienceArrayElementsById(id); - } -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/events/MongoStudentCascadeSaveEventsListener.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/events/MongoStudentCascadeSaveEventsListener.java deleted file mode 100644 index 89ff7d97..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/events/MongoStudentCascadeSaveEventsListener.java +++ /dev/null @@ -1,27 +0,0 @@ -package ru.otus.example.mongodbdemo.events; - -import lombok.RequiredArgsConstructor; -import lombok.val; -import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener; -import org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent; -import org.springframework.stereotype.Component; -import ru.otus.example.mongodbdemo.model.Student; -import ru.otus.example.mongodbdemo.repositories.KnowledgeRepository; - -import java.util.Objects; - -@Component -@RequiredArgsConstructor -public class MongoStudentCascadeSaveEventsListener extends AbstractMongoEventListener { - - private final KnowledgeRepository knowledgeRepository; - - @Override - public void onBeforeConvert(BeforeConvertEvent event) { - super.onBeforeConvert(event); - val student = event.getSource(); - if (student.getExperience() != null) { - student.getExperience().stream().filter(e -> Objects.isNull(e.getId())).forEach(knowledgeRepository::save); - } - } -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/model/Knowledge.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/model/Knowledge.java deleted file mode 100644 index 04583a57..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/model/Knowledge.java +++ /dev/null @@ -1,21 +0,0 @@ -package ru.otus.example.mongodbdemo.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Document -public class Knowledge { - @Id - private String id; - private String name; - - public Knowledge(String name) { - this.name = name; - } -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/model/Student.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/model/Student.java deleted file mode 100644 index bf228359..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/model/Student.java +++ /dev/null @@ -1,29 +0,0 @@ -package ru.otus.example.mongodbdemo.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.DBRef; -import org.springframework.data.mongodb.core.mapping.Document; - -import java.util.Arrays; -import java.util.List; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Document -public class Student { - @Id - private String id; - private String name; - - @DBRef - private List experience; - - public Student(String name, Knowledge... experience) { - this.name = name; - this.experience = Arrays.asList(experience); - } -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/model/Teacher.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/model/Teacher.java deleted file mode 100644 index aa8e1166..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/model/Teacher.java +++ /dev/null @@ -1,28 +0,0 @@ -package ru.otus.example.mongodbdemo.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; - -import java.util.Arrays; -import java.util.List; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Document -public class Teacher { - @Id - private String id; - private String name; - - private List experience; - - public Teacher(String name, Knowledge... experience) { - this.name = name; - this.experience = Arrays.asList(experience); - - } -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/KnowledgeRepository.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/KnowledgeRepository.java deleted file mode 100644 index c8605cb4..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/KnowledgeRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories; - -import org.springframework.data.mongodb.repository.MongoRepository; -import ru.otus.example.mongodbdemo.model.Knowledge; - -public interface KnowledgeRepository extends MongoRepository { -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/StudentRepository.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/StudentRepository.java deleted file mode 100644 index bc603fe5..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/StudentRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories; - -import org.springframework.data.mongodb.repository.MongoRepository; -import ru.otus.example.mongodbdemo.model.Student; - - -public interface StudentRepository extends MongoRepository, StudentRepositoryCustom { -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/StudentRepositoryCustom.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/StudentRepositoryCustom.java deleted file mode 100644 index 8b902bbf..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/StudentRepositoryCustom.java +++ /dev/null @@ -1,12 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories; - -import ru.otus.example.mongodbdemo.model.Knowledge; - -import java.util.List; - -public interface StudentRepositoryCustom { - List getStudentExperienceById(String studentId); - - long getExperienceArrayLengthByStudentId(String id); - void removeExperienceArrayElementsById(String id); -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/StudentRepositoryCustomImpl.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/StudentRepositoryCustomImpl.java deleted file mode 100644 index 91fb3536..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/StudentRepositoryCustomImpl.java +++ /dev/null @@ -1,69 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories; - -import lombok.Data; -import lombok.RequiredArgsConstructor; -import lombok.val; -import org.bson.Document; -import org.bson.types.ObjectId; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.aggregation.Aggregation; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; -import org.springframework.data.mongodb.core.query.Update; -import ru.otus.example.mongodbdemo.model.Knowledge; -import ru.otus.example.mongodbdemo.model.Student; -import ru.otus.example.mongodbdemo.utils.RawResultPrinter; - - -import java.util.List; - -import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; -import static org.springframework.data.mongodb.core.aggregation.ObjectOperators.ObjectToArray.valueOfToArray; -import static org.springframework.data.mongodb.core.query.Criteria.where; - -@RequiredArgsConstructor -public class StudentRepositoryCustomImpl implements StudentRepositoryCustom { - - @Data - private class ArraySizeProjection { - private int size; - } - - private final MongoTemplate mongoTemplate; - private final RawResultPrinter rawResultPrinter; - - @Override - public List getStudentExperienceById(String studentId) { - Aggregation aggregation = newAggregation( - match(Criteria.where("id").is(studentId)) - , unwind("experience") - , project().andExclude("_id").and(valueOfToArray("experience")).as("experience_map") - , project().and("experience_map").arrayElementAt(1).as("experience_id_map") - , project().and("experience_id_map.v").as("experience_id") - , lookup("knowledge", "experience_id", "_id", "experience") - , project().and("experience._id").as("_id").and("experience.name").as("name") - ); - - Document rawResults = mongoTemplate.aggregate(aggregation, Student.class, Knowledge.class).getRawResults(); - rawResultPrinter.prettyPrintRawResult(rawResults); - return mongoTemplate.aggregate(aggregation, Student.class, Knowledge.class).getMappedResults(); - } - - @Override - public long getExperienceArrayLengthByStudentId(String studentId) { - val aggregation = Aggregation.newAggregation( - match(where("id").is(studentId)), - project().andExclude("_id").and("experience").size().as("size")); - - val arraySizeProjection = mongoTemplate.aggregate(aggregation, Student.class, ArraySizeProjection.class).getUniqueMappedResult(); - return arraySizeProjection == null ? 0 : arraySizeProjection.getSize(); - } - - @Override - public void removeExperienceArrayElementsById(String id) { - val query = Query.query(Criteria.where("$id").is(new ObjectId(id))); - val update = new Update().pull("experience", query); - mongoTemplate.updateMulti(new Query(), update, Student.class); - } - -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/TeacherRepository.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/TeacherRepository.java deleted file mode 100644 index b75c5200..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/TeacherRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories; - -import org.springframework.data.mongodb.repository.MongoRepository; -import ru.otus.example.mongodbdemo.model.Teacher; - -public interface TeacherRepository extends MongoRepository, TeacherRepositoryCustom { -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/TeacherRepositoryCustom.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/TeacherRepositoryCustom.java deleted file mode 100644 index adfd9acb..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/TeacherRepositoryCustom.java +++ /dev/null @@ -1,9 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories; - -import ru.otus.example.mongodbdemo.model.Knowledge; - -import java.util.List; - -public interface TeacherRepositoryCustom { - List getTeacherExperienceById(String teacherId); -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/TeacherRepositoryCustomImpl.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/TeacherRepositoryCustomImpl.java deleted file mode 100644 index d529928d..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/repositories/TeacherRepositoryCustomImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories; - -import lombok.RequiredArgsConstructor; -import lombok.val; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import ru.otus.example.mongodbdemo.model.Knowledge; -import ru.otus.example.mongodbdemo.model.Teacher; - -import java.util.List; - -import static org.springframework.data.mongodb.core.aggregation.Aggregation.*; - -@RequiredArgsConstructor -public class TeacherRepositoryCustomImpl implements TeacherRepositoryCustom { - - private final MongoTemplate mongoTemplate; - - @Override - public List getTeacherExperienceById(String teacherId) { - val aggregation = newAggregation( - match(Criteria.where("id").is(teacherId)) - , unwind("experience") - , project().andExclude("_id").and("experience.id").as("_id").and("experience.name").as("name") - ); - return mongoTemplate.aggregate(aggregation, Teacher.class, Knowledge.class).getMappedResults(); - } -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/utils/RawResultPrinter.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/utils/RawResultPrinter.java deleted file mode 100644 index e033d42d..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/utils/RawResultPrinter.java +++ /dev/null @@ -1,8 +0,0 @@ -package ru.otus.example.mongodbdemo.utils; - -import org.bson.Document; - -public interface RawResultPrinter { - @SuppressWarnings("unchecked") - void prettyPrintRawResult(Document document); -} diff --git a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/utils/RawResultPrinterImpl.java b/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/utils/RawResultPrinterImpl.java deleted file mode 100644 index 1fcd9a7c..00000000 --- a/examples/mongo-db-demo/src/main/java/ru/otus/example/mongodbdemo/utils/RawResultPrinterImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -package ru.otus.example.mongodbdemo.utils; - -import org.bson.Document; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.stream.Collectors; - -@Component -public class RawResultPrinterImpl implements RawResultPrinter { - @SuppressWarnings("unchecked") - @Override - public void prettyPrintRawResult(Document document) { - List results = (List) document.get("results"); - String resultsAsString = results.stream().map(Document::toString).collect(Collectors.joining("\n")); - System.out.println(resultsAsString); - } -} diff --git a/examples/mongo-db-demo/src/main/resources/application.yml b/examples/mongo-db-demo/src/main/resources/application.yml deleted file mode 100644 index 4d338124..00000000 --- a/examples/mongo-db-demo/src/main/resources/application.yml +++ /dev/null @@ -1,9 +0,0 @@ -spring: - data: - mongodb: - uri: mongodb://localhost - port: 27017 - database: awesomeMongo -logging: - level: - root: ERROR \ No newline at end of file diff --git a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/AbstractRepositoryTest.java b/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/AbstractRepositoryTest.java deleted file mode 100644 index f1342168..00000000 --- a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/AbstractRepositoryTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories; - -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Import; -import ru.otus.example.mongodbdemo.utils.RawResultPrinterImpl; - -@DataMongoTest -@EnableConfigurationProperties -@ComponentScan({"ru.otus.example.mongodbdemo.config", "ru.otus.example.mongodbdemo.repositories"}) -@Import(RawResultPrinterImpl.class) -public abstract class AbstractRepositoryTest { -} diff --git a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/TeacherRepositoryTest.java b/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/TeacherRepositoryTest.java deleted file mode 100644 index f6fd8713..00000000 --- a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/TeacherRepositoryTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories; - -import lombok.val; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import ru.otus.example.mongodbdemo.model.Knowledge; - -import static org.assertj.core.api.Assertions.assertThat; - -@DisplayName("TeacherRepository должен ") -class TeacherRepositoryTest extends AbstractRepositoryTest { - - @Autowired - private TeacherRepository teacherRepository; - - @DisplayName(" возвращать корректный список знаний преподавателя") - @Test - void shouldReturnCorrectKnowledgeList(){ - val teachers = teacherRepository.findAll(); - val teacher = teachers.get(0); - val experience = teacher.getExperience(); - assertThat(experience).isNotNull().hasSize(3); - - val actualExperience = teacherRepository.getTeacherExperienceById(teacher.getId()); - assertThat(actualExperience).containsExactlyInAnyOrder(experience.toArray(new Knowledge[0])); - - } -} diff --git a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/plain/KnowledgeRepositoryWithoutListenerTest.java b/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/plain/KnowledgeRepositoryWithoutListenerTest.java deleted file mode 100644 index c68d61d6..00000000 --- a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/plain/KnowledgeRepositoryWithoutListenerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories.plain; - -import lombok.val; -import org.assertj.core.api.AbstractObjectAssert; -import org.assertj.core.api.AbstractOptionalAssert; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import ru.otus.example.mongodbdemo.model.Knowledge; -import ru.otus.example.mongodbdemo.model.Student; -import ru.otus.example.mongodbdemo.repositories.AbstractRepositoryTest; -import ru.otus.example.mongodbdemo.repositories.KnowledgeRepository; -import ru.otus.example.mongodbdemo.repositories.StudentRepository; - -import java.util.List; -import java.util.function.Function; - -import static org.assertj.core.api.Assertions.assertThat; - - -@DisplayName("KnowledgeRepository при отсутствии listener-ов в контексте ") -class KnowledgeRepositoryWithoutListenerTest extends AbstractRepositoryTest { - - @Autowired - private KnowledgeRepository knowledgeRepository; - - @Autowired - private StudentRepository studentRepository; - - @DisplayName("при удалении Knowledge не должен удалять его из опыта студента") - @Test - void shouldLeaveKnowledgeInStudentExperienceWhenRemovingKnowledge() { - - // Загрузка студента и его первого знания - val students = studentRepository.findAll(); - val student = students.get(0); - val experience = student.getExperience(); - val firstKnowledge = experience.get(0); - - // Удаление знания из коллекции знаний - knowledgeRepository.delete(firstKnowledge); - - // Загружаем студента заново и проверяем, что знание действительно удалено (размер стал меньше на 1) - val expectedExperienceArrayLength = experience.size() - 1; - val actualStudentOptional = studentRepository.findById(student.getId()); - assertThat(actualStudentOptional) - .isNotEmpty().get() - .matches(s -> s.getExperience() != null && s.getExperience().size() == expectedExperienceArrayLength); - - - // Загружаем размер массива с помощью аггрегаций и проверяем, что на самом деле размер массива в БД не изменился - val actualExperienceArrayLength = studentRepository.getExperienceArrayLengthByStudentId(student.getId()); - assertThat(actualExperienceArrayLength).isNotEqualTo(expectedExperienceArrayLength); - - - - } -} diff --git a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/plain/StudentRepositoryWithoutListenerTest.java b/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/plain/StudentRepositoryWithoutListenerTest.java deleted file mode 100644 index c688bcee..00000000 --- a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/plain/StudentRepositoryWithoutListenerTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories.plain; - -import lombok.val; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mapping.MappingException; -import ru.otus.example.mongodbdemo.model.Knowledge; -import ru.otus.example.mongodbdemo.model.Student; -import ru.otus.example.mongodbdemo.repositories.AbstractRepositoryTest; -import ru.otus.example.mongodbdemo.repositories.StudentRepository; - -import static org.assertj.core.api.Assertions.*; - -@DisplayName("StudentRepository при отсутствии listener-ов в контексте ") -class StudentRepositoryWithoutListenerTest extends AbstractRepositoryTest { - - @Autowired - private StudentRepository studentRepository; - - @DisplayName("должен кидать MappingException во время сохранения студента с отсутствующими в БД знаниями") - @Test - void shouldThrowMappingExceptionWhenSaveStudentWithNewKnowledge(){ - val student = new Student("Student #2", new Knowledge("Knowledge #3")); - assertThatThrownBy(() -> studentRepository.save(student)).isInstanceOf(MappingException.class); - } -} \ No newline at end of file diff --git a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/withlisteners/KnowledgeRepositoryWithListenerTest.java b/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/withlisteners/KnowledgeRepositoryWithListenerTest.java deleted file mode 100644 index 743f3599..00000000 --- a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/withlisteners/KnowledgeRepositoryWithListenerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories.withlisteners; - -import lombok.val; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; -import ru.otus.example.mongodbdemo.repositories.AbstractRepositoryTest; -import ru.otus.example.mongodbdemo.repositories.KnowledgeRepository; -import ru.otus.example.mongodbdemo.repositories.StudentRepository; - -import static org.assertj.core.api.Assertions.assertThat; - -@DisplayName("KnowledgeRepository при наличии listener-ов в контексте ") -@ComponentScan("ru.otus.example.mongodbdemo.events") -class KnowledgeRepositoryWithListenerTest extends AbstractRepositoryTest { - - @Autowired - private KnowledgeRepository knowledgeRepository; - - @Autowired - private StudentRepository studentRepository; - - @DisplayName("при удалении Knowledge должен удалить его из опыта студента") - @Test - void shouldRemoveKnowledgeFromStudentExperienceWhenRemovingKnowledge() { - - // Загрузка студента и его первого знания - val students = studentRepository.findAll(); - val student = students.get(0); - val experience = student.getExperience(); - val firstKnowledge = experience.get(0); - - // Удаление знания из коллекции знаний - knowledgeRepository.delete(firstKnowledge); - - // Загружаем студента заново и проверяем, что знание действительно удалено (размер стал меньше на 1) - val expectedExperienceArrayLength = experience.size() - 1; - val actualStudentOptional = studentRepository.findById(student.getId()); - assertThat(actualStudentOptional) - .isNotEmpty().get() - .matches(s -> s.getExperience() != null && s.getExperience().size() == expectedExperienceArrayLength); - - // Загружаем размер массива с помощью аггрегаций и проверяем, что размер массива в БД тоже изменился - val actualExperienceArrayLength = studentRepository.getExperienceArrayLengthByStudentId(student.getId()); - assertThat(actualExperienceArrayLength).isEqualTo(expectedExperienceArrayLength); - - } -} diff --git a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/withlisteners/StudentRepositoryWithListenersTest.java b/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/withlisteners/StudentRepositoryWithListenersTest.java deleted file mode 100644 index f70740c8..00000000 --- a/examples/mongo-db-demo/src/test/java/ru/otus/example/mongodbdemo/repositories/withlisteners/StudentRepositoryWithListenersTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package ru.otus.example.mongodbdemo.repositories.withlisteners; - -import lombok.val; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; -import ru.otus.example.mongodbdemo.model.Knowledge; -import ru.otus.example.mongodbdemo.model.Student; -import ru.otus.example.mongodbdemo.repositories.AbstractRepositoryTest; -import ru.otus.example.mongodbdemo.repositories.StudentRepository; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -@DisplayName("StudentRepository при наличии listener-ов в контексте ") -@ComponentScan("ru.otus.example.mongodbdemo.events") -class StudentRepositoryWithListenersTest extends AbstractRepositoryTest { - - @Autowired - private StudentRepository studentRepository; - - @DisplayName("должен корректно сохранять студента с отсутствующими в БД знаниями") - @Test - void shouldCorrectSaveStudentWithNewKnowledge(){ - val student = new Student("Student #2", new Knowledge("Knowledge #3")); - val actual = studentRepository.save(student); - assertThat(actual.getId()).isNotNull(); - assertThat(actual.getName()).isEqualTo(student.getName()); - } - - @DisplayName("должен возвращать корректный список знаний студента") - @Test - void shouldReturnCorrectStudentKnowledgeList(){ - val student = studentRepository.findAll().get(0); - List knowledgeList = studentRepository.getStudentExperienceById(student.getId()); - assertThat(knowledgeList).containsExactlyInAnyOrderElementsOf(student.getExperience()); - } - -} diff --git a/examples/mongo-db-demo/src/test/resources/application.yml b/examples/mongo-db-demo/src/test/resources/application.yml deleted file mode 100644 index e4a55735..00000000 --- a/examples/mongo-db-demo/src/test/resources/application.yml +++ /dev/null @@ -1,11 +0,0 @@ -spring: - data: - mongodb: - port: 0 - database: test - #uri: mongodb://localhost - #port: 27017 - #database: awesomeMongo -logging: - level: - root: ERROR \ No newline at end of file diff --git a/examples/oauth2-example/.gitignore b/examples/oauth2-example/.gitignore deleted file mode 100644 index e62c33c2..00000000 --- a/examples/oauth2-example/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.idea/ -*.iml - -target/ diff --git a/examples/oauth2-example/README.md b/examples/oauth2-example/README.md deleted file mode 100644 index 9f2358ec..00000000 --- a/examples/oauth2-example/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Пример аутентификации/авторизации с помощью OAuth2 сервера и JWT - -* *В примере есть проект authorization-server, призванный выдавать jwt токены в ответ на корректный POST запрос по http://localhost:8090/oauth/token * -* *В теле такого запроса нужно передать client_id, grant_type, имя и пароль пользователя пользователя пытающегося выполнить вход* -* *Далее, полученный токен XXX нужно прикладывать к каждому запросу к приложению из проекта resource-server в виде загловка "Authorization Bearer XXX"* -* *Для демонстрации работы примера нужно запустить приложение authorization-server и следом изучить работу E2E теста в проекте resource-server* diff --git a/examples/oauth2-example/authorization-server/.gitignore b/examples/oauth2-example/authorization-server/.gitignore deleted file mode 100644 index a2a3040a..00000000 --- a/examples/oauth2-example/authorization-server/.gitignore +++ /dev/null @@ -1,31 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/** -!**/src/test/** - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ - -### VS Code ### -.vscode/ diff --git a/examples/oauth2-example/authorization-server/pom.xml b/examples/oauth2-example/authorization-server/pom.xml deleted file mode 100644 index 8dd70e7e..00000000 --- a/examples/oauth2-example/authorization-server/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.3.RELEASE - - - ru.otus - authorization-server - 0.0.1-SNAPSHOT - authorization-server - Authorization server demo - - - 13 - 13 - 13 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-security - - - - org.springframework.security.oauth - spring-security-oauth2 - 2.5.0.RELEASE - - - - org.springframework.security - spring-security-jwt - 1.1.1.RELEASE - - - - - com.h2database - h2 - runtime - - - - org.projectlombok - lombok - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - org.springframework.security - spring-security-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/AuthorizationServerApplication.java b/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/AuthorizationServerApplication.java deleted file mode 100644 index ba739fdc..00000000 --- a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/AuthorizationServerApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package ru.otus.authorizationserver; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; - -@EnableConfigurationProperties -@SpringBootApplication -public class AuthorizationServerApplication { - - public static void main(String[] args) { - SpringApplication.run(AuthorizationServerApplication.class, args); - } - -} diff --git a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/AuthorizationServerConfig.java b/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/AuthorizationServerConfig.java deleted file mode 100644 index 502ee502..00000000 --- a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/AuthorizationServerConfig.java +++ /dev/null @@ -1,66 +0,0 @@ -package ru.otus.authorizationserver.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; -import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; -import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; -import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; -import org.springframework.security.oauth2.provider.token.DefaultTokenServices; -import org.springframework.security.oauth2.provider.token.TokenEnhancerChain; -import org.springframework.security.oauth2.provider.token.TokenStore; -import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; -import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; -import ru.otus.authorizationserver.services.CustomTokenEnhancer; - -import javax.sql.DataSource; -import java.util.List; - -@SuppressWarnings("deprecation") -@Configuration -@EnableAuthorizationServer -public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { - - private static final int ACCESS_TOKEN_VALIDITY_SECONDS = 60 * 60 * 3; - private static final int REFRESH_TOKEN_VALIDITY_SECONDS = -1; - - @Autowired - private OAuthProps oAuthProps; - - @Autowired - private AuthenticationManager authManager; - - @Autowired - private TokenStore tokenStore; - - @Autowired - private JwtAccessTokenConverter jwtAccessTokenConverter; - - @Override - public void configure(AuthorizationServerEndpointsConfigurer endpoints) { - TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); - tokenEnhancerChain.setTokenEnhancers(List.of(new CustomTokenEnhancer(), jwtAccessTokenConverter)); - endpoints.authenticationManager(authManager) - .tokenEnhancer(tokenEnhancerChain) - .tokenStore(tokenStore) - .reuseRefreshTokens(false) - ; - } - - @Override - public void configure(ClientDetailsServiceConfigurer clients) throws Exception { - clients - .inMemory() - .withClient(oAuthProps.getClientId()) - .secret(oAuthProps.getClientSecret()) - .authorizedGrantTypes("password", "authorization_code", "refresh_token") - .scopes("read", "write") - .accessTokenValiditySeconds(ACCESS_TOKEN_VALIDITY_SECONDS) - .refreshTokenValiditySeconds(REFRESH_TOKEN_VALIDITY_SECONDS); - } - -} diff --git a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/OAuthProps.java b/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/OAuthProps.java deleted file mode 100644 index a48da2c5..00000000 --- a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/OAuthProps.java +++ /dev/null @@ -1,14 +0,0 @@ -package ru.otus.authorizationserver.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@Data -@Component -@ConfigurationProperties(prefix = "app.oauth2") -public class OAuthProps { - private String clientId; - private String clientSecret; - private String signingKey; -} diff --git a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/SecurityConfig.java b/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/SecurityConfig.java deleted file mode 100644 index de0b9483..00000000 --- a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/SecurityConfig.java +++ /dev/null @@ -1,39 +0,0 @@ -package ru.otus.authorizationserver.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.crypto.password.NoOpPasswordEncoder; -import org.springframework.security.crypto.password.PasswordEncoder; - -@Configuration -@EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) -public class SecurityConfig extends WebSecurityConfigurerAdapter { - - @Autowired - private UserDetailsService userDetailsService; - - @Override - @Bean - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } - - @Bean - public PasswordEncoder passwordEncoder() { - return NoOpPasswordEncoder.getInstance(); - } - - - @Autowired - public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(userDetailsService); - } -} \ No newline at end of file diff --git a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/TokenStoreConfig.java b/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/TokenStoreConfig.java deleted file mode 100644 index 8b6fe664..00000000 --- a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/config/TokenStoreConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -package ru.otus.authorizationserver.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices; -import org.springframework.security.oauth2.provider.token.DefaultTokenServices; -import org.springframework.security.oauth2.provider.token.TokenStore; -import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; -import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; - -@SuppressWarnings("deprecation") -@Configuration -public class TokenStoreConfig { - - @Autowired - private OAuthProps oAuthProps; - - @Bean - public TokenStore tokenStore() { - return new JwtTokenStore(jwtAccessTokenConverter()); - } - - @Bean - public JwtAccessTokenConverter jwtAccessTokenConverter() { - var converter = new JwtAccessTokenConverter(); - converter.setSigningKey(oAuthProps.getSigningKey()); - return converter; - } -} diff --git a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/model/CustomUser.java b/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/model/CustomUser.java deleted file mode 100644 index 89c4e175..00000000 --- a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/model/CustomUser.java +++ /dev/null @@ -1,33 +0,0 @@ -package ru.otus.authorizationserver.model; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.User; - -import java.util.Collection; - -public class CustomUser extends User { - - @Getter - @Setter - private String firstName; - - @Getter - @Setter - private String fatherName; - - public CustomUser(String firstName, String fatherName, - String username, String password, - Collection authorities) { - super(username, password, authorities); - this.firstName = firstName; - this.fatherName = fatherName; - } - - public CustomUser(CustomUser user) { - super(user.getUsername(), user.getPassword(), user.getAuthorities()); - this.firstName = user.getFirstName(); - this.fatherName = user.getFatherName(); - } -} diff --git a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/services/CustomTokenEnhancer.java b/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/services/CustomTokenEnhancer.java deleted file mode 100644 index ef8a899a..00000000 --- a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/services/CustomTokenEnhancer.java +++ /dev/null @@ -1,26 +0,0 @@ -package ru.otus.authorizationserver.services; - -import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; -import org.springframework.security.oauth2.common.OAuth2AccessToken; -import org.springframework.security.oauth2.provider.OAuth2Authentication; -import org.springframework.security.oauth2.provider.token.TokenEnhancer; -import ru.otus.authorizationserver.model.CustomUser; - -import java.util.HashMap; -import java.util.Map; - -@SuppressWarnings("deprecation") -public class CustomTokenEnhancer implements TokenEnhancer { - public static final String KEY_FIRST_NAME = "firstName"; - public static final String KEY_FATHER_NAME = "fatherName"; - - @Override - public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) { - CustomUser user = (CustomUser) authentication.getPrincipal(); - ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(Map.of( - KEY_FIRST_NAME, user.getFirstName(), - KEY_FATHER_NAME, user.getFatherName() - )); - return accessToken; - } -} diff --git a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/services/InMemoryUserDetailsService.java b/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/services/InMemoryUserDetailsService.java deleted file mode 100644 index 893c5922..00000000 --- a/examples/oauth2-example/authorization-server/src/main/java/ru/otus/authorizationserver/services/InMemoryUserDetailsService.java +++ /dev/null @@ -1,39 +0,0 @@ -package ru.otus.authorizationserver.services; - -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; -import ru.otus.authorizationserver.model.CustomUser; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - -@Service -public class InMemoryUserDetailsService implements UserDetailsService { - - private final Map userMap; - - public InMemoryUserDetailsService(PasswordEncoder passwordEncoder) { - userMap = Map.of( - "user1", new CustomUser("Василий", "Григорьевич", - "user1", - passwordEncoder.encode("user1"), - List.of(new SimpleGrantedAuthority("ADMIN"))), - - "user2", new CustomUser("Ираклий", "Спиридонович", - "user2", - passwordEncoder.encode("user2"), - List.of(new SimpleGrantedAuthority("USER"))) - ); - } - - @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - return Optional.ofNullable(userMap.get(username)).map(CustomUser::new) - .orElseThrow(() -> new UsernameNotFoundException(String.format("User %s not found", username))); - } -} diff --git a/examples/oauth2-example/authorization-server/src/main/resources/application.yml b/examples/oauth2-example/authorization-server/src/main/resources/application.yml deleted file mode 100644 index 93cff256..00000000 --- a/examples/oauth2-example/authorization-server/src/main/resources/application.yml +++ /dev/null @@ -1,8 +0,0 @@ -server: - port: 8090 - -app: - oauth2: - client-id: "any_id" - client-secret: "any_secret" - signing-key: 987654321 diff --git a/examples/oauth2-example/pom.xml b/examples/oauth2-example/pom.xml deleted file mode 100644 index bd4fd7e2..00000000 --- a/examples/oauth2-example/pom.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - 4.0.0 - - ru.otus - oauth2-example - 1.0 - - pom - - - authorization-server - resource-server - - diff --git a/examples/oauth2-example/resource-server/.gitignore b/examples/oauth2-example/resource-server/.gitignore deleted file mode 100644 index a2a3040a..00000000 --- a/examples/oauth2-example/resource-server/.gitignore +++ /dev/null @@ -1,31 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/** -!**/src/test/** - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ - -### VS Code ### -.vscode/ diff --git a/examples/oauth2-example/resource-server/pom.xml b/examples/oauth2-example/resource-server/pom.xml deleted file mode 100644 index 47aa30ed..00000000 --- a/examples/oauth2-example/resource-server/pom.xml +++ /dev/null @@ -1,92 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.3.RELEASE - - - ru.otus - resource-server - 0.0.1-SNAPSHOT - resource-server - Resource server demo - - - 13 - 13 - 13 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-security - - - - org.springframework.security.oauth - spring-security-oauth2 - 2.5.0.RELEASE - - - - org.springframework.security - spring-security-jwt - 1.1.1.RELEASE - - - - - com.h2database - h2 - runtime - - - - org.projectlombok - lombok - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - org.springframework.security - spring-security-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/ResourceServerApplication.java b/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/ResourceServerApplication.java deleted file mode 100644 index 1530f5cb..00000000 --- a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/ResourceServerApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package ru.otus.resourceserver; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; - -@EnableConfigurationProperties -@SpringBootApplication -public class ResourceServerApplication { - - public static void main(String[] args) { - SpringApplication.run(ResourceServerApplication.class, args); - } - -} diff --git a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/config/OAuthProps.java b/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/config/OAuthProps.java deleted file mode 100644 index 60e416fd..00000000 --- a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/config/OAuthProps.java +++ /dev/null @@ -1,14 +0,0 @@ -package ru.otus.resourceserver.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@Data -@Component -@ConfigurationProperties(prefix = "app.oauth2") -public class OAuthProps { - private String clientId; - private String clientSecret; - private String signingKey; -} diff --git a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/config/ResourceServerConfig.java b/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/config/ResourceServerConfig.java deleted file mode 100644 index 5e144645..00000000 --- a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/config/ResourceServerConfig.java +++ /dev/null @@ -1,51 +0,0 @@ -package ru.otus.resourceserver.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; -import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; -import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler; -import org.springframework.security.oauth2.provider.token.TokenStore; -import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; -import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; - -@SuppressWarnings("deprecation") -@Configuration -@EnableGlobalMethodSecurity(prePostEnabled = true) -@EnableResourceServer -public class ResourceServerConfig extends ResourceServerConfigurerAdapter { - - @Autowired - private OAuthProps oAuthProps; - - @Bean - public TokenStore tokenStore() { - return new JwtTokenStore(jwtAccessTokenConverter()); - } - - @Bean - public JwtAccessTokenConverter jwtAccessTokenConverter() { - var converter = new JwtAccessTokenConverter(); - converter.setSigningKey(oAuthProps.getSigningKey()); - return converter; - } - - @Override - public void configure(ResourceServerSecurityConfigurer resources) throws Exception { - resources.tokenStore(tokenStore()) - ; - } - - @Override - public void configure(HttpSecurity http) throws Exception { - http.anonymous().disable() - .authorizeRequests() - .antMatchers("/api/**").authenticated() - .and().exceptionHandling().accessDeniedHandler(new OAuth2AccessDeniedHandler()); - } - -} \ No newline at end of file diff --git a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/controllers/ApiController.java b/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/controllers/ApiController.java deleted file mode 100644 index 1a466ccc..00000000 --- a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/controllers/ApiController.java +++ /dev/null @@ -1,41 +0,0 @@ -package ru.otus.resourceserver.controllers; - -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.core.Authentication; -import org.springframework.security.oauth2.common.OAuth2AccessToken; -import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; -import org.springframework.security.oauth2.provider.token.TokenStore; -import org.springframework.web.bind.annotation.*; -import ru.otus.resourceserver.models.CurrentUserRequestResult; - -import java.util.Map; - -@SuppressWarnings("deprecation") -@RequiredArgsConstructor -@RestController -public class ApiController { - - public static final String KEY_FIRST_NAME = "firstName"; - public static final String KEY_FATHER_NAME = "fatherName"; - - private final TokenStore tokenStore; - - @GetMapping("api/current-user") - @ResponseStatus(HttpStatus.OK) - @PreAuthorize("hasAuthority('ADMIN')") - public CurrentUserRequestResult getCurrentUser(Authentication authentication) { - - Map info = getAdditionalInfo(authentication); - return new CurrentUserRequestResult((String) authentication.getPrincipal(), - (String) info.get(KEY_FIRST_NAME), - (String) info.get(KEY_FATHER_NAME)); - } - - private Map getAdditionalInfo(Authentication authentication) { - OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails(); - OAuth2AccessToken accessToken = tokenStore.readAccessToken(details.getTokenValue()); - return accessToken.getAdditionalInformation(); - } -} diff --git a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/models/CurrentUserRequestResult.java b/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/models/CurrentUserRequestResult.java deleted file mode 100644 index 8c7b9d6f..00000000 --- a/examples/oauth2-example/resource-server/src/main/java/ru/otus/resourceserver/models/CurrentUserRequestResult.java +++ /dev/null @@ -1,12 +0,0 @@ -package ru.otus.resourceserver.models; - -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class CurrentUserRequestResult { - private String userName; - private String firstName; - private String fatherName; -} diff --git a/examples/oauth2-example/resource-server/src/main/resources/application.yml b/examples/oauth2-example/resource-server/src/main/resources/application.yml deleted file mode 100644 index f3f557c8..00000000 --- a/examples/oauth2-example/resource-server/src/main/resources/application.yml +++ /dev/null @@ -1,8 +0,0 @@ -server: - port: 8080 - -app: - oauth2: - client-id: "any_id" - client-secret: "any_secret" - signing-key: 987654321 diff --git a/examples/oauth2-example/resource-server/src/test/java/ru/otus/resourceserver/ResourceServerApplicationTests.java b/examples/oauth2-example/resource-server/src/test/java/ru/otus/resourceserver/ResourceServerApplicationTests.java deleted file mode 100644 index e656426b..00000000 --- a/examples/oauth2-example/resource-server/src/test/java/ru/otus/resourceserver/ResourceServerApplicationTests.java +++ /dev/null @@ -1,69 +0,0 @@ -package ru.otus.resourceserver; - -import lombok.Data; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import ru.otus.resourceserver.config.OAuthProps; - -import static org.assertj.core.api.Assertions.assertThat; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -class ResourceServerApplicationTests { - - @Autowired - private TestRestTemplate restTemplate; - - @Autowired - private OAuthProps oAuthProps; - - @Data - static class TokenResponse { - private String access_token; - private String token_type; - private String refresh_token; - private String expires_in; - private String scope; - } - - @Test - void shouldSuccessfullyAccessTheEndpointAfterLoginOnAuthorizationServer() { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - headers.setBasicAuth(oAuthProps.getClientId(), oAuthProps.getClientSecret()); - - ResponseEntity tokenResponse = restTemplate.postForEntity( - "http://localhost:8090/oauth/token?client_id=" + oAuthProps.getClientId() + - "&grant_type=password&username=user1&password=user1", - new HttpEntity<>(headers), - TokenResponse.class); - - -/* - System.out.println(tokenResponse.getStatusCode()); - System.out.println(tokenResponse.getHeaders()); - System.out.println(tokenResponse.getBody()); -*/ - assertThat(tokenResponse.getBody()).isNotNull(); - - headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.setBearerAuth(tokenResponse.getBody().getAccess_token()); - - - ResponseEntity currentUserResponse = restTemplate.exchange( - "http://localhost:8080/api/current-user", - HttpMethod.GET, - new HttpEntity<>(headers), - String.class); - - System.out.println(currentUserResponse.getStatusCode()); - System.out.println(currentUserResponse.getHeaders()); - System.out.println(currentUserResponse.getBody()); - assertThat(currentUserResponse.getBody()) - .isNotNull().isEqualTo("{\"userName\":\"user1\",\"firstName\":\"Василий\",\"fatherName\":\"Григорьевич\"}"); - } - -} diff --git a/examples/readonly-transaction-demo/pom.xml b/examples/readonly-transaction-demo/pom.xml deleted file mode 100644 index 71dc3930..00000000 --- a/examples/readonly-transaction-demo/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - 4.0.0 - - - org.springframework.boot - spring-boot-starter-parent - 2.5.2 - - - - ru.otus - readonly-transaction-demo - 0.0.1-SNAPSHOT - readonly-transaction-demo - Readonly transaction demo - - - 11 - - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - - - com.h2database - h2 - runtime - - - - org.projectlombok - lombok - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - - - diff --git a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/ReadonlyTransactionDemoApplication.java b/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/ReadonlyTransactionDemoApplication.java deleted file mode 100644 index 6220dc01..00000000 --- a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/ReadonlyTransactionDemoApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package ru.otus.demo; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class ReadonlyTransactionDemoApplication { - - public static void main(String[] args) { - SpringApplication.run(ReadonlyTransactionDemoApplication.class, args); - } - -} diff --git a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/model/Email.java b/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/model/Email.java deleted file mode 100644 index 42bbfac5..00000000 --- a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/model/Email.java +++ /dev/null @@ -1,22 +0,0 @@ -package ru.otus.demo.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Entity -public class Email { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - private String address; -} diff --git a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/model/Person.java b/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/model/Person.java deleted file mode 100644 index 58fbdf28..00000000 --- a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/model/Person.java +++ /dev/null @@ -1,23 +0,0 @@ -package ru.otus.demo.model; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.persistence.*; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Entity -public class Person { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - private String name; - - @OneToOne(cascade = CascadeType.ALL) - private Email email; - -} diff --git a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/repository/PersonRepository.java b/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/repository/PersonRepository.java deleted file mode 100644 index c9ebdf9d..00000000 --- a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/repository/PersonRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package ru.otus.demo.repository; - -import ru.otus.demo.model.Person; - -import java.util.List; - -public interface PersonRepository { - - Person save(Person person); - - List findAll(); - Person findById(long id); -} diff --git a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/repository/PersonRepositoryJpa.java b/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/repository/PersonRepositoryJpa.java deleted file mode 100644 index 5aee7bad..00000000 --- a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/repository/PersonRepositoryJpa.java +++ /dev/null @@ -1,48 +0,0 @@ -package ru.otus.demo.repository; - -import lombok.RequiredArgsConstructor; -import org.hibernate.Session; -import org.springframework.stereotype.Repository; -import ru.otus.demo.model.Person; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.TypedQuery; -import java.util.List; - -@Repository -@RequiredArgsConstructor -public class PersonRepositoryJpa implements PersonRepository { - - @PersistenceContext - private final EntityManager em; - - @Override - public Person save(Person person) { - if (person.getId() == 0) { - Person savedPerson = new Person(person.getId(), person.getName(), person.getEmail()); - em.persist(savedPerson); - return savedPerson; - - } - return em.merge(person); - } - - @Override - public List findAll() { - TypedQuery query = em.createQuery("select p from Person p", Person.class); - return query.getResultList(); - } - - @Override - public Person findById(long id) { - System.out.println("FlushMode: " + em.unwrap(Session.class).getHibernateFlushMode()); - return em.find(Person.class, id); -/* - TypedQuery query = em.createQuery("select p from Person p where p.id = :id", Person.class); - query.setParameter("id", id); - return query.getSingleResult(); -*/ - - } -} diff --git a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/services/PersonService.java b/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/services/PersonService.java deleted file mode 100644 index 74629595..00000000 --- a/examples/readonly-transaction-demo/src/main/java/ru/otus/demo/services/PersonService.java +++ /dev/null @@ -1,41 +0,0 @@ -package ru.otus.demo.services; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import ru.otus.demo.model.Person; -import ru.otus.demo.repository.PersonRepository; - -@Service -public class PersonService { - private final PersonRepository personRepository; - - public PersonService(PersonRepository personRepository) { - this.personRepository = personRepository; - } - - public Person findById(long id) { - return personRepository.findById(id); - } - - @Transactional - public void save(Person person){ - personRepository.save(person); - } - - public void updateWithoutTran(long id, String name) { - Person person = personRepository.findById(id); - person.setName(name); - } - - @Transactional - public void updateWithNormalTran(long id, String name) { - Person person = personRepository.findById(id); - person.setName(name); - } - - @Transactional(readOnly = true) - public void updateWithReadonlyTran(long id, String name) { - Person person = personRepository.findById(id); - person.setName(name); - } -} diff --git a/examples/readonly-transaction-demo/src/main/resources/application.yml b/examples/readonly-transaction-demo/src/main/resources/application.yml deleted file mode 100644 index 99cf96dd..00000000 --- a/examples/readonly-transaction-demo/src/main/resources/application.yml +++ /dev/null @@ -1,23 +0,0 @@ -spring: - datasource: - #url: jdbc:postgresql://localhost:5432/persons - #username: postgres - #password: postgres - - url: jdbc:h2:mem:testdb - - initialization-mode: always - - jpa: - generate-ddl: false - hibernate: - ddl-auto: none - - show-sql: true - properties: - hibernate: - #format_sql: true - -logging: - level: - org.hibernate.engine.transaction.internal: DEBUG \ No newline at end of file diff --git a/examples/readonly-transaction-demo/src/main/resources/schema.sql b/examples/readonly-transaction-demo/src/main/resources/schema.sql deleted file mode 100644 index 7a9fc3c4..00000000 --- a/examples/readonly-transaction-demo/src/main/resources/schema.sql +++ /dev/null @@ -1,17 +0,0 @@ -drop table if exists person; -drop table if exists email; - - -create table email ( - id bigserial, - address varchar(200), - primary key(id) -); - -create table person ( - id bigserial, - email_id bigint references email(id), - name varchar(200), - primary key(id) -); - diff --git a/examples/readonly-transaction-demo/src/test/java/ru/otus/demo/services/PersonServiceTest.java b/examples/readonly-transaction-demo/src/test/java/ru/otus/demo/services/PersonServiceTest.java deleted file mode 100644 index 9576a876..00000000 --- a/examples/readonly-transaction-demo/src/test/java/ru/otus/demo/services/PersonServiceTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package ru.otus.demo.services; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import ru.otus.demo.model.Email; -import ru.otus.demo.model.Person; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -@SpringBootTest -@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -@Transactional(propagation = Propagation.NOT_SUPPORTED) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) -class PersonServiceTest { - - @Autowired - private PersonService personService; - - @BeforeEach - void setUp() { - personService.save(new Person(0, "Igor", new Email(0, "noname@nomail.ru"))); - } - - /* - // Изменение имени пёрсона внутри updateWithNormalTran ПОПАДАЮТ в БД после закрытия сессии/транзакции - // Работаем в обычной транзакции (в логах есть ее начало и коммит, а так же update) - // FlushMode: AUTO (есть в логах) - - 2021-07-24 19:21:16.310 DEBUG 8636 --- [ main] o.h.e.t.internal.TransactionImpl : begin - Hibernate: select person0_.id as id1_1_, person0_.email_id as email_id3_1_, person0_.name as name2_1_ from person person0_ where person0_.id=? - Hibernate: select email0_.id as id1_0_0_, email0_.address as address2_0_0_ from email email0_ where email0_.id=? - 2021-07-24 19:21:16.390 DEBUG 8636 --- [ main] o.h.e.t.internal.TransactionImpl : committing - Hibernate: update person set email_id=?, name=? where id=? - */ - @Test - void updateWithNormalTran() { - personService.updateWithNormalTran(1, "Vasya"); - Person actualPerson = personService.findById(1); - assertThat(actualPerson).extracting(Person::getName).isEqualTo("Vasya"); - } - - /* - // Работаем в readonly транзакции (в логах есть ее начало и коммит) - // Изменение имени пёрсона внутри updateWithReadonlyTran НЕ попадают в БД после закрытия сессии/транзакции - // FlushMode: MANUAL (есть в логах), поэтому изменения и не попадают - - 2021-07-24 19:15:22.889 DEBUG 11024 --- [ main] o.h.e.t.internal.TransactionImpl : begin - Hibernate: select person0_.id as id1_1_, person0_.email_id as email_id3_1_, person0_.name as name2_1_ from person person0_ where person0_.id=? - Hibernate: select email0_.id as id1_0_0_, email0_.address as address2_0_0_ from email email0_ where email0_.id=? - 2021-07-24 19:15:22.967 DEBUG 11024 --- [ main] o.h.e.t.internal.TransactionImpl : committing - - */ - @Test - void updateWithReadonlyTran() { - personService.updateWithReadonlyTran(1, "Vasya"); - Person actualPerson = personService.findById(1); - assertThat(actualPerson).extracting(Person::getName).isEqualTo("Igor"); - } - - /* - // Работаем без транзакции (в логах нет ее начала и коммита) - // Изменение имени пёрсона внутри updateWithoutTran НЕ попадают в БД после закрытия сессии/транзакции - // FlushMode: AUTO (есть в логах) - - Hibernate: select person0_.id as id1_1_, person0_.email_id as email_id3_1_, person0_.name as name2_1_ from person person0_ where person0_.id=? - Hibernate: select email0_.id as id1_0_0_, email0_.address as address2_0_0_ from email email0_ where email0_.id=? - */ - @Test - void updateWithoutTran() { - personService.updateWithoutTran(1, "Vasya"); - Person actualPerson = personService.findById(1); - assertThat(actualPerson).extracting(Person::getName).isEqualTo("Igor"); - } -} \ No newline at end of file diff --git a/examples/readonly-transaction-demo/src/test/java/ru/otus/demo/services/TransactionsTest.java b/examples/readonly-transaction-demo/src/test/java/ru/otus/demo/services/TransactionsTest.java deleted file mode 100644 index 505ff189..00000000 --- a/examples/readonly-transaction-demo/src/test/java/ru/otus/demo/services/TransactionsTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package ru.otus.demo.services; - -import org.hibernate.FlushMode; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.transaction.TransactionManager; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.TransactionTemplate; -import ru.otus.demo.model.Email; -import ru.otus.demo.model.Person; - -import javax.persistence.EntityManager; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -@SpringBootTest -@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -@Transactional(propagation = Propagation.NOT_SUPPORTED) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) -class TransactionsTest { - - private static final Person expectedPerson = new Person(1L, "Igor", - new Email(1L, "noname@nomail.ru")); - - @Autowired - private SessionFactory sf; - - @Autowired - private Session s; - - @Autowired - private TransactionTemplate tm; - - @BeforeEach - void setUp() { - tm.setReadOnly(false); - tm.execute(status -> { - s.persist(new Person(0, expectedPerson.getName(), - new Email(0, expectedPerson.getEmail().getAddress()))); - return null; - }); - - sf.getStatistics().setStatisticsEnabled(true); - sf.getStatistics().clear(); - } - - @Test - void findWithNormalTran() { - tm.setReadOnly(false); - Person actualPerson = tm.execute(status -> { - assertThat(s.getHibernateFlushMode()).isEqualTo(FlushMode.AUTO); - return s.find(Person.class, 1L); - }); - assertThat(actualPerson).usingRecursiveComparison().isEqualTo(expectedPerson); - assertThat(sf.getStatistics().getTransactionCount()).isEqualTo(1); - } - - @Test - void findWithReadOnlyTran() { - tm.setReadOnly(true); - Person actualPerson = tm.execute(status -> { - assertThat(s.getHibernateFlushMode()).isEqualTo(FlushMode.MANUAL); - return s.find(Person.class, 1L); - }); - assertThat(actualPerson).usingRecursiveComparison().isEqualTo(expectedPerson); - assertThat(sf.getStatistics().getTransactionCount()).isEqualTo(1); - } - - @Test - void findWithoutTran() { - assertThat(s.getHibernateFlushMode()).isEqualTo(FlushMode.AUTO); - Person actualPerson = s.find(Person.class, 1L); - assertThat(actualPerson).usingRecursiveComparison().isEqualTo(expectedPerson); - assertThat(sf.getStatistics().getTransactionCount()).isEqualTo(0); - } -} \ No newline at end of file