深大统一身份认证平台使用了Jasig Central Authentication Service 3.5.2.1这个 CAS 平台。CAS,全称 Central Authentication Service,是一种比较不错的的单点登录服务框架。使用像 CAS 这样单点登录(Single Sign On, 简称 SSO)方案时,用户只需要登录一次即可访问所有相互信任的系统(比如深大内的各种站点)。
CAS的基本验证原理如图所示:
通过原理图可知,浏览器访问一个使用了 CAS 服务的页面(CAS Client,如BlackBoard)后,将会被重定向至 CAS 验证页面(CAS Server,如深大的统一身份认证平台)进行用户认证。当用户验证成功后,浏览器将获得一条唯一且不可伪造的 Ticket。然后 CAS Server 页面将浏览器重定向回 CAS Client 页面,浏览器紧接提交获得的Ticket给 Client页面,Client 页面接收到Ticket后,从后台验证该Ticket的合法性。验证通过后将自动跳转到登录后的页面,并返回相关的身份信息。
/** * Created by wjw_w on 2017/4/13. */ publicclassMyX509TrustManagerimplementsX509TrustManager{ /* * The default X509TrustManager returned by SunX509. We'll delegate * decisions to it, and fall back to the logic in this class if the * default X509TrustManager doesn't trust it. */ X509TrustManager sunJSSEX509TrustManager;
MyX509TrustManager() throws Exception { // create a "default" JSSE X509TrustManager. KeyStore ks = KeyStore.getInstance("JKS"); //不需要load,因为这个是假的,是特技 //ks.load(new FileInputStream("trustedCerts"), // "passphrase".toCharArray()); TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509", "SunJSSE"); tmf.init(ks); TrustManager tms[] = tmf.getTrustManagers(); /* * Iterate over the returned trustmanagers, look * for an instance of X509TrustManager. If found, * use that as our "default" trust manager. */ for (int i = 0; i < tms.length; i++) { if (tms[i] instanceof X509TrustManager) { sunJSSEX509TrustManager = (X509TrustManager) tms[i]; return; } } /* * Find some other way to initialize, or else we have to fail the * constructor. */ thrownew Exception("Couldn't initialize"); }
/* * Delegate to the default trust manager. */ publicvoidcheckClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { try { sunJSSEX509TrustManager.checkClientTrusted(chain, authType); } catch (CertificateException excep) { // do any special handling here, or rethrow exception. } }
/* * Delegate to the default trust manager. */ publicvoidcheckServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { try { sunJSSEX509TrustManager.checkServerTrusted(chain, authType); } catch (CertificateException excep) { /* * Possibly pop up a dialog box asking whether to trust the * cert chain. */ } }
/* * Merely pass this through. */ public X509Certificate[] getAcceptedIssuers() { return sunJSSEX509TrustManager.getAcceptedIssuers(); } }