package com.blade.security.web.xss;

import com.blade.mvc.http.Response;
import lombok.*;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;

/**
 * @author biezhi
 * @date 2018/6/11
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class XssOption {

    static final Consumer<Response> DEFAULT_ERROR_HANDLER = response -> response.badRequest().text("XSS token mismatch.");

    @Builder.Default
    private Consumer<Response> errorHandler = DEFAULT_ERROR_HANDLER;

    @Builder.Default
    private Set<String> urlExclusions = new HashSet<>();

    public XssOption exclusion(@NonNull String... urls) {
        this.urlExclusions.addAll(Arrays.asList(urls));
        return this;
    }

    public boolean isExclusion(@NonNull String url) {
        for (String excludeURL : this.urlExclusions) {
            if (url.equals(excludeURL)) {
                return true;
            }
        }
        return false;
    }

}

@@ -34,44 +34,8 @@
 s;%0A%0A
-import com.blade.mvc.http.Response;%0A
 impo
@@ -47,16 +47,16 @@
 mbok.*;%0A
+
 %0Aimport 
@@ -124,44 +124,8 @@
 Set;
-%0Aimport java.util.function.Consumer;
 %0A%0A/*
@@ -221,16 +221,16 @@
 tructor%0A
+
 public c
@@ -251,223 +251,8 @@
  %7B%0A%0A
-    static final Consumer%3CResponse%3E DEFAULT_ERROR_HANDLER = response -%3E response.badRequest().text(%22XSS token mismatch.%22);%0A%0A    @Builder.Default%0A    private Consumer%3CResponse%3E errorHandler = DEFAULT_ERROR_HANDLER;%0A%0A
     

add xss middleware