docker部署onlyoffice,开启JWT权限校验Token

原来的部署方式

之前的方式是禁用了JWT:

docker run -itd -p 8080:80 --name docserver --network host  -e JWT_ENABLED=false --restart=always onlyoffice/documentserver:8 

新的部署方式

参考文档:https://helpcenter.onlyoffice.com/installation/docs-developer-install-docker.aspx?from=api

启用JWT Token:-e JWT_SECRET=my_jwt_secret

docker run -itd -p 8080:80 --name docserver --network host  -e JWT_SECRET=my_jwt_secret --restart=always onlyoffice/documentserver:8 

保存容器的数据:
参考命令:

sudo docker run -i -t -d -p 80:80 --restart=always \
    -v /app/onlyoffice/DocumentServer/logs:/var/log/onlyoffice  \
    -v /app/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data  \
    -v /app/onlyoffice/DocumentServer/lib:/var/lib/onlyoffice \
    -v /app/onlyoffice/DocumentServer/db:/var/lib/postgresql -e JWT_SECRET=my_jwt_secret onlyoffice/documentserver-de

创建相关的目录:

cd ~/docker/docserver
mkdir logs data lib db

停止容器:

docker stop docserver && docker rm docserver

构建容器:

docker run -itd --name docserver -p 18889:80 --restart=always \
    -v /home/zhangdapeng/docker/docserver/logs:/var/log/onlyoffice  \
    -v /home/zhangdapeng/docker/docserver/data:/var/www/onlyoffice/Data  \
    -v /home/zhangdapeng/docker/docserver/lib:/var/lib/onlyoffice \
    -v /home/zhangdapeng/docker/docserver/db:/var/lib/postgresql -e JWT_SECRET=zhangdapeng520 onlyoffice/documentserver:8

查看容器日志:

docker logs -f --tail 100 docserver

获取JWT Token

参考文档:https://api.onlyoffice.com/zh/editors/signature/

将配置文件复制出来:

docker cp docserver:/etc/onlyoffice/documentserver/local.json .

原始默认内容:

{
  "services": {
    "CoAuthoring": {
      "sql": {
        "type": "postgres",
        "dbHost": "localhost",
        "dbPort": "5432",
        "dbName": "onlyoffice",
        "dbUser": "onlyoffice",
        "dbPass": "onlyoffice"
      },
      "token": {
        "enable": {
          "request": {
            "inbox": true,
            "outbox": true
          },
          "browser": true
        },
        "inbox": {
          "header": "Authorization",
          "inBody": false
        },
        "outbox": {
          "header": "Authorization",
          "inBody": false
        }
      },
      "secret": {
        "inbox": {
          "string": "zhangdapeng520"
        },
        "outbox": {
          "string": "zhangdapeng520"
        },
        "session": {
          "string": "zhangdapeng520"
        }
      }
    }
  },
  "rabbitmq": {
    "url": "amqp://guest:guest@localhost"
  },
  "wopi": {
    "enable": false,
    "privateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC12HeKvvcytCl7\nvBpXP8uO8SSvntAHTT/hOZIJnCsMRs5OQiETa690iaU+Dos4xY6RyQW7jqioyWlC\n8cQXFu7JG9XhFkEmX2hIM3YouzjVnXr1C75U77q91svj2p2HG7c/UhglS/1plYuG\nmlqTMqxSKqERnbvtxpRweg629o+u9te++dJp+Lco5v0UE17xm5GmW85nG4NpMuf4\nrXx1m43nCjIPJ6+eVyDl1C1q9OoQz9azJjq6B2PDaLC/FI+HVsL55GD+CgFjmAjT\nooyqM7/5adbC4NjNGrxIi6pE28fndSiB3jlgrBYGMzK5G8fwWjbB3K+ZjZWsJY+d\n53PMueH1AgMBAAECggEADol0nDL1W2hoQCi16SkQhbSEv8T2d8oqCkAj16cHdyhH\nGgRF7tUD39EyVG2T0KDua3yCYk+E74iGZMa9OJe2bn2BeBVJqQUlUE9/QygdL4QZ\nQVl3SJ5cTQyZgqh5dMSqitVuJVEkiLPFRY61h4eCzuC/vPZHzaBuqAObhVUQAHPY\n8Y50kXFcCCsQdAuqV+jTG8+Er6nmktBBig6k+QP/XptwLtLpJiAdksVXvCDrHAJC\nzFTfDLCf0D4QIg5ecjIY/TfSOwPmXk11/xLLSmCJ9HnIWh9uReyo+aWKL748MRLk\nsVbRY4xT6DtDv5Ni47lECDQETg5h9d1NsrE4AQn40wKBgQDVbT2lu1Qma7AftFzW\nF1Zdkh1HROjnczTAJNSLhq5MkpD/WEDwbwdGdVZmW/xR+sEU1Wl/W0/gmD6PHK0i\nAJNJmWfy6/hb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+pYl0r2sTIUJOzkYMK5wJkjnhP00H0J6vJPGOyz9XGrx7KbQy976Kd9i1",
    "modulus": "B5D8778ABEF732B4297BBC1A573FCB8EF124AF9ED0074D3FE13992099C2B0C46CE4E4221136BAF7489A53E0E8B38C58E91C905BB8EA8A8C96942F1C41716EEC91BD5E11641265F6848337628BB38D59D7AF50BBE54EFBABDD6CBE3DA9D871BB73F5218254BFD69958B869A5A9332AC522AA1119DBBEDC694707A0EB6F68FAEF6D7BEF9D269F8B728E6FD14135EF19B91A65BCE671B836932E7F8AD7C759B8DE70A320F27AF9E5720E5D42D6AF4EA10CFD6B3263ABA0763C368B0BF148F8756C2F9E460FE0A01639808D3A28CAA33BFF969D6C2E0D8CD1ABC488BAA44DBC7E7752881DE3960AC16063332B91BC7F05A36C1DCAF998D95AC258F9DE773CCB9E1F5",
    "modulusOld": "B5D8778ABEF732B4297BBC1A573FCB8EF124AF9ED0074D3FE13992099C2B0C46CE4E4221136BAF7489A53E0E8B38C58E91C905BB8EA8A8C96942F1C41716EEC91BD5E11641265F6848337628BB38D59D7AF50BBE54EFBABDD6CBE3DA9D871BB73F5218254BFD69958B869A5A9332AC522AA1119DBBEDC694707A0EB6F68FAEF6D7BEF9D269F8B728E6FD14135EF19B91A65BCE671B836932E7F8AD7C759B8DE70A320F27AF9E5720E5D42D6AF4EA10CFD6B3263ABA0763C368B0BF148F8756C2F9E460FE0A01639808D3A28CAA33BFF969D6C2E0D8CD1ABC488BAA44DBC7E7752881DE3960AC16063332B91BC7F05A36C1DCAF998D95AC258F9DE773CCB9E1F5",
    "exponent": 65537,
    "exponentOld": 65537
  },
  "storage": {
    "fs": {
      "secretString": "HD97Gwvu8Z28TVQQOgMS"
    }
  }
}

参数说明:
在这里插入图片描述

修改:

{
  "services": {
    "CoAuthoring": {
      "sql": {
        "type": "postgres",
        "dbHost": "localhost",
        "dbPort": "5432",
        "dbName": "onlyoffice",
        "dbUser": "onlyoffice",
        "dbPass": "onlyoffice"
      },
      "token": {
        "enable": {
          "request": {
            "inbox": true,
            "outbox": true
          },
          "browser": true
        },
        "inbox": {
          "header": "Authorization",
          "inBody": true
        },
        "outbox": {
          "header": "Authorization",
          "inBody": true
        }
      },
      "secret": {
        "inbox": {
          "string": "zhangdapeng520"
        },
        "outbox": {
          "string": "zhangdapeng520"
        },
        "session": {
          "string": "zhangdapeng520"
        }
      }
    }
  },
  "rabbitmq": {
    "url": "amqp://guest:guest@localhost"
  },
  "wopi": {
    "enable": false,
    "privateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC12HeKvvcytCl7\nvBpXP8uO8SSvntAHTT/hOZIJnCsMRs5OQiETa690iaU+Dos4xY6RyQW7jqioyWlC\n8cQXFu7JG9XhFkEmX2hIM3YouzjVnXr1C75U77q91svj2p2HG7c/UhglS/1plYuG\nmlqTMqxSKqERnbvtxpRweg629o+u9te++dJp+Lco5v0UE17xm5GmW85nG4NpMuf4\nrXx1m43nCjIPJ6+eVyDl1C1q9OoQz9azJjq6B2PDaLC/FI+HVsL55GD+CgFjmAjT\nooyqM7/5adbC4NjNGrxIi6pE28fndSiB3jlgrBYGMzK5G8fwWjbB3K+ZjZWsJY+d\n53PMueH1AgMBAAECggEADol0nDL1W2hoQCi16SkQhbSEv8T2d8oqCkAj16cHdyhH\nGgRF7tUD39EyVG2T0KDua3yCYk+E74iGZMa9OJe2bn2BeBVJqQUlUE9/QygdL4QZ\nQVl3SJ5cTQyZgqh5dMSqitVuJVEkiLPFRY61h4eCzuC/vPZHzaBuqAObhVUQAHPY\n8Y50kXFcCCsQdAuqV+jTG8+Er6nmktBBig6k+QP/XptwLtLpJiAdksVXvCDrHAJC\nzFTfDLCf0D4QIg5ecjIY/TfSOwPmXk11/xLLSmCJ9HnIWh9uReyo+aWKL748MRLk\nsVbRY4xT6DtDv5Ni47lECDQETg5h9d1NsrE4AQn40wKBgQDVbT2lu1Qma7AftFzW\nF1Zdkh1HROjncz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ndrjy9a9uu9Uvgv1ep3VOLsodjNIaF8mQRbh1RvJ7hYXxPFCacmoqI67BcmRjsU4iw4+pYl0r2sTIUJOzkYMK5wJkjnhP00H0J6vJPGOyz9XGrx7KbQy976Kd9i1",
    "modulus": "B5D8778ABEF732B4297BBC1A573FCB8EF124AF9ED0074D3FE13992099C2B0C46CE4E4221136BAF7489A53E0E8B38C58E91C905BB8EA8A8C96942F1C41716EEC91BD5E11641265F6848337628BB38D59D7AF50BBE54EFBABDD6CBE3DA9D871BB73F5218254BFD69958B869A5A9332AC522AA1119DBBEDC694707A0EB6F68FAEF6D7BEF9D269F8B728E6FD14135EF19B91A65BCE671B836932E7F8AD7C759B8DE70A320F27AF9E5720E5D42D6AF4EA10CFD6B3263ABA0763C368B0BF148F8756C2F9E460FE0A01639808D3A28CAA33BFF969D6C2E0D8CD1ABC488BAA44DBC7E7752881DE3960AC16063332B91BC7F05A36C1DCAF998D95AC258F9DE773CCB9E1F5",
    "modulusOld": "B5D8778ABEF732B4297BBC1A573FCB8EF124AF9ED0074D3FE13992099C2B0C46CE4E4221136BAF7489A53E0E8B38C58E91C905BB8EA8A8C96942F1C41716EEC91BD5E11641265F6848337628BB38D59D7AF50BBE54EFBABDD6CBE3DA9D871BB73F5218254BFD69958B869A5A9332AC522AA1119DBBEDC694707A0EB6F68FAEF6D7BEF9D269F8B728E6FD14135EF19B91A65BCE671B836932E7F8AD7C759B8DE70A320F27AF9E5720E5D42D6AF4EA10CFD6B3263ABA0763C368B0BF148F8756C2F9E460FE0A01639808D3A28CAA33BFF969D6C2E0D8CD1ABC488BAA44DBC7E7752881DE3960AC16063332B91BC7F05A36C1DCAF998D95AC258F9DE773CCB9E1F5",
    "exponent": 65537,
    "exponentOld": 65537
  },
  "storage": {
    "fs": {
      "secretString": "HD97Gwvu8Z28TVQQOgMS"
    }
  }
}

复制回去:

docker cp local.json docserver:/etc/onlyoffice/documentserver/local.json

重启:

docker restart docserver

使用Python生成Token

官方文档实例:https://api.onlyoffice.com/zh/editors/signature/#python

def encode(payload):
    return jwt.encode(payload, config.DOC_SERV_JWT_SECRET, algorithm='HS256')

使用zdppy_jwt框架生成Token:

import jwt

key = "zhangdapeng520"
algorithm = "HS256"
data = {"id": "1", "username": "zhangdapeng", "role": "admin"}
encoded = jwt.encode(data, key, algorithm=algorithm)
print(encoded)

得到结果:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEiLCJ1c2VybmFtZSI6InpoYW5nZGFwZW5nIiwicm9sZSI6ImFkbWluIn0.EyayWbKV5arHahTiXkSIKb6e1wF5a2pf6NhszyjZYfE

使用之前成功的代码进行测试

后端代码:

import json
import req

import api
from api import middleware
from api.zjson.response import JSONResponse


async def doc_callback(request):
    data = await api.req.get_json(request)
    print("callback === ", data)
    # status == 2 文档准备好被保存
    if data.get("status") == 2:
        req.download(data.get("url"), "data/test.docx")
    if data.get("status") == 6:
        req.download(data.get("url"), "data/test.docx")
    # status == 6 文档编辑会话关闭
    data = {"error": 0}
    # return JSONResponse('{"error":0}')
    return JSONResponse(json.dumps(data))


app = api.Api(
    routes=[
        api.resp.dir_route("/dist", "data"),
        api.resp.post("/callback", doc_callback),
    ],
    middleware=[middleware.cors()],
)

if __name__ == "__main__":
    app.run(port=18888)

前端代码:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite + Vue</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="text/javascript" src="http://127.0.0.1:18889/web-apps/apps/api/documents/api.js"></script>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

但是,现在当我们点击加载的时候,会报如下错误:
在这里插入图片描述

错误原因是因为我们之前的docserver是禁用了JWT的,但是现在我们启用了,而代码还是原来的代码,没有做任何修改。

实际上,我们应该加上JWT Token相关的信息配置。

添加JWT Token

注意:token的payload必须是文档config的完整信息:https://api.onlyoffice.com/zh/editors/signature/browser
在这里插入图片描述

改完后token生成代码如下:

import jwt

key = "zhangdapeng520"
algorithm = "HS256"
data = {
    "document": {
      "fileType": "docx",
      "key": "Khirz6zTPdfd7",
      "title": "Example Document Title.docx",
      "url": "http://127.0.0.1:18888/dist/test.docx"
    },
    "editorConfig": {
      "callbackUrl": "http://127.0.0.1:18888/callback",
      "lang": "zh-CN",
      "user": {
        "id": 1,
        "name": "zdp"
      },
      "customization": {
        "forcesave": True,
      },
      "coEditing": {
        "mode": "fast",
        "change": True
      },
    },
    "documentType": "word",
    "height": '500px',
    "width": '100%',
  }
encoded = jwt.encode(data, key, algorithm=algorithm)
print(encoded)

改完后前端代码如下:

<script setup>
import {message} from "ant-design-vue";

const onLoadDocumentClick = () => {
  message.success("load document")
  // isDocument.value = true
  new DocsAPI.DocEditor("doc", {
    "document": {
      "fileType": "docx",
      "key": `Khirz6zTPdfd7`,
      "title": "Example Document Title.docx",
      "url": "http://127.0.0.1:18888/dist/test.docx"
    },
    "editorConfig": {
      "callbackUrl": "http://127.0.0.1:18888/callback",
      "lang": "zh-CN",
      "user": {
        "id": 1,
        "name": `zdp`
      },
      "customization": {
        "forcesave": true,
      },
      "coEditing": {
        "mode": "fast",
        "change": true
      },
    },
    "documentType": "word",
    height: '500px',
    width: '100%',
    token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb2N1bWVudCI6eyJmaWxlVHlwZSI6ImRvY3giLCJrZXkiOiJLaGlyejZ6VFBkZmQ3IiwidGl0bGUiOiJFeGFtcGxlIERvY3VtZW50IFRpdGxlLmRvY3giLCJ1cmwiOiJodHRwOi8vMTI3LjAuMC4xOjE4ODg4L2Rpc3QvdGVzdC5kb2N4In0sImVkaXRvckNvbmZpZyI6eyJjYWxsYmFja1VybCI6Imh0dHA6Ly8xMjcuMC4wLjE6MTg4ODgvY2FsbGJhY2siLCJsYW5nIjoiemgtQ04iLCJ1c2VyIjp7ImlkIjoxLCJuYW1lIjoiemRwIn0sImN1c3RvbWl6YXRpb24iOnsiZm9yY2VzYXZlIjp0cnVlfSwiY29FZGl0aW5nIjp7Im1vZGUiOiJmYXN0IiwiY2hhbmdlIjp0cnVlfX0sImRvY3VtZW50VHlwZSI6IndvcmQiLCJoZWlnaHQiOiI1MDBweCIsIndpZHRoIjoiMTAwJSJ9.AolS4haisOZc9IxQcd99ovD5FixcfswrhWOnbSRaCJw",
  });
}
</script>
<template>
  <div class="bg-indigo-50 p-8 min-h-screen">
    <div class="bg-amber-200 p-8">
      <a-button type="primary" @click="onLoadDocumentClick">Load Document</a-button>
    </div>
    <div class="bg-amber-400 p-8 min-h-96">
      <div id="doc">doc</div>
    </div>
  </div>
</template>

此时token错误的问题已经解决了,但是出现了下载失败的问题:
在这里插入图片描述

解决下载失败的问题

把配置文件复制出来:

docker cp docserver:/etc/onlyoffice/documentserver/default.json ~/Downloads/default.json

修改:之前

"allowPrivateIPAddress": false,
"allowMetaIPAddress": false

修改:之后

"allowPrivateIPAddress": true,
"allowMetaIPAddress": true

把文件复制进去:

docker cp default.json docserver:/etc/onlyoffice/documentserver/default.json 

进入容器:

docker exec -it docserver bash

重启相关服务:

supervisorctl restart all

或者一次性执行:

docker exec docserver supervisorctl restart all

最终解决方案

生成token:

import jwt

key = "zhangdapeng520"
algorithm = "HS256"
data = {
    "document": {
      "fileType": "docx",
      "key": "Khirz6zTPdfd7",
      "title": "Example Document Title.docx",
      "url": "http://192.168.234.138:18888/dist/test.docx"
    },
    "editorConfig": {
      "callbackUrl": "http://192.168.234.138:18888/callback",
      "lang": "zh-CN",
      "user": {
        "id": "1",
        "name": "zdp"
      },
      "customization": {
        "forcesave": True,
      },
      "coEditing": {
        "mode": "fast",
        "change": True
      },
    },
    "documentType": "word",
    "height": '500px',
    "width": '100%',
  }
encoded = jwt.encode(data, key, algorithm=algorithm)
print(encoded)

前端代码:

<script setup>
import {message} from "ant-design-vue";

const onLoadDocumentClick = () => {
  message.success("load document")
  // isDocument.value = true
  new DocsAPI.DocEditor("doc", {
    "document": {
      "fileType": "docx",
      "key": `Khirz6zTPdfd7`,
      "title": "Example Document Title.docx",
      "url": "http://192.168.234.138:18888/dist/test.docx"
    },
    "editorConfig": {
      "callbackUrl": "http://192.168.234.138:18888/callback",
      "lang": "zh-CN",
      "user": {
        "id": "1",
        "name": "zdp"
      },
      "customization": {
        "forcesave": true,
      },
      "coEditing": {
        "mode": "fast",
        "change": true
      },
    },
    "documentType": "word",
    height: '500px',
    width: '100%',
    token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb2N1bWVudCI6eyJmaWxlVHlwZSI6ImRvY3giLCJrZXkiOiJLaGlyejZ6VFBkZmQ3IiwidGl0bGUiOiJFeGFtcGxlIERvY3VtZW50IFRpdGxlLmRvY3giLCJ1cmwiOiJodHRwOi8vMTkyLjE2OC4yMzQuMTM4OjE4ODg4L2Rpc3QvdGVzdC5kb2N4In0sImVkaXRvckNvbmZpZyI6eyJjYWxsYmFja1VybCI6Imh0dHA6Ly8xOTIuMTY4LjIzNC4xMzg6MTg4ODgvY2FsbGJhY2siLCJsYW5nIjoiemgtQ04iLCJ1c2VyIjp7ImlkIjoiMSIsIm5hbWUiOiJ6ZHAifSwiY3VzdG9taXphdGlvbiI6eyJmb3JjZXNhdmUiOnRydWV9LCJjb0VkaXRpbmciOnsibW9kZSI6ImZhc3QiLCJjaGFuZ2UiOnRydWV9fSwiZG9jdW1lbnRUeXBlIjoid29yZCIsImhlaWdodCI6IjUwMHB4Iiwid2lkdGgiOiIxMDAlIn0.vnSYKU22-IsBmuoSn5Po-Ukz1RrnM-G3ch3-JuJd1xg",
  });
}
</script>
<template>
  <div class="bg-indigo-50 p-8 min-h-screen">
    <div class="bg-amber-200 p-8">
      <a-button type="primary" @click="onLoadDocumentClick">Load Document</a-button>
    </div>
    <div class="bg-amber-400 p-8 min-h-96">
      <div id="doc">doc</div>
    </div>
  </div>
</template>

总结

虽然上面的方案解决了Token校验的问题,但是,我们一开始的目标并没有实现。 那就是我们想要解决文件下载失败和保存文件失败的问题。

在这里插入图片描述

在这里插入图片描述

这两个错误实际上都是警告,不是严格错误。而且,我们的文档最终也都被成功的加载或者是保存了,实际上并没有发生错误,而我docserver文档服务发出的警告。

如果要提高用户的体验,我们还是得想办法就这两个警告给禁止掉或者解决掉。

后面继续研究。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/779199.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

实验1 主成分分析

目 录 二、实验环境... 1 三、实验内容... 1 3.1 导入数据... 2 3.2 求相关系数矩阵.. 3 3.3 数据规范化处理.. 3 3.4 主成分分析... 4 四 实验心得... 5 一、实验目的 &#xff08;1&#xff09;理解主成分分析的思想&#xff1b; &#xff08;2&#xff09;掌握主成分分析方…

Python 异步编程介绍与代码示例

Python 异步编程介绍与代码示例 一、异步编程概述 异步编程是一种编程范式&#xff0c;它旨在处理那些需要等待I/O操作完成或执行耗时任务的情况。在传统的同步编程中&#xff0c;代码会按照顺序逐行执行&#xff0c;直到遇到一个耗时操作&#xff0c;它会阻塞程序的执行直到…

测试人应该懂的!自动化测试必会之数据驱动测试

数据驱动测试 在实际的测试过程中&#xff0c;我们会发现好几组用例都是相同的操作步骤&#xff0c;只是测试数据的不同&#xff0c;而我们往往需要编写多次用例来进行测试&#xff0c;此时我们可以利用数据驱动测试来简化该种操作。 参数化&#xff1a; 输入数据的不同从而产…

【云计算】公有云、私有云、混合云、社区云、多云

公有云、私有云、混合云、社区云、多云 1.云计算的形态1.1 公有云1.2 私有云1.3 混合云1.4 社区云1.5 多云1.5.1 多云和混合云之间的关系1.5.2 多云的用途1.5.3 影子 IT 和多云1.5.4 优缺点 2.不同云形态的对比 1.云计算的形态 张三⾃⼰在家做饭吃&#xff0c;这是 私有云&…

非堆成加密是公私钥使用

对称加密学习-CSDN博客 加密算法学习-CSDN博客 非对称加密算法使用一对密钥&#xff0c;包括一个公钥和一个私钥&#xff0c;它们是数学上相关联的&#xff0c;但公钥可以公开分享&#xff0c;而私钥必须保密。以下是使用非对称加密算法的一般步骤&#xff1a; 密钥生成&…

Spring相关面试题(四)

49 JavaConfig方式如何启用AOP?如何强制使用cglib&#xff1f; 在JavaConfig类&#xff0c;加上EnableAspectJAutoProxy 如果要强制使用CGLIB动态代理 &#xff0c;加上(proxyTargetClass true) 加上(exposeProxy true) 就是将对象暴露到线程池中。 50 介绍AOP在Spring中…

打开浏览器控制台,点击应用,浏览器崩溃

调试的时候&#xff0c;打开控制台&#xff0c;点击 “应用” 立马浏览器奔溃&#xff0c;但是点击别的没问题 调查发现是因为manifest.json这个文件引起的 manifest.json 最主要的原因是因为没有设置这个sizes字段 Google浏览器更新大概到126之后的版本会有问题&#xff0c;之…

关于CPU你一定要注意的重要参数,警惕韭菜陷阱

昨天遇到个奇葩事&#xff0c;有个粉丝喷我“懂不懂什么叫I9&#xff1f;”言下之意就是CPU中I9>i7>I5>I3&#xff0c;我也不知道咋说&#xff0c;只是提醒大家小心被坑&#xff0c;花了多的钱用的差的性能。作为回应&#xff0c;仅以此篇说下CPU咱们臭打游戏一定要知…

新手学Cocos报错 [Assets] Failed to open

两个都在偏好设置里面调&#xff08;文件下面的偏好设置&#xff09;&#xff1a; 1.设置中文&#xff1f; 2.报错 [Assets] Failed to open&#xff1f; 这样在点击打开ts文件的时候就不会报错&#xff0c;并且用vscode编辑器打开了&#xff0c; 同样也可以改成你们自己喜欢…

彻底解决Path with “WEB-INF“ or “META-INF“: [WEB-INF/views/index.jsp]

背景描述 项目使用的是springboot2jsp的架构。以前好好的项目复制了一份&#xff0c;然后就无法访问报错。百度了好久都乱七八糟的&#xff0c;还没有解决问题。错误消息如下&#xff1a; 2024-07-05 15:45:51.335 INFO [http-nio-12581-exec-1]org.springframework.web.ser…

【Selenium配置】WebDriver安装浏览器驱动(ChromeEdge)

【Selenium配置】WebDriver安装浏览器驱动&#xff08;Chrome&Edge&#xff09; 文章目录 【Selenium配置】WebDriver安装浏览器驱动&#xff08;Chrome&Edge&#xff09;Chrome确认Chrome版本下载对应driver把解压后的chromedriver文件放在chrome安装目录下&#xff0…

字节跳动与南开联合开源 StoryDiffusion:一键生成漫画和视频故事的神器!完全免费!

大家好&#xff0c;我是程序员X小鹿&#xff0c;前互联网大厂程序员&#xff0c;自由职业2年&#xff0c;也一名 AIGC 爱好者&#xff0c;持续分享更多前沿的「AI 工具」和「AI副业玩法」&#xff0c;欢迎一起交流~ 漫画&#xff0c;是多少人童年的回忆啊&#xff01; 记得小学…

VMware安装centos9详细教程(保姆级)

前言 centos9最新的centos版本&#xff0c;在近期的使用中发现它的操作界面与以往的centos7/8更加舒适&#xff0c;界面优化更加精细 项目终止日期&#xff08;EOL&#xff09; 从公告可知&#xff0c;CentOS 项目重心从 CentOS Linux 转移到了 CentOS Stream。下面是各个项…

初识STM32:开发方式及环境

STM32的编程模型 假如使用C语言的方式写了一段程序&#xff0c;这段程序首先会被烧录到芯片当中&#xff08;Flash存储器中&#xff09;&#xff0c;Flash存储器中的程序会逐条的进入CPU里面去执行。 CPU相当于人的一个大脑&#xff0c;虽然能执行运算和执行指令&#xff0c;…

沪上繁花:上海电信的5G-A之跃

2024年6月18日下午&#xff0c;在上海举行的3GPP RAN第104次会议上&#xff0c;3GPP正式宣布R18标准冻结。R18是无线网络面向5G-A的第一个版本&#xff0c;其成功冻结正式宣布了5G发展迎来新机遇&#xff0c;5G-A商用已进入全新的发展阶段。 在5G-A滚滚而来的时代洪流中&#x…

基于STM32的通用红外遥控器设计: 解码、学习与发射(代码示例)

摘要&#xff1a; 本文将带你使用STM32打造一款功能强大的万能红外遥控器&#xff0c;它可以学习和复制多种红外信号&#xff0c;并通过OLED屏幕和按键实现便捷操作。我们将深入探讨红外通信原理、STM32编程、OLED显示和EEPROM数据存储等关键技术&#xff0c;并提供完整的代码示…

【Linux进阶】文件系统7——文件系统简单操作

1.磁盘与目录的容量 现在我们知道磁盘的整体数据是在超级区块中&#xff0c;但是每个文件的容量则在inode 当中记载。 那在命令行模式下面该如何显示这几个数据&#xff1f;下面就让我们来谈一谈这两个命令&#xff1a; df&#xff1a;列出文件系统的整体磁盘使用量&#xf…

(阿里云在线播放)基于SpringBoot+Vue前后端分离的在线教育平台项目

&#x1f497;博主介绍&#x1f497;&#xff1a;✌在职Java研发工程师、专注于程序设计、源码分享、技术交流、专注于Java技术领域和毕业设计✌ 温馨提示&#xff1a;文末有 CSDN 平台官方提供的老师 Wechat / QQ 名片 :) Java精品实战案例《700套》 2025最新毕业设计选题推荐…

公务员考试、事业编考试、教师资格证、面试、K12资料、电子书

点击上方△腾阳 关注 作者 l 腾阳 转载请联系授权 你好&#xff0c;我是腾阳。 在这个自媒体的海洋里&#xff0c;我曾是一只迷失方向的小鸟&#xff0c;多次尝试飞翔却总是跌跌撞撞。 但每一次跌倒&#xff0c;都让我更坚定地相信&#xff0c;只要不放弃&#xff0c;总…

【Android】自定义换肤框架01之皮肤包制作

前言 目前为止&#xff0c;市面上主流的安卓换肤方案&#xff0c;其实原理都是差不多的 虽然大多都号称一行代码集成&#xff0c;但其实想要做到完全适配&#xff0c;并不简单 这个系列&#xff0c;就是让大家从零开始&#xff0c;完全掌握这方面知识&#xff0c;这样才能对…