Springboot 2.1.2集成CAS5.2.6版本之客户端集成

       在这之前由于没有使用过Cas用来做单点登录,结果是一个坑接一个坑,我相信大多数第一次使用这个来做单点登录的大牛们=都会有类似的经历,今天就简单的把CAS客户端以SpringBoot的方式来讲述一下.(重点说一下忽略某些Url不使用CAS的情况)

代码下载地址:暂无

目录结构

Springboot 2.1.2集成CAS5.2.6版本之客户端集成_第1张图片

 

简单明了直接上代码相信大家都能看明白:

1.pom.xml中添加以下依赖:

        
            net.unicon.cas
            cas-client-autoconfig-support
            1.7.0-GA
        

 

 

2.启动主类中添加以下注解用于开启CAS单点登录:@EnableCasClient

package com.qf.swar;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import net.unicon.cas.client.configuration.EnableCasClient;

@SpringBootApplication
@EnableCasClient
@Controller
public class DemoApplication {

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

	@RequestMapping("/hello")
	@ResponseBody
	public String hello() {
		return "Hello World!";
	}
	
	@RequestMapping("/api")
	@ResponseBody
	public String api() {
		return "Hello api!";
	}
	
	
	@RequestMapping(value="/login")
	public String requestMethodName() {
			return "s/index";
	}
}

3.application.properties配置文件中添加以下:

server.port=8083

cas.validation-type=CAS
cas.server-url-prefix=http://localhost:8080/cas
cas.server-login-url=http://localhost:8080/cas/login
cas.client-host-url=http://localhost:8083/login
 #指定需要经过CAS验证的链接,未指定的不需要配置
cas.authentication-url-patterns=/login/*,/api/*

4.index.html








     

Hello, world!

5.运行效果如下:

输入以下地址直接跳转到登陆页面:

http://localhost:8083/login

Springboot 2.1.2集成CAS5.2.6版本之客户端集成_第2张图片

浏览器输入以下地址可以直接访问不用登陆:

http://localhost:8083/hello

Springboot 2.1.2集成CAS5.2.6版本之客户端集成_第3张图片

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Java开发,SpringBoot)