mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-26 05:54:41 +00:00
30 lines
683 B
Java
30 lines
683 B
Java
package com.commafeed.security;
|
|
|
|
import com.commafeed.backend.dao.UserDAO;
|
|
import com.commafeed.backend.model.User;
|
|
|
|
import io.quarkus.security.identity.SecurityIdentity;
|
|
import jakarta.inject.Singleton;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
@RequiredArgsConstructor
|
|
@Singleton
|
|
public class AuthenticationContext {
|
|
|
|
private final SecurityIdentity securityIdentity;
|
|
private final UserDAO userDAO;
|
|
|
|
public User getCurrentUser() {
|
|
if (securityIdentity.isAnonymous()) {
|
|
return null;
|
|
}
|
|
|
|
String userId = securityIdentity.getPrincipal().getName();
|
|
if (userId == null) {
|
|
return null;
|
|
}
|
|
|
|
return userDAO.findById(Long.valueOf(userId));
|
|
}
|
|
}
|