mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-11-16 01:21:16 +01:00
missed class from previous merge
This commit is contained in:
parent
de05d38a47
commit
abbfde0756
@ -2,13 +2,14 @@ package stirling.software.SPDF.service.pdfjson;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import stirling.software.common.service.UserServiceInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to manage job ownership and access control for PDF JSON operations. When security is
|
* Service to manage job ownership and access control for PDF JSON operations. When security is
|
||||||
* enabled, jobs are scoped to authenticated users. When security is disabled, jobs are globally
|
* enabled, jobs are scoped to authenticated users. When security is disabled, jobs are globally
|
||||||
@ -20,23 +21,28 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
public class JobOwnershipServiceImpl
|
public class JobOwnershipServiceImpl
|
||||||
implements stirling.software.common.service.JobOwnershipService {
|
implements stirling.software.common.service.JobOwnershipService {
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private UserServiceInterface userService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current authenticated user's identifier. Returns empty if no user is authenticated.
|
* Get the current authenticated user's identifier. Returns empty if no user is authenticated.
|
||||||
*
|
*
|
||||||
* @return Optional containing user identifier, or empty if not authenticated
|
* @return Optional containing user identifier, or empty if not authenticated
|
||||||
*/
|
*/
|
||||||
public Optional<String> getCurrentUserId() {
|
public Optional<String> getCurrentUserId() {
|
||||||
|
if (userService == null) {
|
||||||
|
log.debug("UserService not available");
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
String username = userService.getCurrentUsername();
|
||||||
if (authentication != null
|
if (username != null && !username.isEmpty() && !"anonymousUser".equals(username)) {
|
||||||
&& authentication.isAuthenticated()
|
|
||||||
&& !"anonymousUser".equals(authentication.getPrincipal())) {
|
|
||||||
String username = authentication.getName();
|
|
||||||
log.debug("Current authenticated user: {}", username);
|
log.debug("Current authenticated user: {}", username);
|
||||||
return Optional.of(username);
|
return Optional.of(username);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Failed to get current user from security context: {}", e.getMessage());
|
log.warn("Failed to get current username from UserService: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user