Added forum system

This commit is contained in:
redtea committed 2022-08-30 13:01:42 +03:00
1 parent 0d6fce8c48
commit e49c871fd3
13 files changed
+304 -77

No files matched your search

@@ -1,7 +1,8 @@
package site.easystartup.web.service;
import lombok.RequiredArgsConstructor;
import org.hibernate.query.criteria.internal.predicate.PredicateImplementor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import site.easystartup.web.domain.User;
@@ -21,4 +22,12 @@ public class UserService {
public User getUserById(Long userId) {
return userRepo.findById(userId).orElseThrow(() -> new UsernameNotFoundException("User not found"));
}
public User getCurrentUser() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if(auth.isAuthenticated()) throw new UserNotAuthenticatedException();
org.springframework.security.core.userdetails.User user = (org.springframework.security.core.userdetails.User)
auth.getPrincipal();
return userRepo.findByUsername(user.getUsername());
}
}