Search in sources :

Example 26 with Command

use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.

the class TrustBundleCommands method listDomainBundles.

@Command(name = "ListDomainBundles", usage = LIST_DOMAIN_BUNDLES_USAGE)
public void listDomainBundles(String[] args) {
    final long domainId = Long.parseLong(StringArrayUtil.getRequiredValue(args, 0));
    try {
        final Domain domain = proxy.getDomain(domainId);
        if (domain == null) {
            System.out.println("Domain with id " + domainId + " does not exist.");
            return;
        }
        // make sure there isn't already an association
        final TrustBundleDomainReltn[] reltns = proxy.getTrustBundlesByDomain(domainId, false);
        if (reltns == null || reltns.length == 0) {
            System.out.println("No bundles associated with domain " + domain.getDomainName());
            return;
        }
        List<TrustBundle> bundles = new ArrayList<TrustBundle>();
        for (TrustBundleDomainReltn reltn : reltns) bundles.add(reltn.getTrustBundle());
        System.out.println("Bundles associated with domain " + domain.getDomainName());
        bundlePrinter.printRecords(bundles);
    } catch (Exception e) {
        System.out.println("Error getting domain bundles : " + e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) TrustBundle(org.nhind.config.TrustBundle) Domain(org.nhind.config.Domain) TrustBundleDomainReltn(org.nhind.config.TrustBundleDomainReltn) Command(org.nhindirect.dns.tools.utils.Command)

Example 27 with Command

use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.

the class TrustBundleCommands method deleteTrustBundleFromDomain.

@Command(name = "DeleteTrustBundleFromDomain", usage = REMOVE_BUNDLE_FROM_DOMAIN)
public void deleteTrustBundleFromDomain(String[] args) {
    final long bundleId = Long.parseLong(StringArrayUtil.getRequiredValue(args, 0));
    final long domainId = Long.parseLong(StringArrayUtil.getRequiredValue(args, 1));
    try {
        final TrustBundle bundle = proxy.getTrustBundleById(bundleId);
        if (bundle == null) {
            System.out.println("Bundle with id " + bundleId + " does not exist.");
            return;
        }
        final Domain domain = proxy.getDomain(domainId);
        if (domain == null) {
            System.out.println("Domain with id " + domainId + " does not exist.");
            return;
        }
        // make sure there is already an association
        boolean associationExists = false;
        final TrustBundleDomainReltn[] reltns = proxy.getTrustBundlesByDomain(domainId, false);
        if (reltns != null && reltns.length > 0) {
            for (TrustBundleDomainReltn reltn : reltns) {
                if (reltn.getTrustBundle().getId() == bundleId) {
                    associationExists = true;
                    break;
                }
            }
        }
        if (!associationExists) {
            System.out.println("Bundle " + bundle.getBundleName() + " is not associated with domain " + domain.getDomainName());
            return;
        }
        proxy.disassociateTrustBundleFromDomain(domainId, bundleId);
        System.out.println("Trust bundle " + bundle.getBundleName() + " removed from domain " + domain.getDomainName());
    } catch (Exception e) {
        System.out.println("Error removing bundle from domain : " + e.getMessage());
    }
}
Also used : TrustBundle(org.nhind.config.TrustBundle) Domain(org.nhind.config.Domain) TrustBundleDomainReltn(org.nhind.config.TrustBundleDomainReltn) Command(org.nhindirect.dns.tools.utils.Command)

Example 28 with Command

use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.

the class CertCommands method importPublicCert.

@Command(name = "AddPublicCert", usage = IMPORT_PUBLIC_CERT_USAGE)
public void importPublicCert(String[] args) {
    final String fileLoc = StringArrayUtil.getRequiredValue(args, 0);
    try {
        final X509Certificate cert = new CertUtils().certFromFile(fileLoc);
        final org.nhind.config.Certificate addCert = new org.nhind.config.Certificate();
        addCert.setData(cert.getEncoded());
        addCert.setOwner(CryptoExtensions.getSubjectAddress(cert));
        addCert.setPrivateKey(false);
        addCert.setStatus(EntityStatus.ENABLED);
        proxy.addCertificates(new org.nhind.config.Certificate[] { addCert });
        System.out.println("Successfully imported public certificate.");
    } catch (IOException e) {
        System.out.println("Error reading file " + fileLoc + " : " + e.getMessage());
        return;
    }///CLOVER:OFF
     catch (Exception e) {
        System.out.println("Error importing certificate " + fileLoc + " : " + e.getMessage());
    }
///CLOVER:ON
}
Also used : CertUtils(org.nhindirect.config.model.utils.CertUtils) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) IOException(java.io.IOException) X509Certificate(java.security.cert.X509Certificate) Command(org.nhindirect.dns.tools.utils.Command)

Example 29 with Command

use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.

the class DNSRecordCommands method ensureMX.

/**
	 * Adds an MX records to the configuration service only if the record does not exist.
	 * @param args Contains the MX record attributes.
	 * 
	 * @since 1.0
	 */
@Command(name = "Dns_MX_Ensure", usage = ENSURE_MX_USAGE)
public void ensureMX(String[] args) {
    DnsRecord record = fromRecord(parser.parseMX(args));
    if (!verifyIsUnique(record, false)) {
        return;
    }
    addDNS(record);
}
Also used : DnsRecord(org.nhind.config.DnsRecord) Command(org.nhindirect.dns.tools.utils.Command)

Example 30 with Command

use of org.nhindirect.dns.tools.utils.Command in project nhin-d by DirectProject.

the class DNSRecordCommands method addANAME.

/**
	 * Adds an A records to the configuration service.
	 * @param args Contains the A record attributes.
	 * 
	 * @since 1.0
	 */
@Command(name = "Dns_ANAME_Add", usage = ADD_ANAME_USAGE)
public void addANAME(String[] args) {
    DnsRecord record = fromRecord(parser.parseANAME(args));
    addDNS(record);
}
Also used : DnsRecord(org.nhind.config.DnsRecord) Command(org.nhindirect.dns.tools.utils.Command)

Aggregations

Command (org.nhindirect.dns.tools.utils.Command)33 DnsRecord (org.nhind.config.DnsRecord)14 IOException (java.io.IOException)11 Domain (org.nhind.config.Domain)9 File (java.io.File)7 X509Certificate (java.security.cert.X509Certificate)6 TrustBundle (org.nhind.config.TrustBundle)6 ArrayList (java.util.ArrayList)4 PolicyParseException (org.nhindirect.policy.PolicyParseException)4 CertPolicyGroupDomainReltn (org.nhind.config.CertPolicyGroupDomainReltn)3 TrustBundleDomainReltn (org.nhind.config.TrustBundleDomainReltn)3 X509CertificateEx (org.nhindirect.stagent.cert.X509CertificateEx)3 RemoteException (java.rmi.RemoteException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Anchor (org.nhind.config.Anchor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 PolicyLexicon (org.nhind.config.PolicyLexicon)1 TrustBundleAnchor (org.nhind.config.TrustBundleAnchor)1