preface

Previous: CAS single Sign-on – Introduction

Next: CAS Single Sign-on – Configuration Center

Scaffolding code download

The code download

Download tool is officially provided (FQ is required)

  1. For now, you only need to choose Tomcat

  1. Fill in project information

  1. Click Generate Project to Generate the Project

Project to adjust

Create a project

  1. Creating a Folder (SSO)
  2. Create maven project in SSO folder (SSO-Base)
  3. Copy the downloaded SSO-server to SSO

Maven adjustment

parent pom.xml

Sso -base as the main project, cas.version as the focus, adjusted to 5.1.3, and adjusted maven’s repository

<? xml version="1.0" encoding="UTF-8"? > <project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> < modelVersion > 4.0.0 < / modelVersion > < groupId > com. Cxy. Auth < / groupId > < artifactId > sso - base < / artifactId > 1.0 the SNAPSHOT < version > < / version > < packaging > pom < / packaging > < properties > < Java version > 1.8 < / Java. Version > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> Piler < maven.com. Source > 1.8 < / maven.com piler. Source > < maven.com piler. Target > 1.8 < / maven.com piler. Target > < cas version > 5.1.3 < / cas. Version > < springboot. Version > 1.5.3. RELEASE < / springboot version > < / properties > < modules > <module>.. /sso-server</module> </modules> <! > > <repository> < Releases > <enabled>true</enabled>
            </releases>
            <id>maven2-release</id>
            <url>http://uk.maven.org/maven2/</url>
        </repository>

        <repository>
            <snapshots>
                <enabled>true</enabled> <! <updatePolicy>interval:120</updatePolicy> </snapshots> <id>oss-snapshots</id> <url>http://repository.jboss.org/nexus/content/groups/public/</url> </repository> </repositories> </project>Copy the code

sso-server pom.xml

Delete unnecessary configurations that are already configured in the parent project, including maven repositories, properties information, profiles.

<? xml version="1.0" encoding="UTF-8"? > <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.cxy.auth</groupId> <artifactId> sso. base</artifactId> < version > 1.0 - the SNAPSHOT < / version > < relativePath >). /sso-base/pom.xml</relativePath> </parent> <artifactId>sso-server</artifactId> <packaging>war</packaging> <name> Sso-server </name> <description>CAS authentication service, SSO </description> <dependencies> <dependency> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-webapp-tomcat</artifactId> <version>${cas.version}</version>
            <type>war</type>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apereo.cas</groupId>
                <artifactId>cas-server-support-bom</artifactId>
                <version>${cas.version}</version>
                <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>com.rimerosolutions.maven.plugins</groupId> <artifactId>wrapper-maven-plugin</artifactId> The < version > 0.0.5 < / version > < configuration > < verifyDownload >true</verifyDownload>
                    <checksumAlgorithm>MD5</checksumAlgorithm>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${springboot.version}</version>
                <configuration>
                    <mainClass>org.springframework.boot.loader.WarLauncher</mainClass>
                    <addResources>true</addResources> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> The < artifactId > maven - war - the plugin < / artifactId > < version > 3.1.0 < / version > < configuration > < warName > cas < / warName > <failOnMissingWebXml>false</failOnMissingWebXml>
                    <recompressZippedFiles>false</recompressZippedFiles>
                    <archive>
                        <compress>false</compress>
                        <manifestFile>${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp-tomcat/META-INF/MANIFEST.MF</manifestFile> </archive> <overlays> <overlay> <groupId>org.apereo.cas</groupId> <artifactId>cas-server-webapp-tomcat</artifactId> </overlay> </overlays> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId> Maven-compiler-plugin </artifactId> <version>3.3</version> </plugin> </finalName> cas</finalName> </build> </project>Copy the code

log4j2.xml

The/etc/cas/config/log4j2. XML in the project of SRC/main/resources, Dir . Change to logs

application.properties

Cas-server-webapp-tomcat /5.1.3/cas-server-webapp-tomcat-5.1.3.war! / WEB – INF/classes/application. Copies of the properties under the SRC/main/resources and adjust

Focus:

server.ssl.enabled=false

If you don’t mind, you can just copy and paste the code below

# #
# CAS Server Context Configuration
#
server.context-path=/cas
server.port=8443

server.ssl.enabled=false

server.max-http-header-size=2097152
server.use-forward-headers=true
server.connection-timeout=20000
server.error.include-stacktrace=NEVER

server.tomcat.max-http-post-size=2097152
server.tomcat.basedir=build/tomcat
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)
server.tomcat.accesslog.suffix=.log
server.tomcat.max-threads=10
server.tomcat.port-header=X-Forwarded-Port
server.tomcat.protocol-header=X-Forwarded-Proto
server.tomcat.protocol-header-https-value=https
server.tomcat.remote-ip-header=X-FORWARDED-FOR
server.tomcat.uri-encoding=UTF-8

spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

# #
# CAS Cloud Bus Configuration
#
spring.cloud.bus.enabled=false

endpoints.enabled=false
endpoints.sensitive=true

endpoints.restart.enabled=false
endpoints.shutdown.enabled=false

management.security.enabled=true
management.security.roles=ACTUATOR,ADMIN
management.security.sessions=if_required
management.context-path=/status
management.add-application-context-header=false

security.basic.authorize-mode=role
security.basic.enabled=false
security.basic.path=/cas/status/**

# #
# CAS Web Application Session Configuration
#
server.session.timeout=300
server.session.cookie.http-only=true
server.session.tracking-modes=COOKIE

# #
# CAS Thymeleaf View Configuration
#
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=true
spring.thymeleaf.mode=HTML
# #
# CAS Log4j Configuration
#
# logging.config=file:/etc/cas/log4j2.xml
server.context-parameters.isLog4jAutoInitializationDisabled=true

# #
# CAS AspectJ Configuration
#
spring.aop.auto=true
spring.aop.proxy-target-class=true

# #
# CAS Authentication Credentials
#
cas.authn.accept.users=casuser::Mellon
Copy the code

.java

Delete Java files, including SRC /main/ Java and SRC /test/ Java, otherwise the operation will be affected

run

Start the project

Since this project is Spring Boot, it can be run directly with the Java-jar instruction, so let’s run the script provided to CAS

All commands must be executed on the project

Initialization command:

build.cmd init

Package command:

build.cmd package

Clear target directory files:

build.cmd clean

Start command:

build.cmd run

If the following figure is displayed, the startup is successful

test

Go to http://localhost:8443/cas/login

landing

The default user name and password are casuser and Mellon

** Note: ** As the current user is statically configured, use the default user to log in.

conclusion

  1. Cas was built by hand and foot frame, and the configuration file was adjusted
  2. Cas was briefly introduced

This article refers to others blog learning arrangement, need to see the original blog or view the follow-up article can be click