// Path: com.swookiee.runtime.authentication/src/main/java/com/swookiee/runtime/authentication/AdminUserConfiguration.java
// public class AdminUserConfiguration implements Configuration {
// 
//     public static final String pid = "com.swookiee.runtime.authentication";
// 
//     public String username;
// 
//     public String password;
// 
//     @Override
//     public String getPid() {
//         return pid;
//     }
// }
// 
// Path: com.swookiee.runtime.util/src/main/java/com/swookiee/runtime/util/configuration/ConfigurationConsumer.java
// public final class ConfigurationConsumer<T> {
// 
//     private final ObjectMapper mapper = new ObjectMapper();
// 
//     private final Map<String, Object> configuration = new ConcurrentHashMap<>();
//     {
//         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//     }
// 
//     private ConfigurationConsumer() {
//     }
// 
//     @SuppressWarnings({"unchecked", "rawtypes"})
//     private ConfigurationConsumer(final T defaultConfig) {
//         final Hashtable defaultValues = mapper.convertValue(defaultConfig, Hashtable.class);
//         configuration.putAll(defaultValues);
//     }
// 
//     public static <T> ConfigurationConsumer<T> withDefaultConfiguration(final T defaultConfig) {
//         return new ConfigurationConsumer<T>(defaultConfig);
//     }
// 
//     public static <T> ConfigurationConsumer<T> newConsumer() {
//         return new ConfigurationConsumer<T>();
//     }
// 
//     public ConfigurationConsumer<T> applyConfiguration(final Map<String, ?> configuration) {
//         this.configuration.putAll(configuration);
//         return this;
//     }
// 
//     public T getConfiguration(final Class<T> clazz) {
//         return mapper.convertValue(configuration, clazz);
//     }
// }


import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.useradmin.Role;
import org.osgi.service.useradmin.User;
import org.osgi.service.useradmin.UserAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.swookiee.runtime.authentication.AdminUserConfiguration;
import com.swookiee.runtime.util.configuration.ConfigurationConsumer;
/*******************************************************************************
 * Copyright (c) 2014 Lars Pfannenschmidt and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Lars Pfannenschmidt - initial API and implementation, ongoing development and documentation
 *******************************************************************************/

package com.swookiee.runtime.authentication.internal;




@Component(configurationPolicy = ConfigurationPolicy.OPTIONAL, configurationPid = AdminUserConfiguration.pid)
public class AdminUserManagementSerice {

    private static final Logger logger = LoggerFactory.getLogger(AdminUserManagementSerice.class);

    private static final String DEFAULT_ADMIN_USERNAME = "admin";
    private static final String DEFAULT_ADMIN_PASSWORD = "admin123";

    private static final String USER_ADMIN_USERNAME_PROPERTY = "username";
    private static final String USER_ADMIN_PASSWORD_PROPERTY = "password";

    private ConfigurationConsumer<AdminUserConfiguration> configurationConsumer;

    private UserAdmin userAdmin;

    @Activate
    private void activate(final Map<String, String> properties) {
        this.configurationConsumer = ConfigurationConsumer.withDefaultConfiguration(getDefaultConfiguration())
                .applyConfiguration(properties);

        final AdminUserConfiguration adminUserConfiguration = configurationConsumer.getConfiguration(AdminUserConfiguration.class);

        setAdminUser(adminUserConfiguration);
    }

    @Modified
    private void modified(final Map<String, String> properties) {
        removeAdminUser();
        configurationConsumer.applyConfiguration(properties);

        final AdminUserConfiguration adminUserConfiguration = configurationConsumer.getConfiguration(AdminUserConfiguration.class);
        setAdminUser(adminUserConfiguration);
    }

// Path: com.swookiee.runtime.authentication/src/main/java/com/swookiee/runtime/authentication/AdminUserConfiguration.java
// public class AdminUserConfiguration implements Configuration {
// 
//     public static final String pid = "com.swookiee.runtime.authentication";
// 
//     public String username;
// 
//     public String password;
// 
//     @Override
//     public String getPid() {
//         return pid;
//     }
// }
// 
// Path: com.swookiee.runtime.util/src/main/java/com/swookiee/runtime/util/configuration/ConfigurationConsumer.java
// public final class ConfigurationConsumer<T> {
// 
//     private final ObjectMapper mapper = new ObjectMapper();
// 
//     private final Map<String, Object> configuration = new ConcurrentHashMap<>();
//     {
//         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//     }
// 
//     private ConfigurationConsumer() {
//     }
// 
//     @SuppressWarnings({"unchecked", "rawtypes"})
//     private ConfigurationConsumer(final T defaultConfig) {
//         final Hashtable defaultValues = mapper.convertValue(defaultConfig, Hashtable.class);
//         configuration.putAll(defaultValues);
//     }
// 
//     public static <T> ConfigurationConsumer<T> withDefaultConfiguration(final T defaultConfig) {
//         return new ConfigurationConsumer<T>(defaultConfig);
//     }
// 
//     public static <T> ConfigurationConsumer<T> newConsumer() {
//         return new ConfigurationConsumer<T>();
//     }
// 
//     public ConfigurationConsumer<T> applyConfiguration(final Map<String, ?> configuration) {
//         this.configuration.putAll(configuration);
//         return this;
//     }
// 
//     public T getConfiguration(final Class<T> clazz) {
//         return mapper.convertValue(configuration, clazz);
//     }
// }


// Path: com.swookiee.runtime.authentication/src/main/java/com/swookiee/runtime/authentication/internal/AdminUserManagementSerice.java
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.useradmin.Role;
import org.osgi.service.useradmin.User;
import org.osgi.service.useradmin.UserAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.swookiee.runtime.authentication.AdminUserConfiguration;
import com.swookiee.runtime.util.configuration.ConfigurationConsumer;

/*******************************************************************************
 * Copyright (c) 2014 Lars Pfannenschmidt and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Lars Pfannenschmidt - initial API and implementation, ongoing development and documentation
 *******************************************************************************/

package com.swookiee.runtime.authentication.internal;




@Component(configurationPolicy = ConfigurationPolicy.OPTIONAL, configurationPid = AdminUserConfiguration.pid)
public class AdminUserManagementSerice {

    private static final Logger logger = LoggerFactory.getLogger(AdminUserManagementSerice.class);

    private static final String DEFAULT_ADMIN_USERNAME = "admin";
    private static final String DEFAULT_ADMIN_PASSWORD = "admin123";

    private static final String USER_ADMIN_USERNAME_PROPERTY = "username";
    private static final String USER_ADMIN_PASSWORD_PROPERTY = "password";

    private ConfigurationConsumer<AdminUserConfiguration> configurationConsumer;

    private UserAdmin userAdmin;

    @Activate
    private void activate(final Map<String, String> properties) {
        this.configurationConsumer = ConfigurationConsumer.withDefaultConfiguration(getDefaultConfiguration())
                .applyConfiguration(properties);

        final AdminUserConfiguration adminUserConfiguration = configurationConsumer.getConfiguration(AdminUserConfiguration.class);

        setAdminUser(adminUserConfiguration);
    }

    @Modified
    private void modified(final Map<String, String> properties) {
        removeAdminUser();
        configurationConsumer.applyConfiguration(properties);

        final AdminUserConfiguration adminUserConfiguration = configurationConsumer.getConfiguration(AdminUserConfiguration.class);
        setAdminUser(adminUserConfiguration);
    }

    private AdminUserConfiguration getDefaultConfiguration() {