提交 b450e9bd 编写于 作者: J Jesse Glick 提交者: Oliver Gondža

[JENKINS-47429] User.getLegacyConfigFilesFor no longer seems to be necessary.

(cherry picked from commit 3853b381)
上级 6be05b80
......@@ -432,6 +432,10 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
* {@code create} is false.
*/
private static @Nullable User getOrCreate(@Nonnull String id, @Nonnull String fullName, boolean create) {
return getOrCreate(id, fullName, create, getUnsanitizedLegacyConfigFileFor(id));
}
private static @Nullable User getOrCreate(@Nonnull String id, @Nonnull String fullName, boolean create, File unsanitizedLegacyConfigFile) {
String idkey = idStrategy().keyFor(id);
byNameLock.readLock().lock();
......@@ -442,49 +446,17 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
byNameLock.readLock().unlock();
}
final File configFile = getConfigFileFor(id);
if (u == null && !configFile.isFile() && !configFile.getParentFile().isDirectory()) {
// check for legacy users and migrate if safe to do so.
File[] legacy = getLegacyConfigFilesFor(id);
if (legacy != null && legacy.length > 0) {
for (File legacyUserDir : legacy) {
final XmlFile legacyXml = new XmlFile(XSTREAM, new File(legacyUserDir, "config.xml"));
try {
Object o = legacyXml.read();
if (o instanceof User) {
if (idStrategy().equals(id, legacyUserDir.getName()) && !idStrategy().filenameOf(legacyUserDir.getName())
.equals(legacyUserDir.getName())) {
if (legacyUserDir.renameTo(configFile.getParentFile())) {
LOGGER.log(Level.INFO, "Migrated user record from {0} to {1}", new Object[] {legacyUserDir, configFile.getParentFile()});
} else {
LOGGER.log(Level.WARNING, "Failed to migrate user record from {0} to {1}",
new Object[]{legacyUserDir, configFile.getParentFile()});
}
break;
}
} else {
LOGGER.log(Level.FINE, "Unexpected object loaded from {0}: {1}",
new Object[]{ legacyUserDir, o });
}
} catch (IOException e) {
LOGGER.log(Level.FINE, String.format("Exception trying to load user from %s: %s",
new Object[]{ legacyUserDir, e.getMessage() }), e);
}
}
}
}
File unsanitizedLegacyConfigFile = getUnsanitizedLegacyConfigFileFor(id);
if (unsanitizedLegacyConfigFile.exists() && !unsanitizedLegacyConfigFile.equals(configFile)) {
File ancestor = unsanitizedLegacyConfigFile.getParentFile();
if (!configFile.exists()) {
try {
Files.createDirectory(configFile.getParentFile().toPath());
Files.move(unsanitizedLegacyConfigFile.toPath(), configFile.toPath());
LOGGER.log(Level.INFO, "Migrated unsafe user record from {0} to {1}", new Object[] {unsanitizedLegacyConfigFile, configFile});
LOGGER.log(Level.INFO, "Migrated user record from {0} to {1}", new Object[] {unsanitizedLegacyConfigFile, configFile});
} catch (IOException | InvalidPathException e) {
LOGGER.log(
Level.WARNING,
String.format("Failed to migrate user record from %s to %s, see SECURITY-499 for more information", idStrategy().legacyFilenameOf(id), idStrategy().filenameOf(id)),
String.format("Failed to migrate user record from %s to %s", unsanitizedLegacyConfigFile, configFile),
e);
}
}
......@@ -726,16 +698,6 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
return new File(getRootDir(), idStrategy().filenameOf(id) +"/config.xml");
}
private static final File[] getLegacyConfigFilesFor(final String id) {
return getRootDir().listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory() && new File(pathname, "config.xml").isFile() && idStrategy().equals(
pathname.getName(), id);
}
});
}
private static File getUnsanitizedLegacyConfigFileFor(String id) {
return new File(getRootDir(), idStrategy().legacyFilenameOf(id) + "/config.xml");
}
......@@ -1056,9 +1018,10 @@ public class User extends AbstractModelObject implements AccessControlled, Descr
File[] subdirs = getRootDir().listFiles((FileFilter) DirectoryFileFilter.INSTANCE);
if (subdirs != null) {
for (File subdir : subdirs) {
if (new File(subdir, "config.xml").exists()) {
File configFile = new File(subdir, "config.xml");
if (configFile.exists()) {
String name = strategy.idFromFilename(subdir.getName());
getOrCreate(name, /* <init> calls load(), probably clobbering this anyway */name, true);
getOrCreate(name, /* <init> calls load(), probably clobbering this anyway */name, true, configFile);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册