|
43 | 43 | /**
|
44 | 44 | * Thread-safe file implementation of a credential store.
|
45 | 45 | *
|
46 |
| -* <p>For security purposes, the file's permissions are set to be accessible only by the file's |
47 |
| -* owner. Note that Java 1.5 does not support manipulating file permissions, and must be done |
48 |
| -* manually or using the JNI. |
| 46 | +* <p>For security purposes, the file's permissions are set such that the |
| 47 | +* file is only accessible by the file's owner. |
49 | 48 | *
|
50 | 49 | * @since 1.16
|
51 | 50 | * @author Yaniv Inbar
|
@@ -136,26 +135,21 @@ public FileDataStoreFactory getDataStoreFactory() {
|
136 | 135 | * executed by the file's owner.
|
137 | 136 | *
|
138 | 137 | * @param file the file's permissions to modify
|
139 |
| -* @throws IOException |
| 138 | +* @throws IOException if the permissions can't be set |
140 | 139 | */
|
141 |
| -static void setPermissionsToOwnerOnly(File file) throws IOException { |
| 140 | +private static void setPermissionsToOwnerOnly(File file) throws IOException { |
142 | 141 | Set permissions = new HashSet<PosixFilePermission>();
|
143 | 142 | permissions.add(PosixFilePermission.OWNER_READ);
|
144 | 143 | permissions.add(PosixFilePermission.OWNER_WRITE);
|
145 | 144 | permissions.add(PosixFilePermission.OWNER_EXECUTE);
|
146 | 145 | try {
|
147 | 146 | Files.setPosixFilePermissions(Paths.get(file.getAbsolutePath()), permissions);
|
148 |
| -} catch (UnsupportedOperationException exception) { |
149 |
| -LOGGER.warning("Unable to set permissions for " + file |
150 |
| -+ ", because you are running on a non-POSIX file system."); |
151 |
| -} catch (SecurityException exception) { |
152 |
| -// ignored |
153 |
| -} catch (IllegalArgumentException exception) { |
154 |
| -// ignored |
| 147 | +} catch (RuntimeException exception) { |
| 148 | +throw new IOException("Unable to set permissions for " + file, exception); |
155 | 149 | }
|
156 | 150 | }
|
157 | 151 |
|
158 |
| -static void setPermissionsToOwnerOnlyWindows(File file) throws IOException { |
| 152 | +private static void setPermissionsToOwnerOnlyWindows(File file) throws IOException { |
159 | 153 | Path path = Paths.get(file.getAbsolutePath());
|
160 | 154 | FileOwnerAttributeView fileAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
|
161 | 155 | UserPrincipal owner = fileAttributeView.getOwner();
|
@@ -188,6 +182,11 @@ static void setPermissionsToOwnerOnlyWindows(File file) throws IOException {
|
188 | 182 | .build();
|
189 | 183 |
|
190 | 184 | // Overwrite the ACL with only this permission
|
191 |
| -view.setAcl(ImmutableList.of(entry)); |
| 185 | +try { |
| 186 | +view.setAcl(ImmutableList.of(entry)); |
| 187 | +} catch (SecurityException ex) { |
| 188 | +throw new IOException("Unable to set permissions for " + file, ex); |
| 189 | +} |
| 190 | + |
192 | 191 | }
|
193 | 192 | }
|
0 commit comments