git clone git@github.com:apereo/cas-overlay-template.git
或直接下載zip包 https://github.com/apereo/cas-overlay-template/archive/5.3.ziphtml
<dependencies> <dependency> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-support-rest</artifactId> <version>${cas.version}</version> </dependency> </dependencies>
mvn clean package
- 修改 \WEB-INF\classes\services\HTTPSandIMAPS-10000001.json,將"serviceId"修改成"^(https|http|imaps)://.*",修改後的內容以下:java
{ "@class" : "org.apereo.cas.services.RegexRegisteredService", "serviceId" : "^(https|http|imaps)://.*", "name" : "HTTPS and IMAPS", "id" : 10000001, "description" : "This service definition authorizes all application urls that support HTTPS and IMAPS protocols.", "evaluationOrder" : 10000 }
- 修改 \WEB-INF\classes\application.properties,新增cas.tgc.secure和cas.serviceRegistry.initFromJson配置git
cas.tgc.secure=false cas.serviceRegistry.initFromJson=true
- 修改 \WEB-INF\classes\application.properties,cas.authn.accept.users配置,修改默認帳戶爲admin/123456github
cas.authn.accept.users=admin::123456
啓動tomcatweb
CAS官方java客戶端demo項目地址:https://github.com/cas-projects/cas-sample-java-webappjson
網絡不佳的同窗請使用這個備份地址下載:https://files.cnblogs.com/files/nihaorz/cas-sample-java-webapp-master.zip瀏覽器
執行mvn clean package打成war包,解壓war包修改web.xml中cas服務端以及demo程序自身訪問地址,部署至tomcat,此處應用上下文修改成demo,訪問/demotomcat
常規狀況是輸入帳戶密碼完成登陸,下面咱們使用REST完成登陸bash
curl -i -X POST \ http://cas.gfstack.geo:8080/cas/v1/tickets \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'username=admin&password=123456'
返回以下:服務器
HTTP/1.1 201 Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Content-Type-Options: nosniff X-Frame-Options: DENY X-XSS-Protection: 1; mode=block Location: http://cas.gfstack.geo:8080/cas/v1/tickets/TGT-24-92zYMWlqhJLKwdrZlzo3lVYGNP2J5ZpRYy1Zvg8ePO-qUvotV1qy-uUmm22-njz1QkAtes-cas-server Content-Type: text/html;charset=UTF-8 Content-Length: 396 Date: Wed, 27 Feb 2019 09:50:15 GMT <!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><html><head><title>201 Created</title></head><body><h1>TGT Created</h1><form action="http://cas.gfstack.geo:8080/cas/v1/tickets/TGT-24-92zYMWlqhJLKwdrZlzo3lVYGNP2J5ZpRYy1Zvg8ePO-qUvotV1qy-uUmm22-njz1QkAtes-cas-server" method="POST">Service:<input type="text" name="service" value=""><br><input type="submit" value="Submit"></form></body></html>
或者直接使用postman獲取到返回頭中的Location
curl -X POST \ http://cas.gfstack.geo:8080/cas/v1/tickets/TGT-31-hDZZ7-FyHALeny6rV4WgI9rdiSUf5FIFs91oHOf4PO2-nPJB2ndRb6BLLlaqDNvt6Zotes-cas-server \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'service=http%3A%2F%2F192.168.36.158%3A8080%2Fdemo%2F'
返回以下:
ST-23-CKL6FVwjJevI3gG61rW5QD9iKZItes-cas-server
注意,此處的service是通過URLEncoder編碼以後的客戶端地址,客戶端地址必須以「/」結尾,這裏的service原值爲「http://192.168.36.158:8080/demo/」
若是是postman則會自動完成編碼,以下圖所示
curl -X DELETE \ http://cas.gfstack.geo:8080/cas/v1/tickets/TGT-32-RzWUHSRvvQIWpsYn3YdRYcyf40Aa1qCf2Y-RFIqsAVkv-PGAJjd0LLyLVLa5TuaoBx0tes-cas-server