Skip to content

Commit

Permalink
VIC-35: Make all data accessible per tenant
Browse files Browse the repository at this point in the history
add forward origin headers
  • Loading branch information
adnanalicic committed Feb 3, 2022
1 parent 381405a commit e354ac2
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
import de.caritas.cob.agencyservice.consultingtypeservice.generated.ApiClient;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.ConsultingTypeControllerApi;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import java.util.Collections;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
* Service class to communicate with the ConsultingTypeService.
Expand Down Expand Up @@ -36,6 +42,26 @@ public ExtendedConsultingTypeResponseDTO getExtendedConsultingTypeResponseDTO(

private void addDefaultHeaders(ApiClient apiClient) {
var headers = this.securityHeaderSupplier.getCsrfHttpHeaders();
addOriginHeader(headers);
headers.forEach((key, value) -> apiClient.addDefaultHeader(key, value.iterator().next()));
}

private void addOriginHeader(HttpHeaders headers) {
String originHeaderValue = getOriginHeaderValue();
if (originHeaderValue != null) {
headers.add("origin", originHeaderValue);
}
}

private String getOriginHeaderValue() {
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
.getRequest();

return Collections.list(request.getHeaderNames())
.stream()
.collect(Collectors.toMap(h -> h, request::getHeader)).get("host");
}


}

0 comments on commit e354ac2

Please sign in to comment.