CAS登入添加手机验证码

时间:2022-03-14 21:09:12

(1):casLoginView.jsp  添加如下信息


1
2
3
4
5
6
7
8
9
10
11
12
13
14
< view-state  id = "viewLoginForm"  view = "casLoginView"  model = "credentials" >
     < binder >
         < binding  property = "username"  />
         < binding  property = "password"  />
         <binding property="captcha" /> 
     </ binder >
     < on-entry >
         < set  name = "viewScope.commandName"  value = "'credentials'"  />
     </ on-entry >
     < transition  on = "submit"  bind = "true"  validate = "true"  to = "realSubmit" >
         < evaluate
             expression = "authenticationViaFormAction.doBind(flowRequestContext, flowScope.credentials)"  />
     </ transition >
</ view-state >

(2):casLoginView.jsp 添加如下信息


1
2
3
4
5
6
7
8
9
< div  class = "log_input_box" >
     < span  class = "log_tit" >动态码</ span >
     < div  class = "login_box_input"  style = "padding:0px;" >
         < input  tabindex = "3"  type = "text"  id = "captcha"  name = "captcha"  autocomplete = "off"  class = "login_box_input"  placeholder = "请输入动态码"  style = "width:120px;border:none;margin-right:9px;" >
         < span  style = "float:left;" >|</ span >
         < a  href = "javascript:;"  class = "log_btn_01"  style = "float:left;"  id = "getPhoneCode"  onclick = "javascript:getPhoneCode();" >获取动态码</ a >
         < span  id = "timeShow"  style = "float:left;display:none;backgronclick=" javascript:submitInfo();"ound-color:rgba(222, 222, 222, 1)!important;color:rgba(102, 102, 102, 1)!important;"  class = "log_btn_01" ></ span >
     </ div >
</ div >

(3):UsernamePasswordCredentials 添加captcha字段,


1
2
3
     @NotNull
     @Size (min= 1 ,message =  "required.captcha" )
     private  String captcha;

             在  equals 和 hashCode 添加判断条件


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
     @Override
     public  boolean  equals( final  Object o) {
         if  ( this  == o)  return  true ;
         if  (o ==  null  || getClass() != o.getClass())  return  false ;
 
         UsernamePasswordCredentials that = (UsernamePasswordCredentials) o;
 
         if  (password !=  null  ? !password.equals(that.password) : that.password !=  null return  false ;
         if  (username !=  null  ? !username.equals(that.username) : that.username !=  null return  false ;
         if  (captcha !=  null  ? !captcha.equals(that.captcha) : that.captcha !=  null return  false ;  
         return  true ;
     }
 
     @Override
     public  int  hashCode() {
         int  result = username !=  null  ? username.hashCode() :  0 ;
         result =  31  * result + (password !=  null  ? password.hashCode() :  0 );
         result =  31  * result + (captcha !=  null  ? captcha.hashCode() :  0 );
         return  result;
     }


(4):根据配置文件的Class 重写 类


1
2
3
4
5
6
7
8
9
<bean id= "primaryAuthenticationHandler"  class = "org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler" >
     <property name= "dataSource"  ref= "dataSource"  ></property>
     <property name= "sql"  value= "select apassword from sys_t_user where del_flag='0' and alogin_name=?"  ></property>
     <property name= "passwordEncoder"  ref= "MD5PasswordEncoder"  ></property>              
</bean>
<bean id= "secondaryAuthenticationHandler"  class = "com.unknow.cas.server.web.flow.QueryDatabaseAuthenticationWithUsernameHandler" >
     <property name= "dataSource"  ref= "dataSource"  ></property>
     <property name= "sql"  value= "select apassword from sys_t_user where del_flag='0' and alogin_name=?"  ></property>
</bean>


重写 QueryDatabaseAuthenticationWithUsernameHandler



AuthenticationManagerImpl extends AbstractAuthenticationManager


AbstractAuthenticationManager extends AuthenticationManager


问题:

(1):UsernamePasswordCredentialsToPrincipalResolver 与Credentials 如何关联

(2):什么时候调用 UsernameOnlyCredentialsToPrincipalResolver