<commit_before>package com.whenling.castle.security;

import javax.servlet.ServletContext;

import org.springframework.core.annotation.Order;
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.filter.RequestContextFilter;

import com.whenling.castle.core.CastleConstants;
import com.whenling.castle.core.StaticConfigSupplier;
import com.whenling.castle.security.captcha.CaptchaConfigBean;

@Order(-10)
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {

	@Override
	protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
		super.beforeSpringSecurityFilterChain(servletContext);

		Boolean captchaEnabled = StaticConfigSupplier.getConfiguration().getBoolean("captcha.enabled", true);
		if (captchaEnabled) {
			String[] urlPatterns = StaticConfigSupplier.getConfiguration().getStringArray("captcha.urlPatterns");
			if (urlPatterns == null || urlPatterns.length == 0) {
				urlPatterns = new String[] { "/login", "/forgotPassword" };
			}

			DelegatingFilterProxy captchaFilter = new DelegatingFilterProxy(CaptchaConfigBean.CAPTCHA_FILTER_NAME);
			insertFilters(servletContext, captchaFilter);
		}

		insertFilters(servletContext, new RequestContextFilter(), new CharacterEncodingFilter(CastleConstants.characterEncoding, true));
	}

	@Override
	protected void afterSpringSecurityFilterChain(ServletContext servletContext) {
		super.afterSpringSecurityFilterChain(servletContext);

	}

}<commit_msg>captcha<commit_after>package com.whenling.castle.security;

import javax.servlet.FilterRegistration.Dynamic;
import javax.servlet.ServletContext;

import org.springframework.core.annotation.Order;
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.filter.RequestContextFilter;

import com.whenling.castle.core.CastleConstants;
import com.whenling.castle.core.StaticConfigSupplier;
import com.whenling.castle.security.captcha.CaptchaConfigBean;

@Order(-10)
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {

	@Override
	protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
		super.beforeSpringSecurityFilterChain(servletContext);

		Boolean captchaEnabled = StaticConfigSupplier.getConfiguration().getBoolean("captcha.enabled", true);
		if (captchaEnabled) {
			String[] urlPatterns = StaticConfigSupplier.getConfiguration().getStringArray("captcha.urlPatterns");
			if (urlPatterns == null || urlPatterns.length == 0) {
				urlPatterns = new String[] { "/login", "/forgotPassword" };
			}
			
			DelegatingFilterProxy captchaFilter = new DelegatingFilterProxy(CaptchaConfigBean.CAPTCHA_FILTER_NAME);
			Dynamic captchaRegistration = servletContext.addFilter(CaptchaConfigBean.CAPTCHA_FILTER_NAME, captchaFilter);
			captchaRegistration.setAsyncSupported(isAsyncSecuritySupported());
			captchaRegistration.addMappingForUrlPatterns(getSecurityDispatcherTypes(), false, urlPatterns);
		}

		insertFilters(servletContext, new RequestContextFilter(), new CharacterEncodingFilter(CastleConstants.characterEncoding, true));
	}

	@Override
	protected void afterSpringSecurityFilterChain(ServletContext servletContext) {
		super.afterSpringSecurityFilterChain(servletContext);

	}

}
{'fraction_non_alphanumeric': 0.08824343015214385, 'fraction_numerical': 0.0016597510373443983, 'mean_word_length': 7.9950248756218905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6749700', 'n_tokens_mistral': 1009, 'n_tokens_neox': 931, 'n_words': 146}