From f43888bc2c4c6f7a96cc5da8e3d7f7346985d8ec Mon Sep 17 00:00:00 2001 From: longjuan <769022681@qq.com> Date: Tue, 14 Mar 2023 10:58:17 +0800 Subject: [PATCH] fix: RSA key cannot be saved normally in the Windows environment (#3510) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /area core #### What this PR does / why we need it: 修复Windows下开发环境不能正常保存Rsa密钥 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3497 #### Special notes for your reviewer: windows不支持posix标准,也无法精细控制用户访问权限,因此在不支持posix的系统直接不设置权限。 https://stackoverflow.com/questions/21541455/how-to-check-if-the-os-is-posix-compliant #### Does this PR introduce a user-facing change? ```release-note None ``` --- .../authentication/login/impl/RsaKeyService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/run/halo/app/security/authentication/login/impl/RsaKeyService.java b/src/main/java/run/halo/app/security/authentication/login/impl/RsaKeyService.java index f2f47598f..46b525336 100644 --- a/src/main/java/run/halo/app/security/authentication/login/impl/RsaKeyService.java +++ b/src/main/java/run/halo/app/security/authentication/login/impl/RsaKeyService.java @@ -6,6 +6,7 @@ import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.PosixFilePermissions; @@ -123,8 +124,12 @@ public class RsaKeyService implements CryptoService { return Mono.fromRunnable(() -> { try { Files.createDirectories(path.getParent()); - Files.createFile(path, - PosixFilePermissions.asFileAttribute(Set.of(OWNER_READ, OWNER_WRITE))); + if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { + Files.createFile(path, + PosixFilePermissions.asFileAttribute(Set.of(OWNER_READ, OWNER_WRITE))); + } else { + Files.createFile(path); + } } catch (IOException e) { // ignore the error log.warn("Failed to create file for {}", path, e);