Search in sources :

Example 1 with Setting

use of org.nhindirect.config.model.Setting in project nhin-d by DirectProject.

the class SettingResource method getSettingByName.

/**
     * Gets a setting by name.
     * @param name The name of the setting to retrieve.
     * @return A JSON representation of the setting.  Returns a status of 404 if a setting with the given name does not exist.
     */
@Produces(MediaType.APPLICATION_JSON)
@Path("{name}")
@GET
public Response getSettingByName(@PathParam("name") String name) {
    try {
        final Collection<org.nhindirect.config.store.Setting> retSettings = settingDao.getByNames(Arrays.asList(name));
        if (retSettings.isEmpty())
            return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
        final Setting modelSetting = EntityModelConversion.toModelSetting(retSettings.iterator().next());
        return Response.ok(modelSetting).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up setting.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
}
Also used : Setting(org.nhindirect.config.model.Setting) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Setting

use of org.nhindirect.config.model.Setting in project nhin-d by DirectProject.

the class SettingResource method addSetting.

/**
     * Adds a setting to the system.
     * @param uriInfo Injected URI context used for building the location URI.
     * @param name The name of the setting to add.
     * @param value The value of the setting.
     * @return Status of 201 if the setting was created or a status of 409 if a setting with the same name
     * already exists.
     */
@PUT
@Path("{name}/{value}")
public Response addSetting(@Context UriInfo uriInfo, @PathParam("name") String name, @PathParam("value") String value) {
    // check to see if it already exists
    try {
        final Collection<org.nhindirect.config.store.Setting> retSettings = settingDao.getByNames(Arrays.asList(name));
        if (!retSettings.isEmpty())
            return Response.status(Status.CONFLICT).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error looking up setting.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
    try {
        settingDao.add(name, value);
        final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
        final URI newLoc = newLocBuilder.path("setting/" + name).build();
        return Response.created(newLoc).cacheControl(noCache).build();
    } catch (Exception e) {
        log.error("Error adding setting.", e);
        return Response.serverError().cacheControl(noCache).build();
    }
}
Also used : Setting(org.nhindirect.config.model.Setting) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 3 with Setting

use of org.nhindirect.config.model.Setting in project nhin-d by DirectProject.

the class RESTSmtpAgentConfig method buildMDNSettings.

protected void buildMDNSettings() {
    Setting autoResponseSettings;
    Setting prodNameSetting;
    Setting textSetting;
    try {
        autoResponseSettings = settingsService.getSetting("MDNAutoResponse");
        prodNameSetting = settingsService.getSetting("MDNProdName");
        textSetting = settingsService.getSetting("MDNProdName");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting MDN settings: " + e.getMessage(), e);
    }
    boolean autoResponse = (autoResponseSettings == null) ? true : Boolean.parseBoolean(autoResponseSettings.getValue());
    String prodName = (prodNameSetting == null) ? "" : prodNameSetting.getValue();
    String text = (textSetting == null) ? "" : textSetting.getValue();
    notificationProducer = new NotificationProducer(new NotificationSettings(autoResponse, prodName, text));
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) NotificationProducer(org.nhindirect.gateway.smtp.NotificationProducer) Setting(org.nhindirect.config.model.Setting) NotificationSettings(org.nhindirect.gateway.smtp.NotificationSettings) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 4 with Setting

use of org.nhindirect.config.model.Setting in project nhin-d by DirectProject.

the class RESTSmtpAgentConfig method buildMessageSettings.

protected void buildMessageSettings(String type) {
    Setting folderSettings;
    try {
        folderSettings = settingsService.getSetting("MessageSaveFolder");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting " + type + " message settings: " + e.getMessage(), e);
    }
    String saveFolder = (folderSettings == null) ? null : folderSettings.getValue();
    MessageProcessingSettings settings = null;
    if (type.equalsIgnoreCase(MESSAGE_SETTING_RAW))
        settings = rawSettings = new RawMessageSettings();
    else if (type.equalsIgnoreCase(MESSAGE_SETTING_INCOMING))
        settings = incomingSettings = new ProcessIncomingSettings();
    else if (type.equalsIgnoreCase(MESSAGE_SETTING_OUTGOING))
        settings = outgoingSettings = new ProcessOutgoingSettings();
    else if (type.equalsIgnoreCase(MESSAGE_SETTING_BAD))
        settings = badSettings = new ProcessBadMessageSettings();
    if (saveFolder != null && settings != null)
        settings.setSaveMessageFolder(new File(saveFolder));
}
Also used : ProcessOutgoingSettings(org.nhindirect.gateway.smtp.ProcessOutgoingSettings) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) ProcessBadMessageSettings(org.nhindirect.gateway.smtp.ProcessBadMessageSettings) Setting(org.nhindirect.config.model.Setting) MessageProcessingSettings(org.nhindirect.gateway.smtp.MessageProcessingSettings) ProcessIncomingSettings(org.nhindirect.gateway.smtp.ProcessIncomingSettings) RawMessageSettings(org.nhindirect.gateway.smtp.RawMessageSettings) File(java.io.File) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 5 with Setting

use of org.nhindirect.config.model.Setting in project nhin-d by DirectProject.

the class RESTSmtpAgentConfig method buildPrivateCertStore.

protected void buildPrivateCertStore() {
    Provider<CertificateResolver> resolverProvider = null;
    Setting setting = null;
    String storeType;
    try {
        setting = settingsService.getSetting("PrivateStoreType");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting public store type: " + e.getMessage(), e);
    }
    if (setting == null || setting.getValue() == null || setting.getValue().isEmpty())
        // default to WS
        storeType = STORE_TYPE_WS;
    else
        storeType = setting.getValue();
    /*
		 * KeyStore based resolver
		 */
    if (storeType.equalsIgnoreCase(STORE_TYPE_KEYSTORE)) {
        Setting file;
        Setting pass;
        Setting privKeyPass;
        try {
            file = settingsService.getSetting("PrivateStoreFile");
            pass = settingsService.getSetting("PrivateStoreFilePass");
            privKeyPass = settingsService.getSetting("PrivateStorePrivKeyPass");
        } catch (Exception e) {
            throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting private store file settings: " + e.getMessage(), e);
        }
        resolverProvider = new KeyStoreCertificateStoreProvider((file == null) ? null : file.getValue(), (pass == null) ? null : pass.getValue(), (privKeyPass == null) ? null : privKeyPass.getValue());
    } else if (storeType.equalsIgnoreCase(STORE_TYPE_LDAP)) {
        resolverProvider = buildLdapCertificateStoreProvider("PrivateStore", "LDAPPrivateCertStore");
    } else if (storeType.equalsIgnoreCase(STORE_TYPE_WS)) {
        resolverProvider = new ConfigServiceRESTCertificateStoreProvider(certificateService, null, new ConfigServiceCertificateStore.DefaultConfigStoreCachePolicy(), this.storeProvider);
    } else {
        throw new SmtpAgentException(SmtpAgentError.InvalidPrivateCertStoreSettings);
    }
    privateCertModule = new PrivateCertStoreModule(resolverProvider);
}
Also used : PrivateCertStoreModule(org.nhindirect.stagent.module.PrivateCertStoreModule) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) KeyStoreCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider) Setting(org.nhindirect.config.model.Setting) ConfigServiceRESTCertificateStoreProvider(org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceRESTCertificateStoreProvider) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Aggregations

Setting (org.nhindirect.config.model.Setting)12 AddressException (javax.mail.internet.AddressException)7 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)7 PolicyParseException (org.nhindirect.policy.PolicyParseException)7 ArrayList (java.util.ArrayList)5 X509Certificate (java.security.cert.X509Certificate)4 Collection (java.util.Collection)4 LDAPCertificateStore (org.nhindirect.stagent.cert.impl.LDAPCertificateStore)3 IOException (java.io.IOException)2 KeyStore (java.security.KeyStore)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 PrivateKey (java.security.PrivateKey)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CertificateEncodingException (javax.security.cert.CertificateEncodingException)2 Path (javax.ws.rs.Path)2 MutableKeyStoreProtectionManager (org.nhindirect.common.crypto.MutableKeyStoreProtectionManager)2 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)2 Certificate (org.nhindirect.config.model.Certificate)2 TrustBundle (org.nhindirect.config.model.TrustBundle)2