JustNote
  • Introduction
  • DesignPattern
    • 七大原则
      • 开闭原则(OCP)
      • 依赖倒置原则(DIP)
      • 单一职责原则(SRP)
      • 接口隔离原则(ISP)
      • 迪米特法则(LoD)
      • 里氏代换原则(LSP)
      • 合成复用原则(CRP)
    • 创建型模式
      • 简单工厂模式
      • 工厂方法模式
      • 抽象工厂模式
      • 建造者模式
      • 单例模式
      • 原型模式
    • 结构型模式
      • 外观模式
      • 装饰模式
      • 适配器模式
      • 享元模式
      • 组合模式
      • 桥接模式
      • 代理模式
    • 行为型模式
      • 模板方法模式
      • 迭代器模式
      • 策略模式
      • 解释器模式
      • 观察者模式
      • 备忘录模式
      • 命令模式
      • 中介者模式
      • 责任链模式
      • 访问者模式
      • 状态模式
  • Java
    • Java Core
      • JVM 如何加载类
      • JVM 垃圾回收
      • JVM G1GC
      • JVM G1GC Q&A
      • JVM 与 Hbase
      • JVM ZGC Overview
      • JVM ZGC 内存管理
      • JVM ZGC 线程
      • JVM ZGC 垃圾回收
      • JVM ZGC 日志分析
      • JVM ZGC 参数调优
    • checkstyle
  • Golang
    • 源码阅读
      • Goroutines
      • Channel
    • gRPC
      • 1、快速开始
      • 2、什么是gRPC
      • 3、gRPC概念梳理
      • 4、基于Golang的gRPC入门
      • 5、gRPC组件ProtocolBuffers介绍
      • 6、gRPC组件Http 2.0
      • 7、错误处理和Debug
      • 8、gRPC身份验证
      • 9、服务注册与发现
      • 10、gRPC与gRPC Gateway
      • 11、gRPC与分布式链路追踪
  • Scala
    • 数据结构与算法
      • 数组
      • 队列
    • 函数式编程
      • 高阶函数
      • 偏函数
    • Immutable Collection
      • List
    • Mutable Collection
      • Array
    • 常见函数操作
      • A
        • aggregate
        • andThen
        • appended
        • appendedAll
      • C
        • chain
        • collect
        • collectFirst
        • combinations
        • compose
        • concat
        • cond
        • condOpt
        • const
        • contains
        • containsSlice
        • copyToArray
        • corresponds
        • count
        • curried
      • D
        • diff
        • distinct
        • distinctBy
        • drop
        • dropRight
        • dropWhile
      • E
        • empty(PartialFunction)
        • empty(collections)
        • endsWith
        • exists
      • F
        • fill
        • filter
        • filterKeys
        • filterNot
        • find
        • findLast
        • flatMap
        • flatten
        • fold
        • foldLeft
        • foldRight
        • forall
        • foreach
        • fromFunction
      • G
        • getOrElse (Map)
        • getOrElse (Option)
        • groupBy
        • groupMap
        • groupMapReduce
        • grouped
      • H
        • head
        • headOption
      • I
        • indexOf
        • indexOfSlice
        • indexWhere
        • indices
        • init
        • inits
        • intersect
        • isDefinedAt (Map)
        • isDefinedAt (Seq)
        • isEmpty
        • isTraversableAgain
      • K
        • keys
      • L
        • last
        • lastIndexOf
        • lastIndexOfSlice
        • lastIndexWhere
        • lastOption
        • length
        • lift
      • M
        • map
        • mapConserve
        • mapValues
        • max
        • maxBy
        • maxByOption
        • maxOption
        • min
        • minBy
        • minByOption
        • minOption
        • mkString
      • N
        • nonEmpty
      • O
        • orElse
      • P
        • padTo
        • par
        • partition
        • partitionMap
        • patch
        • permutations
        • prefixLength
        • prepended
        • prependedAll
        • product
      • R
        • range
        • reduce
        • reduceLeft
        • reduceLeftOption
        • reduceOption
        • reduceRight
        • reduceRightOption
        • reverse
        • reverseIterator
        • reverseMap
        • runWith
      • S
        • sameElements
        • scan
        • scanLeft
        • scanRight
        • search
        • segmentLength
        • size
        • slice
        • sliding
        • sortBy
        • sortWith
        • sorted
        • span
        • splitAt
        • startsWith
        • sum
      • T
        • tabulate
        • tail
        • tails
        • take
        • takeRight
        • takeWhile
        • transpose
        • tupled
      • U
        • unfold
        • union
        • unlift
        • untupled
        • unzip
        • unzip3
        • updated
      • V
        • values
        • view
      • W
        • withFilter
        • withDefault
        • withDefaultValue
      • Z
        • zip
        • zipAll
        • zipWithIndex
      • map
      • flatmap
      • filter
      • reduceLeft
      • foldLeft
    • Futures
      • Method with future as return type
      • Non blocking future result
      • Chain futures using flatMap
      • Chain futures using for comprehension
      • Future Option with for comprehension
      • Future Option with map
      • Composing Futures
      • Future Sequence
      • Future Traverse
      • Future foldLeft
      • Future reduceLeft
      • Future firstCompletedOf
      • Future zip
      • Future zipWith
      • Future andThen
      • Future configure threadpool
      • Future recover
      • Future recoverWith
      • Future fallbackTo
      • Future promise
    • Akka
  • Algorithm
  • Docker
  • Kubernetes
    • 二进制安装kubernetes
      • 00.从零开始
  • Architecture
    • Infrastructure
      • Opentracing
      • Jaeger && ZipKin
      • SkyWalking
      • Consul
      • Envoy
      • Service Mesh
      • Service Mesh: Istio 详解
      • Service Mesh: 基于 Istio 的落地实践(一)
    • CAS
      • CAS Server
      • CAS Service Management
      • CAS 集成LDAP
      • CAS 集成gitlab
      • CAS SSO & SLO
      • CAS Gitbook
    • xCAT
  • Netty
  • DDD
  • Reactive Programming
    • Reactor
      • Publisher
      • Subscriber
      • Subscription
      • Processor
    • WebFlux
  • Gitlab
    • Git Hook
  • CICD
    • Jenkins
      • Kubectl
Powered by GitBook
On this page
  • Gibook 与 CAS 的集成
  • 参考
  • Springboot 项目
  • 初始化项目
  • 添加CAS Client的依赖。
  • 修改gradle配置
  • 修改application.properties
  • 修改代码
  • 项目结构
  • 注册服务
  • 启动Gitbook Service

Was this helpful?

  1. Architecture
  2. CAS

CAS Gitbook

PreviousCAS SSO & SLONextxCAT

Last updated 4 years ago

Was this helpful?

关于Gitbook的介绍这里不再赘述。只说明一点,gitbook是将一系列组织好的markdown文件,生成对应静态文件的框架 。有了gitbook生成的静态文件,我们就可以将其单独部署在nginx或者apache下,来单独进行访问。当然也可以直接使用gitbook的命令来搭建一个gitbook站点。

Gibook 与 CAS 的集成

前面说到,gitbook 本质上就是一系列的静态文件,而且不支持RBAC等功能。一般来说我们在技术类社区看到的gitbook其实都是开放性的,由于应用场景的特殊性,我们需要将Gitbook与CAS 结合,为用户提供基于CAS的认证访问方式。并且与前面文章中介绍到的WordPress以及Gitlab打通。

这样的话,我们就可以通过Springboot集成CAS Client ,然后将 Gitbook build 之后的静态文件与Springboot 结合,就可以构建出一个基于CAS的JAVA应用。

参考

Springboot 项目

初始化项目

初始化一个 springboot 项目,在项目目录 resources 下创建一个 gitboot 目录。将 gitbook build 之后的内容放在这个目录下面。

添加CAS Client的依赖。

截止到本地实验的时候,官方发布的版本是 cas-client-support-springboot:3.6.0,经过实验以及查看源代码发现,这个版本中还没有将 Sing Logout 的功能包含进去,所以我们需要单独从源码进行构建依赖包。

在项目目录下,创建一个lib目录,将构建好的jar吧,拷贝到这个lib 目录下。

修改gradle配置

在build.gradle中添加如下的配置。

dependencies {
    compile fileTree(dir: 'lib', includes: ['*.jar'])
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
//    implementation 'org.jasig.cas.client:cas-client-support-springboot:3.6.0'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
}

修改application.properties

新增如下的配置

cas.server-url-prefix=https://cas.domain.com:8090/cas
cas.server-login-url=https://cas.domain.com:8090/cas/login
cas.client-host-url=http://cas.domain.com:8092

# 这个配置如果想生效,应该需要重新构建 jar包
cas.single-logout.enabled=true
cas.validation-type=CAS3

server.port=8092

spring.web.resources.static-locations=classpath:/gitbook/,classpath:/test/

#cas.authentication-url-patterns
#cas.validation-url-patterns
#cas.request-wrapper-url-patterns
#cas.assertion-thread-local-url-patterns
#cas.gateway
#cas.use-session
#cas.attribute-authorities
#cas.redirect-after-validation
#cas.allowed-proxy-chains
#cas.proxy-callback-url
#cas.proxy-receptor-url
#cas.accept-any-proxy
#server.context-parameters.renew

修改代码

修改程序入口文件。

package tech.selinux.gitbookcas;

import org.jasig.cas.client.boot.configuration.EnableCasClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableCasClient
public class GitbookCASApplication {

    public static void main(String[] args) {

        SpringApplication.run(GitbookCASApplication.class, args);
    }

}

项目结构

整个项目结构非常简单,完全采用CAS Client的自动配置就可以完成。项目目录如下图所示。

注册服务

将新开发的服务,注册到CAS Service中。在 /etc/cas/services/ 目录中,添加一个 Gitbook-10000006.json 的文件。

{
  "@class": "org.apereo.cas.services.RegexRegisteredService",
  "serviceId": "^http://cas.domain.com:8092/.*",
  "name": "Gitbook",
  "id": 10000006,
  "description": "Gitbook sample service",
  "singleSignOnParticipationPolicy": {
    "@class": "org.apereo.cas.services.DefaultRegisteredServiceSingleSignOnParticipationPolicy",
    "createCookieOnRenewedAuthentication": "TRUE"
  },
  "evaluationOrder": 30000,
  "usernameAttributeProvider": {
    "@class": "org.apereo.cas.services.DefaultRegisteredServiceUsernameProvider"
  },
  "logoutType": "BACK_CHANNEL",
  "attributeReleasePolicy": {
    "@class": "org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy",
    "principalAttributesRepository": {
      "@class": "org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository"
    },
    "authorizedToReleaseCredentialPassword": true,
    "authorizedToReleaseProxyGrantingTicket": true
  },
  "accessStrategy": {
    "@class": "org.apereo.cas.services.DefaultRegisteredServiceAccessStrategy",
    "unauthorizedRedirectUrl" : "http://cas.domain.com",
    "enabled": true,
    "ssoEnabled": true
  },
  "properties" : {
    "@class" : "java.util.HashMap",
    "skipRequiredServiceCheck" : {
      "@class" : "org.apereo.cas.services.DefaultRegisteredServiceProperty",
      "values" : [
        "java.util.HashSet",
        [
          "true" ] ]
    }
  }
}

启动Gitbook Service

启动gitbook Service ,然后访问服务地址,就可以实现基于CAS 的单点登录了。

下载 项目到本地workspace,然后 本别构建 cas-client-core,cas-client-support-saml,cas-client-support-springboot,这三个项目。

项目的实力代码 可以点击连接进行下载

SpringBoot 集成CAS 与Gitbook
Gibook 与 CAS 的集成
参考
Springboot 项目
初始化项目
添加CAS Client的依赖。
修改gradle配置
修改application.properties
修改代码
项目结构
注册服务
启动Gitbook Service
CAS Client
java-cas-client
gitbook-cas
CAS-GITBOOK
gitbook cas sso