-
-
Notifications
You must be signed in to change notification settings - Fork 148
feat: 优化授权码登录 #5914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 优化授权码登录 #5914
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,24 +19,16 @@ | |
|
|
||
| import io.minio.BucketExistsArgs; | ||
| import io.minio.GetPresignedObjectUrlArgs; | ||
| import io.minio.Http; | ||
| import io.minio.MakeBucketArgs; | ||
| import io.minio.MinioClient; | ||
| import io.minio.PutObjectArgs; | ||
| import io.minio.errors.ErrorResponseException; | ||
| import io.minio.errors.InsufficientDataException; | ||
| import io.minio.errors.InternalException; | ||
| import io.minio.errors.InvalidResponseException; | ||
| import io.minio.errors.ServerException; | ||
| import io.minio.errors.XmlParserException; | ||
| import io.minio.http.Method; | ||
| import io.minio.errors.MinioException; | ||
| import org.laokou.common.i18n.common.exception.BizException; | ||
| import org.laokou.common.oss.model.BaseOss; | ||
| import org.laokou.common.oss.model.FileInfo; | ||
| import org.laokou.common.oss.model.MinIO; | ||
|
|
||
| import java.io.IOException; | ||
| import java.security.InvalidKeyException; | ||
| import java.security.NoSuchAlgorithmException; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
|
|
@@ -61,9 +53,7 @@ protected MinioClient getObj() { | |
| } | ||
|
|
||
| @Override | ||
| protected void checkBucket(MinioClient minioClient) throws ServerException, InsufficientDataException, | ||
| ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, | ||
| InvalidResponseException, XmlParserException, InternalException { | ||
| protected void checkBucket(MinioClient minioClient) throws MinioException { | ||
| String bucketName = this.minIO.getBucketName(); | ||
| boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); | ||
| if (!isExist) { | ||
|
|
@@ -73,35 +63,29 @@ protected void checkBucket(MinioClient minioClient) throws ServerException, Insu | |
| } | ||
|
|
||
| @Override | ||
| protected void upload(MinioClient minioClient) throws ServerException, InsufficientDataException, | ||
| ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, | ||
| InvalidResponseException, XmlParserException, InternalException { | ||
| protected void upload(MinioClient minioClient) throws MinioException { | ||
| PutObjectArgs objectArgs = PutObjectArgs.builder() | ||
| .bucket(this.minIO.getBucketName()) | ||
| .object(fileInfo.name()) | ||
| .stream(fileInfo.inputStream(), fileInfo.size(), -1) | ||
| .stream(fileInfo.inputStream(), fileInfo.size(), -1L) | ||
| .contentType(fileInfo.contentType()) | ||
| .build(); | ||
| minioClient.putObject(objectArgs); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getUrl(MinioClient minioClient) throws ServerException, InsufficientDataException, | ||
| ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, | ||
| InvalidResponseException, XmlParserException, InternalException { | ||
| protected String getUrl(MinioClient minioClient) throws MinioException { | ||
| GetPresignedObjectUrlArgs objectUrlArgs = GetPresignedObjectUrlArgs.builder() | ||
| .bucket(this.minIO.getBucketName()) | ||
| .object(fileInfo.name()) | ||
| .method(Method.GET) | ||
| .method(Http.Method.GET) | ||
|
Comment on lines
+77
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): 在 MinIO 的 之前这里使用的是 MinIO 的 Original comment in Englishissue (bug_risk): Using This previously used MinIO’s |
||
| .expiry(5, TimeUnit.DAYS) | ||
| .build(); | ||
| return minioClient.getPresignedObjectUrl(objectUrlArgs); | ||
| } | ||
|
|
||
| @Override | ||
| public void createBucket() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, | ||
| NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, | ||
| InternalException { | ||
| public void createBucket() throws MinioException { | ||
| MinioClient minioClient = getObj(); | ||
| String bucketName = this.minIO.getBucketName(); | ||
| boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build()); | ||
|
|
||
This file was deleted.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| <meta charset="UTF-8"/> | ||
| <meta name="viewport" content="width=device-width,initial-scale=1"/> | ||
| <title>老寇IoT云平台统一认证</title> | ||
| <script src="js/axios.min.js"></script> | ||
| <style> | ||
| html, body { | ||
| height: 100%; | ||
|
|
@@ -13,7 +14,7 @@ | |
| overflow-x: hidden; | ||
| min-height: 100vh; | ||
| font-family: Arial, Helvetica, sans-serif; | ||
| background: url('/api/img/FfdJeJRQWjEeGTpqgBKj.png') no-repeat center center; | ||
| background: url('img/FfdJeJRQWjEeGTpqgBKj.png') no-repeat center center; | ||
| background-size: cover; | ||
|
|
||
| /* 更健壮的居中布局:适配不同屏幕尺寸 */ | ||
|
|
@@ -98,32 +99,56 @@ | |
| <h2>老寇IoT云平台统一认证</h2> | ||
| </div> | ||
|
|
||
| <div class="alert alert-danger" th:if="${session.SPRING_SECURITY_LAST_EXCEPTION != null}"> | ||
| <div class="alert alert-danger" th:if="${param.error != null and session.SPRING_SECURITY_LAST_EXCEPTION != null}"> | ||
| <span th:text="${session.SPRING_SECURITY_LAST_EXCEPTION?.message}"></span> | ||
| </div> | ||
| <form method="post" th:action="@{/login}"> | ||
| <form method="post" th:action="@{/login}" autocomplete="off"> | ||
|
|
||
| <div class="form-item row" style="width: 100%;"> | ||
| <input id="tenant" name="tenant" type="text" placeholder="请输入租户编号" required autofocus/> | ||
| <input id="uuid" name="uuid" type="text" autocomplete="new-password" hidden="hidden" placeholder="请输入唯一标识" required/> | ||
| </div> | ||
|
|
||
| <div class="form-item row" style="width: 100%;"> | ||
| <input id="username" name="username" type="text" placeholder="请输入用户名" required/> | ||
| <input id="tenant_code" name="tenant_code" autocomplete="new-password" value="laokouyun" type="text" placeholder="请输入租户编号" required autofocus/> | ||
| </div> | ||
|
|
||
| <div class="form-item row" style="width: 100%;"> | ||
| <input id="password" name="password" type="password" placeholder="请输入密码" required/> | ||
| <input id="username" name="username" type="text" autocomplete="new-password" value="admin" placeholder="请输入用户名" required/> | ||
| </div> | ||
|
|
||
| <div class="form-item row" style="width: 100%;"> | ||
| <input id="password" name="password" type="password" autocomplete="new-password" value="admin123" placeholder="请输入密码" required/> | ||
| </div> | ||
|
Comment on lines
+108
to
121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Hardcoded admin credentials 两个 login.html 模板将 tenant_code/username/password 预填为 laokouyun/admin/admin123,任何未认证访问者都能直接看到并一键尝试该组合,存在明显账号安全风险。 Agent Prompt
|
||
|
|
||
| <div class="form-item"> | ||
| <div class="row"> | ||
| <input id="captcha" name="captcha" type="text" placeholder="请输入验证码" required/> | ||
| <img class="captcha" th:src="@{/captcha}" alt="captcha" | ||
| onclick="this.src='/captcha?ts='+Date.now()"/> | ||
| <input id="captcha" name="captcha" autocomplete="new-password" type="text" placeholder="请输入验证码" required/> | ||
| <img id="captcha-img" class="captcha" alt="验证码" onclick="getCaptcha()"/> | ||
|
Check warning on line 126 in laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html
|
||
| </div> | ||
| </div> | ||
|
|
||
| <button class="btn" type="submit">登 录</button> | ||
| </form> | ||
| </div> | ||
| <script> | ||
| function getUuid() { | ||
| if (window.crypto && crypto.randomUUID) { | ||
|
Check warning on line 135 in laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html
|
||
| return crypto.randomUUID(); | ||
| } | ||
| return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
|
Check warning on line 138 in laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html
|
||
| const r = Math.random() * 16 | 0; | ||
|
Check failure on line 139 in laokou-service/laokou-auth/laokou-auth-start/src/main/resources/templates/login.html
|
||
| const v = c === 'x' ? r : (r & 0x3 | 0x8); | ||
| return v.toString(16); | ||
| }); | ||
| } | ||
| function getCaptcha() { | ||
| const uuid = getUuid() | ||
| document.getElementById("uuid").value = uuid | ||
| axios.get("v1/authorization-code/captchas/" + uuid).then(res => { | ||
| document.getElementById("captcha-img").src = res.data.data | ||
| }) | ||
| } | ||
| getCaptcha() | ||
| </script> | ||
|
Comment on lines
123
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. Captcha not validated server-side 登录页强制填写 uuid/captcha 并从 /v1/authorization-code/captchas/{uuid} 获取验证码,但当前 formLogin 认证链路使用默认
DaoAuthenticationProvider,未看到对 uuid/captcha 的服务端校验,验证码形同虚设且可被直接绕过。
Agent Prompt
|
||
| </body> | ||
| </html> | ||
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Login blocked by gateway
🐞 Bug✓ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools