Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

自己署名証明書でhttpsに対応、--spring.config.locationで切り替え。 #2

Merged
merged 2 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SpringBoot2.x系で非同期メッセージングを使ったチャットアプ
内容:

* 2018-12 : Spring MVC で SseEmitter を使った Server-Sent Events のサンプルを作成。
* 2019-03 : Spring MVC で WebSocket API を使ったデモを作成。
* 2019-03 : Spring MVC で WebSocket API を使ったデモを作成。HTTPS有効化のデモ用設定ファイル/キーストア追加。

## 実行環境

Expand All @@ -30,7 +30,19 @@ cd springboot2-async-chat-demo/
./mvnw package

jarファイルから実行:
java -jar target/springboot2-async-chat-demo-v20181227.1.jar
java -jar target/springboot2-async-chat-demo-v201903.26.1.jar
```

https(自己署名証明書)を有効にして https://localhost:18089/ で起動するには:

```
java -jar target/springboot2-async-chat-demo-v201903.26.1.jar --spring.config.location=application-https.properties
```

※ `keystore.p12` は AdoptOpenJDK8 の `keytool` で以下のように生成しています。

```
keytool -genkeypair -keyalg RSA -dname "CN=test0, OU=ou0, O=org0, L=loc0, S=s0, C=JP" -alias self-signed-cert-t0 -keypass changeit -keystore keystore.p12 -storepass changeit -storetype PKCS12 -validity 3600
```

2018-12時点で以下のブラウザで動作確認しています。
Expand Down
9 changes: 9 additions & 0 deletions application-https.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server.port=18089

# https://docs.spring.io/spring-boot/docs/2.1.3.RELEASE/reference/htmlsingle/#howto-configure-ssl
server.ssl.key-store=keystore.p12
server.ssl.key-store-password=changeit
server.ssl.key-password=changeit

logging.level.root=INFO
logging.level.org.springframework.web=DEBUG
Binary file added keystore.p12
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/resources/static/plain-ws-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h2>Spring Framework 組み込みのWebSocket APIのデモ</h2>
};
talog('event=' + JSON.stringify(eventInfo));
}
const endpoint = 'ws://' + location.host + '/plain-ws-demo';
const endpoint = (location.protocol.startsWith('https') ? 'wss://' : 'ws://') + location.host + '/plain-ws-demo';
let websocket = null;

document.querySelector('#connect-to-server').addEventListener('click', function(event) {
Expand Down