SecurityConfig.java
package se.jobtechdev.personaldatagateway.api.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Component;
import se.jobtechdev.personaldatagateway.api.exception.EndpointSecurityParseException;
import se.jobtechdev.personaldatagateway.api.security.RequestMethodPattern;
import java.io.IOException;
import java.util.List;
@Component
public class SecurityConfig {
public static List<RequestMethodPattern> readEndpointSecurityJson() throws IOException {
try (var is =
SecurityConfig.class.getClassLoader().getResourceAsStream("endpointSecurity.json")) {
final var mapper = new ObjectMapper();
return List.of(mapper.readValue(is, RequestMethodPattern[].class));
}
}
public List<RequestMethodPattern> getMethodPatterns() {
try {
return SecurityConfig.readEndpointSecurityJson();
} catch (IOException e) {
throw new EndpointSecurityParseException(e);
}
}
}