CAS Server and Client - http

Posted kongxx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CAS Server and Client - http相关的知识,希望对你有一定的参考价值。

CAS Server and Client

cas server

cas-overlay-template

从 https://github.com/apereo/cas-overlay-template/tree/5.2 下载 cas-overlay-template 包,这里选择5.2版本。

配置与打包

build copy
# build gencert
build package

修改 cas.war 文件中的 WEB-INF/classes/services/HTTPSandIMAPS-10000001.json 文件


  "@class" : "org.apereo.cas.services.RegexRegisteredService",
  "serviceId" : "^(http|https|imaps)://.*",
  "name" : "HTTPS and IMAPS",
  "id" : 10000001,
  "description" : "This service definition authorizes all application urls that support HTTPS and IMAPS protocols.",
  "evaluationOrder" : 10000

部署

下载Tomcat 8.x,将cas.war部署到tomcat的webapp目录下,启动tomcat,然后访问 http://localhost:8080/cas

使用 casuser/Mellon 登录 CAS。

cas client

  1. 创建一个spring boot工程。

  2. 添加 Cas 配置类 CasConfigure.java,内容如下:

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Configuration;

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

@Configuration
@EnableCasClient
public class CasConfigure extends CasClientConfigurerAdapter 
	@Override
	public void configureAuthenticationFilter(FilterRegistrationBean authenticationFilter) 
		super.configureAuthenticationFilter(authenticationFilter);
		authenticationFilter.getInitParameters().put("authenticationRedirectStrategyClass",
				"com.patterncat.CustomAuthRedirectStrategy");
	

  1. 添加一个Controller类TestController.java,内容如下:
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

@RestController
public class TestController 
	
	@GetMapping("/auth/test")
	public Object test() 
		ObjectMapper mapper = new ObjectMapper();
		ObjectNode jsonObj = mapper.createObjectNode();
		jsonObj.put("message", "hello world");
		return jsonObj;
	


  1. 添加配置文件 application.properties,内容如下
server.port=9090
cas.server-url-prefix: http://localhost:8080/cas/
cas.server-login-url: http://localhost:8080/cas/login
cas.client-host-url: http://localhost:9090
cas.validation-type: cas
  1. 运行工程
mvn spring-boot:run
  1. 访问 http://localhost:9090/myapp/test, 页面会被转到 cas 登录页,登录会跳回到 test 页面。

以上是关于CAS Server and Client - http的主要内容,如果未能解决你的问题,请参考以下文章

CAS Server and Client - http

CAS Server and Client - https

CAS Server and Client - https

CAS Server and Client - https

CAS Server and Client - https

CAS集成源码解析