captcha fix
use config/kaptcha.properties
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
package org.maxkey;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
|
||||
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
|
||||
import org.maxkey.authz.oauth2.provider.endpoint.TokenEndpointAuthenticationFilter;
|
||||
import org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler;
|
||||
import org.maxkey.crypto.password.PasswordReciprocal;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
|
||||
@@ -15,12 +22,19 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import com.google.code.kaptcha.Producer;
|
||||
import com.google.code.kaptcha.impl.DefaultKaptcha;
|
||||
import com.google.code.kaptcha.util.Config;
|
||||
|
||||
@Configuration
|
||||
@ImportResource(locations = { "classpath:spring/maxkey.xml" })
|
||||
@PropertySource("classpath:/application.properties")
|
||||
public class MaxKeyConfig {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(MaxKeyConfig.class);
|
||||
@Value("${server.port:8080}")
|
||||
private int port;
|
||||
|
||||
@@ -86,5 +100,32 @@ public class MaxKeyConfig {
|
||||
tomcat.addAdditionalTomcatConnectors(connector);
|
||||
return tomcat;
|
||||
}
|
||||
|
||||
@Bean(name = "passwordReciprocal")
|
||||
public PasswordReciprocal passwordReciprocal() {
|
||||
return new PasswordReciprocal();
|
||||
}
|
||||
|
||||
@Bean(name = "savedRequestSuccessHandler")
|
||||
public SavedRequestAwareAuthenticationSuccessHandler SavedRequestAwareAuthenticationSuccessHandler() {
|
||||
return new SavedRequestAwareAuthenticationSuccessHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Captcha Producer Config .
|
||||
* @return Producer
|
||||
* @throws IOException
|
||||
*/
|
||||
@Bean(name = "captchaProducer")
|
||||
public Producer captchaProducer() throws IOException{
|
||||
Resource resource = new ClassPathResource("config/kaptcha.properties");
|
||||
_logger.debug("Kaptcha config file " + resource.getURL());
|
||||
DefaultKaptcha kaptcha=new DefaultKaptcha();
|
||||
Properties properties = new Properties();
|
||||
properties.load(resource.getInputStream());
|
||||
Config config = new Config(properties);
|
||||
kaptcha.setConfig(config);
|
||||
return kaptcha;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
kaptcha.image.width=80
|
||||
kaptcha.image.height=25
|
||||
kaptcha.border=no
|
||||
kaptcha.obscurificator.impl=com.google.code.kaptcha.impl.ShadowGimpy
|
||||
kaptcha.textproducer.font.size=23
|
||||
kaptcha.textproducer.char.string=0123456789
|
||||
kaptcha.textproducer.char.length=4
|
||||
kaptcha.noise.impl=com.google.code.kaptcha.impl.NoNoise
|
||||
#kaptcha.noise.color=white
|
||||
@@ -72,12 +72,6 @@
|
||||
|
||||
<ref bean="localeChangeInterceptor" />
|
||||
</mvc:interceptors>
|
||||
<!--
|
||||
<bean id="remeberMeService" class="org.maxkey.authn.support.rememberme.JdbcRemeberMeService">
|
||||
<constructor-arg ref="jdbcTemplate"/>
|
||||
<property name="validity" value="${config.login.remeberme.validity}"/>
|
||||
</bean>
|
||||
-->
|
||||
|
||||
<bean id="remeberMeService" class="org.maxkey.authn.support.rememberme.InMemoryRemeberMeService">
|
||||
</bean>
|
||||
@@ -88,7 +82,6 @@
|
||||
<property name="issuer" value="MaxKey" />
|
||||
<property name="domain" value="MaxKey.org" />
|
||||
<property name="period" value="30" />
|
||||
|
||||
</bean>
|
||||
|
||||
<bean id="tfaOptAuthn" class="org.maxkey.crypto.password.opt.impl.TimeBasedOtpAuthn">
|
||||
@@ -109,33 +102,6 @@
|
||||
<!-- Authentication Password Encoder Config -->
|
||||
<bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"></bean>
|
||||
|
||||
<bean id="passwordReciprocal" class="org.maxkey.crypto.password.PasswordReciprocal"></bean>
|
||||
|
||||
<!-- Captcha Producer Config -->
|
||||
<bean id="captchaProducer" class="com.google.code.kaptcha.impl.DefaultKaptcha">
|
||||
<property name="config">
|
||||
<bean id="kaptchaConfig" class="com.google.code.kaptcha.util.Config">
|
||||
<constructor-arg type="java.util.Properties">
|
||||
<props>
|
||||
<prop key="kaptcha.image.width">80</prop>
|
||||
<prop key="kaptcha.image.height">25</prop>
|
||||
<prop key="kaptcha.border">no</prop>
|
||||
<prop key="kaptcha.obscurificator.impl">com.google.code.kaptcha.impl.ShadowGimpy</prop>
|
||||
<prop key="kaptcha.textproducer.font.size">23</prop>
|
||||
<prop key="kaptcha.textproducer.char.string">0123456789</prop>
|
||||
<prop key="kaptcha.textproducer.char.length">4</prop>
|
||||
<prop key="kaptcha.noise.impl">com.google.code.kaptcha.impl.NoNoise</prop>
|
||||
<!-- 干扰线
|
||||
<prop key="kaptcha.noise.color">white</prop>
|
||||
-->
|
||||
</props>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="savedRequestSuccessHandler" class="org.maxkey.authn.SavedRequestAwareAuthenticationSuccessHandler"> </bean>
|
||||
|
||||
<!-- LDAP Realm
|
||||
<bean id="authenticationRealm" class="org.maxkey.web.authentication.realm.ldap.LdapAuthenticationRealm">
|
||||
<constructor-arg ref="jdbcTemplate"/>
|
||||
|
||||
@@ -101,9 +101,6 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- View Resolver
|
||||
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/templates/" p:suffix=".jsp" p:order="2" />
|
||||
-->
|
||||
<!-- upload file support -->
|
||||
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
||||
<property name="maxUploadSize" value="4194304" />
|
||||
|
||||
Reference in New Issue
Block a user