Package org.apache.geronimo.deployment.cli

Source Code of org.apache.geronimo.deployment.cli.CommandEncrypt

/**
*  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.geronimo.deployment.cli;

import javax.enterprise.deploy.spi.DeploymentManager;

import jline.ConsoleReader;

import org.apache.geronimo.cli.deployer.CommandArgs;
import org.apache.geronimo.common.DeploymentException;
import org.apache.geronimo.crypto.EncryptionManager;
import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.system.util.ConfiguredEncryption;

/**
* The CLI command to encrypt a given string.
*
* @version $Rev: 896333 $ $Date: 2010-01-06 01:52:05 -0500 (Wed, 06 Jan 2010) $
*/
public class CommandEncrypt extends AbstractCommand {

    public void execute(ConsoleReader consoleReader, ServerConnection connection, CommandArgs commandArgs) throws DeploymentException {
        try {
            consoleReader.printString(DeployUtils.reformat("String to encrypt: "+commandArgs.getArgs()[0], 4, 72));
            DeploymentManager dm = connection.getDeploymentManager();
            if (dm instanceof RemoteDeploymentManager) {
                // Online encryption
                Kernel k = ((RemoteDeploymentManager)dm).getKernel();
                Object ret = k.invoke(ConfiguredEncryption.class, "encrypt", new Object[] {commandArgs.getArgs()[0]}, new String[] {"java.lang.String"});
                consoleReader.printString(DeployUtils.reformat("Online encryption result: "+ret, 4, 72));
            } else {
                // Offline encryption
                Object ret = EncryptionManager.encrypt(commandArgs.getArgs()[0]);
                consoleReader.printString(DeployUtils.reformat("Offline encryption result: "+ret, 4, 72));
            }
            consoleReader.printNewline();
        } catch (Exception e) {
            throw new DeploymentException("Unable to reach the server to do the encryption.", e);
        }
    }
}
TOP

Related Classes of org.apache.geronimo.deployment.cli.CommandEncrypt

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.