Skip to content
Snippets Groups Projects
Unverified Commit 273b26ce authored by Matej Hrica's avatar Matej Hrica
Browse files

Pass auth header to api in report

parent 92f43085
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -6,13 +6,19 @@ import java.util.List;
import java.util.Map;
import cz.muni.fi.pa165.core.client.*;
import cz.muni.fi.pa165.core.client.invoker.ApiClient;
import cz.muni.fi.pa165.core.client.invoker.ApiException;
import cz.muni.fi.pa165.core.client.model.*;
import cz.muni.fi.pa165.report.server.ReportType;
import cz.muni.fi.pa165.report.server.exceptions.ResourceNotFoundException;
import cz.muni.fi.pa165.report.server.service.ReportDocumentService;
import cz.muni.fi.pa165.user.client.UserApi;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.core.OAuth2AccessToken;
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthentication;
import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionAuthenticatedPrincipal;
import org.springframework.stereotype.Service;
@Service
......@@ -26,15 +32,28 @@ public class ReportFacadeImpl implements ReportFacade{
this.documentData = new HashMap<>();
}
ApiClient getApiClient() {
var client = new ApiClient();
client.setRequestInterceptor((builder -> {
var authentication = SecurityContextHolder.getContext().getAuthentication();
var authPrincipal = (OAuth2IntrospectionAuthenticatedPrincipal) authentication.getPrincipal();
var token = (OAuth2AccessToken) (((BearerTokenAuthentication) authentication).getToken());
builder.header("Authorization", "Bearer " + token.getTokenValue());
}));
return client;
}
@Override
public Resource getReportAirportById(Long id){
AirportDto airport;
CityDto cityDto;
CountryDto countryDto;
CountryApi countryApi = new CountryApi();
CityApi cityApi = new CityApi();
AirportApi airportApi = new AirportApi();
var client = getApiClient();
CountryApi countryApi = new CountryApi(client);
CityApi cityApi = new CityApi(client);
AirportApi airportApi = new AirportApi(client);
List<String> airportData = new ArrayList<>();
List<String> cityData = new ArrayList<>();
......@@ -68,11 +87,11 @@ public class ReportFacadeImpl implements ReportFacade{
@Override
public Resource getReportFlightById(Long id){
FlightApi flightApi = new FlightApi();
StewardApi stewardApi = new StewardApi();
AirplaneApi airplaneApi = new AirplaneApi();
AirportApi airportApi = new AirportApi();
var client = getApiClient();
FlightApi flightApi = new FlightApi(client);
StewardApi stewardApi = new StewardApi(client);
AirplaneApi airplaneApi = new AirplaneApi(client);
AirportApi airportApi = new AirportApi(client);
AirplaneDto airplaneDto;
AirportDto arrivalAirportDto;
AirportDto departureAirportDto;
......@@ -129,9 +148,9 @@ public class ReportFacadeImpl implements ReportFacade{
@Override
public Resource getReportAirplaneById(Long id){
AirplaneApi airplaneApi = new AirplaneApi();
AirplaneTypeApi airplaneTypeApi = new AirplaneTypeApi();
var client = getApiClient();
AirplaneApi airplaneApi = new AirplaneApi(client);
AirplaneTypeApi airplaneTypeApi = new AirplaneTypeApi(client);
AirplaneTypeDto airplaneTypeDto;
AirplaneDto airplane;
List<String> airplaneData = new ArrayList<>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment