From 7ccdc4de0054423644655c4366bd750fb99b2c15 Mon Sep 17 00:00:00 2001 From: _Bastler Date: Tue, 12 Dec 2023 21:20:25 +0100 Subject: [PATCH] migrate to spring boot 3.2 --- .gitignore | 4 +- pom.xml | 48 +++++++-------- src/main/java/de/bstly/board/JPAConfig.java | 2 +- .../board/businesslogic/EntryManager.java | 16 +++-- .../board/businesslogic/SearchManager.java | 4 +- .../controller/AuthenticationController.java | 5 +- .../board/controller/DebugController.java | 59 ++++++++----------- .../EntityResponseStatusException.java | 4 +- .../controller/support/RequestBodyErrors.java | 1 - .../controller/validation/ViewValidator.java | 4 +- .../board/i18n/controller/I18nController.java | 2 +- .../java/de/bstly/board/i18n/model/I18n.java | 14 ++--- .../java/de/bstly/board/model/Bookmarks.java | 20 +++---- .../java/de/bstly/board/model/Comment.java | 24 ++++---- src/main/java/de/bstly/board/model/Entry.java | 24 ++++---- src/main/java/de/bstly/board/model/Flag.java | 14 ++--- .../java/de/bstly/board/model/LocalUser.java | 28 ++++----- .../de/bstly/board/model/PersistentLogin.java | 8 +-- src/main/java/de/bstly/board/model/Tag.java | 10 ++-- src/main/java/de/bstly/board/model/View.java | 32 +++++----- src/main/java/de/bstly/board/model/Vote.java | 14 ++--- .../security/LocalRememberMeServices.java | 2 +- .../OAuth2AuthenticationSuccessHandler.java | 6 +- .../bstly/board/security/SecurityConfig.java | 35 +++++------ 24 files changed, 175 insertions(+), 205 deletions(-) diff --git a/.gitignore b/.gitignore index ca82d20..c860d75 100755 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ target/ hs_err*.log application.properties usernames.txt -lucene \ No newline at end of file +lucene + +.vscode \ No newline at end of file diff --git a/pom.xml b/pom.xml index b121700..596289f 100644 --- a/pom.xml +++ b/pom.xml @@ -9,15 +9,16 @@ UTF-8 - 11 - 2.19.0 - 1.5.0 + 17 + 5.0.0 + 6.4.0.Final + 2.0.0 org.springframework.boot spring-boot-starter-parent - 2.7.6 + 3.2.0 @@ -58,35 +59,39 @@ spring-session-jdbc - + org.hibernate.search hibernate-search-mapper-orm - 6.0.7.Final + 7.0.0.Final org.hibernate.search hibernate-search-backend-lucene - 6.0.7.Final + 7.0.0.Final com.querydsl querydsl-apt + ${querydsl.version} + jakarta com.querydsl querydsl-jpa + ${querydsl.version} + jakarta commons-validator commons-validator - 1.7 + 1.8.0 @@ -97,7 +102,7 @@ com.googlecode.owasp-java-html-sanitizer owasp-java-html-sanitizer - 20200713.1 + 20220608.1 @@ -108,7 +113,13 @@ org.bouncycastle bcprov-jdk15on - 1.68 + 1.70 + + + + org.mariadb.jdbc + mariadb-java-client + runtime @@ -175,23 +186,6 @@ - - com.mysema.maven - apt-maven-plugin - 1.1.3 - - - - process - - - target/generated-sources/java - com.querydsl.apt.jpa.JPAAnnotationProcessor - - - - - \ No newline at end of file diff --git a/src/main/java/de/bstly/board/JPAConfig.java b/src/main/java/de/bstly/board/JPAConfig.java index ff6f9b4..533a318 100644 --- a/src/main/java/de/bstly/board/JPAConfig.java +++ b/src/main/java/de/bstly/board/JPAConfig.java @@ -3,7 +3,7 @@ */ package de.bstly.board; -import javax.persistence.EntityManager; +import jakarta.persistence.EntityManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/de/bstly/board/businesslogic/EntryManager.java b/src/main/java/de/bstly/board/businesslogic/EntryManager.java index a4e261d..9b2ca8d 100644 --- a/src/main/java/de/bstly/board/businesslogic/EntryManager.java +++ b/src/main/java/de/bstly/board/businesslogic/EntryManager.java @@ -3,13 +3,9 @@ */ package de.bstly.board.businesslogic; -import java.math.BigInteger; import java.time.Instant; import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.Query; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -35,6 +31,8 @@ import de.bstly.board.model.support.Types; import de.bstly.board.model.support.VoteType; import de.bstly.board.repository.EntryRepository; import de.bstly.board.repository.VoteRepository; +import jakarta.persistence.EntityManager; +import jakarta.persistence.Query; /** * The Class EntryManager. @@ -110,7 +108,7 @@ public class EntryManager { @SuppressWarnings("unchecked") List list = query.getResultList(); Query queryTotal = createCountQuery(COUNT_QUERY, username, filter); - long countResult = ((BigInteger) queryTotal.getSingleResult()).longValue(); + long countResult = ((Long) queryTotal.getSingleResult()).longValue(); return new PageImpl(list, PageRequest.of(page, size), countResult); } @@ -131,7 +129,7 @@ public class EntryManager { @SuppressWarnings("unchecked") List list = query.getResultList(); Query queryTotal = createCountQuery(COUNT_QUERY, username, filter); - long countResult = ((BigInteger) queryTotal.getSingleResult()).longValue(); + long countResult = ((Long) queryTotal.getSingleResult()).longValue(); return new PageImpl(list, PageRequest.of(page, size), countResult); } @@ -156,7 +154,7 @@ public class EntryManager { @SuppressWarnings("unchecked") List list = query.getResultList(); Query queryTotal = createCountQuery(COUNT_QUERY, username, filter); - long countResult = ((BigInteger) queryTotal.getSingleResult()).longValue(); + long countResult = ((Long) queryTotal.getSingleResult()).longValue(); return new PageImpl(list, PageRequest.of(page, size), countResult); } @@ -178,7 +176,7 @@ public class EntryManager { @SuppressWarnings("unchecked") List list = query.getResultList(); Query queryTotal = createCountQuery(COUNT_QUERY, username, filter); - long countResult = ((BigInteger) queryTotal.getSingleResult()).longValue(); + long countResult = ((Long) queryTotal.getSingleResult()).longValue(); return new PageImpl(list, PageRequest.of(page, size), countResult); } @@ -204,7 +202,7 @@ public class EntryManager { List list = query.getResultList(); Query queryTotal = createCountQuery(COUNT_QUERY, username, filter); queryTotal.setParameter("username", username); - long countResult = ((BigInteger) queryTotal.getSingleResult()).longValue(); + long countResult = ((Long) queryTotal.getSingleResult()).longValue(); return new PageImpl(list, PageRequest.of(page, size), countResult); } diff --git a/src/main/java/de/bstly/board/businesslogic/SearchManager.java b/src/main/java/de/bstly/board/businesslogic/SearchManager.java index 305126e..b493794 100644 --- a/src/main/java/de/bstly/board/businesslogic/SearchManager.java +++ b/src/main/java/de/bstly/board/businesslogic/SearchManager.java @@ -5,8 +5,8 @@ package de.bstly.board.businesslogic; import java.util.List; -import javax.persistence.EntityManager; -import javax.transaction.Transactional; +import jakarta.persistence.EntityManager; +import jakarta.transaction.Transactional; import org.hibernate.search.engine.search.query.SearchResult; import org.hibernate.search.mapper.orm.Search; diff --git a/src/main/java/de/bstly/board/controller/AuthenticationController.java b/src/main/java/de/bstly/board/controller/AuthenticationController.java index 3da6e9e..779e7b1 100755 --- a/src/main/java/de/bstly/board/controller/AuthenticationController.java +++ b/src/main/java/de/bstly/board/controller/AuthenticationController.java @@ -61,11 +61,10 @@ public class AuthenticationController extends BaseController { ResolvableType type = ResolvableType.forInstance(clientRegistrationRepository).as(Iterable.class); if (type != ResolvableType.NONE && ClientRegistration.class.isAssignableFrom(type.resolveGenerics()[0])) { clientRegistrations = (Iterable) clientRegistrationRepository; + clientRegistrations.forEach(registration -> clients.add(new Client(registration.getRegistrationId(), + authorizationRequestBaseUri + "/" + registration.getRegistrationId()))); } - clientRegistrations.forEach(registration -> clients.add(new Client(registration.getRegistrationId(), - authorizationRequestBaseUri + "/" + registration.getRegistrationId()))); - return clients; } diff --git a/src/main/java/de/bstly/board/controller/DebugController.java b/src/main/java/de/bstly/board/controller/DebugController.java index 8ea1877..77acddf 100644 --- a/src/main/java/de/bstly/board/controller/DebugController.java +++ b/src/main/java/de/bstly/board/controller/DebugController.java @@ -5,9 +5,9 @@ package de.bstly.board.controller; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.SplittableRandom; import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.lang3.RandomUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -26,6 +26,7 @@ import de.bstly.board.model.QLocalUser; import de.bstly.board.model.Vote; import de.bstly.board.model.support.EntryStatus; import de.bstly.board.model.support.EntryType; +import de.bstly.board.model.support.FlaggedStatus; import de.bstly.board.model.support.Types; import de.bstly.board.model.support.VoteType; import de.bstly.board.repository.CommentRepository; @@ -43,58 +44,44 @@ public class DebugController extends BaseController { @Autowired private PasswordEncoder passwordEncoder; - @Autowired private LocalUserRepository localUserRepository; - @Autowired private CommentRepository commentRepository; - @Autowired private VoteRepository voteRepository; - @Autowired private EntryManager entryManager; @Value("${debug.random.users:0}") private int users; - @Value("${debug.random.minEntries:0}") private int minEntries; - @Value("${debug.random.maxEntries:10}") private int maxEntries; - @Value("${debug.random.entryAge:63115200}") private long entryAge; - @Value("${debug.random.minComments:0}") private int minComments; - @Value("${debug.random.maxComments:10}") private int maxComments; - @Value("${debug.random.subCommentsFactor:0.5}") private float subCommentsFactor; - @Value("${debug.random.subCommentsThresh:0.3}") private float subCommentsThresh; - @Value("${debug.random.subCommentsDepth:2}") private int subCommentsDepth; - @Value("${debug.random.minUpvotes:5}") private int minUpvotes; - @Value("${debug.random.maxUpvotes:10}") private int maxUpvotes; - @Value("${debug.random.minDownvotes:0}") private int minDownvotes; - @Value("${debug.random.maxDownvotes:10}") private int maxDownvotes; + SplittableRandom splittableRandom = new SplittableRandom(); + /** * Random. */ @@ -110,6 +97,7 @@ public class DebugController extends BaseController { String username = "user" + i; localUser.setUsername(username); localUser.setPasswordHash(passwordEncoder.encode(username)); + localUser.setLocale("en"); localUserRepository.save(localUser); logger.trace("Created user: '" + username + "'"); } @@ -130,15 +118,16 @@ public class DebugController extends BaseController { * @param userCount the user count */ protected void entries(String username, long userCount) { - long numEntries = RandomUtils.nextLong(minEntries, maxEntries); + long numEntries = splittableRandom.nextLong(minEntries, maxEntries); for (int i = 0; i < numEntries; i++) { Entry entry = new Entry(); entry.setEntryType(EntryType.INTERN); entry.setAuthor(username); - entry.setCreated(Instant.now().minus(RandomUtils.nextLong(0, entryAge), ChronoUnit.SECONDS)); - entry.setTitle(RandomStringUtils.randomAscii(RandomUtils.nextInt(10, 250))); - entry.setText(RandomStringUtils.randomAscii(RandomUtils.nextInt(0, 2500))); + entry.setCreated(Instant.now().minus(splittableRandom.nextLong(0, entryAge), ChronoUnit.SECONDS)); + entry.setTitle(RandomStringUtils.randomAscii(splittableRandom.nextInt(10, 250))); + entry.setText(RandomStringUtils.randomAscii(splittableRandom.nextInt(0, 2500))); entry.setEntryStatus(EntryStatus.NORMAL); + entry.setFlaggedStatus(FlaggedStatus.NORMAL); entry = entryManager.save(entry); logger.trace("Created entry: '" + entry.getId() + "'"); comments(entry.getId(), entry.getCreated(), userCount); @@ -155,15 +144,16 @@ public class DebugController extends BaseController { * @param userCount the user count */ protected void comments(Long target, Instant date, long userCount) { - long numComments = RandomUtils.nextLong(minComments, maxComments); + long numComments = splittableRandom.nextLong(minComments, maxComments); logger.debug("Create " + numComments + " comments for '" + target + "'"); for (int i = 0; i < numComments; i++) { Comment comment = new Comment(); comment.setTarget(target); - comment.setAuthor("user" + RandomUtils.nextLong(0, userCount)); - comment.setText(RandomStringUtils.randomAscii(RandomUtils.nextInt(0, 2500))); + comment.setAuthor("user" + splittableRandom.nextLong(0, userCount)); + comment.setText(RandomStringUtils.randomAscii(splittableRandom.nextInt(0, 2500))); + comment.setFlaggedStatus(FlaggedStatus.NORMAL); comment.setCreated(Instant.now().minus( - RandomUtils.nextLong(0, (Instant.now().toEpochMilli() - date.toEpochMilli()) / 1000), + splittableRandom.nextLong(0, (Instant.now().toEpochMilli() - date.toEpochMilli()) / 1000), ChronoUnit.SECONDS)); comment = commentRepository.save(comment); logger.trace("Created comment: '" + comment.getId() + "'"); @@ -185,17 +175,18 @@ public class DebugController extends BaseController { */ protected void subComments(Long target, Long parent, Instant date, float factor, float thresh, int depth, long userCount) { - if (depth < subCommentsDepth && RandomUtils.nextFloat(0, 1) < thresh) { - long numSubComments = RandomUtils.nextLong(0, Math.round(maxComments * factor)); + if (depth < subCommentsDepth && splittableRandom.nextFloat(0, 1) < thresh) { + long numSubComments = splittableRandom.nextLong(0, Math.round(maxComments * factor)); logger.debug("Create " + numSubComments + " subComments for '" + parent + "'"); for (int i = 0; i < numSubComments; i++) { Comment comment = new Comment(); comment.setTarget(target); comment.setParent(parent); - comment.setAuthor("user" + RandomUtils.nextLong(0, userCount)); - comment.setText(RandomStringUtils.randomAscii(RandomUtils.nextInt(0, 2500))); + comment.setAuthor("user" + splittableRandom.nextLong(0, userCount)); + comment.setText(RandomStringUtils.randomAscii(splittableRandom.nextInt(0, 2500))); + comment.setFlaggedStatus(FlaggedStatus.NORMAL); comment.setCreated(Instant.now().minus( - RandomUtils.nextLong(0, (Instant.now().toEpochMilli() - date.toEpochMilli()) / 1000), + splittableRandom.nextLong(0, (Instant.now().toEpochMilli() - date.toEpochMilli()) / 1000), ChronoUnit.SECONDS)); comment = commentRepository.save(comment); logger.trace("Created subComment: '" + comment.getId() + "'"); @@ -213,26 +204,26 @@ public class DebugController extends BaseController { * @param userCount the user count */ protected void votes(Long target, Types targetType, long userCount) { - long numUpvotes = RandomUtils.nextLong(minUpvotes, maxUpvotes); + long numUpvotes = splittableRandom.nextLong(minUpvotes, maxUpvotes); logger.debug("Create " + numUpvotes + " upvotes for '" + target + "'"); for (int i = 0; i < numUpvotes; i++) { Vote upvote = new Vote(); upvote.setTarget(target); upvote.setType(VoteType.up); upvote.setTargetType(targetType); - upvote.setAuthor("user" + RandomUtils.nextLong(0, userCount)); + upvote.setAuthor("user" + splittableRandom.nextLong(0, userCount)); upvote = voteRepository.save(upvote); logger.trace("Created upvote: '" + upvote.getId() + "'"); } - long numDownvotes = RandomUtils.nextLong(minDownvotes, maxDownvotes); + long numDownvotes = splittableRandom.nextLong(minDownvotes, maxDownvotes); logger.debug("Create " + numDownvotes + " downvotes for '" + target + "'"); for (int i = 0; i < numDownvotes; i++) { Vote downvote = new Vote(); downvote.setTarget(target); downvote.setType(VoteType.down); downvote.setTargetType(targetType); - downvote.setAuthor("user" + RandomUtils.nextLong(0, userCount)); + downvote.setAuthor("user" + splittableRandom.nextLong(0, userCount)); downvote = voteRepository.save(downvote); logger.trace("Created downvote: '" + downvote.getId() + "'"); } diff --git a/src/main/java/de/bstly/board/controller/support/EntityResponseStatusException.java b/src/main/java/de/bstly/board/controller/support/EntityResponseStatusException.java index caab719..5d89d45 100644 --- a/src/main/java/de/bstly/board/controller/support/EntityResponseStatusException.java +++ b/src/main/java/de/bstly/board/controller/support/EntityResponseStatusException.java @@ -5,7 +5,6 @@ package de.bstly.board.controller.support; import javax.annotation.Nullable; -import org.springframework.core.NestedExceptionUtils; import org.springframework.core.NestedRuntimeException; import org.springframework.http.HttpStatus; import org.springframework.util.Assert; @@ -79,8 +78,7 @@ public class EntityResponseStatusException extends NestedRuntimeException { */ @Override public String getMessage() { - String msg = this.status + (this.body != null ? " \"" + this.body + "\"" : ""); - return NestedExceptionUtils.buildMessage(msg, getCause()); + return this.status + (this.body != null ? " \"" + this.body + "\"" : ""); } } diff --git a/src/main/java/de/bstly/board/controller/support/RequestBodyErrors.java b/src/main/java/de/bstly/board/controller/support/RequestBodyErrors.java index 5757f73..8cf377a 100644 --- a/src/main/java/de/bstly/board/controller/support/RequestBodyErrors.java +++ b/src/main/java/de/bstly/board/controller/support/RequestBodyErrors.java @@ -9,7 +9,6 @@ import org.springframework.validation.AbstractBindingResult; /** * The Class RequestBodyErrors. */ -@SuppressWarnings("serial") public class RequestBodyErrors extends AbstractBindingResult { @Nullable diff --git a/src/main/java/de/bstly/board/controller/validation/ViewValidator.java b/src/main/java/de/bstly/board/controller/validation/ViewValidator.java index 52a0982..fde5be6 100644 --- a/src/main/java/de/bstly/board/controller/validation/ViewValidator.java +++ b/src/main/java/de/bstly/board/controller/validation/ViewValidator.java @@ -52,9 +52,7 @@ public class ViewValidator implements Validator { View origView = viewManager.get(view.getId()); if (origView == null) { errors.rejectValue("id", "INVALID"); - } - - if (!origView.getUsername().equals(view.getUsername())) { + } else if (!origView.getUsername().equals(view.getUsername())) { throw new EntityResponseStatusException(HttpStatus.FORBIDDEN); } diff --git a/src/main/java/de/bstly/board/i18n/controller/I18nController.java b/src/main/java/de/bstly/board/i18n/controller/I18nController.java index 5d84bfd..90aab85 100644 --- a/src/main/java/de/bstly/board/i18n/controller/I18nController.java +++ b/src/main/java/de/bstly/board/i18n/controller/I18nController.java @@ -6,7 +6,7 @@ package de.bstly.board.i18n.controller; import java.io.IOException; import java.util.List; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/src/main/java/de/bstly/board/i18n/model/I18n.java b/src/main/java/de/bstly/board/i18n/model/I18n.java index 15eb780..2c5480c 100644 --- a/src/main/java/de/bstly/board/i18n/model/I18n.java +++ b/src/main/java/de/bstly/board/i18n/model/I18n.java @@ -3,12 +3,12 @@ */ package de.bstly.board.i18n.model; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; /** * The Class I18n. @@ -22,7 +22,7 @@ public class I18n { private String locale; @Lob - @Column(name = "label") + @Column(name = "label", length = 100000) private String label; /** diff --git a/src/main/java/de/bstly/board/model/Bookmarks.java b/src/main/java/de/bstly/board/model/Bookmarks.java index cb7a6a5..cd8aae8 100644 --- a/src/main/java/de/bstly/board/model/Bookmarks.java +++ b/src/main/java/de/bstly/board/model/Bookmarks.java @@ -5,16 +5,15 @@ package de.bstly.board.model; import java.util.List; -import javax.persistence.CollectionTable; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.FetchType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import com.google.common.collect.Lists; @@ -30,8 +29,7 @@ public class Bookmarks { @Id @Column(name = "username", nullable = false) private String username; - @ElementCollection - @LazyCollection(LazyCollectionOption.FALSE) + @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "bookmark_entries") private List entries; diff --git a/src/main/java/de/bstly/board/model/Comment.java b/src/main/java/de/bstly/board/model/Comment.java index 10202bc..e1e7b57 100644 --- a/src/main/java/de/bstly/board/model/Comment.java +++ b/src/main/java/de/bstly/board/model/Comment.java @@ -6,17 +6,17 @@ package de.bstly.board.model; import java.time.Instant; import java.util.Map; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.Table; -import javax.persistence.Transient; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; import org.hibernate.search.engine.backend.types.Projectable; import org.hibernate.search.engine.backend.types.Searchable; @@ -56,7 +56,7 @@ public class Comment { @Column(name = "parent", nullable = true) private Long parent; @Lob - @Column(name = "text", nullable = false) + @Column(name = "text", nullable = false, length = 100000) @FullTextField(name = "text", searchable = Searchable.YES, analyzer = "english", searchAnalyzer = "english_search") @FullTextField(name = "text_de", searchable = Searchable.YES, analyzer = "german", searchAnalyzer = "german_search") private String text; diff --git a/src/main/java/de/bstly/board/model/Entry.java b/src/main/java/de/bstly/board/model/Entry.java index 569d8d3..6a5fe20 100644 --- a/src/main/java/de/bstly/board/model/Entry.java +++ b/src/main/java/de/bstly/board/model/Entry.java @@ -7,17 +7,17 @@ import java.time.Instant; import java.util.List; import java.util.Map; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.Table; -import javax.persistence.Transient; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; import org.hibernate.search.engine.backend.types.Projectable; import org.hibernate.search.engine.backend.types.Searchable; @@ -74,7 +74,7 @@ public class Entry { @FullTextField(name = "title_de", searchable = Searchable.YES, analyzer = "german", searchAnalyzer = "german_search") private String title; @Lob - @Column(name = "text") + @Column(name = "text", length = 100000) @FullTextField(name = "text", searchable = Searchable.YES, analyzer = "english", searchAnalyzer = "english_search") @FullTextField(name = "text_de", searchable = Searchable.YES, analyzer = "german", searchAnalyzer = "german_search") private String text; diff --git a/src/main/java/de/bstly/board/model/Flag.java b/src/main/java/de/bstly/board/model/Flag.java index 26361dd..425ef60 100644 --- a/src/main/java/de/bstly/board/model/Flag.java +++ b/src/main/java/de/bstly/board/model/Flag.java @@ -3,13 +3,13 @@ */ package de.bstly.board.model; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import org.springframework.data.jpa.domain.support.AuditingEntityListener; diff --git a/src/main/java/de/bstly/board/model/LocalUser.java b/src/main/java/de/bstly/board/model/LocalUser.java index 6d946ae..8caf281 100644 --- a/src/main/java/de/bstly/board/model/LocalUser.java +++ b/src/main/java/de/bstly/board/model/LocalUser.java @@ -6,17 +6,14 @@ package de.bstly.board.model; import java.util.List; import java.util.Map; -import javax.persistence.CollectionTable; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.Table; -import javax.persistence.Transient; - -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Lob; +import jakarta.persistence.Table; +import jakarta.persistence.Transient; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -24,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.google.common.collect.Maps; import de.bstly.board.model.support.Types; +import jakarta.persistence.FetchType; /** * The Class LocalUser. @@ -41,12 +39,11 @@ public class LocalUser { @JsonIgnore @Column(name = "password_hash", nullable = true) private String passwordHash; - @ElementCollection - @LazyCollection(LazyCollectionOption.FALSE) + @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "users_roles") private List roles; @Lob - @Column(name = "about", nullable = true) + @Column(name = "about", nullable = true, length = 100000) private String about; @Column(name = "email", nullable = true) private String email; @@ -54,8 +51,7 @@ public class LocalUser { private String locale; @Column(name = "dark_theme", columnDefinition = "boolean default false") private boolean darkTheme; - @ElementCollection - @LazyCollection(LazyCollectionOption.FALSE) + @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "users_settings") private Map settings; @Transient diff --git a/src/main/java/de/bstly/board/model/PersistentLogin.java b/src/main/java/de/bstly/board/model/PersistentLogin.java index 2582513..99c5f69 100644 --- a/src/main/java/de/bstly/board/model/PersistentLogin.java +++ b/src/main/java/de/bstly/board/model/PersistentLogin.java @@ -5,10 +5,10 @@ package de.bstly.board.model; import java.time.Instant; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; /** * The Class PersistentLogin. diff --git a/src/main/java/de/bstly/board/model/Tag.java b/src/main/java/de/bstly/board/model/Tag.java index 9169948..0c2120a 100644 --- a/src/main/java/de/bstly/board/model/Tag.java +++ b/src/main/java/de/bstly/board/model/Tag.java @@ -5,11 +5,11 @@ package de.bstly.board.model; import java.io.Serializable; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.IdClass; +import jakarta.persistence.Table; /** * The Class Tag. diff --git a/src/main/java/de/bstly/board/model/View.java b/src/main/java/de/bstly/board/model/View.java index cbde5b9..f77f695 100644 --- a/src/main/java/de/bstly/board/model/View.java +++ b/src/main/java/de/bstly/board/model/View.java @@ -5,24 +5,22 @@ package de.bstly.board.model; import java.util.List; -import javax.persistence.CollectionTable; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import de.bstly.board.model.support.EntryType; import de.bstly.board.model.support.ViewSorting; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; /** * The Class View. @@ -45,12 +43,10 @@ public class View { private ViewSorting sorting; @Column(name = "indexNumber") private int index = 99; - @ElementCollection - @LazyCollection(LazyCollectionOption.FALSE) + @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "views_tags") private List tags; - @ElementCollection - @LazyCollection(LazyCollectionOption.FALSE) + @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "views_excluded_tags") private List excludedTags; @Column(name = "entry_type", nullable = true) diff --git a/src/main/java/de/bstly/board/model/Vote.java b/src/main/java/de/bstly/board/model/Vote.java index 130a4c9..fe4da70 100644 --- a/src/main/java/de/bstly/board/model/Vote.java +++ b/src/main/java/de/bstly/board/model/Vote.java @@ -3,13 +3,13 @@ */ package de.bstly.board.model; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import org.springframework.data.jpa.domain.support.AuditingEntityListener; diff --git a/src/main/java/de/bstly/board/security/LocalRememberMeServices.java b/src/main/java/de/bstly/board/security/LocalRememberMeServices.java index 2ee48ff..eb19b44 100644 --- a/src/main/java/de/bstly/board/security/LocalRememberMeServices.java +++ b/src/main/java/de/bstly/board/security/LocalRememberMeServices.java @@ -3,7 +3,7 @@ */ package de.bstly.board.security; -import javax.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequest; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices; diff --git a/src/main/java/de/bstly/board/security/OAuth2AuthenticationSuccessHandler.java b/src/main/java/de/bstly/board/security/OAuth2AuthenticationSuccessHandler.java index 49222a2..80e0aef 100644 --- a/src/main/java/de/bstly/board/security/OAuth2AuthenticationSuccessHandler.java +++ b/src/main/java/de/bstly/board/security/OAuth2AuthenticationSuccessHandler.java @@ -6,9 +6,9 @@ package de.bstly.board.security; import java.io.IOException; import java.util.List; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; diff --git a/src/main/java/de/bstly/board/security/SecurityConfig.java b/src/main/java/de/bstly/board/security/SecurityConfig.java index dc124ce..c487cb4 100755 --- a/src/main/java/de/bstly/board/security/SecurityConfig.java +++ b/src/main/java/de/bstly/board/security/SecurityConfig.java @@ -10,8 +10,9 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.crypto.argon2.Argon2PasswordEncoder; @@ -36,7 +37,8 @@ import de.bstly.board.businesslogic.UserManager; * The Class SecurityConfig. */ @EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled = true) +@EnableMethodSecurity(prePostEnabled = true) +@Configuration public class SecurityConfig { @Autowired @@ -65,28 +67,27 @@ public class SecurityConfig { http // crsf - .csrf().disable() + .csrf((csrf) -> csrf.disable()) // cors // .cors().configurationSource(corsConfigurationSource()).and() // anonymous - .anonymous().disable() + .anonymous((anonymous) -> anonymous.disable()) // login - .formLogin().loginPage("/login").defaultSuccessUrl(loginTargetUrl) - .failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?error")).and() + .formLogin((formLogin) -> formLogin.loginPage("/login").defaultSuccessUrl(loginTargetUrl) + .failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?error"))) // remember me - .rememberMe().rememberMeServices(rememberMeServices()).and() + .rememberMe((rememberMe) -> rememberMe.rememberMeServices(rememberMeServices())) // logout - .logout().logoutUrl("/logout") - .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)).and() + .logout((logout) -> logout.logoutUrl("/logout") + .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK))) // exception - .exceptionHandling() - .defaultAuthenticationEntryPointFor(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED), - new AntPathRequestMatcher("/api/**")) - .and() + .exceptionHandling((exceptionHandling) -> exceptionHandling + .defaultAuthenticationEntryPointFor(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED), + new AntPathRequestMatcher("/api/**"))) // oidc - .oauth2Login().successHandler(oAuth2AuthenticationSuccessHandler) - .failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?externalError")) - .loginPage("/login"); + .oauth2Login((oauth2Login) -> oauth2Login.successHandler(oAuth2AuthenticationSuccessHandler) + .failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?externalError")) + .loginPage("/login")); return http.build(); } @@ -98,7 +99,7 @@ public class SecurityConfig { */ @Bean(name = "passwordEncoder") public Argon2PasswordEncoder passwordEncoder() { - return new Argon2PasswordEncoder(); + return Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8(); } /**