test interface
This commit is contained in:
parent
d9b5d08b06
commit
690720f4e3
4 changed files with 35 additions and 1 deletions
|
@ -16,11 +16,12 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import stirling.software.SPDF.controller.api.pipeline.UserServiceInterface;
|
||||
import stirling.software.SPDF.model.Authority;
|
||||
import stirling.software.SPDF.model.User;
|
||||
import stirling.software.SPDF.repository.UserRepository;
|
||||
@Service
|
||||
public class UserService {
|
||||
public class UserService implements UserServiceInterface{
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.zip.ZipOutputStream;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpEntity;
|
||||
|
@ -51,6 +52,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||
import stirling.software.SPDF.model.ApplicationProperties;
|
||||
import stirling.software.SPDF.model.PipelineConfig;
|
||||
import stirling.software.SPDF.model.PipelineOperation;
|
||||
import stirling.software.SPDF.model.Role;
|
||||
import stirling.software.SPDF.model.api.HandleDataRequest;
|
||||
import stirling.software.SPDF.utils.WebResponseUtils;
|
||||
|
||||
|
@ -98,6 +100,12 @@ public class PipelineController {
|
|||
@Autowired
|
||||
ApplicationProperties applicationProperties;
|
||||
|
||||
@Autowired
|
||||
private UserServiceInterface userService;
|
||||
|
||||
private String getApiKeyForUser() {
|
||||
return userService.getApiKeyForUser(Role.INTERNAL_API_USER.getRoleId());
|
||||
}
|
||||
|
||||
private void handleDirectory(Path dir) throws Exception {
|
||||
logger.info("Handling directory: {}", dir);
|
||||
|
@ -292,6 +300,10 @@ public class PipelineController {
|
|||
}
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
String apiKey = getApiKeyForUser();
|
||||
headers.add("X-API-Key", apiKey);
|
||||
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(body, headers);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package stirling.software.SPDF.controller.api.pipeline;
|
||||
public interface UserServiceInterface {
|
||||
// Define methods that you need
|
||||
String getApiKeyForUser(String username);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package stirling.software.SPDF.controller.api.pipeline;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@ConditionalOnProperty(name = "DOCKER_ENABLE_SECURITY", havingValue = "false")
|
||||
public class UserServiceNoOpImpl implements UserServiceInterface {
|
||||
// Implement the methods with no-op
|
||||
@Override
|
||||
public String getApiKeyForUser(String username) {
|
||||
// No-op implementation
|
||||
return "";
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue