Search in sources :

Example 6 with ConfigurationServiceProxy

use of org.nhind.config.ConfigurationServiceProxy in project nhin-d by DirectProject.

the class AddDomainCAAndPrivCert method main.

public static void main(String[] args) {
    final String configServiceUrl = args[0];
    final String domainName = args[1];
    final String caCommonName = args[2];
    final String certCommonName = args[3];
    try {
        final ConfigurationServiceProxy cfService = new ConfigurationServiceProxy(configServiceUrl);
        final Domain domain = new Domain();
        domain.setDomainName(domainName);
        domain.setPostMasterEmail("postmaster@" + domainName);
        domain.setStatus(EntityStatus.ENABLED);
        cfService.addDomain(domain);
        // now add the anchor and cert
        final File caFile = AbstractCertCreator.createNewFileName(caCommonName, false);
        final Anchor anchor = new Anchor();
        anchor.setData(FileUtils.readFileToByteArray(caFile));
        anchor.setOwner(domainName);
        anchor.setIncoming(true);
        anchor.setOutgoing(true);
        anchor.setStatus(EntityStatus.ENABLED);
        cfService.addAnchor(new Anchor[] { anchor });
        final File certFile = AbstractCertCreator.createNewFileName(certCommonName, false);
        final String certFileName = certFile.getName();
        int idx = certFileName.lastIndexOf(".der");
        final String p12FileName = certFileName.substring(0, idx) + ".p12";
        final Certificate cert = new Certificate();
        cert.setData(FileUtils.readFileToByteArray(new File(p12FileName)));
        cert.setStatus(EntityStatus.ENABLED);
        cfService.addCertificates(new Certificate[] { cert });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Anchor(org.nhind.config.Anchor) Domain(org.nhind.config.Domain) File(java.io.File) ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy) Certificate(org.nhind.config.Certificate)

Example 7 with ConfigurationServiceProxy

use of org.nhind.config.ConfigurationServiceProxy in project nhin-d by DirectProject.

the class AddHardcodedRecord method main.

public static void main(String[] args) {
    try {
        ConfigurationServiceProxy proxy = new ConfigurationServiceProxy("http://securehealthemail.com:8080/config-service/ConfigurationService");
        // clean everything
        DnsRecord[] recs = proxy.getDNSByType(Type.ANY);
        if (recs != null && recs.length > 0)
            proxy.removeDNS(recs);
        recs = proxy.getDNSByType(Type.ANY);
        assertNull(recs);
        // now add
        ArrayList<DnsRecord> recsAdd = new ArrayList<DnsRecord>();
        DnsRecord rec = DNSRecordUtil.createARecord("direct.securehealthemail.com", "184.73.173.57");
        recsAdd.add(rec);
        rec = DNSRecordUtil.createARecord("ns1.direct.securehealthemail.com", "184.73.173.57");
        recsAdd.add(rec);
        rec = DNSRecordUtil.createARecord("mail1.direct.securehealthemail.com", "184.73.173.57");
        recsAdd.add(rec);
        rec = DNSRecordUtil.createSOARecord("direct.securehealthemail.com", "ns1.direct.securehealthemail.com", "greg.meyer@direct.securehealthemail.com");
        recsAdd.add(rec);
        rec = DNSRecordUtil.createMXRecord("direct.securehealthemail.com", "mail1.direct.securehealthemail.com", 0);
        recsAdd.add(rec);
        proxy.addDNS(recsAdd.toArray(new DnsRecord[recsAdd.size()]));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) DnsRecord(org.nhind.config.DnsRecord) ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy)

Example 8 with ConfigurationServiceProxy

use of org.nhind.config.ConfigurationServiceProxy in project nhin-d by DirectProject.

the class ConfigServiceDNSStore_configCertPolicyTest method setUp.

public void setUp() {
    try {
        if (!ConfigServiceRunner.isServiceRunning())
            ConfigServiceRunner.startConfigService();
        proxy = new ConfigurationServiceProxy(ConfigServiceRunner.getConfigServiceURL());
        cleanRecords();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy)

Example 9 with ConfigurationServiceProxy

use of org.nhind.config.ConfigurationServiceProxy in project nhin-d by DirectProject.

the class RESTSmtpAgentConfigFunctional_Test method setUp.

/**
     * Initialize the servers- LDAP and HTTP.
     */
@SuppressWarnings("unchecked")
@Override
public void setUp() throws Exception {
    // check for Windows... it doens't like file://<drive>... turns it into FTP
    File file = new File("./src/test/resources/bundles/testBundle.p7b");
    if (file.getAbsolutePath().contains(":/"))
        filePrefix = "file:///";
    else
        filePrefix = "file:///";
    CertCacheFactory.getInstance().flushAll();
    /*
		 * Setup the LDAP Server
		 */
    MutablePartitionConfiguration pcfg = new MutablePartitionConfiguration();
    pcfg.setName("lookupTest");
    pcfg.setSuffix("cn=lookupTest");
    // Create some indices
    Set<String> indexedAttrs = new HashSet<String>();
    indexedAttrs.add("objectClass");
    indexedAttrs.add("cn");
    pcfg.setIndexedAttributes(indexedAttrs);
    // Create a first entry associated to the partition
    Attributes attrs = new BasicAttributes(true);
    // First, the objectClass attribute
    Attribute attr = new BasicAttribute("objectClass");
    attr.add("top");
    attrs.put(attr);
    // Associate this entry to the partition
    pcfg.setContextEntry(attrs);
    // As we can create more than one partition, we must store
    // each created partition in a Set before initialization
    Set<MutablePartitionConfiguration> pcfgs = new HashSet<MutablePartitionConfiguration>();
    pcfgs.add(pcfg);
    //
    //
    //
    // add the lookupTestPublic
    //
    //
    pcfg = new MutablePartitionConfiguration();
    pcfg.setName("lookupTestPublic");
    pcfg.setSuffix("cn=lookupTestPublic");
    // Create some indices
    indexedAttrs = new HashSet<String>();
    indexedAttrs.add("objectClass");
    indexedAttrs.add("cn");
    pcfg.setIndexedAttributes(indexedAttrs);
    // Create a first entry associated to the partition
    attrs = new BasicAttributes(true);
    // First, the objectClass attribute
    attr = new BasicAttribute("objectClass");
    attr.add("top");
    attrs.put(attr);
    // Associate this entry to the partition
    pcfg.setContextEntry(attrs);
    // As we can create more than one partition, we must store
    // each created partition in a Set before initialization
    pcfgs.add(pcfg);
    configuration.setContextPartitionConfigurations(pcfgs);
    this.configuration.setWorkingDirectory(new File("LDAP-TEST"));
    // add the private key schema
    ///
    Set<AbstractBootstrapSchema> schemas = configuration.getBootstrapSchemas();
    schemas.add(new PrivkeySchema());
    configuration.setBootstrapSchemas(schemas);
    super.setUp();
    // import the ldif file
    InputStream stream = TestUtils.class.getResourceAsStream("/ldifs/privCertsOnly.ldif");
    if (stream == null)
        throw new IOException("Failed to load ldif file");
    importLdif(stream);
    // setup the mock DNS SRV adapter
    mockLookup = mock(Lookup.class);
    LookupFactory.getFactory().addOverrideImplementation(mockLookup);
    SRVRecord srvRecord = new SRVRecord(new Name("_ldap._tcp.example.com."), DClass.IN, 3600, 0, 1, port, new Name("localhost."));
    when(mockLookup.run()).thenReturn(new Record[] { srvRecord });
    // create the web service and proxy
    ConfigServiceRunner.startConfigService();
    proxy = new ConfigurationServiceProxy(ConfigServiceRunner.getConfigServiceURL());
    certService = new DefaultCertificateService(ConfigServiceRunner.getRestAPIBaseURL(), HttpClientFactory.createHttpClient(), new OpenServiceSecurityManager());
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attribute(javax.naming.directory.Attribute) BasicAttribute(javax.naming.directory.BasicAttribute) DefaultCertificateService(org.nhind.config.rest.impl.DefaultCertificateService) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) OpenServiceSecurityManager(org.nhindirect.common.rest.OpenServiceSecurityManager) IOException(java.io.IOException) PrivkeySchema(org.nhindirect.ldap.PrivkeySchema) Name(org.xbill.DNS.Name) AbstractBootstrapSchema(org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema) MutablePartitionConfiguration(org.apache.directory.server.core.configuration.MutablePartitionConfiguration) Lookup(org.nhindirect.stagent.cert.impl.util.Lookup) SRVRecord(org.xbill.DNS.SRVRecord) File(java.io.File) ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy) HashSet(java.util.HashSet)

Example 10 with ConfigurationServiceProxy

use of org.nhind.config.ConfigurationServiceProxy in project nhin-d by DirectProject.

the class RoutingResolverImplTest method startService.

private void startService() throws Exception {
    /*
         * Setup the configuration service server
         */
    server = new Server();
    SocketConnector connector = new SocketConnector();
    HTTPPort = AvailablePortFinder.getNextAvailable(1024);
    connector.setPort(HTTPPort);
    WebAppContext context = new WebAppContext();
    context.setContextPath("/config");
    context.setServer(server);
    context.setWar("war/config-service.war");
    server.setSendServerVersion(false);
    server.addConnector(connector);
    server.addHandler(context);
    server.start();
    configServiceURL = "http://localhost:" + HTTPPort + "/config/ConfigurationService";
    proxy = new ConfigurationServiceProxy(configServiceURL);
    cleanConfig();
}
Also used : WebAppContext(org.mortbay.jetty.webapp.WebAppContext) Server(org.mortbay.jetty.Server) SocketConnector(org.mortbay.jetty.bio.SocketConnector) ConfigurationServiceProxy(org.nhind.config.ConfigurationServiceProxy)

Aggregations

ConfigurationServiceProxy (org.nhind.config.ConfigurationServiceProxy)11 File (java.io.File)3 BeforeClass (org.junit.BeforeClass)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 Attribute (javax.naming.directory.Attribute)2 Attributes (javax.naming.directory.Attributes)2 BasicAttribute (javax.naming.directory.BasicAttribute)2 BasicAttributes (javax.naming.directory.BasicAttributes)2 MutablePartitionConfiguration (org.apache.directory.server.core.configuration.MutablePartitionConfiguration)2 AbstractBootstrapSchema (org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema)2 Anchor (org.nhind.config.Anchor)2 Certificate (org.nhind.config.Certificate)2 Domain (org.nhind.config.Domain)2 PrivkeySchema (org.nhindirect.ldap.PrivkeySchema)2 Lookup (org.nhindirect.stagent.cert.impl.util.Lookup)2 Name (org.xbill.DNS.Name)2 SRVRecord (org.xbill.DNS.SRVRecord)2