Extract String to Set transformation.
This commit is contained in:
@ -2,10 +2,10 @@ package ch.psi.daq.queryrest.filter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -24,17 +24,18 @@ public class CorsFilter extends OncePerRequestFilter {
|
||||
@Value("${queryrest.cors.forceallheaders}")
|
||||
private boolean forceAllHeaders;
|
||||
|
||||
private Set<String> allowedOrigins;
|
||||
|
||||
@PostConstruct
|
||||
public void afterPropertiesSet(){
|
||||
allowedOrigins = Arrays.stream(configuredOrigins.split(","))
|
||||
.map(s -> s.trim())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
|
||||
Set<String> allowedOrigins = new HashSet<String>(Arrays.asList(configuredOrigins.split(","))
|
||||
.stream()
|
||||
.map(s -> {
|
||||
return s.trim(); })
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
throws ServletException, IOException {
|
||||
String originHeader = request.getHeader("Origin");
|
||||
if (forceAllHeaders) {
|
||||
// include headers no matter what - good for development
|
||||
|
Reference in New Issue
Block a user