You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IdentityManager.java 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.config;
  18. import com.dmdirc.Precondition;
  19. import com.dmdirc.config.provider.AggregateConfigProvider;
  20. import com.dmdirc.config.provider.ConfigProvider;
  21. import com.dmdirc.config.provider.ConfigProviderMigrator;
  22. import com.dmdirc.interfaces.config.IdentityController;
  23. import com.dmdirc.interfaces.config.IdentityFactory;
  24. import com.dmdirc.util.ClientInfo;
  25. import com.dmdirc.util.io.ConfigFile;
  26. import com.dmdirc.util.io.FileUtils;
  27. import com.dmdirc.util.io.InvalidConfigFileException;
  28. import com.google.common.collect.ArrayListMultimap;
  29. import com.google.common.collect.Multimap;
  30. import java.io.IOException;
  31. import java.lang.ref.WeakReference;
  32. import java.net.URISyntaxException;
  33. import java.nio.file.DirectoryStream;
  34. import java.nio.file.Files;
  35. import java.nio.file.Path;
  36. import java.util.ArrayList;
  37. import java.util.Collection;
  38. import java.util.Collections;
  39. import java.util.HashMap;
  40. import java.util.List;
  41. import java.util.Map;
  42. import java.util.Objects;
  43. import java.util.concurrent.ConcurrentHashMap;
  44. import java.util.stream.Collectors;
  45. import org.slf4j.Logger;
  46. import org.slf4j.LoggerFactory;
  47. import static com.dmdirc.util.LogUtils.FATAL_APP_ERROR;
  48. import static com.dmdirc.util.LogUtils.FATAL_USER_ERROR;
  49. import static com.dmdirc.util.LogUtils.USER_ERROR;
  50. import static com.google.common.base.Preconditions.checkArgument;
  51. import static com.google.common.base.Preconditions.checkNotNull;
  52. public class IdentityManager implements IdentityFactory, IdentityController {
  53. private static final Logger LOG = LoggerFactory.getLogger(IdentityManager.class);
  54. /** A regular expression that will match all characters illegal in file names. */
  55. private static final String ILLEGAL_CHARS = "[\\\\\"/:\\*\\?\"<>\\|]";
  56. /** The domain used for identity settings. */
  57. private static final String IDENTITY_DOMAIN = "identity";
  58. /** The domain used for profile settings. */
  59. private static final String PROFILE_DOMAIN = "profile";
  60. /** Base configuration directory where the main configuration file will be located. */
  61. private final Path configDirectory;
  62. /** Directory to save and load identities in. */
  63. private final Path identitiesDirectory;
  64. /**
  65. * The identities that have been loaded into this manager.
  66. *
  67. * Standard identities are inserted with a {@code null} key, custom identities use their
  68. * custom type as the key.
  69. */
  70. private final Multimap<String, ConfigFileBackedConfigProvider> identities = ArrayListMultimap.create();
  71. /** Map of paths to corresponding config providers, to facilitate reloading. */
  72. private final Map<Path, ConfigFileBackedConfigProvider> configProvidersByPath = new ConcurrentHashMap<>();
  73. /**
  74. * The {@link ConfigProviderListener}s that have registered with this manager.
  75. *
  76. * Listeners for standard identities are inserted with a {@code null} key, listeners for a
  77. * specific custom type use their type as the key.
  78. */
  79. private final Multimap<String, WeakReference<ConfigProviderListener>> listeners =
  80. ArrayListMultimap.create();
  81. /** Client info objecty. */
  82. private final ClientInfo clientInfo;
  83. /** The identity file used for the global config. */
  84. private ConfigFileBackedConfigProvider config;
  85. /** The identity file used for addon defaults. */
  86. private ConfigFileBackedConfigProvider addonConfig;
  87. /** The identity file bundled with the client containing version info. */
  88. private ConfigFileBackedConfigProvider versionConfig;
  89. /** The config manager used for global settings. */
  90. private AggregateConfigProvider globalconfig;
  91. /**
  92. * Creates a new instance of IdentityManager.
  93. *
  94. * @param baseDirectory The BASE config directory.
  95. * @param identitiesDirectory The directory to store identities in.
  96. */
  97. public IdentityManager(final Path baseDirectory, final Path identitiesDirectory,
  98. final ClientInfo clientInfo) {
  99. this.configDirectory = baseDirectory;
  100. this.identitiesDirectory = identitiesDirectory;
  101. this.clientInfo = clientInfo;
  102. }
  103. /**
  104. * Loads all identity files.
  105. *
  106. * @throws InvalidIdentityFileException If there is an error with the config file.
  107. */
  108. public void initialise() throws InvalidIdentityFileException {
  109. identities.clear();
  110. loadVersionIdentity();
  111. loadDefaults();
  112. loadUserIdentities();
  113. loadConfig();
  114. // Set up the identity used for the addons defaults
  115. final ConfigTarget target = new ConfigTarget();
  116. target.setGlobalDefault();
  117. target.setOrder(500000);
  118. final ConfigFile addonConfigFile = new ConfigFile((Path) null);
  119. final Map<String, String> addonSettings = new HashMap<>();
  120. addonSettings.put("name", "Addon defaults");
  121. addonConfigFile.addDomain("identity", addonSettings);
  122. addonConfig = new ConfigFileBackedConfigProvider(this, addonConfigFile, target);
  123. addConfigProvider(addonConfig);
  124. }
  125. /** Loads the default (built in) identities. */
  126. private void loadDefaults() {
  127. try {
  128. loadIdentity(FileUtils.getPathForResource(getClass().getResource(
  129. "defaults/default/defaults")));
  130. loadIdentity(FileUtils.getPathForResource(getClass().getResource(
  131. "defaults/default/formatter")));
  132. } catch (URISyntaxException ex) {
  133. LOG.error(FATAL_APP_ERROR, "Unable to load settings", ex);
  134. }
  135. final Path file = identitiesDirectory.resolve("modealiases");
  136. if (!Files.exists(file)) {
  137. try {
  138. Files.createDirectories(file);
  139. } catch (IOException ex) {
  140. LOG.info(USER_ERROR, "Unable to create modealiases directory", file, ex);
  141. }
  142. }
  143. try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(file)) {
  144. if (!directoryStream.iterator().hasNext()) {
  145. extractIdentities("modealiases");
  146. }
  147. } catch (IOException ex) {
  148. LOG.error(FATAL_USER_ERROR, "Unable to iterate required directory '{}'. Please check"
  149. + "file permissions or specify a different configuration directory.", file, ex);
  150. return;
  151. }
  152. loadUser(file);
  153. }
  154. /**
  155. * Extracts the specific set of default identities to the user's identity folder.
  156. *
  157. * @param target The target to be extracted
  158. */
  159. private void extractIdentities(final String target) {
  160. try {
  161. FileUtils.copyResources(getClass().getResource("defaults/" + target),
  162. identitiesDirectory);
  163. } catch (IOException ex) {
  164. LOG.warn(USER_ERROR, "Unable to extract default identities: {}", ex.getMessage(), ex);
  165. }
  166. }
  167. @Override
  168. public void loadUserIdentities() {
  169. if (!Files.exists(identitiesDirectory)) {
  170. try {
  171. Files.createDirectories(identitiesDirectory);
  172. } catch (IOException ex) {
  173. LOG.warn(USER_ERROR, "Unable to create identity dir", ex);
  174. }
  175. }
  176. loadUser(identitiesDirectory);
  177. }
  178. /**
  179. * Recursively loads files from the specified directory.
  180. *
  181. * @param dir The directory to be loaded
  182. */
  183. @Precondition({
  184. "The specified File is not null",
  185. "The specified File is a directory"
  186. })
  187. private void loadUser(final Path dir) {
  188. checkNotNull(dir);
  189. checkArgument(Files.isDirectory(dir));
  190. try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(dir)) {
  191. for (Path child : directoryStream) {
  192. if (Files.isDirectory(child)) {
  193. loadUser(child);
  194. } else {
  195. loadIdentity(child);
  196. }
  197. }
  198. } catch (IOException ex) {
  199. LOG.warn(USER_ERROR, "Unable to load user identity files from: {}", dir, ex);
  200. }
  201. }
  202. /**
  203. * Loads an identity from the specified file. If the identity already exists, it is told to
  204. * reload instead.
  205. *
  206. * @param file The file to load the identity from.
  207. */
  208. private void loadIdentity(final Path file) {
  209. synchronized (identities) {
  210. if (configProvidersByPath.containsKey(file)) {
  211. try {
  212. configProvidersByPath.get(file).reload();
  213. } catch (IOException ex) {
  214. LOG.warn(USER_ERROR, "I/O error when reloading identity file: {} ({})",
  215. file, ex.getMessage(), ex);
  216. } catch (InvalidConfigFileException ex) {
  217. // Do nothing
  218. }
  219. }
  220. }
  221. try {
  222. final ConfigFileBackedConfigProvider provider = new ConfigFileBackedConfigProvider(this, file, false);
  223. addConfigProvider(provider);
  224. configProvidersByPath.put(file, provider);
  225. } catch (InvalidIdentityFileException ex) {
  226. LOG.warn(USER_ERROR, "Invalid identity file: {} ({})", file, ex.getMessage(), ex);
  227. } catch (IOException ex) {
  228. LOG.warn(USER_ERROR, "I/O error when reading identity file: {}", file, ex);
  229. }
  230. }
  231. /**
  232. * Retrieves all known identities.
  233. *
  234. * @return A set of all known identities
  235. *
  236. * @since 0.6.4
  237. */
  238. private Iterable<ConfigFileBackedConfigProvider> getAllIdentities() {
  239. return identities.values();
  240. }
  241. /**
  242. * Returns the "group" to which the specified identity belongs. For custom identities this is
  243. * the custom identity type, otherwise this is <code>null</code>.
  244. *
  245. * @param identity The identity whose group is being retrieved
  246. *
  247. * @return The group of the specified identity
  248. *
  249. * @since 0.6.4
  250. */
  251. private String getGroup(final ConfigFileBackedConfigProvider identity) {
  252. return identity.getTarget().getType() == ConfigTarget.TYPE.CUSTOM
  253. ? identity.getTarget().getData() : null;
  254. }
  255. @Override
  256. public void loadVersionIdentity() {
  257. try {
  258. versionConfig = new ConfigFileBackedConfigProvider(IdentityManager.class.
  259. getResourceAsStream("/com/dmdirc/version.config"), false);
  260. addConfigProvider(versionConfig);
  261. } catch (IOException | InvalidIdentityFileException ex) {
  262. LOG.warn(USER_ERROR, "Unable to load version information.", ex);
  263. }
  264. }
  265. /**
  266. * Loads the config identity.
  267. *
  268. * @throws InvalidIdentityFileException if there is a problem with the config file.
  269. */
  270. private void loadConfig() throws InvalidIdentityFileException {
  271. try {
  272. final Path file = configDirectory.resolve("dmdirc.config");
  273. if (!Files.exists(file)) {
  274. Files.createFile(file);
  275. }
  276. config = new ConfigFileBackedConfigProvider(this, file, true);
  277. config.setOption("identity", "name", "Global config");
  278. configProvidersByPath.put(file, config);
  279. addConfigProvider(config);
  280. } catch (IOException ex) {
  281. LOG.warn(USER_ERROR, "I/O error when loading global config: {}", ex.getMessage(), ex);
  282. }
  283. }
  284. @Override
  285. public ConfigProvider getUserSettings() {
  286. return config;
  287. }
  288. @Override
  289. public ConfigProvider getAddonSettings() {
  290. return addonConfig;
  291. }
  292. @Override
  293. public ConfigProvider getVersionSettings() {
  294. return versionConfig;
  295. }
  296. @Override
  297. public void saveAll() {
  298. synchronized (identities) {
  299. for (ConfigProvider identity : getAllIdentities()) {
  300. identity.save();
  301. }
  302. }
  303. }
  304. @Override
  305. public void addConfigProvider(final ConfigFileBackedConfigProvider identity) {
  306. checkNotNull(identity);
  307. final String target = getGroup(identity);
  308. if (identities.containsEntry(target, identity)) {
  309. removeConfigProvider(identity);
  310. }
  311. synchronized (identities) {
  312. identities.put(target, identity);
  313. }
  314. LOG.debug("Adding identity: {} (group: {})", new Object[]{identity, target});
  315. synchronized (listeners) {
  316. listeners.get(target).stream()
  317. .map(WeakReference::get)
  318. .filter(Objects::nonNull)
  319. .forEach(l -> l.configProviderAdded(identity));
  320. }
  321. }
  322. @Override
  323. public void removeConfigProvider(final ConfigFileBackedConfigProvider identity) {
  324. checkNotNull(identity);
  325. final String group = getGroup(identity);
  326. checkArgument(identities.containsEntry(group, identity));
  327. Path path = null;
  328. for (Map.Entry<Path, ConfigFileBackedConfigProvider> entry : configProvidersByPath.entrySet()) {
  329. if (entry.getValue() == identity) {
  330. path = entry.getKey();
  331. }
  332. }
  333. if (path != null) {
  334. configProvidersByPath.remove(path);
  335. }
  336. synchronized (identities) {
  337. identities.remove(group, identity);
  338. }
  339. synchronized (listeners) {
  340. listeners.get(group).stream()
  341. .map(WeakReference::get)
  342. .filter(Objects::nonNull)
  343. .forEach(l -> l.configProviderRemoved(identity));
  344. }
  345. }
  346. private void registerIdentityListener(final ConfigProviderListener listener) {
  347. registerIdentityListener(null, listener);
  348. }
  349. // TODO: It feels like this method should be called at some point...
  350. private void unregisterIdentityListener(final ConfigProviderListener listener) {
  351. synchronized (listeners) {
  352. listeners.entries().stream().filter(e -> {
  353. final ConfigProviderListener value = e.getValue().get();
  354. return value == null || value.equals(listener);
  355. }).forEach(e -> listeners.remove(e.getKey(), e.getValue()));
  356. }
  357. }
  358. private void registerIdentityListener(final String type, final ConfigProviderListener listener) {
  359. checkNotNull(listener);
  360. synchronized (listeners) {
  361. listeners.put(type, new WeakReference<>(listener));
  362. }
  363. }
  364. @Override
  365. public Collection<ConfigProvider> getProvidersByType(final String type) {
  366. return Collections.unmodifiableCollection(identities.get(type));
  367. }
  368. /**
  369. * Retrieves a list of all config sources that should be applied to the specified config
  370. * manager.
  371. *
  372. * @param manager The manager requesting sources
  373. *
  374. * @return A list of all matching config sources
  375. */
  376. List<ConfigFileBackedConfigProvider> getIdentitiesForManager(final ConfigManager manager) {
  377. final List<ConfigFileBackedConfigProvider> sources = new ArrayList<>();
  378. synchronized (identities) {
  379. sources.addAll(identities.get(null).stream()
  380. .filter(manager::identityApplies)
  381. .collect(Collectors.toList()));
  382. }
  383. sources.sort(new ConfigProviderTargetComparator());
  384. LOG.debug("Found {} source(s) for {}", sources.size(), manager);
  385. return sources;
  386. }
  387. @Override
  388. public synchronized AggregateConfigProvider getGlobalConfiguration() {
  389. if (globalconfig == null) {
  390. globalconfig = createAggregateConfig("", "", "", "");
  391. }
  392. return globalconfig;
  393. }
  394. @Override
  395. public ConfigProvider createChannelConfig(final String network, final String channel) {
  396. if (network == null || network.isEmpty()) {
  397. throw new IllegalArgumentException("getChannelConfig called "
  398. + "with null or empty network\n\nNetwork: " + network);
  399. }
  400. if (channel == null || channel.isEmpty()) {
  401. throw new IllegalArgumentException("getChannelConfig called "
  402. + "with null or empty channel\n\nChannel: " + channel);
  403. }
  404. final String myTarget = (channel + '@' + network).toLowerCase();
  405. synchronized (identities) {
  406. for (ConfigFileBackedConfigProvider identity : identities.get(null)) {
  407. if (identity.getTarget().getType() == ConfigTarget.TYPE.CHANNEL
  408. && identity.getTarget().getData().equalsIgnoreCase(myTarget)) {
  409. return identity;
  410. }
  411. }
  412. }
  413. // We need to create one
  414. final ConfigTarget target = new ConfigTarget();
  415. target.setChannel(myTarget);
  416. return createConfig(target);
  417. }
  418. @Override
  419. public ConfigProvider createNetworkConfig(final String network) {
  420. if (network == null || network.isEmpty()) {
  421. throw new IllegalArgumentException("getNetworkConfig called "
  422. + "with null or empty network\n\nNetwork:" + network);
  423. }
  424. final String myTarget = network.toLowerCase();
  425. synchronized (identities) {
  426. for (ConfigFileBackedConfigProvider identity : identities.get(null)) {
  427. if (identity.getTarget().getType() == ConfigTarget.TYPE.NETWORK
  428. && identity.getTarget().getData().equalsIgnoreCase(myTarget)) {
  429. return identity;
  430. }
  431. }
  432. }
  433. // We need to create one
  434. final ConfigTarget target = new ConfigTarget();
  435. target.setNetwork(myTarget);
  436. return createConfig(target);
  437. }
  438. @Override
  439. public ConfigProvider createServerConfig(final String server) {
  440. if (server == null || server.isEmpty()) {
  441. throw new IllegalArgumentException("getServerConfig called "
  442. + "with null or empty server\n\nServer: " + server);
  443. }
  444. final String myTarget = server.toLowerCase();
  445. synchronized (identities) {
  446. for (ConfigFileBackedConfigProvider identity : identities.get(null)) {
  447. if (identity.getTarget().getType() == ConfigTarget.TYPE.SERVER
  448. && identity.getTarget().getData().equalsIgnoreCase(myTarget)) {
  449. return identity;
  450. }
  451. }
  452. }
  453. // We need to create one
  454. final ConfigTarget target = new ConfigTarget();
  455. target.setServer(myTarget);
  456. return createConfig(target);
  457. }
  458. @Override
  459. public ConfigProvider createCustomConfig(final String name, final String type) {
  460. final Map<String, Map<String, String>> settings = new HashMap<>();
  461. settings.put(IDENTITY_DOMAIN, new HashMap<>(2));
  462. settings.get(IDENTITY_DOMAIN).put("name", name);
  463. settings.get(IDENTITY_DOMAIN).put("type", type);
  464. try {
  465. return createIdentity(settings);
  466. } catch (InvalidIdentityFileException | IOException ex) {
  467. LOG.warn(USER_ERROR, "Unable to create identity", ex);
  468. return null;
  469. }
  470. }
  471. @Override
  472. public ConfigProvider createProfileConfig(final String name) {
  473. final Map<String, Map<String, String>> settings = new HashMap<>();
  474. settings.put(IDENTITY_DOMAIN, new HashMap<>(1));
  475. settings.put(PROFILE_DOMAIN, new HashMap<>(2));
  476. final String nick = System.getProperty("user.name").replace(' ', '_');
  477. settings.get(IDENTITY_DOMAIN).put("name", name);
  478. settings.get(PROFILE_DOMAIN).put("nicknames", nick);
  479. settings.get(PROFILE_DOMAIN).put("realname", nick);
  480. try {
  481. return createIdentity(settings);
  482. } catch (InvalidIdentityFileException | IOException ex) {
  483. LOG.warn(USER_ERROR, "Unable to create identity", ex);
  484. return null;
  485. }
  486. }
  487. @Override
  488. public ConfigProvider createConfig(final ConfigTarget target) {
  489. final Map<String, Map<String, String>> settings = new HashMap<>();
  490. settings.put(IDENTITY_DOMAIN, new HashMap<>(2));
  491. settings.get(IDENTITY_DOMAIN).put("name", target.getData());
  492. settings.get(IDENTITY_DOMAIN).put(target.getTypeName(), target.getData());
  493. try {
  494. return createIdentity(settings);
  495. } catch (InvalidIdentityFileException | IOException ex) {
  496. LOG.warn(USER_ERROR, "Unable to create identity", ex);
  497. return null;
  498. }
  499. }
  500. /**
  501. * Creates a new identity containing the specified properties.
  502. *
  503. * @param settings The settings to populate the identity with
  504. *
  505. * @return A new identity containing the specified properties
  506. *
  507. * @throws IOException If the file cannot be created
  508. * @throws InvalidIdentityFileException If the settings are invalid
  509. * @since 0.6.3m1
  510. */
  511. private ConfigFileBackedConfigProvider createIdentity(
  512. final Map<String, Map<String, String>> settings)
  513. throws IOException, InvalidIdentityFileException {
  514. if (!settings.containsKey(IDENTITY_DOMAIN)
  515. || !settings.get(IDENTITY_DOMAIN).containsKey("name")
  516. || settings.get(IDENTITY_DOMAIN).get("name").isEmpty()) {
  517. throw new InvalidIdentityFileException("identity.name is not set");
  518. }
  519. final String name = settings.get(IDENTITY_DOMAIN).get("name").replaceAll(ILLEGAL_CHARS, "_");
  520. Path file = identitiesDirectory.resolve(name);
  521. int attempt = 1;
  522. while (Files.exists(file)) {
  523. file = identitiesDirectory.resolve(name + '-' + attempt);
  524. attempt++;
  525. }
  526. final ConfigFile configFile = new ConfigFile(file);
  527. for (Map.Entry<String, Map<String, String>> entry : settings.entrySet()) {
  528. configFile.addDomain(entry.getKey(), entry.getValue());
  529. }
  530. configFile.write();
  531. final ConfigFileBackedConfigProvider identity = new ConfigFileBackedConfigProvider(this,
  532. file, false);
  533. addConfigProvider(identity);
  534. return identity;
  535. }
  536. /**
  537. * Finds and adds sources for the given manager, and adds it as an identity listener.
  538. *
  539. * @param configManager The manager to be initialised.
  540. */
  541. private void setUpConfigManager(final ConfigManager configManager) {
  542. final List<ConfigFileBackedConfigProvider> sources = getIdentitiesForManager(configManager);
  543. for (ConfigFileBackedConfigProvider identity : sources) {
  544. LOG.trace("Found {}", identity);
  545. configManager.checkIdentity(identity);
  546. }
  547. registerIdentityListener(configManager);
  548. }
  549. @Override
  550. public ConfigProviderMigrator createMigratableConfig(final String protocol,
  551. final String ircd, final String network, final String server) {
  552. final ConfigManager configManager = new ConfigManager(clientInfo, this, protocol,
  553. ircd, network, server);
  554. setUpConfigManager(configManager);
  555. return new ConfigManagerMigrator(configManager);
  556. }
  557. @Override
  558. public ConfigProviderMigrator createMigratableConfig(final String protocol,
  559. final String ircd, final String network, final String server, final String channel) {
  560. final ConfigManager configManager = new ConfigManager(clientInfo, this, protocol,
  561. ircd, network, server, channel);
  562. setUpConfigManager(configManager);
  563. return new ConfigManagerMigrator(configManager);
  564. }
  565. @Override
  566. public AggregateConfigProvider createAggregateConfig(final String protocol, final String ircd,
  567. final String network, final String server) {
  568. final ConfigManager configManager = new ConfigManager(clientInfo, this, protocol,
  569. ircd, network, server);
  570. setUpConfigManager(configManager);
  571. return configManager;
  572. }
  573. @Override
  574. public AggregateConfigProvider createAggregateConfig(final String protocol, final String ircd,
  575. final String network, final String server, final String channel) {
  576. final ConfigManager configManager = new ConfigManager(clientInfo, this, protocol,
  577. ircd, network, server, channel);
  578. setUpConfigManager(configManager);
  579. return configManager;
  580. }
  581. }