001package systems.dmx.accesscontrol.migrations;
002
003import systems.dmx.config.ConfigService;
004
005import systems.dmx.core.Topic;
006import systems.dmx.core.service.Inject;
007import systems.dmx.core.service.Migration;
008
009import java.util.List;
010import java.util.logging.Logger;
011
012
013
014/**
015 * Adds "Login enabled" config topic to each username.
016 * Runs only in UPDATE mode.
017 * <p>
018 * Note: when CLEAN_INSTALLing the admin user already got its config topics
019 * as the Config service is already in charge.
020 * <p>
021 * Part of DM 4.7
022 */
023public class Migration11 extends Migration {
024
025    // ---------------------------------------------------------------------------------------------- Instance Variables
026
027    @Inject
028    private ConfigService configService;
029
030    private Logger logger = Logger.getLogger(getClass().getName());
031
032    // -------------------------------------------------------------------------------------------------- Public Methods
033
034    @Override
035    public void run() {
036        List<Topic> usernames = dmx.getTopicsByType("dmx.accesscontrol.username");
037        logger.info("########## Adding \"dmx.accesscontrol.login_enabled\" config topic to " + usernames.size() +
038            " usernames");
039        for (Topic username : usernames) {
040            configService.createConfigTopic("dmx.accesscontrol.login_enabled", username);
041        }
042    }
043}