migrate to spring boot 3.2

This commit is contained in:
_Bastler 2023-12-12 21:20:25 +01:00
parent fabd70fe56
commit 7ccdc4de00
24 changed files with 175 additions and 205 deletions

4
.gitignore vendored
View File

@ -6,4 +6,6 @@ target/
hs_err*.log
application.properties
usernames.txt
lucene
lucene
.vscode

48
pom.xml
View File

@ -9,15 +9,16 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
<log4j2.version>2.19.0</log4j2.version>
<revision>1.5.0</revision>
<java.version>17</java.version>
<querydsl.version>5.0.0</querydsl.version>
<hibernate.version>6.4.0.Final</hibernate.version>
<revision>2.0.0</revision>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.6</version>
<version>3.2.0</version>
<relativePath />
</parent>
@ -58,35 +59,39 @@
<artifactId>spring-session-jdbc</artifactId>
</dependency>
<!-- Search -->
<!-- Search -->
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-mapper-orm</artifactId>
<version>6.0.7.Final</version>
<version>7.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-lucene</artifactId>
<version>6.0.7.Final</version>
<version>7.0.0.Final</version>
</dependency>
<!-- Query DSL -->
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version>
<classifier>jakarta</classifier>
</dependency>
<!-- Utils -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.7</version>
<version>1.8.0</version>
</dependency>
<dependency>
@ -97,7 +102,7 @@
<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>owasp-java-html-sanitizer</artifactId>
<version>20200713.1</version>
<version>20220608.1</version>
</dependency>
<dependency>
@ -108,7 +113,13 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.68</version>
<version>1.70</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
@ -175,23 +186,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor
</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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;

View File

@ -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<Entry> 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<Entry>(list, PageRequest.of(page, size), countResult);
}
@ -131,7 +129,7 @@ public class EntryManager {
@SuppressWarnings("unchecked")
List<Entry> 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<Entry>(list, PageRequest.of(page, size), countResult);
}
@ -156,7 +154,7 @@ public class EntryManager {
@SuppressWarnings("unchecked")
List<Entry> 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<Entry>(list, PageRequest.of(page, size), countResult);
}
@ -178,7 +176,7 @@ public class EntryManager {
@SuppressWarnings("unchecked")
List<Entry> 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<Entry>(list, PageRequest.of(page, size), countResult);
}
@ -204,7 +202,7 @@ public class EntryManager {
List<Entry> 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<Entry>(list, PageRequest.of(page, size), countResult);
}

View File

@ -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;

View File

@ -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<ClientRegistration>) 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;
}

View File

@ -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() + "'");
}

View File

@ -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 + "\"" : "");
}
}

View File

@ -9,7 +9,6 @@ import org.springframework.validation.AbstractBindingResult;
/**
* The Class RequestBodyErrors.
*/
@SuppressWarnings("serial")
public class RequestBodyErrors extends AbstractBindingResult {
@Nullable

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
/**

View File

@ -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<Long> entries;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<String> 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<String, String> settings;
@Transient

View File

@ -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.

View File

@ -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.

View File

@ -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<String> tags;
@ElementCollection
@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "views_excluded_tags")
private List<String> excludedTags;
@Column(name = "entry_type", nullable = true)

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();
}
/**