/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.core.yaml.swapper.impl;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.apache.shardingsphere.core.rule.Authentication;
import org.apache.shardingsphere.core.yaml.config.common.YamlAuthentication;
import org.apache.shardingsphere.core.yaml.swapper.YamlSwapper;

/**
 * Authentication YAML swapper.
 *
 * @author zhangliang
 */
public final class AuthenticationYamlSwapper implements YamlSwapper<YamlAuthentication, Authentication> {
    
    @Override
    public YamlAuthentication swap(final Authentication data) {
        YamlAuthentication result = new YamlAuthentication();
        result.setUsername(data.getUsername());
        result.setPassword(data.getPassword());
        return result;
    }
    
    @Override
    public Authentication swap(final YamlAuthentication yamlConfiguration) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(yamlConfiguration.getUsername()), "Username is required.");
        return new Authentication(yamlConfiguration.getUsername(), yamlConfiguration.getPassword());
    }
}

@@ -885,29 +885,24 @@
 on.base.
-Precondi
+Func
 tion
-s
 ;%0Aimport
@@ -924,19 +924,19 @@
 mon.
-base.String
+collect.Map
 s;%0Ai
@@ -985,32 +985,81 @@
 Authentication;%0A
+import org.apache.shardingsphere.core.rule.User;%0A
 import org.apach
@@ -1111,32 +1111,99 @@
 Authentication;%0A
+import org.apache.shardingsphere.core.yaml.config.common.YamlUser;%0A
 import org.apach
@@ -1423,24 +1423,104 @@
 ion%3E %7B%0A    %0A
+    private final UserYamlSwapper userYamlSwapper = new UserYamlSwapper();%0A    %0A
     @Overrid
@@ -1666,432 +1666,742 @@
 ult.
-s
+g
 etUser
-name(data.getUsername());%0A        result.setPassword(data.getPassword());%0A        return result;%0A    %7D%0A    %0A    @Override%0A    public Authentication swap(final YamlAuthentication yamlConfiguration) %7B%0A        Preconditions.checkArgument(!Strings.isNullOrEmpty(yamlConfiguration.getUsername()), %22Username is required.%22);%0A        return new Authentication(yamlConfiguration.getUsername(), yamlConfiguration.getPassword())
+s().putAll(Maps.transformValues(data.getUsers(), new Function%3CUser, YamlUser%3E() %7B%0A    %0A            @Override%0A            public YamlUser apply(final User input) %7B%0A                return userYamlSwapper.swap(input);%0A            %7D%0A        %7D));%0A        return result;%0A    %7D%0A    %0A    @Override%0A    public Authentication swap(final YamlAuthentication yamlConfiguration) %7B%0A        Authentication result = new Authentication();%0A        result.getUsers().putAll(Maps.transformValues(yamlConfiguration.getUsers(), new Function%3CYamlUser, User%3E() %7B%0A            %0A            @Override%0A            public User apply(final YamlUser input) %7B%0A                return userYamlSwapper.swap(input);%0A            %7D%0A        %7D));%0A        return result
 ;%0A  

modify swap()