乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      CAS干單點(diǎn)登陸(SSO)

       時(shí)間要去哪 2014-06-11
      CAS做單點(diǎn)登陸(SSO)——集成Java Web 項(xiàng)目

      添加cas-client的jar包

      下載cas-client,地址:http://www./downloads/cas-clients/,當(dāng)前最新版本是cas-client-3.2.1-release.zip。然后解壓cas-client-3.2.1-release.zip,在modules拷貝cas-client-core-3.2.1.jar應(yīng)用的WEB-INF/lib目錄中

      撰寫支持CAS集成的客戶化包

      除了在web.xml添加CAS內(nèi)置的filter外(具體看配置web.xml),我們需要撰寫自己支持CAS集成的客戶化包。大致思路如下:

      	@Override
      	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
      		
      		HttpServletRequest request = (HttpServletRequest)servletRequest;
      		HttpServletResponse response = (HttpServletResponse)servletResponse;
      		
      		HttpSession session = request.getSession();
      		//在session中自定義一個(gè)參數(shù),以它來校驗(yàn)是否完成過自動(dòng)登陸
      		Object user_login = session.getAttribute(AURORA_USER_LOGIN);
      		if (user_login != null){
      			//登陸過,就繼續(xù)執(zhí)行其他filter
      			filterChain.doFilter(request, response);
      			return;
      		}
      		//通過CAS的API獲得登陸賬號(hào)
      		String loginName = AssertionHolder.getAssertion().getPrincipal().getName();
      		try {
      			//執(zhí)行本系統(tǒng)的登陸。跟平常同時(shí)校驗(yàn)用戶名和密碼不同,這里只有用戶名。
      			executeLoginProc(request,response,loginName);
      		} catch (Exception e) {
      			logger.log(Level.SEVERE, "executeLoginProc error:", e);
      			return;
      		}
      		//登陸成功
      		session.setAttribute(AURORA_USER_LOGIN, Boolean.TRUE);
      		//跳轉(zhuǎn)到登陸成功后的頁面
      		response.sendRedirect(roleSelectPageUrl);
      	}

      把這個(gè)class打包成一個(gè)jar拷貝到應(yīng)用的WEB-INF/lib目錄中

      如果有興趣,還可以簡(jiǎn)單了解下org.jasig.cas.client.authentication.AuthenticationFilter這個(gè)CAS內(nèi)置filter的功能

      public final void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {     HttpServletRequest request = (HttpServletRequest)servletRequest;     HttpServletResponse response = (HttpServletResponse)servletResponse;     HttpSession session = request.getSession(false);  //檢查自定義屬性"_const_cas_assertion_"     Assertion assertion = session != null ? (Assertion)session.getAttribute("_const_cas_assertion_") : null;

          if (assertion != null) {    //已經(jīng)成功登陸過CAS       filterChain.doFilter(request, response);       return;     }   //拿到url,并檢查url參數(shù)中的ticket是否有效     String serviceUrl = constructServiceUrl(request, response);     String ticket = CommonUtils.safeGetParameter(request, getArtifactParameterName());     boolean wasGatewayed = this.gatewayStorage.hasGatewayedAlready(request, serviceUrl);

          if ((CommonUtils.isNotBlank(ticket)) || (wasGatewayed)) {    //ticket有效       filterChain.doFilter(request, response);       return;     }

          this.log.debug("no ticket and no assertion found");     String modifiedServiceUrl;     String modifiedServiceUrl;     if (this.gateway) {       this.log.debug("setting gateway attribute in session");       modifiedServiceUrl = this.gatewayStorage.storeGatewayInformation(request, serviceUrl);     } else {       modifiedServiceUrl = serviceUrl;     }

          if (this.log.isDebugEnabled()) {       this.log.debug("Constructed service url: " + modifiedServiceUrl);     }

          String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, getServiceParameterName(), modifiedServiceUrl, this.renew, this.gateway);

          if (this.log.isDebugEnabled()) {       this.log.debug("redirecting to \"" + urlToRedirectTo + "\"");     }   //重定向到cas的登陸頁面     response.sendRedirect(urlToRedirectTo);   }


       

      修改web.xml

      在應(yīng)用WEB-INF/web.xml添加filter的內(nèi)容,效果如下所示

      <!-- ======================== 單點(diǎn)登錄開始 ======================== -->
      	<!-- 用于單點(diǎn)退出,該過濾器用于實(shí)現(xiàn)單點(diǎn)登出功能,可選配置-->
      	<listener>
      		<listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
      	</listener>
      
      	<!-- 該過濾器用于實(shí)現(xiàn)單點(diǎn)登出功能,可選配置。 -->
      	<filter>
      		<filter-name>CAS Single Sign Out Filter</filter-name>
      		<filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
      	</filter>
      	<filter-mapping>
      		<filter-name>CAS Single Sign Out Filter</filter-name>
      		<url-pattern>/*</url-pattern>
      	</filter-mapping>
      
      	<!-- 該過濾器負(fù)責(zé)用戶的認(rèn)證工作,必須啟用它 -->
      	<filter>
      		<filter-name>CASFilter</filter-name>
      		<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
      		<init-param>
      			<param-name>casServerLoginUrl</param-name>
      			<param-value>https://sso.:8080/cas/login</param-value>
      			<!--這里的server是服務(wù)端的IP-->
      		</init-param>
      		<init-param>
      			<param-name>serverName</param-name>
      			<param-value>https://sso.:8080</param-value>
      		</init-param>
      	</filter>
      	<filter-mapping>
      		<filter-name>CASFilter</filter-name>
      		<url-pattern>/*</url-pattern>
      	</filter-mapping>
      
      	<!-- 該過濾器負(fù)責(zé)對(duì)Ticket的校驗(yàn)工作,必須啟用它 -->
      	<filter>
      		<filter-name>CAS Validation Filter</filter-name>
      		<filter-class>
      			org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
      		<init-param>
      			<param-name>casServerUrlPrefix</param-name>
      			<param-value>https://sso.:8080/cas</param-value>
      		</init-param>
      		<init-param>
      			<param-name>serverName</param-name>
      			<param-value>https://sso.:8080</param-value>
      		</init-param>
      	</filter>
      	<filter-mapping>
      		<filter-name>CAS Validation Filter</filter-name>
      		<url-pattern>/*</url-pattern>
      	</filter-mapping>
      
      	<!--
      		該過濾器負(fù)責(zé)實(shí)現(xiàn)HttpServletRequest請(qǐng)求的包裹,
      		比如允許開發(fā)者通過HttpServletRequest的getRemoteUser()方法獲得SSO登錄用戶的登錄名,可選配置。
      	-->
      	<filter>
      		<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
      		<filter-class>
      			org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
      	</filter>
      	<filter-mapping>
      		<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
      		<url-pattern>/*</url-pattern>
      	</filter-mapping>
      
      	<!--
      		該過濾器使得開發(fā)者可以通過org.jasig.cas.client.util.AssertionHolder來獲取用戶的登錄名。
      		比如AssertionHolder.getAssertion().getPrincipal().getName()。
      	-->
      	<filter>
      		<filter-name>CAS Assertion Thread Local Filter</filter-name>
      		<filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class>
      	</filter>
      	<filter-mapping>
      		<filter-name>CAS Assertion Thread Local Filter</filter-name>
      		<url-pattern>/*</url-pattern>
      	</filter-mapping>
      	
      	<!-- 自動(dòng)根據(jù)單點(diǎn)登錄的結(jié)果設(shè)置本系統(tǒng)的用戶信息-->
      	<filter>
      		<display-name>AutoSetUserAdapterFilter</display-name>
      		<filter-name>AutoSetUserAdapterFilter</filter-name>
      		<filter-class>aurora.plugin.sso.cas.AutoSetUserFilter</filter-class>
      		<init-param>
      			<param-name>roleSelectPageUrl</param-name>
      			<param-value>https://sso.:8080/yourapp/role_select.screen</param-value>
      		</init-param>
      	</filter>
      	<filter-mapping>
      		<filter-name>AutoSetUserAdapterFilter</filter-name>
      		<url-pattern>/*</url-pattern>
      	</filter-mapping>
      	<!-- ======================== 單點(diǎn)登錄結(jié)束 ======================== -->

       

      前面幾個(gè)都是CAS標(biāo)準(zhǔn)配置,最后一個(gè)AutoSetUserAdapterFilter(自定義,可以取其他任意名字)才是我們支持cas的客戶化程序。其中roleSelectPageUrl是指用戶完成單點(diǎn)登錄后跳轉(zhuǎn)的頁面。

      本文檔撰寫時(shí)java web項(xiàng)目和CAS用同一個(gè)tomcat,所以都用的https。否則只需要配置CAS的鏈接為HTTPS,本項(xiàng)目連接用HTTP。

       

      修改CAS的認(rèn)證邏輯

      CAS默認(rèn)的邏輯是用戶名和密碼一致就可以登陸,現(xiàn)在需要把原web系統(tǒng)的用戶名和密碼校驗(yàn)挪到CAS中。這里假設(shè)原先web系統(tǒng)中有一張sys_user表存儲(chǔ)了用戶名和MD5散列后的密碼。

       

      打開cas/WEB-INF/deployerConfigContext.xml

      1. 注釋掉SimpleTestUsernamePasswordAuthenticationHandler這個(gè)Handler,并添加

         

        <bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
        	<property ref="dataSource" name="dataSource"></property>
        	<property name="sql" value="select t.encrypted_user_password from sys_user t where t.user_name=?"></property>                     
        	<property ref="MD5PasswordEncoder" name="passwordEncoder"></property>
        </bean>


         

      2.  在文件末尾之前加入數(shù)據(jù)庫的鏈接:

            <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <property name="driverClassName">
                    <value>oracle.jdbc.driver.OracleDriver</value>
                </property>
                <property name="url">
                    <value>jdbc:oracle:thin:@yourIP:1521:yourOracleInstanceId</value>
                </property>
                <property name="username">
                    <value>yourName</value>
                </property>
                <property name="password">
                    <value>yourPassword</value>
                </property>
            </bean>
            <bean id="MD5PasswordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder">
                <constructor-arg index="0">
                    <value>MD5</value>
                </constructor-arg>
            </bean>

         

      3. cas加入jdbc支持
        復(fù)制cas-server-3.5.2\modules\cas-server-support-jdbc-3.5.2.jaroracle驅(qū)動(dòng)(這里采用oracle數(shù)據(jù))的ojdbc14.jar或者classes12.jar放到cas/WEB-INF/lib目錄下。

      4. 重新登陸Web系統(tǒng)

        重啟tomcat,在瀏覽器中輸入https://sso.:8080/yourapp/,自動(dòng)跳轉(zhuǎn)到如下頁面:

      5. 輸入web系統(tǒng)預(yù)先定義的用戶名和密碼,并跳轉(zhuǎn)到自定義(web.xml中定義的)登陸成功后的頁面。

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多