Search in sources :

Example 6 with CommandResult

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

the class ListCertCommand method execute.

@Override
public CommandResult execute(final IAliasedCertificateFactory certFx, final Object[] params) throws OpenAS2Exception {
    synchronized (certFx) {
        final Map<String, Certificate> certs = certFx.getCertificates();
        final CommandResult cmdRes = new CommandResult(ECommandResultType.TYPE_OK);
        for (final String sCertName : certs.keySet()) cmdRes.addResult(sCertName);
        if (cmdRes.hasNoResult())
            cmdRes.addResult("No certificates available");
        return cmdRes;
    }
}
Also used : Certificate(java.security.cert.Certificate) CommandResult(com.helger.as2.cmd.CommandResult)

Example 7 with CommandResult

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

the class AddPartnerCommand 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 IMicroDocument doc = new MicroDocument();
    final IMicroElement root = doc.appendElement("partner");
    for (int i = 0; i < params.length; i++) {
        final String param = (String) params[i];
        final int pos = param.indexOf('=');
        if (i == 0) {
            root.setAttribute("name", param);
        } else if (pos == 0) {
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing name");
        } else if (pos > 0) {
            root.setAttribute(param.substring(0, pos), param.substring(pos + 1));
        } else
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing value");
    }
    final Partner aNewPartner = ((XMLPartnershipFactory) partFx).loadPartner(root);
    partFx.addPartner(aNewPartner);
    return new CommandResult(ECommandResultType.TYPE_OK);
}
Also used : IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument) Partner(com.helger.as2lib.partner.xml.Partner) XMLPartnershipFactory(com.helger.as2lib.partner.xml.XMLPartnershipFactory) CommandResult(com.helger.as2.cmd.CommandResult)

Example 8 with CommandResult

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

the class AddPartnershipCommand method execute.

@Override
public CommandResult execute(final IPartnershipFactoryWithPartners partFx, final Object[] params) throws OpenAS2Exception {
    if (params.length < 3)
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    final IMicroDocument doc = new MicroDocument();
    final IMicroElement root = doc.appendElement("partnership");
    for (int nIndex = 0; nIndex < params.length; nIndex++) {
        final String param = (String) params[nIndex];
        final int pos = param.indexOf('=');
        if (nIndex == 0) {
            root.setAttribute("name", param);
        } else if (nIndex == 1) {
            final IMicroElement elem = root.appendElement("sender");
            elem.setAttribute("name", param);
        } else if (nIndex == 2) {
            final IMicroElement elem = root.appendElement("receiver");
            elem.setAttribute("name", param);
        } else if (pos == 0) {
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing name");
        } else if (pos > 0) {
            final IMicroElement elem = root.appendElement("attribute");
            elem.setAttribute("name", param.substring(0, pos));
            elem.setAttribute("value", param.substring(pos + 1));
        } else
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing value");
    }
    final XMLPartnershipFactory aXMLPartnershipFactory = (XMLPartnershipFactory) partFx;
    final Partnership aPartnership = aXMLPartnershipFactory.loadPartnership(root, aXMLPartnershipFactory.getPartnerMap());
    if (aXMLPartnershipFactory.getPartnershipByName(aPartnership.getName()) != null)
        return new CommandResult(ECommandResultType.TYPE_ERROR, "A partnership with name '" + aPartnership.getName() + "' is already present!");
    // add the partnership to the list of available partnerships
    partFx.addPartnership(aPartnership);
    return new CommandResult(ECommandResultType.TYPE_OK);
}
Also used : IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) Partnership(com.helger.as2lib.partner.Partnership) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument) XMLPartnershipFactory(com.helger.as2lib.partner.xml.XMLPartnershipFactory) CommandResult(com.helger.as2.cmd.CommandResult)

Example 9 with CommandResult

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

the class DeletePartnerCommand method execute.

@Override
public CommandResult execute(@Nonnull final IPartnershipFactoryWithPartners partFx, final Object[] aParams) throws OpenAS2Exception {
    if (aParams.length < 1)
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    final String sName = aParams[0].toString();
    if (!partFx.getAllPartnerNames().contains(sName))
        return new CommandResult(ECommandResultType.TYPE_ERROR, "Unknown partner name '" + sName + "'");
    for (final Partnership aPartnership : partFx.getAllPartnerships()) if (aPartnership.containsReceiverID(sName) || aPartnership.containsSenderID(sName)) {
        return new CommandResult(ECommandResultType.TYPE_ERROR, "Can not delete partner '" + sName + "'; it is tied to some partnerships");
    }
    partFx.removePartner(sName);
    return new CommandResult(ECommandResultType.TYPE_OK);
}
Also used : Partnership(com.helger.as2lib.partner.Partnership) CommandResult(com.helger.as2.cmd.CommandResult)

Example 10 with CommandResult

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

the class ImportCertCommand method importPrivateKey.

protected CommandResult importPrivateKey(@Nonnull final IKeyStoreType aKeyStoreType, final IAliasedCertificateFactory aFactory, final String sAlias, final String sFilename, final String sPassword) throws Exception {
    final KeyStore aKeyStore = AS2Helper.getCryptoHelper().createNewKeyStore(aKeyStoreType);
    try (final InputStream aIS = new FileInputStream(sFilename)) {
        aKeyStore.load(aIS, sPassword.toCharArray());
    }
    final Enumeration<String> aliases = aKeyStore.aliases();
    while (aliases.hasMoreElements()) {
        final String sCertAlias = aliases.nextElement();
        final Certificate aCert = aKeyStore.getCertificate(sCertAlias);
        if (aCert instanceof X509Certificate) {
            aFactory.addCertificate(sAlias, (X509Certificate) aCert, true);
            final Key certKey = aKeyStore.getKey(sCertAlias, sPassword.toCharArray());
            aFactory.addPrivateKey(sAlias, certKey, sPassword);
            return new CommandResult(ECommandResultType.TYPE_OK, "Imported certificate and key: " + aCert.toString());
        }
    }
    return new CommandResult(ECommandResultType.TYPE_ERROR, "No valid X509 certificates found");
}
Also used : NonBlockingBufferedInputStream(com.helger.commons.io.stream.NonBlockingBufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) X509Certificate(java.security.cert.X509Certificate) Key(java.security.Key) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) 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