Spring Security中自定义AuthenticationProcessingFilter

<http entry-point-ref="authenticationProcessingFilterEntryPoint">  
        <intercept-url pattern="/admin/**" access="ROLE_ADMIN" />  
        <intercept-url pattern="/user/**" access="ROLE_USER,ROLE_ADMIN" />  
    </http>  
  
    <authentication-provider user-service-ref="securityManager" />  
              
    <beans:bean id="authenticationProcessingFilter" class="com.XXX.security.CustomAuthenticationProcessingFilter">  
        <custom-filter position="AUTHENTICATION_PROCESSING_FILTER" />  
        <beans:property name="authenticationManager" ref="authenticationManager" />  
        <beans:property name="defaultTargetUrl" value="/user/userList.action" />  
    </beans:bean>  
      
    <authentication-manager alias="authenticationManager"/>  
      
    <beans:bean id="authenticationProcessingFilterEntryPoint" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint">    
        <beans:property name="loginFormUrl" value="/login.do" />    
        <beans:property name="forceHttps" value="false" />    
    </beans:bean>   

 

public Authentication attemptAuthentication(  
            HttpServletRequest httpServletRequest)  
            throws AuthenticationException {  
        String check_code = httpServletRequest.getParameter("j_checkcode");  
        String sys_code = (String) httpServletRequest.getSession().getAttribute(checkCodeName);  
  
        if (sys_code == null) {  
            throw new AuthCodeValidationException("验证码不正确");  
        } else if (!sys_code.equals(check_code)) {  
            String username = obtainUsername(httpServletRequest);  
            httpServletRequest.getSession().setAttribute(SPRING_SECURITY_LAST_USERNAME_KEY, username);  
            throw new AuthCodeValidationException("验证码输入不正确");  
        }  
        return super.attemptAuthentication(httpServletRequest);  
    } 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值