服务端改造(登录页及登录方式的自定义)

来源:互联网 发布:linux vim 强制保存 编辑:程序博客网 时间:2024/05/22 15:27

上一篇文章(http://blog.csdn.net/u012116457/article/details/52161201)提到,为了更好的满足我们的要求,还需要对服务端进行改造。

1.新建cas_server

为了方便,首先我们现在工作区间新建一个项目,名为cas_server,然后解压cas.war,将文件中的内容替换到cas_server的WebRoot目录下,并将web_Inf下的内容拷贝到src下。

完成后运行,输入localhost:8080/cas_server后如果界面与上篇文章中的一致,则表示服务端搭建成功。


2.修改WEB-INF\spring-configuration\applicationContext.xml

将文件中的beansnames属性改为如下:

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. <util:list id="basenames">  
  2.       <value>classpath:custom_messages</value>  
  3.       <value>classpath:messages_zh_CN</value>  
  4.   </util:list>  

将国际化配置文件切换为汉语


3.修改登录页

登录页位于:WebRoot\WEB-INF\view\jsp\default\ui\casLoginView.jsp  引用了WebRoot\WEB-INF\view\jsp\default\ui\includes文件夹中的两个文件

可以自行对这三个文件的样式进行修改,比如对casLoginView.jsp 进行如下修改,仅仅保留表单部分以及对top.jsp文件的引用

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. <jsp:directive.include file="includes/top.jsp" />   
  2.   
  3. <div class="box" id="login">  
  4.   <form:form method="post" id="fm1" commandName="${commandName}" htmlEscape="true">  
  5.   
  6.     <form:errors path="*" id="msg" cssClass="errors" element="div" htmlEscape="false" />  
  7.     
  8.     <h2><spring:message code="screen.welcome.instructions" /></h2>  
  9.     
  10.     <section class="row">  
  11.       <label for="username"><spring:message code="screen.welcome.label.netid" /></label>  
  12.       <c:choose>  
  13.         <c:when test="${not empty sessionScope.openIdLocalId}">  
  14.           <strong>${sessionScope.openIdLocalId}</strong>  
  15.           <input type="hidden" id="username" name="username" value="${sessionScope.openIdLocalId}" />  
  16.         </c:when>  
  17.         <c:otherwise>  
  18.           <spring:message code="screen.welcome.label.netid.accesskey" var="userNameAccessKey" />  
  19.           <form:input cssClass="required" cssErrorClass="error" id="username" size="25" tabindex="1" accesskey="${userNameAccessKey}" path="username" autocomplete="off" htmlEscape="true" />  
  20.         </c:otherwise>  
  21.       </c:choose>  
  22.     </section>  
  23.       
  24.     <section class="row">  
  25.       <label for="password"><spring:message code="screen.welcome.label.password" /></label>  
  26.       <spring:message code="screen.welcome.label.password.accesskey" var="passwordAccessKey" />  
  27.       <form:password cssClass="required" cssErrorClass="error" id="password" size="25" tabindex="2" path="password"  accesskey="${passwordAccessKey}" htmlEscape="true" autocomplete="off" />  
  28.     </section>  
  29.       
  30.     <section class="row check">  
  31.       <input id="warn" name="warn" value="true" tabindex="3" accesskey="<spring:message code="screen.welcome.label.warn.accesskey" />type="checkbox" />  
  32.       <label for="warn"><spring:message code="screen.welcome.label.warn" /></label>  
  33.     </section>  
  34.       
  35.     <section class="row btn-row">  
  36.       <input type="hidden" name="lt" value="${loginTicket}" />  
  37.       <input type="hidden" name="execution" value="${flowExecutionKey}" />  
  38.       <input type="hidden" name="_eventId" value="submit" />  
  39.   
  40.       <input class="btn-submit" name="submit" accesskey="l" value="<spring:message code="screen.welcome.button.login" />tabindex="4" type="submit" />  
  41.       <input class="btn-reset" name="reset" accesskey="c" value="<spring:message code="screen.welcome.button.clear" />tabindex="5" type="reset" />  
  42.     </section>  
  43.   </form:form>  
  44. </div>  
对top.jsp文件的内容进行简单修改后,刷新页面,页面大概会显示为:

输入用户名密码:casuser与Mellon,跳转到如下页面:



4.修改登录方式

a.首先将cas-server-4.0.0-release\cas-server-4.0.0\modules\cas-server-support-jdbc-4.0.0.jar以及对于数据库的jar包加入到cas_server的lib目录下

b.修改WebRoot\WEB-INF\deployerConfigContext.xml ,

将下面代码注释掉:

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. <bean id="primaryAuthenticationHandler"  
  2.           class="org.jasig.cas.authentication.AcceptUsersAuthenticationHandler">  
  3.         <property name="users">  
  4.             <map>  
  5.                 <entry key="casuser" value="Mellon"/>  
  6.             </map>  
  7.         </property>  
  8.     </bean>  

添加如下代码,更新为JDBC验证方式:
[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. <!-- 更新为JDBC验证方式 开始 -->  
  2.      <!-- 配置数据源 -->  
  3.        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
  4.         <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>  
  5.         <property name="url"><value>jdbc:mysql://localhost:3306/etoak?characterEncoding=utf8</value></property>  
  6.         <property name="username"><value>root</value></property>  
  7.         <property name="password"><value>root</value></property>   
  8.     </bean>   
  9.     <bean id="primaryAuthenticationHandler" class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">  
  10.         <property name="dataSource" ref="dataSource"></property>  
  11.         <property name="sql" value="select login_Password from tb_rds_user where login_name=?"></property>  
  12.         <!--   如果需要加密,则配置加密器 ,我这里不需要-->  
  13.         <!--  <property name="passwordEncoder" ref="MD5PasswordEncoder"></property> -->  
  14.     </bean>  
  15.     <!-- 添加MD5密码加密功能 -->  
  16.     <bean id="MD5PasswordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder">  
  17.         <constructor-arg index="0">  
  18.         <value>MD5</value>  
  19.         </constructor-arg>   
  20.     </bean>   
  21.    <!-- 更新为JDBC验证方式 结束 -->  
c.配置客户端

在上一篇文章客户端的基础上进行修改,修改web.xml,

将http://localhost:8080/cas/login 修改为http://localhost:8080/cas_server/login

将http://localhost:8080/cas修改为http://localhost:8080/cas_server

浏览器输入localhost:8080/cas_client进行测试

0 0
原创粉丝点击