求情验证要加时间搓Math.random()才会刷新
<div align="left" style="float: left;"><img height="29px" id="yz" alt="请点击刷新验证码" title="请点击刷新验证码" src="${pageContext.request.contextPath}/system/validate/validateCode.do" onclick="valid()" /></div>
verify.setAttribute('src','${pageContext.request.contextPath}/system/validate/validateCode.do?'+Math.random());
<security:custom-filter before="FORM_LOGIN_FILTER" ref="validateCodeAuthenticationFilter" />//对应验证jsp中的一些关键字
<bean id="validateCodeAuthenticationFilter"
class="com.wondersgroup.employeeBenefits.core.author.util.ValidateCodeAuthenticationFilter">
<property name="postOnly" value="false"></property>
<property name="authenticationSuccessHandler" ref="loginLogAuthenticationSuccessHandler"></property>
<property name="authenticationFailureHandler" ref="simpleUrlAuthenticationFailureHandler"></property>
<property name="authenticationManager" ref="authenticationManager"></property>
</bean>
<bean id="loginLogAuthenticationSuccessHandler"
class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
<property name="defaultTargetUrl" value="/index.do"></property>
</bean>
<bean id="simpleUrlAuthenticationFailureHandler"
class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
<property name="defaultFailureUrl" value="/login.do?error=true"></property>
</bean>
=====================
提示信息
UsernamePasswordAuthenticationFilter认证失败后,抛出的异常信息会写到Session中,key为SPRING_SECURITY_LAST_EXCEPTION,这个是通过国际化写的
可以通过El表达式来获取到异常的信息。
${sessionScope.SPRING_SECURITY_LAST_EXCEPTION.message} 所有的异常回写到这里
异常处理1,全局的异常处理2,ajax回调3,${sessionScope.SPRING_SECURITY_LAST_EXCEPTION.message} 所有的异常回写到这里
<div class="one" align="center">
<span style="azimuth: center;color: red;">${sessionScope.SPRING_SECURITY_LAST_EXCEPTION.message}</span>
</div>
这样,我们就可以在自定义的userDetailsService类中,像SpringSecurity3那样方便的使用国际化资源文件了。
http://kennylee26.iteye.com/blog/1473505
private MessageSourceAccessor messages = SpringMessageSource.getAccessor();
==========================================================
....
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
if (StringUtils.isBlank(username)) {
throw new UsernameNotFoundException(
messages.getMessage("PasswordComparisonAuthenticator.badCredentials"), //异常中用国际化
username);
}
...
}
DaoAuthenticationProvider类//重写,或者标签判断
if (loadedUser == null) {
throw new AuthenticationServiceException(
"UserDetailsService returned null, which is an interface contract violation");///这个才国际化文件找不到
}
这句改为
if (loadedUser == null) {
throw new AuthenticationServiceException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.noUser",""));
}
============================
国际化处理方式
国际化处理有两种处理方式.
1.
在security的配置文件里加入
Java代码 收藏代码
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:org/springframework/security/messages_zh_CN" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver" />
其中
Java代码 收藏代码
classpath:org/springframework/security/messages_zh_CN
表示引用spring-security-core-3.0.5.jar中的messages_zh_CN.properties文件
2.
springsecurity自带的国际化中文配置翻译的不是很准确,需要我们手动更改.
下载springsecurity3的src包后解压出messages_zh_CN.properties文件更改其中的提示信息.
把文件拷贝到src文件夹下(maven项目拷贝到src/main/resource下)
springsecurity配置文件添加:
Java代码 收藏代码
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages_zh_CN" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver" />
登录验证(验证码)
猜你喜欢
转载自yuhuiblog6338999322098842.iteye.com/blog/2249802
今日推荐
周排行