CAS Server and Client
cas server
cas-overlay-template
Download the cas-overlay-template package from https://github.com/apereo/cas-overlay-template/tree/5.2. Select version 5.2 here.
Configuration and packaging
build copy
# build gencert
build package
Modify the WEB-INF/classes/services/HTTPSandIMAPS-10000001.json file in the cas.war file
{
"@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
}
deploy
Download Tomcat 8.x, deploy cas.war to tomcat's webapp directory, start tomcat, and then visit http://localhost:8080/cas
Log in to CAS using casuser/Mellon.
cas client
-
Create a spring boot project.
-
Add the Cas configuration class CasConfigure.java with the following content:
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");
}
}
- Add a Controller class TestController.java with the following content:
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;
}
}
- Add the configuration file application.properties with the following content
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
- Run project
mvn spring-boot:run
- Visit http://localhost:9090/myapp/test, the page will be redirected to the cas login page, and the login page will jump back to the test page.