Skip to content

Commit

Permalink
Merge pull request #31 from Laceyoo/main
Browse files Browse the repository at this point in the history
添加apereo/cas目录,提供Dockerfile
  • Loading branch information
freedomkk-qfeng authored Feb 27, 2024
2 parents 7de67ac + d2ee905 commit 8bd4144
Show file tree
Hide file tree
Showing 67 changed files with 4,663 additions and 16 deletions.
49 changes: 41 additions & 8 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ chmod +x control

### docker运行

内置测试的oauth2 server服务)
内置用于测试的oauth2 server服务)

#### 1.给`cas_init_script.sh`文件添加执行权限

Expand Down Expand Up @@ -117,20 +117,22 @@ environment:

修改容器的`ports`字段

如第1步中`SERVER_PORT`非默认值8444,则需将`cas-demo`容器的端口修改为`SERVER_PORT`的值,注意容器和宿主机端口必须相同
如第1步中`SERVER_PORT`非默认值8444,则需将`cas-demo`容器的端口修改为您设置的`SERVER_PORT`的值,注意容器和宿主机端口必须相同

```yml
# open-oauth2playground容器端口,可自行修改
ports:
- "8080:80"
# cas-demo容器
# cas-demo容器端口,两者需一致
ports:
- "your_port:your_port"
```

#### 3. 修改`cfg.json`配置

`cfg.json`文件中的`endpoints`字段中`cas server`域名设置为第1步的`CAS_SERVER_NAME`,如第1步中未设置,则设置为`http://localhost:8444`
##### 3.1 修改`endpoints`字段

`cfg.json`文件中的`endpoints`字段中`cas server`的域名设置为第1步的`CAS_SERVER_NAME`,如第1步中未设置,则设置为`http://localhost:8444`

```json
"endpoints": {
Expand All @@ -139,7 +141,14 @@ ports:
"userinfo": "http://localhost:8444/cas/oauth2.0/profile"
}
```
##### 3.2 修改`trust_domain`字段
`CAS_SERVER_NAME``http://localhost:8444`,则在`cfg.json`文件中的`trust_domain`字段中添加`localhost:8444`,反之添加您设置的`CAS_SERVER_NAME`的值

```json
"trust_domain": [
"localhost:8444",
]
```

#### 4. 启动容器

Expand All @@ -151,17 +160,41 @@ docker-compose up

`cas-domo`容器日志中看到`ready`字样,即启动成功,访问`http://localhost:8080`即可。

cas测试用户为:

#### 5. 注意

- **cas测试用户为**
```txt
user:cas
password:123456
```
可编辑`cas_init_script.sh`文件或启动后,进入`cas-demo`容器内部修改
可编辑`cas_init_script.sh`脚本添加新用户或修改用户名、密码
```shell
INSERT INTO user (username, password, name) VALUES ('cas', '123456', '测试用户');
```

或启动后进入`cas-demo`容器/export/data/目录下,连接sqlite数据库cas.db后修改
```shell
# 进入cas-demo容器
docker exec -it container_id /bin/bash

cd /export/data
# 连接数据库
sqlite3 cas.db
```

#### (可选)自定义`cas_init_script.sh`脚本
- **cas的service**
- authorization_code | client_credentials | device_flow模式:
```txt
client_id:open-oauth2playground
password:open-oauth2playground
```
- pkce模式:
```txt
client_id:open-oauth2playground-pkce
```
可在Open-OAuth2Playground/apereo-cas/etc/services目录下自行添加新的service

根据需要对cas的配置进行修改,如数据库中增加用户

### 配置
#### 后端配置
Expand Down
48 changes: 40 additions & 8 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ chmod +x control
```

### Running via Docker
(oauth2 server service with built-in tests)
(Built-in oauth2 server for testing)

#### 1. Grant execute permission to the `cas_init_script.sh` file

Expand Down Expand Up @@ -117,16 +117,18 @@ Modify the `ports` field of the container in the `docker-compose.yml` file
If `SERVER_PORT` in step 1 is not the default value of 8444, then you need to change the port of the `cas-demo` container to the value of `SERVER_PORT`, noting that the container and host ports must be the same.

```yml
# open-oauth2playground container, you can modify it on your own
# he port of the open-oauth2playground container, you can modify it on your own
ports:
- "8080:80"
# cas-demo container
# The port of the cas-demo container, both need to be identical
ports:
- "your_port:your_port"
```

#### 3. Modify the `cfg.json` configuration

##### 3.1 Modify the `endpoints` field

Set the `cas server` domain name in the `endpoints` field in the `cfg.json` file to `CAS_SERVER_NAME` from step 1, or to `http://localhost:8444` if not set in step 1

```json
Expand All @@ -137,6 +139,16 @@ Set the `cas server` domain name in the `endpoints` field in the `cfg.json` file
}
```

##### 3.2 Modify the `trust_domain` field

If `CAS_SERVER_NAME` filed is `http://localhost:8444`, add `localhost:8444` to the `trust_domain` field in the `cfg.json` file, and vice versa, add the value of `CAS_SERVER_NAME` that you set.

```json
"trust_domain": [
"localhost:8444",
]
```

#### 4. Start the container

Execute the following command in the directory where `docker-compose.yml` is located
Expand All @@ -147,19 +159,39 @@ docker-compose up

If you see the word `ready` in the `cas-domo` container log, the startup was successful.

And the cas user for test is:

#### 5. Note

- **cas test users are as follows:**
```txt
user:cas
password:123456
```
You can edit the `cas_init_script.sh` file or enter the `cas-demo` container after startup to update your user.
You can edit the `cas_init_script.sh` script to add a new user or change the username and password.
```shell
INSERT INTO user (username, password, name) VALUES ('cas', '123456', '测试用户');
```

Or start the `cas-demo` container and go to the /export/data/ directory, connect to the sqlite database cas.db and modify it.
```shell
# Enter the cas-demo container
docker exec -it container_id /bin/bash

#### (Optional) Customize the `cas_init_script.sh` script
cd /export/data
# Connect to the database
sqlite3 cas.db
```

Make changes to the cas configuration as needed, such as adding users to the database
- **the service of the cas**
- authorization_code | client_credentials | device_flow mode:
```txt
client_id:open-oauth2playground
password:open-oauth2playground
```
- pkce mode:
```txt
client_id:open-oauth2playground-pkce
```
You can add a new service yourself in the Open-OAuth2Playground/apereo-cas/etc/services directory.


### Configuration
Expand Down
7 changes: 7 additions & 0 deletions apereo-cas/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
target/**
build/**
bin/**
.idea/**
.history/**
.github/**
.git/**
6 changes: 6 additions & 0 deletions apereo-cas/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Set line endings to LF, even on Windows. Otherwise, execution within Docker fails.
# See https://help.github.com/articles/dealing-with-line-endings/
*.sh text eol=lf
gradlew text eol=lf
*.cmd text eol=crlf
*.bat text eol=crlf
48 changes: 48 additions & 0 deletions apereo-cas/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
.classpath
!/.project
.project
.settings
.history
.vscode
target/
.idea/
.DS_Store
.idea
overlays/
.gradle/
build/
log/
bin/
*.war
*.iml
*.log
tmp/
.java-version
./apache-tomcat
apache-tomcat.zip
config-metadata.properties
45 changes: 45 additions & 0 deletions apereo-cas/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM eclipse-temurin:11-jdk AS overlay

RUN mkdir -p cas-overlay
COPY ./src cas-overlay/src/
COPY ./gradle/ cas-overlay/gradle/
COPY ./gradlew ./settings.gradle ./build.gradle ./gradle.properties ./lombok.config /cas-overlay/

RUN mkdir -p ~/.gradle \
&& echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties \
&& echo "org.gradle.configureondemand=true" >> ~/.gradle/gradle.properties \
&& cd cas-overlay \
&& chmod 750 ./gradlew \
&& ./gradlew --version;

RUN cd cas-overlay \
&& ./gradlew clean build --parallel --no-daemon;

FROM eclipse-temurin:11-jdk AS cas

LABEL "Organization"="Apereo"
LABEL "Description"="Apereo CAS"

# 安装 sqlite3
RUN apt-get update \
&& apt-get install -y --no-install-recommends sqlite3 \
&& rm -rf /var/lib/apt/lists/*

RUN cd / \
&& mkdir -p /etc/cas/config \
&& mkdir -p /etc/cas/services \
&& mkdir -p /etc/cas/saml \
&& mkdir -p cas-overlay;

COPY --from=overlay cas-overlay/build/libs/cas.war cas-overlay/
COPY etc/cas/ /etc/cas/
COPY etc/cas/config/ /etc/cas/config/
COPY etc/cas/services/ /etc/cas/services/
COPY etc/cas/saml/ /etc/cas/saml/

EXPOSE 8080 8443

ENV PATH $PATH:$JAVA_HOME/bin:.

WORKDIR cas-overlay
ENTRYPOINT ["java", "-server", "-noverify", "-Xmx2048M", "-jar", "cas.war"]
Loading

0 comments on commit 8bd4144

Please sign in to comment.