Commit f78e1cd5 authored by Denis's avatar Denis Committed by Denis Ligin

Security issue fix

parent 6c420f34
Pipeline #372 canceled with stage
...@@ -47,6 +47,7 @@ public class SecurityConfiguration { ...@@ -47,6 +47,7 @@ public class SecurityConfiguration {
http.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS)); http.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
http.csrf(AbstractHttpConfigurer::disable); http.csrf(AbstractHttpConfigurer::disable);
http.anonymous(AbstractHttpConfigurer::disable);
http.exceptionHandling(eh -> eh.authenticationEntryPoint((request, response, authException) -> { http.exceptionHandling(eh -> eh.authenticationEntryPoint((request, response, authException) -> {
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, "Bearer realm=\"Restricted Content\""); response.addHeader(HttpHeaders.WWW_AUTHENTICATE, "Bearer realm=\"Restricted Content\"");
...@@ -57,9 +58,7 @@ public class SecurityConfiguration { ...@@ -57,9 +58,7 @@ public class SecurityConfiguration {
.requestMatchers("/actuator/health/readiness", .requestMatchers("/actuator/health/readiness",
"/actuator/health/liveness", "/actuator/health/liveness",
"/api-docs/**", "/api-docs/**",
"/swagger-ui/**", "/swagger-ui/**"
BASE_PATH + TemplateController.GET_TEMPLATE,
DTemplateTypeController.BASE_PATH+DTemplateTypeController.GET_ALL
) )
.permitAll() .permitAll()
...@@ -93,7 +92,13 @@ public class SecurityConfiguration { ...@@ -93,7 +92,13 @@ public class SecurityConfiguration {
.requestMatchers(GitlabTemplateController.EDIT) .requestMatchers(GitlabTemplateController.EDIT)
.hasAnyRole(EDITOR, ADMIN) .hasAnyRole(EDITOR, ADMIN)
.anyRequest().authenticated() .requestMatchers(
BASE_PATH + TemplateController.GET_TEMPLATE,
DTemplateTypeController.BASE_PATH + DTemplateTypeController.GET_ALL)
.permitAll()
.anyRequest().fullyAuthenticated()
); );
......
...@@ -2,6 +2,7 @@ package kz.project.printedFormsService.service.impl; ...@@ -2,6 +2,7 @@ package kz.project.printedFormsService.service.impl;
import kz.project.printedFormsService.data.dto.GitlabMultipartFile; import kz.project.printedFormsService.data.dto.GitlabMultipartFile;
import kz.project.printedFormsService.service.GitlabClient; import kz.project.printedFormsService.service.GitlabClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -11,6 +12,7 @@ import reactor.core.publisher.Mono; ...@@ -11,6 +12,7 @@ import reactor.core.publisher.Mono;
import java.io.File; import java.io.File;
@Service @Service
@Slf4j
public class GitlabClientImpl implements GitlabClient { public class GitlabClientImpl implements GitlabClient {
private final WebClient webClient; private final WebClient webClient;
...@@ -22,7 +24,6 @@ public class GitlabClientImpl implements GitlabClient { ...@@ -22,7 +24,6 @@ public class GitlabClientImpl implements GitlabClient {
.build(); .build();
} }
//http://gitlab.lan.arta.kz/d.ermakov/templates/-/raw/master/dto.txt?inline=false
@Override @Override
public Mono<byte[]> downloadFileFromGitLab(String projectName, String filePath, String branch) { public Mono<byte[]> downloadFileFromGitLab(String projectName, String filePath, String branch) {
String urlPath = String.format("/api/v4/projects/%s/repository/files/%s/raw", projectName, filePath); String urlPath = String.format("/api/v4/projects/%s/repository/files/%s/raw", projectName, filePath);
...@@ -33,7 +34,7 @@ public class GitlabClientImpl implements GitlabClient { ...@@ -33,7 +34,7 @@ public class GitlabClientImpl implements GitlabClient {
.build()) .build())
.retrieve() .retrieve()
.bodyToMono(byte[].class) .bodyToMono(byte[].class)
.doOnError(error -> System.err.println("Error downloading file: " + error.getMessage())); .doOnError(error -> log.error("Error downloading file: {}", error.getMessage()));
} }
@Override @Override
...@@ -46,7 +47,7 @@ public class GitlabClientImpl implements GitlabClient { ...@@ -46,7 +47,7 @@ public class GitlabClientImpl implements GitlabClient {
.build()) .build())
.retrieve() .retrieve()
.bodyToMono(String.class) .bodyToMono(String.class)
.doOnError(error -> System.err.println("Error downloading file: " + error.getMessage())); .doOnError(error -> log.error("Error downloading file: {}", error.getMessage()));
} }
@Override @Override
...@@ -63,7 +64,7 @@ public class GitlabClientImpl implements GitlabClient { ...@@ -63,7 +64,7 @@ public class GitlabClientImpl implements GitlabClient {
File file = new File(filePath); File file = new File(filePath);
return new GitlabMultipartFile(file.getName(), file.getName(), null, bytes); return new GitlabMultipartFile(file.getName(), file.getName(), null, bytes);
}) })
.doOnError(error -> System.err.println("Error downloading file: " + error.getMessage())) .doOnError(error -> log.error("Error downloading file: {}", error.getMessage()))
.block(); .block();
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment