在上节中,我们运行CAS服务器是打成war包在tomcat中进行运行,这节介绍在IDEA中运行CAS服务器。

1.下载CAS 模板 Overlay Template,我这里使用 Apereo CAS 5.3.x 版本,JDK需要1.8+

地址:https://github.com/apereo/cas-overlay-template/tree/5.3

2.进行解压,使用IDEA添加解压的项目,点击File—>New—>Project from Existing Sources...

使用IDEA运行CAS5.3服务器  springBoot客户端

 

选择解压好的项目

 使用IDEA运行CAS5.3服务器  springBoot客户端

 

 选择Maven

使用IDEA运行CAS5.3服务器  springBoot客户端

 

 使用IDEA运行CAS5.3服务器  springBoot客户端

 

 点击next,next...直到finish   项目加载。加载完成后,项目结构是这样子的

使用IDEA运行CAS5.3服务器  springBoot客户端

项目是一个overlay项目,下一节进行讲解

3.项目加载完成后,我们要在IDEA中配置tomcat,点击右上角的下三角,选择Edit Configurations...

使用IDEA运行CAS5.3服务器  springBoot客户端

 

点击+号

使用IDEA运行CAS5.3服务器  springBoot客户端

 

 向下拉,会有tomcat server,

使用IDEA运行CAS5.3服务器  springBoot客户端

 

 点击选择本地的,tomcat

使用IDEA运行CAS5.3服务器  springBoot客户端

 

 使用IDEA运行CAS5.3服务器  springBoot客户端

 

 使用IDEA运行CAS5.3服务器  springBoot客户端

 

使用IDEA运行CAS5.3服务器  springBoot客户端

 

 打包完成后的目录结构

使用IDEA运行CAS5.3服务器  springBoot客户端

 

 使用IDEA运行CAS5.3服务器  springBoot客户端

 

 运行成功后就会加载界面了

使用IDEA运行CAS5.3服务器  springBoot客户端

 

 

 

三:springBoot客户端

3.1 导包

使用IDEA运行CAS5.3服务器  springBoot客户端
    <parent> 
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.13.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    
    <dependencies>
        <!--web场景启动器,包含 Tomcat 和 spring-mvc restful  aop jackjson支持。 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- CAS依赖包 -->
        <dependency>
            <groupId>net.unicon.cas</groupId>
            <artifactId>cas-client-autoconfig-support</artifactId>
            <version>1.5.0-GA</version>
        </dependency>
    </dependencies>
使用IDEA运行CAS5.3服务器  springBoot客户端

3.2 application.properties

使用IDEA运行CAS5.3服务器  springBoot客户端
server.port=8081

cas.server-url-prefix=http\://127.0.0.1\:9080/cas
cas.server-login-url=http\://127.0.0.1\:9080/cas/login
cas.client-host-url=http\://127.0.0.1\:8081
cas.validation-type=CAS
使用IDEA运行CAS5.3服务器  springBoot客户端

3.3 配置类

使用IDEA运行CAS5.3服务器  springBoot客户端
import net.unicon.cas.client.configuration.CasClientConfigurerAdapter;
import net.unicon.cas.client.configuration.EnableCasClient;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableCasClient
public class CasConfigure extends CasClientConfigurerAdapter {
@Override
public void configureAuthenticationFilter(FilterRegistrationBean authenticationFilter) {
    super.configureAuthenticationFilter(authenticationFilter);
        authenticationFilter.getInitParameters().put("authenticationRedirectStrategyClass","com.patterncat.CustomAuthRedirectStrategy");
    }
}
使用IDEA运行CAS5.3服务器  springBoot客户端

3.4 控制器

使用IDEA运行CAS5.3服务器  springBoot客户端
@RestController
public class IndexController {
    
    @RequestMapping("/login")
    public String auth() {
        return "login success";
    }
}
使用IDEA运行CAS5.3服务器  springBoot客户端

3.5 主函数

使用IDEA运行CAS5.3服务器  springBoot客户端
@SpringBootApplication
public class Application {

     private static Logger log = Logger.getLogger(Application.class);
     
     public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
            log.info("SpringBoot Start Success");
        }
}
使用IDEA运行CAS5.3服务器  springBoot客户端

 

相关文章:

  • 2021-08-23
  • 2021-11-05
  • 2021-06-04
  • 2021-07-12
  • 2021-04-07
  • 2022-12-23
  • 2021-07-23
  • 2021-11-11
猜你喜欢
  • 2022-02-07
  • 2021-12-23
  • 2021-08-17
  • 2021-12-06
  • 2022-01-08
  • 2022-12-23
相关资源
相似解决方案