使用IDEA運行CAS5.3服務器 springBoot客戶端


在上節中,我們運行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...

 

選擇解壓好的項目

 

 

 選擇Maven

 

 

 

 點擊next,next...直到finish   項目加載。加載完成后,項目結構是這樣子的

項目是一個overlay項目,下一節進行講解

3.項目加載完成后,我們要在IDEA中配置tomcat,點擊右上角的下三角,選擇Edit Configurations...

 

點擊+號

 

 向下拉,會有tomcat server,

 

 點擊選擇本地的,tomcat

 

 

 

 

 

 

 打包完成后的目錄結構

 

 

 

 運行成功后就會加載界面了

 

 

 

三:springBoot客戶端

3.1 導包

復制代碼
    <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>
復制代碼

3.2 application.properties

復制代碼
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
復制代碼

3.3 配置類

復制代碼
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");
    }
}
復制代碼

3.4 控制器

復制代碼
@RestController
public class IndexController {
    
    @RequestMapping("/login")
    public String auth() {
        return "login success";
    }
}
復制代碼

3.5 主函數

復制代碼
@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");
        }
}
復制代碼

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM