Search in sources :

Example 1 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 = 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 : 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 2 with Command

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

the class DNSRecordCommands method addSOA.

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

Example 3 with Command

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

the class DNSRecordCommands method match.

/**
	 * Looks up all records for a given domain and any sub domains.
	 * @param args The first entry in the array contains the domain name (required).
	 * 
	 * @since 1.0
	 */
@Command(name = "Dns_Match", usage = "Resolve all records for the given domain")
public void match(String[] args) {
    String domain = StringArrayUtil.getRequiredValue(args, 0);
    DnsRecord[] records = null;
    Pattern pattern = Pattern.compile(domain);
    ArrayList<DnsRecord> matchedRecords = new ArrayList<DnsRecord>();
    try {
        records = proxy.getDNSByType(Type.ANY);
    } catch (Exception e) {
        throw new RuntimeException("Error accessing configuration service: " + e.getMessage(), e);
    }
    if (records == null || records.length == 0) {
        System.out.println("No records found");
        return;
    } else {
        for (DnsRecord record : records) {
            Matcher matcher = pattern.matcher(record.getName());
            if (matcher.find()) {
                matchedRecords.add(record);
            }
        }
    }
    if (matchedRecords.size() == 0) {
        System.out.println("No records found");
        return;
    }
    print(matchedRecords.toArray(new DnsRecord[matchedRecords.size()]));
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) DnsRecord(org.nhind.config.DnsRecord) RemoteException(java.rmi.RemoteException) Command(org.nhindirect.dns.tools.utils.Command)

Example 4 with Command

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

the class DNSRecordCommands method ensureSOA.

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

Example 5 with Command

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

the class DNSRecordCommands method addMX.

/**
	 * Adds an MX records to the configuration service.
	 * @param args Contains the MX record attributes.
	 * 
	 * @since 1.0
	 */
@Command(name = "Dns_MX_Add", usage = ADD_MX_USAGE)
public void addMX(String[] args) {
    DnsRecord record = fromRecord(parser.parseMX(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