免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
CAS單點(diǎn)登錄集成

OpenJWeb應(yīng)用開發(fā)平臺(tái)與CAS的單點(diǎn)登錄產(chǎn)品進(jìn)行了集成, CAS單點(diǎn)登錄產(chǎn)品的默認(rèn)的認(rèn)證類是SimpleTestUsernamePasswordAuthenticationHandler,這個(gè)類的實(shí)現(xiàn)是當(dāng)用戶名和口令相等時(shí)認(rèn)證通過,所以這個(gè)類肯定不能在生產(chǎn)環(huán)境使用的,現(xiàn)在需要將此類替換掉,實(shí)現(xiàn)一個(gè)基于數(shù)據(jù)庫(kù)訪問的認(rèn)證方式.本文講述如何實(shí)現(xiàn)這個(gè)類(數(shù)據(jù)源在tomcat中如何配置從略,我想大家都知道配置方式).

    在CAS的WEB-INF目錄下有個(gè)deployerConfigContext.xml文件,將<bean
     class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />改為

<bean
     class="org.jasig.cas.authentication.handler.support.CasDaoAuthenticationHandler" />

其中CasDaoAuthenticationHandler是我自己開發(fā)的實(shí)現(xiàn)類,代碼如下:

package org.jasig.cas.authentication.handler.support;

import java.sql.Connection;
import java.sql.ResultSet;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
 
import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;

public final class CasDaoAuthenticationHandler extends AbstractUsernamePasswordAuthenticationHandler
{
    public CasDaoAuthenticationHandler()
     {
     }

     public boolean authenticateUsernamePasswordInternal(UsernamePasswordCredentials credentials)
     {
      boolean bool = false;
         String username = credentials.getUsername();
         String password = credentials.getPassword();
         System.out.println("開始CAS認(rèn)證......");
            System.out.println("userName:"+username);
            System.out.println("password:"+password);
         //首先連接權(quán)限數(shù)據(jù)庫(kù)
         try
         {
          DataSource ds = null;
             InitialContext ctx=new InitialContext();
             Context contx = (Context)ctx.lookup("java:comp/env");
             ds = (DataSource) contx.lookup("jdbc/mysql");
             Connection con =  ds.getConnection();
             if(con == null)
             System.out.println("con is null");

             String sql  = "select count(*)  from eas_login_user where  user_id='"+username+"' and user_password='"+password+"'";
             ResultSet res = con.prepareStatement(sql).executeQuery();
             while(res.next())
             {
              int i = Integer.parseInt(res.getObject(1).toString());
              if(i>0)
              {
               System.out.println("認(rèn)證成功!");
               bool = true;
               break;
              }
             }
            con.close();
         }
         catch(Exception ex)
         {
          ex.printStackTrace();
          System.out.println("數(shù)據(jù)庫(kù)連接失敗!");
          return bool;
         }
        
         return bool;
     }

     protected void afterPropertiesSetInternal()
         throws Exception
     {
         super.afterPropertiesSetInternal();
     }

}

上面的代碼是取CAS登錄頁面的用戶名和口令到數(shù)據(jù)庫(kù)檢驗(yàn)是否存在用戶名和口令相同的記錄,當(dāng)然在生產(chǎn)環(huán)境中

用戶口令是加密存儲(chǔ)的,所以實(shí)際應(yīng)用中增加一個(gè)加密算法就可以了.


本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Yale CAS + .net Client 實(shí)現(xiàn) SSO(5)
速動(dòng)畫教程第二十九集 單點(diǎn)登錄CAS的使用方法 - oksonic博客 - BlogJav...
提供JDBC連接
Shiro系列之Shiro+Mysql實(shí)現(xiàn)用戶認(rèn)證(Authentication)
shiro框架學(xué)習(xí)-4- Shiro內(nèi)置JdbcRealm
配置高并發(fā)jdbc連接池
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服