All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.robozonky.cli.MasterPasswordFeature Maven / Gradle / Ivy

There is a newer version: 6.4.1
Show newest version
/*
 * Copyright 2020 The RoboZonky Project
 *
 * Licensed 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 com.github.robozonky.cli;

import static picocli.CommandLine.Command;
import static picocli.CommandLine.Option;

import java.io.File;

@Command(name = "master-password", description = MasterPasswordFeature.DESCRIPTION)
public final class MasterPasswordFeature extends KeyStoreLeveragingFeature {

    static final String DESCRIPTION = "Change password of the master keystore.";
    @Option(names = { "-n",
            "--new-secret" }, description = "Username to use to authenticate with Zonky servers.", required = true, interactive = true, arity = "0..1")
    private char[] newSecret = null;

    public MasterPasswordFeature(final File keystore, final char[] keystoreSecret, final char... newSecret) {
        super(keystore, keystoreSecret);
        this.newSecret = newSecret.clone();
    }

    MasterPasswordFeature() {
        // for Picocli
    }

    @Override
    public String describe() {
        return DESCRIPTION;
    }

    @Override
    public void setup() throws SetupFailedException {
        super.setup();
        try {
            this.getStorage()
                .save(newSecret);
        } catch (final Exception ex) {
            throw new SetupFailedException(ex);
        }
    }

    @Override
    public void test() throws TestFailedException {
        super.test(newSecret);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy