Skip to content

Commit 4a02175

Browse files
committed
update csrf allowedMethods code
1 parent 2e542b6 commit 4a02175

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/main/java/org/joychou/WebSecurityConfig.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import org.springframework.security.web.util.matcher.RequestMatcher;
99

1010
import javax.servlet.http.HttpServletRequest;
11-
import java.util.regex.Pattern;
11+
import java.util.Arrays;
12+
import java.util.HashSet;
1213

1314
@EnableWebSecurity
1415
@Configuration
@@ -17,14 +18,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
1718
RequestMatcher csrfRequestMatcher = new RequestMatcher() {
1819

1920
// 配置不需要CSRF校验的请求方式
20-
private Pattern allowedMethods =
21-
Pattern.compile("^(GET|HEAD|TRACE|OPTIONS)$");
21+
private final HashSet<String> allowedMethods = new HashSet<String>(
22+
Arrays.asList("GET", "HEAD", "TRACE", "OPTIONS"));
2223

2324
@Override
2425
public boolean matches(HttpServletRequest request) {
25-
// CSRF disabled on allowedMethod
26-
// false表示不校验csrf
27-
return !(allowedMethods.matcher(request.getMethod()).matches());
26+
// return false表示不校验csrf
27+
return !this.allowedMethods.contains(request.getMethod());
2828
}
2929

3030
};

0 commit comments

Comments
 (0)