学习笔记:微服务-4.spring boot 单点登录cas

36 篇文章 0 订阅
28 篇文章 2 订阅

spring boot 与单点登录CAS整合实现cas client

1. pom.xml 加入依赖

        <dependency>
            <groupId>net.unicon.cas</groupId>
            <artifactId>cas-client-autoconfig-support</artifactId>
            <version>2.1.0-GA</version>
        </dependency>

2. application.properties

server.port=8082
spring.application.name=Euredaclientcas
cas.server-url-prefix=https://author.linbsoft.com
cas.server-login-url=https://author.linbsoft.com/cas/
cas.client-host-url=http://centos7:8082
cas.validation-type=CAS

cas.use-session=true

3. 启动类中加入@EnableCasClient 注解

@SpringBootApplication
@EnableCasClient
public class EuredaClientCasApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(EuredaClientCasApplication.class, args);
    }

}

4. 获取cas登录账号

@RestController
public class UserController {
@RequestMapping("/user")
public Map<String, String> queryUser(HttpServletRequest request){
    Map<String,String> map = new HashMap<>();
    Assertion ass=AssertionHolder.getAssertion();
    AttributePrincipal p=ass.getPrincipal();
    String name=p.getName();
    map.put("loginuser", name);
    //map.put("session", request.getSession.getId());
    return map;
  }
}

其中需要使用 org.jasig.cas.client 包

5. 启动应用,输入应用网址,http://centos7.linbsoft.com:8082/user    自动跳转到cas登录页面,登录后,显示登录用户名

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值