栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

CAS Server and Client - http

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

    创建一个spring boot工程。

    添加 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");
	}
}
    添加一个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;
	}

}
    添加配置文件 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
    运行工程
mvn spring-boot:run
    访问 http://localhost:9090/myapp/test, 页面会被转到 cas 登录页,登录会跳回到 test 页面。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/754904.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号