Source:
<code>public void initialize() { GatewayConfig configuration = getConfigAs(GatewayConfig.class); if (Strings.isNullOrEmpty(configuration.host)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Host must be specified in the configuration!"); return; } if (Strings.isNullOrEmpty(configuration.code)) { if(Strings.isNullOrEmpty(configuration.username) || Strings.isNullOrEmpty(configuration.userkey)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Security code must be provided in the configuration when initializing for first time!"); return; } <START> } else { <END> configuration = getUsernameAndKey(configuration); } if(Strings.isNullOrEmpty(configuration.username) || Strings.isNullOrEmpty(configuration.userkey)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Obtaining username and key failed!"); return; } this.gatewayURI = "coaps://" + configuration.host + ":" + configuration.port + "/" + DEVICES; this.gatewayInfoURI = "coaps://" + configuration.host + ":" + configuration.port + "/" + GATEWAY + "/" + GATEWAY_DETAILS; try { URI uri = new URI(gatewayURI); deviceClient = new TradfriCoapClient(uri); } catch (URISyntaxException e) { logger.debug("Illegal gateway URI `{}`: {}", gatewayURI, e.getMessage()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage()); return; } DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(0)); builder.setPskStore(new StaticPskStore(configuration.username, configuration.userkey.getBytes())); dtlsConnector = new DTLSConnector(builder.build()); endPoint = new CoapEndpoint(dtlsConnector, NetworkConfig.getStandard()); endPoint.setExecutor(Executors.newSingleThreadScheduledExecutor(new Utils.DaemonThreadFactory())); deviceClient.setEndpoint(endPoint); updateStatus(ThingStatus.UNKNOWN); scanJob = scheduler.scheduleWithFixedDelay(() -> { startScan(); }, 0, 1, TimeUnit.MINUTES); }</code><technical_language>overwriting configuration here? if user manually configured a username/key</technical_language>

Target:
public void initialize() { TradfriGatewayConfig configuration = getConfigAs(TradfriGatewayConfig.class); if (isNullOrEmpty(configuration.host)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Host must be specified in the configuration!"); return; } if (isNullOrEmpty(configuration.code)) { if (isNullOrEmpty(configuration.identity) || isNullOrEmpty(configuration.preSharedKey)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Either security code or identity and pre-shared key must be provided in the configuration!"); return; } else { setupCoapClient(); } } else { if (isOldFirmware()) { logger.warn("Gateway with old firmware - please consider upgrading to the latest version."); Configuration editedConfig = editConfiguration(); editedConfig.put(TradfriBindingConstants.GATEWAY_CONFIG_IDENTITY, ""); editedConfig.put(TradfriBindingConstants.GATEWAY_CONFIG_PRE_SHARED_KEY, configuration.code); updateConfiguration(editedConfig); setupCoapClient(); } else { scheduler.execute(this::obtainIdentityAndPreSharedKey); } } }