Search in sources :

Example 11 with CommandResult

use of com.helger.as2.cmd.CommandResult in project as2-server by phax.

the class ImportCertCommand method importCert.

@Nonnull
protected CommandResult importCert(final IAliasedCertificateFactory certFx, final String sAlias, final String sFilename) throws IOException, CertificateException, OpenAS2Exception {
    try (final FileInputStream fis = new FileInputStream(sFilename);
        final NonBlockingBufferedInputStream bis = new NonBlockingBufferedInputStream(fis)) {
        final CertificateFactory cf = CertificateFactory.getInstance("X.509");
        while (bis.available() > 0) {
            final Certificate aCert = cf.generateCertificate(bis);
            if (aCert instanceof X509Certificate) {
                certFx.addCertificate(sAlias, (X509Certificate) aCert, true);
                final CommandResult cmdRes = new CommandResult(ECommandResultType.TYPE_OK, "Certificate(s) imported successfully");
                cmdRes.addResult("Imported certificate: " + aCert.toString());
                return cmdRes;
            }
        }
        return new CommandResult(ECommandResultType.TYPE_ERROR, "No valid X509 certificates found");
    }
}
Also used : NonBlockingBufferedInputStream(com.helger.commons.io.stream.NonBlockingBufferedInputStream) IAliasedCertificateFactory(com.helger.as2lib.cert.IAliasedCertificateFactory) CertificateFactory(java.security.cert.CertificateFactory) FileInputStream(java.io.FileInputStream) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) CommandResult(com.helger.as2.cmd.CommandResult) Nonnull(javax.annotation.Nonnull)

Example 12 with CommandResult

use of com.helger.as2.cmd.CommandResult in project as2-server by phax.

the class ViewCertCommand method execute.

@Override
protected CommandResult execute(final IAliasedCertificateFactory certFx, final Object[] params) throws OpenAS2Exception {
    if (params.length < 1)
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    synchronized (certFx) {
        final String sAlias = params[0].toString();
        final X509Certificate cert = certFx.getCertificate(sAlias);
        return new CommandResult(ECommandResultType.TYPE_OK, cert.toString());
    }
}
Also used : X509Certificate(java.security.cert.X509Certificate) CommandResult(com.helger.as2.cmd.CommandResult)

Example 13 with CommandResult

use of com.helger.as2.cmd.CommandResult in project as2-server by phax.

the class DeletePartnershipCommand method execute.

@Override
public CommandResult execute(final IPartnershipFactoryWithPartners partFx, final Object[] params) throws OpenAS2Exception {
    if (params.length < 1) {
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    }
    final String name = params[0].toString();
    final Partnership part = partFx.getPartnershipByName(name);
    if (part != null) {
        partFx.removePartnership(part);
        return new CommandResult(ECommandResultType.TYPE_OK, "deleted " + name);
    }
    return new CommandResult(ECommandResultType.TYPE_ERROR, "Unknown partnership name");
}
Also used : Partnership(com.helger.as2lib.partner.Partnership) CommandResult(com.helger.as2.cmd.CommandResult)

Aggregations

CommandResult (com.helger.as2.cmd.CommandResult)13 Partnership (com.helger.as2lib.partner.Partnership)4 Certificate (java.security.cert.Certificate)4 X509Certificate (java.security.cert.X509Certificate)4 ICommand (com.helger.as2.cmd.ICommand)2 CommandTokenizer (com.helger.as2.util.CommandTokenizer)2 IAliasedCertificateFactory (com.helger.as2lib.cert.IAliasedCertificateFactory)2 XMLPartnershipFactory (com.helger.as2lib.partner.xml.XMLPartnershipFactory)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 NonBlockingBufferedInputStream (com.helger.commons.io.stream.NonBlockingBufferedInputStream)2 IMicroDocument (com.helger.xml.microdom.IMicroDocument)2 IMicroElement (com.helger.xml.microdom.IMicroElement)2 MicroDocument (com.helger.xml.microdom.MicroDocument)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 CertificateFactory (java.security.cert.CertificateFactory)2 OpenAS2Exception (com.helger.as2lib.exception.OpenAS2Exception)1 WrappedOpenAS2Exception (com.helger.as2lib.exception.WrappedOpenAS2Exception)1 IPartner (com.helger.as2lib.partner.xml.IPartner)1 Partner (com.helger.as2lib.partner.xml.Partner)1