A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 谷粒姐姐 于 2018-10-23 10:26 编辑

品优购用户中心
5.1 需求分析用户中心实现单点登录。
5.2 代码实现
5.2.1 用户中心实现单点登录
(1)将用户中心相关的页面(home-开头的)拷贝至        pinnyougou-user-web
(1) pom.xml 引入 springSecurity、cas 客户端和 springSecurity Cas 整合包依赖(参照
casclient_demo3)。
(2) ) web.xml        添加 spring-security 过滤器( 参照参照 casclient_demo3 ) 设置首页为home-index.html

[AppleScript] 纯文本查看 复制代码
<welcome-file-list>


<welcome-file>home-index.html</welcome-file>


</welcome-file-list>
(4)构建 UserDetailsServiceImpl.java        (参照 casclient_demo3)
(5)添加 spring-security.xml(参照 casclient_demo3),并做以下修改配置匿名访问资源
[AppleScript] 纯文本查看 复制代码
<!-- 匿名访问资源 -->

<http  pattern="/css/**"  security="none"></http>

<http  pattern="/js/**"  security="none"></http>

<http  pattern="/image/**"  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/sendCode.do"  security="none"></http>
设置服务地址属性
[AppleScript] 纯文本查看 复制代码
<        beans:bean        id="serviceProperties"
class="org.springframework.security.cas.ServiceProperties">

<beans:property  name="service"  value="http://localhost:9106/login/cas"/>

</beans:bean>
[img=66,24]设置认证类
[AppleScript] 纯文本查看 复制代码
<beans:bean

id="userDetailsService"  class="com.pinyougou.user.service.UserDetailServiceImpl"/>
5.1.1 页面显示用户名
(1)pinyougou-user-web 创建 LoginController.java
[AppleScript] 纯文本查看 复制代码
@RestController @RequestMapping("/login") public  class  LoginController  {
@RequestMapping("/name")
public  Map  showName(){ String  name  =
SecurityContextHolder.getContext().getAuthentication().getName();//得到登陆人账号 Map  map=new  HashMap<>();

map.put("loginName",  name);


return  map;


}


}
(2)创建 loginService.js
[AppleScript] 纯文本查看 复制代码
//服务层app.service('loginService',function($http){
//读取列表数据绑定到表单中

this.showName=function(){


return  $http.get('../login/name.do');


}
});


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马