X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Ftools%2Fnetconf-cli%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fcli%2Freader%2Fcustom%2FPasswordReader.java;fp=opendaylight%2Fnetconf%2Ftools%2Fnetconf-cli%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fcli%2Freader%2Fcustom%2FPasswordReader.java;h=4804455c60f28694194bc585cf6ea50cd5e1aeea;hb=23fe9ca678ada6263fec5dd996f4025e4a32fcf5;hp=0000000000000000000000000000000000000000;hpb=071a641d7c12c0e6112d5ce0afe806b54f116ed2;p=controller.git diff --git a/opendaylight/netconf/tools/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/custom/PasswordReader.java b/opendaylight/netconf/tools/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/custom/PasswordReader.java new file mode 100644 index 0000000000..4804455c60 --- /dev/null +++ b/opendaylight/netconf/tools/netconf-cli/src/main/java/org/opendaylight/controller/netconf/cli/reader/custom/PasswordReader.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. 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 + */ +package org.opendaylight.controller.netconf.cli.reader.custom; + +import com.google.common.base.Preconditions; +import java.io.IOException; +import jline.console.completer.Completer; +import jline.console.completer.NullCompleter; +import org.opendaylight.controller.netconf.cli.io.BaseConsoleContext; +import org.opendaylight.controller.netconf.cli.io.ConsoleContext; +import org.opendaylight.controller.netconf.cli.io.ConsoleIO; +import org.opendaylight.controller.netconf.cli.reader.impl.BasicDataHolderReader; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; + +public class PasswordReader extends BasicDataHolderReader { + + private static final char PASSWORD_MASK = '*'; + + public PasswordReader(final ConsoleIO console, final SchemaContext schemaContext) { + super(console, schemaContext); + } + + @Override + protected ConsoleContext getContext(final DataSchemaNode schemaNode) { + return new BaseConsoleContext(schemaNode) { + @Override + public Completer getCompleter() { + return new NullCompleter(); + } + }; + } + + @Override + protected TypeDefinition getType(final DataSchemaNode schemaNode) { + Preconditions.checkArgument(schemaNode instanceof LeafSchemaNode); + return ((LeafSchemaNode)schemaNode).getType(); + } + + @Override + protected String readValue() throws IOException { + return console.read(PASSWORD_MASK); + } +}