new auth, hot entries

This commit is contained in:
2021-10-05 14:39:49 +02:00
parent e9e9a22719
commit 4a2b8b08bb
13 changed files with 279 additions and 107 deletions
@@ -44,9 +44,9 @@ public class BookmarksManager {
/**
* Checks for entry.
*
*
* @param username the username
* @param entryId the entry id
* @param entryId the entry id
* @return true, if successful
*/
public boolean hasEntry(String username, Long entryId) {
@@ -58,7 +58,7 @@ public class BookmarksManager {
* Adds the entry.
*
* @param username the username
* @param entryId the entry id
* @param entryId the entry id
*/
public void addEntry(String username, Long entryId) {
Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid");
@@ -80,7 +80,7 @@ public class BookmarksManager {
* Removes the entry.
*
* @param username the username
* @param entryId the entry id
* @param entryId the entry id
*/
public void removeEntry(String username, Long entryId) {
Assert.isTrue(entryRepository.existsById(entryId), "Invalid entryid");
@@ -45,12 +45,12 @@ public class CommentManager {
/**
* Fetch by ranking.
*
* @param target the target
* @param parent the parent
* @param date the date
* @param target the target
* @param parent the parent
* @param date the date
* @param gravity the gravity
* @param page the page
* @param size the size
* @param page the page
* @param size the size
* @return the page
*/
@@ -70,10 +70,10 @@ public class CommentManager {
*
* @param target the target
* @param parent the parent
* @param date the date
* @param page the page
* @param size the size
* @param desc the desc
* @param date the date
* @param page the page
* @param size the size
* @param desc the desc
* @return the page
*/
public Page<Comment> fetchByDate(Long target, Long parent, Instant date, int page, int size,
@@ -95,11 +95,11 @@ public class CommentManager {
* Fetch by username.
*
* @param username the username
* @param orElse the or else
* @param date the date
* @param page the page
* @param size the size
* @param asc the asc
* @param orElse the or else
* @param date the date
* @param page the page
* @param size the size
* @param asc the asc
* @return the page
*/
public Page<Comment> fetchByUsername(String username, Long orElse, Instant date, int page,
@@ -141,7 +141,8 @@ public class CommentManager {
* Apply metadata.
*
* @param username the username
* @param comment the comment
* @param comment the comment
* @param ignore the ignore
*/
public void applyMetadata(String username, Comment comment, List<String> ignore) {
@@ -192,7 +193,8 @@ public class CommentManager {
* Apply metadata.
*
* @param username the username
* @param entries the entries
* @param entries the entries
* @param ignore the ignore
*/
public void applyMetadata(String username, List<Comment> entries, List<String> ignore) {
for (Comment comment : entries) {
@@ -63,6 +63,19 @@ public class EntryManager {
return entryRepository.findAllByRanking(date, gravity, PageRequest.of(page, size));
}
/**
* Fetch by comments.
*
* @param date the date
* @param gravity the gravity
* @param page the page
* @param size the size
* @return the page
*/
public Page<RankedEntry> fetchByComments(Instant date, double gravity, int page, int size) {
return entryRepository.findAllByComments(date, gravity, PageRequest.of(page, size));
}
/**
* Fetch by date.
*
@@ -116,7 +129,9 @@ public class EntryManager {
* Apply metadata.
*
* @param username the username
* @param karma the karma
* @param entry the entry
* @param ignore the ignore
*/
public void applyMetadata(String username, long karma, Entry entry, List<String> ignore) {
@@ -170,7 +185,9 @@ public class EntryManager {
* Apply metadata.
*
* @param username the username
* @param karma the karma
* @param entries the entries
* @param ignore the ignore
*/
public void applyMetadata(String username, long karma, List<Entry> entries,
List<String> ignore) {
@@ -15,7 +15,6 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -32,6 +31,7 @@ import de.bstly.board.model.QEntry;
import de.bstly.board.model.QLocalUser;
import de.bstly.board.repository.EntryRepository;
import de.bstly.board.repository.LocalUserRepository;
import de.bstly.board.security.LocalUserDetails;
/**
* The Class UserManager.
@@ -43,22 +43,19 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
@Autowired
private LocalUserRepository localUserRepository;
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private EntryManager entryManager;
@Autowired
private EntryRepository entryRepository;
private QLocalUser qLocalUser = QLocalUser.localUser;
private QEntry qEntry = QEntry.entry;
@Value("${admin.password:}")
private String adminPassword;
@Value("${bstly.board.ranking.gravity:1.2}")
private double GRAVITY;
/*
* @see org.springframework.security.core.userdetails.UserDetailsService#
@@ -76,6 +73,9 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* @see org.springframework.security.core.userdetails.UserDetailsService#
* loadUserByUsername(java.lang.String)
*/
/*
* @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
*/
/*
* @see
* de.bstly.board.businesslogic.LocalUserManager#loadUserByUsername(java.lang.
@@ -102,7 +102,20 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
passwordHash = "";
}
return new User(username, passwordHash, authorities);
LocalUserDetails userDetails = new LocalUserDetails(username, passwordHash, authorities);
userDetails.setGravity(GRAVITY);
if (localUser.getSettings().containsKey("gravity")) {
try {
userDetails.setGravity(Double.parseDouble(localUser.getSettings().get("gravity")));
} catch (Exception e) {
}
}
userDetails.setKarma(getKarma(username));
return userDetails;
}
/*
@@ -121,6 +134,9 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* @see org.springframework.beans.factory.SmartInitializingSingleton#
* afterSingletonsInstantiated()
*/
/*
* @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
*/
/*
*
* @see org.springframework.beans.factory.SmartInitializingSingleton#
@@ -156,7 +172,7 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
/**
* Gets the by external id.
*
*
* @param externalId the external id
* @return the by external id
*/
@@ -231,7 +247,7 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
* Apply metadata.
*
* @param username the username
* @param user the user
* @param user the user
*/
public void applyMetadata(String username, LocalUser user) {
if (user.getUsername().equalsIgnoreCase(username)
@@ -245,9 +261,10 @@ public class UserManager implements UserDetailsService, SmartInitializingSinglet
}
/**
*
* @param username
* @return
* Gets the karma.
*
* @param username the username
* @return the karma
*/
public long getKarma(String username) {
long karma = 0;