電商專案day15(單點登入&cas框架)
今日目標:
掌握單點的登陸的解決方案
入門實現
配置檔案詳解
cas與spring-security整合
完成商城使用者中心
一.單點登入的實現方案
1.什麼是單點登入
單點登入(Single Sign On),簡稱為 SSO,是目前比較流行的企業業務整合的解決方案之一。SSO 的定義是在多個應用系統中,使用者只需要登入一次就可以訪問所有相互信任的應用系統。
單點登陸時一個系統中,多個子應用,只要登陸一次,就能相互信任,無序二次登陸.
2.常用的解決方案
1.通用的CAS框架實現
2.redis實現session共享
3.XXL-SSO 分散式單點登入框架實現
3.什麼是CAS?
CAS 是 Yale 大學發起的一個開源專案,旨在為 Web 應用系統提供一種可靠的單點登入方法,CAS 在 2004 年 12 月正式成為 JA-SIG 的一個專案。CAS 具有以下特點:
【1】開源的企業級單點登入解決方案。
【2】CAS Server 為需要獨立部署的 Web 應用。
【3】CAS Client 支援非常多的客戶端(這裡指單點登入系統中的各個 Web 應用),包括Java, .Net, PHP, Perl, Apache, uPortal, Ruby 等。
從結構上看,CAS 包含兩個部分: CAS Server 和 CAS Client。CAS Server 需要獨立部署,主要負責對使用者的認證工作;CAS Client 負責處理對客戶端受保護資源的訪問請求,需要登入時,重定向到 CAS Server。
SSO 單點登入訪問流程主要有以下步驟:
1. 訪問服務:SSO 客戶端傳送請求訪問應用系統提供的服務資源。
2. 定向認證:SSO 客戶端會重定向使用者請求到 SSO 伺服器。
3. 使用者認證:使用者身份認證。
4. 發放票據:SSO 伺服器會產生一個隨機的 Service Ticket。
5. 驗證票據:SSO 伺服器驗證票據 Service Ticket 的合法性,驗證通過後,允許客戶端訪問
服務。
6. 傳輸使用者資訊:SSO 伺服器驗證票據通過後,傳輸使用者認證結果資訊給客戶端。
安裝:
cas服務端就是一個war包
在資源\cas\source\cas-server-4.0.0-release\cas-server-4.0.0\modules 目錄下
cas-server-webapp-4.0.0.war 將其改名為 cas.war 放入 tomcat 目錄下的 webapps 下。啟動tomcat 自動解壓 war 包。瀏覽器輸入 http://localhost:8080/cas/login
登陸預設密碼為:casuser /Mellon
1.注意,考慮到可能會佔用埠號,所以可以改變tomcat的埠號9100
同時修改cas目錄下WEB-INF/cas.properties
2.server.name=http://localhost:9100
3.取出https認證
修改 cas 的 WEB-INF/deployerConfigContext.xml
<!-- Required for proxy ticket mechanism. -->
<bean id="proxyAuthenticationHandler"
class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler"
p:httpClient-ref="httpClient" />
在上面檔案中新增引數 p:requireSecure="false",requireSecure 屬性意思為是否需要安全驗證,即
HTTPS,false 為不採用
4.修改 cas 的/WEB-INF/spring-configuration/ticketGrantingTicketCookieGenerator.xml
<bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="true"
p:cookieMaxAge="-1"
p:cookieName="CASTGC"
p:cookiePath="/cas" />
修改如上的引數:
引數 p:cookieSecure="true",同理為 HTTPS 驗證相關,TRUE 為採用 HTTPS 驗證,FALSE 為不採用 https 驗證。
引數 p:cookieMaxAge="-1",是 COOKIE 的最大生命週期,-1 為無生命週期,即只在當前開啟的視窗有效,關閉或重新開啟其它視窗,仍會要求驗證。可以根據需要修改為大於 0 的數字,比如 3600 等,意思是在 3600 秒內,開啟任意視窗,都不需要驗證。我們這裡將 cookieSecure 改為 false , cookieMaxAge 改為 3600
5.修改 cas 的 WEB-INF/spring-configuration/warnCookieGenerator.xml
<bean id="warnCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="true"
p:cookieMaxAge="-1"
p:cookieName="CASPRIVACY"
p:cookiePath="/cas" />
同理我們將cookieSecure設定為false cookiemaxAge設定為3600
二.開源單點登入系統CAS入門
思路:我們搭建連個客戶端,測試基於cas實現單點登入的效果
1.首先建立CASClinet_demo1
匯入 映入配置檔案
<!-- cas -->
<dependency>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-core</artifactId>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
注意配置檔案非常重要:web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<!-- ======================== 單點登入開始 ======================== -->
<!-- 用於單點退出,該過濾器用於實現單點登出功能,可選配置 -->
<listener>
<listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
</listener>
<!-- 該過濾器用於實現單點登出功能,可選配置。 -->
<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>
<!-- 該過濾器負責使用者的認證工作,必須啟用它 -->
<filter>
<filter-name>CASFilter</filter-name>
<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
<init-param>
<param-name>casServerLoginUrl</param-name>
<!--這裡的server是服務端的IP -->
<param-value>http://localhost:9100/cas/login</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://localhost:9001</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 該過濾器負責對Ticket的校驗工作,必須啟用它 -->
<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>
<!--這是伺服器的ip地址 注意與上面的區別-->
<param-value>http://localhost:9100/cas</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://localhost:9001</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CAS Validation Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 該過濾器負責實現HttpServletRequest請求的包裹, 比如允許開發者通過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>
<!-- 該過濾器使得開發者可以通過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>
<!-- ======================== 單點登入結束 ======================== -->
</web-app>
必須配置的一定要記住
過濾器負責使用者的認證工作,必須啟用它
AuthenticationFilter
過濾器負責對Ticket的校驗工作,必須啟用它
Cas20ProxyReceivingTicketValidationFilter
2.編寫index.jsp頁面進行測試
歡迎來到神奇的CAS <%=request.getRemoteUser()%>
這個是獲取遠端登入名
同樣的建立另一個工程,這個工程的的server的埠號為9002注意修改,其他都一樣 ,啟動檢視效果
第一我們需要輸入密碼,成功登陸後,我們的第二個工程就不用輸入密碼
第二個也登陸了,沒有輸入密碼
下面我們進行單點登出
http://localhost:9100/cas/logout
可以在index.html中新增測試
<a href="http://localhost:9100/cas/logout">登出</a>
那麼我們還是希望在登出的時候跳轉到指定的頁面
修改 cas 系統的配置檔案 cas-servlet.xml
<bean id="logoutAction" class="org.jasig.cas.web.flow.LogoutAction"
p:servicesManager-ref="servicesManager"
p:followServiceRedirects="${cas.logout.followServiceRedirects:false}"/>
我們將fase設定為true
在index.jsp頁面中新增
<a href="http://localhost:9100/cas/logout?service=http://www.baidu.com">退出登入</a>
測試後我們,退出登入,跳轉到百度的頁面
三.CAS服務端資料來源的配置
分析:我們希望通過資料庫查詢我們自己的使用者名稱和密碼
1.配置資料來源
(1)修改 cas 服務端中 web-inf 下 deployerConfigContext.xml ,新增如下配置
//文件下面加上
<!--c3p0資料來源的配置-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://127.0.0.1:3306/pinyougoudb?characterEncoding=utf8"
p:user="root"
p:password="123" />
<!--密碼用了md5所以需要配置對應p:passwordEncoder-ref-->
<bean id="passwordEncoder"
class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder"
c:encodingAlgorithm="MD5"
p:characterEncoding="UTF-8" />
<!--負責驗證使用者登入-->
<bean id="dbAuthHandler"
class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"
p:dataSource-ref="dataSource"
p:sql="select password from tb_user where username = ?"
p:passwordEncoder-ref="passwordEncoder"/>
在當前檔案下我們找到<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />
一句是使用固定的使用者名稱和密碼,我們在下面可以看到這兩個 bean ,如果我們使用資料庫認
證使用者名稱和密碼,需要將這句註釋掉。
然後新增資料庫的entity
<entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />
<!--<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />-->
<entry key-ref="dbAuthHandler" value-ref="primaryPrincipalResolver"/>
(2)將以下三個 jar 包放入 webapps\cas\WEB-INF\lib 下
然後我們進行測試
注意:配置檔案中註釋的中文一定要去掉,如果不去掉就會報錯
四.伺服器介面的改造
1.引入資源
2.將原來的頁面改為.bak檔案作為備份
3.username password submit 的修改
<form:input id="username" placeholder="郵箱/使用者名稱/手機號" class="span2 input-xfat" tabindex="1" accesskey="${userNameAccessKey}" path="username" autocomplete="off" htmlEscape="true" />
<form:password id="password" placeholder="請輸入密碼" class="span2 input-xfat" tabindex="2" path="password" accesskey="${passwordAccessKey}" htmlEscape="true" autocomplete="off" />
<input class="sui-btn btn-block btn-xlarge btn-danger" name="submit" accesskey="l" value="登 錄" tabindex="4" type="submit" />
改造後就可以登入了
因為輸入錯誤,提示的是英文,那我們想要用中文就要用到i18n
測試:輸入錯誤的使用者名稱和密碼,提示是英文。這個提示資訊是在 WEB-INF\classes 目錄下
的 messages.properties 檔案中
設定國際化為 zn_CN ,修改 cas-servlet.xml
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"
p:defaultLocale="zh_CN" />
我們需要將此資訊拷貝到 messages_zh_CN.properties 下,並改為中文提示(轉碼)
authenticationFailure.AccountNotFoundException=\u7528\u6237\u4E0D\u5B58\u5728.
authenticationFailure.FailedLoginException=\u5BC6\u7801\u9519\u8BEF.
五.CAS客戶端與spring-security的整合
建立一個CASClient_demo3工程,我們與spring-security整合
導包 springmvc包 整合包 cas包
新增配置檔案
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<!-- entry-point-ref 入口點引用 -->
<http use-expressions="false" entry-point-ref="casProcessingFilterEntryPoint">
<intercept-url pattern="/**" access="ROLE_USER"/>
<!--跨站請求偽造-->
<csrf disabled="true"/>
<!-- custom-filter為過濾器, position 表示將過濾器放在指定的位置上,before表示放在指定位置之前 ,after表示放在指定的位置之後 -->
<custom-filter ref="casAuthenticationFilter" position="CAS_FILTER" />
<custom-filter ref="requestSingleLogoutFilter" before="LOGOUT_FILTER"/>
<custom-filter ref="singleLogoutFilter" before="CAS_FILTER"/>
</http>
<!-- CAS入口點 開始 -->
<beans:bean id="casProcessingFilterEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
<!-- 單點登入伺服器登入URL -->
<beans:property name="loginUrl" value="http://localhost:9100/cas/login"/>
<beans:property name="serviceProperties" ref="serviceProperties"/>
</beans:bean>
<beans:bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
<!--service 配置自身工程的根地址+/login/cas -->
<beans:property name="service" value="http://localhost:9003/login/cas"/>
</beans:bean>
<!-- CAS入口點 結束 -->
<!-- 認證過濾器 開始 -->
<beans:bean id="casAuthenticationFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
<beans:property name="authenticationManager" ref="authenticationManager"/>
</beans:bean>
<!-- 認證管理器 -->
<authentication-manager alias="authenticationManager">
<authentication-provider ref="casAuthenticationProvider">
</authentication-provider>
</authentication-manager>
<!-- 認證提供者 -->
<beans:bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
<beans:property name="authenticationUserDetailsService">
<beans:bean class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
<beans:constructor-arg ref="userDetailsService" />
</beans:bean>
</beans:property>
<beans:property name="serviceProperties" ref="serviceProperties"/>
<!-- ticketValidator 為票據驗證器 -->
<beans:property name="ticketValidator">
<beans:bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
<beans:constructor-arg index="0" value="http://localhost:9100/cas"/>
</beans:bean>
</beans:property>
<beans:property name="key" value="an_id_for_this_auth_provider_only"/>
</beans:bean>
<!-- 認證類 -->
<beans:bean id="userDetailsService" class="cn.itcast.demo.service.UserDetailServiceImpl"/>
<!-- 認證過濾器 結束 -->
<!-- 單點登出 開始 -->
<beans:bean id="singleLogoutFilter" class="org.jasig.cas.client.session.SingleSignOutFilter"/>
<beans:bean id="requestSingleLogoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">
<beans:constructor-arg value="http://localhost:9100/cas/logout?service=http://www.baidu.com"/>
<beans:constructor-arg>
<beans:bean class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/>
</beans:constructor-arg>
<!-- 以下配置含義:當訪問/logout/cas地址時,會跳轉訪問 beans:constructor-arg value中配置的地址-->
<beans:property name="filterProcessesUrl" value="/logout/cas"/>
</beans:bean>
<!-- 單點登出 結束 -->
</beans:beans>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 指定載入的配置檔案 ,通過引數contextConfigLocation載入-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-security.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- springsecurity入口 -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
編寫UserDetailService通過spring-security框架獲取認證系統的中的name
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//cas與springsecurity整合 cas認證登入操作,所有的認證服務類操作
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
return new User(username,"",authorities);
}
編寫UserController
@RestController
public class UserController {
@RequestMapping("/getName")
public void getName(){
//獲取使用者名稱,基於spring-security獲取的使用者名稱相同
String username = SecurityContextHolder.getContext().getAuthentication().getName();
System.out.println(username);
}
}
通過瀏覽器測試可知:
控制檯輸出username
六.商城的使用者中心
業務分析:
訂單管理
收藏商品
檢視物流資訊
修改維護個人資訊
收件地址管理
個人安全資訊管理(修改密碼以及重新繫結手機號等)
我們在這隻做使用者名稱的顯示和單點登出
步驟:導包 配置檔案
spring-security.xml
<!--可匿名訪問的資源-->
<http pattern="/css/**" security="none"></http>
<http pattern="/data/**" security="none"></http>
<http pattern="/fonts/**" security="none"></http>
<http pattern="/img/**" security="none"></http>
<http pattern="/js/**" security="none"></http>
<http pattern="/plugins/**" security="none"></http>
<http pattern="/register.html" security="none"></http>
<http pattern="/user/add.do" security="none"></http>
<http pattern="/user/sendSmsCode.do" security="none"></http>
<!-- entry-point-ref 入口點引用 -->
<http use-expressions="false" entry-point-ref="casProcessingFilterEntryPoint">
<intercept-url pattern="/**" access="ROLE_USER"/>
<csrf disabled="true"/>
<!-- custom-filter為過濾器, position 表示將過濾器放在指定的位置上,before表示放在指定位置之前 ,after表示放在指定的位置之後 -->
<custom-filter ref="casAuthenticationFilter" position="CAS_FILTER" />
<custom-filter ref="requestSingleLogoutFilter" before="LOGOUT_FILTER"/>
<custom-filter ref="singleLogoutFilter" before="CAS_FILTER"/>
</http>
<!-- CAS入口點 開始 -->
<beans:bean id="casProcessingFilterEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
<!-- 單點登入伺服器登入URL -->
<beans:property name="loginUrl" value="http://localhost:9100/cas/login"/>
<beans:property name="serviceProperties" ref="serviceProperties"/>
</beans:bean>
<beans:bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
<!--service 配置自身工程的根地址+/login/cas -->
<beans:property name="service" value="http://localhost:8086/login/cas"/>
</beans:bean>
<!-- CAS入口點 結束 -->
<!-- 認證過濾器 開始 -->
<beans:bean id="casAuthenticationFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
<beans:property name="authenticationManager" ref="authenticationManager"/>
</beans:bean>
<!-- 認證管理器 -->
<authentication-manager alias="authenticationManager">
<authentication-provider ref="casAuthenticationProvider">
</authentication-provider>
</authentication-manager>
<!-- 認證提供者 -->
<beans:bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
<beans:property name="authenticationUserDetailsService">
<beans:bean class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
<beans:constructor-arg ref="userDetailsService" />
</beans:bean>
</beans:property>
<beans:property name="serviceProperties" ref="serviceProperties"/>
<!-- ticketValidator 為票據驗證器 -->
<beans:property name="ticketValidator">
<beans:bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
<beans:constructor-arg index="0" value="http://localhost:9100/cas"/>
</beans:bean>
</beans:property>
<beans:property name="key" value="an_id_for_this_auth_provider_only"/>
</beans:bean>
<!-- 認證類 -->
<beans:bean id="userDetailsService" class="com.pinyougou.user.service.UserDetailServiceImpl"/>
<!-- 認證過濾器 結束 -->
<!-- 單點登出 開始 -->
<beans:bean id="singleLogoutFilter" class="org.jasig.cas.client.session.SingleSignOutFilter"/>
<beans:bean id="requestSingleLogoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">
<beans:constructor-arg value="http://localhost:9100/cas/logout?service=http://www.pinyougou.com"/>
<beans:constructor-arg>
<beans:bean class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/>
</beans:constructor-arg>
<!-- 以下配置含義:當訪問/logout/cas地址時,會跳轉訪問 beans:constructor-arg value中配置的地址-->
<beans:property name="filterProcessesUrl" value="/logout/cas"/>
</beans:bean>
<!-- 單點登出 結束 -->
</beans:beans>
編寫UserDetailService.java
public class UserDetailServiceImpl implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//由於cas與springsecurity整合,cas做認證(登入)操作,所以認證服務類做授權操作
List<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
return new User(username,"",authorities);
}
}
loginController.java
@RestController
@RequestMapping("/login")
public class LoginController {
/**
* 基於安全框架獲取使用者資訊
* {loginName:"admin"}
*/
@RequestMapping("/getName")
public Map<String,String> getName(){
//基於安全框架獲取使用者資訊
String loginName = SecurityContextHolder.getContext().getAuthentication().getName();
Map<String,String> map = new HashMap<>();
map.put("loginName",loginName);
//{loginName:"admin"}
return map;
}
}
編寫前端程式碼:獲取使用者名稱
controler層
app.controller("indexController",function ($scope,$controller,loginService) {
//控制器繼承程式碼 引數一:繼承的父控制器名稱 引數二:固定寫法,共享$scope物件
$controller("baseController",{$scope:$scope});
//定義查詢所有品牌列表的方法
$scope.getName=function () {
//response接受相應結果
loginService.getName().success(function (response) {
$scope.loginName = response.loginName;
})
}
})
loginService.js
app.service("loginService",function ($http) {
//查詢所有
this.getName=function () {
return $http.get("login/getName.do");
}
})
我們登陸home-inde.html頁面的時候,我們要先進行認證,認證完後進行登陸
一定注意: cas的tomcat的三個埠號,一定不能和專案的中的埠號衝突,不然會出現閃退的情況