Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cs alert 1 req forgery #1316

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
14 changes: 14 additions & 0 deletions .intelliJ_ddl/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,13 @@ CREATE INDEX flyway_schema_history_s_idx ON public.flyway_schema_history USING b
CREATE INDEX idx_bruker_identer_person ON public.bruker_identer USING btree (person);


--
-- Name: idx_foreldreansvar_barn_ident; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_foreldreansvar_barn_ident ON public.foreldreansvar USING btree (barn_ident);


--
-- Name: idx_freg_ident; Type: INDEX; Schema: public; Owner: -
--
Expand All @@ -1016,6 +1023,13 @@ CREATE INDEX idx_freg_ident ON public.bruker_statsborgerskap USING btree (freg_i
CREATE INDEX idx_gyldig_til ON public.bruker_statsborgerskap USING btree (gyldig_til);


--
-- Name: idx_oppfolging_data_oppfolging; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX idx_oppfolging_data_oppfolging ON public.oppfolging_data USING btree (oppfolging);


--
-- Name: nav_kontor_idx; Type: INDEX; Schema: public; Owner: -
--
Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
<version>3.1.5</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import no.nav.common.rest.client.RestUtils;
import no.nav.common.types.identer.AktorId;
import no.nav.pto.veilarbportefolje.config.EnvironmentProperties;
import no.nav.pto.veilarbportefolje.opensearch.domene.OpensearchClientConfig;
import okhttp3.*;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -45,14 +46,15 @@ public class OpensearchAdminService {
private final OpensearchClientConfig openSearchClientConfig;
private final OkHttpClient httpClient;

private final String opensearchUri;

@Autowired
public OpensearchAdminService(RestHighLevelClient restHighLevelClient, OpensearchClientConfig openSearchClientConfig) {
public OpensearchAdminService(EnvironmentProperties environmentProperties, RestHighLevelClient restHighLevelClient, OpensearchClientConfig openSearchClientConfig) {
this.opensearchUri = environmentProperties.getOpensearchUri();
this.restHighLevelClient = restHighLevelClient;
this.openSearchClientConfig = openSearchClientConfig;

this.httpClient = baseClient();
}

@SneakyThrows
public String opprettNyIndeks() {
return opprettNyIndeks(createIndexName());
Expand Down Expand Up @@ -165,7 +167,6 @@ public String getSettingsOnIndex(String indexName) {
.url(url).get()
.addHeader("Authorization", getAuthHeaderValue(openSearchClientConfig))
.build();

return callAndGetBody(request);
}

Expand Down Expand Up @@ -239,14 +240,24 @@ private String readJsonFromFileStream(InputStream settings) {

@SneakyThrows
private String callAndGetBody(Request request) {
try (Response response = httpClient.newCall(request).execute()) {
RestUtils.throwIfNotSuccessful(response);
try (ResponseBody responseBody = response.body()) {
if (responseBody == null) {
return null;

if (Objects.equals(this.opensearchUri, request.url().uri().toString())) {
log.info("Logger uri OpensearchAdminService callAndGetBody {}", request.url().uri());
try (Response response = httpClient.newCall(request).execute()) {
RestUtils.throwIfNotSuccessful(response);
try (ResponseBody responseBody = response.body()) {
if (responseBody == null) {
return null;
}
return responseBody.string();
}
return responseBody.string();
}
}
} else {
log.error("Feil i uri OpensearchAdminService callAndGetBody {}", request.url().uri());
Response.Builder builder = new Response.Builder();
builder.code(400).message("Illegal URI");
Response responseBadUri = builder.build();
return responseBadUri.toString();
}
}
}

This file was deleted.