Search in sources :

Example 1 with IProxySettings

use of com.helger.network.proxy.settings.IProxySettings in project phoss-smp by phax.

the class SMPServerConfiguration method getAsHttpsProxySettings.

/**
 * @return A single object for all https (but not http) proxy settings. May be
 *         <code>null</code>.
 * @see #getAsHttpProxySettings()
 * @since 5.0.7
 */
@Nullable
public static IProxySettings getAsHttpsProxySettings() {
    final String sHostname = getHttpsProxyHost();
    final int nPort = getHttpsProxyPort();
    if (sHostname != null && nPort > 0)
        return new ProxySettings(Proxy.Type.HTTP, sHostname, nPort, getProxyUsername(), getProxyPassword());
    return null;
}
Also used : IProxySettings(com.helger.network.proxy.settings.IProxySettings) ProxySettings(com.helger.network.proxy.settings.ProxySettings) Nullable(javax.annotation.Nullable)

Example 2 with IProxySettings

use of com.helger.network.proxy.settings.IProxySettings in project phoss-smp by phax.

the class SMPServerConfiguration method getAsHttpProxySettings.

/**
 * @return A single object for all http (but not https) proxy settings. May be
 *         <code>null</code>.
 * @see #getAsHttpsProxySettings()
 * @since 5.0.7
 */
@Nullable
public static IProxySettings getAsHttpProxySettings() {
    final String sHostname = getHttpProxyHost();
    final int nPort = getHttpProxyPort();
    if (sHostname != null && nPort > 0)
        return new ProxySettings(Proxy.Type.HTTP, sHostname, nPort, getProxyUsername(), getProxyPassword());
    return null;
}
Also used : IProxySettings(com.helger.network.proxy.settings.IProxySettings) ProxySettings(com.helger.network.proxy.settings.ProxySettings) Nullable(javax.annotation.Nullable)

Example 3 with IProxySettings

use of com.helger.network.proxy.settings.IProxySettings in project ph-web by phax.

the class ProxyAutoConfigHelper method getProxyListForURL.

@Nonnull
public ICommonsList<IProxySettings> getProxyListForURL(@Nonnull final String sURL, @Nonnull final String sHost) throws ScriptException {
    final ICommonsList<IProxySettings> ret = new CommonsArrayList<>();
    String sProxyCode = findProxyForURL(sURL, sHost);
    if (sProxyCode != null) {
        // parse result of PAC call
        sProxyCode = sProxyCode.trim();
        if (sProxyCode.length() > 0) {
            for (String sDirective : StringHelper.getExploded(';', sProxyCode)) {
                boolean bError = true;
                sDirective = sDirective.trim();
                if (sDirective.equals("DIRECT")) {
                    ret.add(ProxySettings.createNoProxySettings());
                    bError = false;
                } else if (sDirective.startsWith("PROXY")) {
                    String[] aParts = StringHelper.getExplodedArray(' ', sDirective, 2);
                    if (aParts.length == 2) {
                        aParts = StringHelper.getExplodedArray(':', aParts[1], 2);
                        if (aParts.length == 2) {
                            final String sProxyHost = aParts[0];
                            final String sProxyPort = aParts[1];
                            final int nProxyPort = StringParser.parseInt(sProxyPort, -1);
                            ret.add(new ProxySettings(Proxy.Type.HTTP, sProxyHost, nProxyPort));
                            bError = false;
                        }
                    }
                } else if (sDirective.startsWith("SOCKS")) {
                    String[] aParts = StringHelper.getExplodedArray(' ', sDirective, 2);
                    if (aParts.length == 2) {
                        aParts = StringHelper.getExplodedArray(':', aParts[1], 2);
                        if (aParts.length == 2) {
                            final String sProxyHost = aParts[0];
                            final String sProxyPort = aParts[1];
                            final int nProxyPort = StringParser.parseInt(sProxyPort, SocksProxyConfig.DEFAULT_SOCKS_PROXY_PORT);
                            ret.add(new ProxySettings(Proxy.Type.SOCKS, sProxyHost, nProxyPort));
                            bError = false;
                        }
                    }
                }
                if (bError)
                    if (LOGGER.isWarnEnabled())
                        LOGGER.warn("Found unknown proxy directive '" + sDirective + "'");
            }
        }
    }
    return ret;
}
Also used : IProxySettings(com.helger.network.proxy.settings.IProxySettings) IProxySettings(com.helger.network.proxy.settings.IProxySettings) ProxySettings(com.helger.network.proxy.settings.ProxySettings) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Nonnull(javax.annotation.Nonnull)

Example 4 with IProxySettings

use of com.helger.network.proxy.settings.IProxySettings in project ph-web by phax.

the class ProxyAutoConfigHelperTest method testGetProxyListForURL.

@Test
public void testGetProxyListForURL() throws ScriptException {
    for (final String sFile : PAC_FILES) {
        LOGGER.info("Reading " + sFile);
        final IReadableResource aRes = new ClassPathResource("proxyautoconf/pacfiles/" + sFile);
        assertTrue(aRes.exists());
        final ProxyAutoConfigHelper aPACHelper = new ProxyAutoConfigHelper(aRes);
        final ICommonsList<IProxySettings> aPC = aPACHelper.getProxyListForURL(URLHelper.getAsURI("http://www.orf.at/index.html"));
        assertNotNull(sFile + " failed", aPC);
        assertFalse(sFile + " failed", aPC.isEmpty());
        LOGGER.info("  Found the following " + aPC.size() + " entries: " + aPC);
    }
}
Also used : IProxySettings(com.helger.network.proxy.settings.IProxySettings) IReadableResource(com.helger.commons.io.resource.IReadableResource) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 5 with IProxySettings

use of com.helger.network.proxy.settings.IProxySettings in project phoss-smp by phax.

the class SMPWebAppListener method initManagers.

@Override
protected void initManagers() {
    {
        LOGGER.info("Init of ConfigurationFileManager");
        final ConfigurationFileManager aCFM = ConfigurationFileManager.getInstance();
        aCFM.registerConfigurationFile(new ConfigurationFile(new ClassPathResource("log4j2.xml")).setDescription("Log4J2 configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.XML));
        aCFM.registerConfigurationFile(new ConfigurationFile(SMPWebAppConfiguration.getSettingsResource()).setDescription("SMP web application configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.PROPERTIES));
        final IReadableResource aConfigRes = SMPServerConfiguration.getConfigFile().getReadResource();
        if (aConfigRes != null) {
            aCFM.registerConfigurationFile(new ConfigurationFile(aConfigRes).setDescription("SMP server configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.PROPERTIES));
        }
        aCFM.registerAll(PDClientConfiguration.getConfig());
    }
    {
        LOGGER.info("Init of Directory client stuff");
        // If the SMP settings change, the PD client must be re-created
        SMPMetaManager.getSettingsMgr().callbacks().add(x -> PDClientProvider.getInstance().resetPDClient());
        // Callback on BusinessCard manager - if something happens, notify PD
        // server
        final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
        if (aBusinessCardMgr != null) {
            aBusinessCardMgr.bcCallbacks().add(new ISMPBusinessCardCallback() {

                public void onSMPBusinessCardCreatedOrUpdated(@Nonnull final ISMPBusinessCard aBusinessCard) {
                    final ISMPSettings aSettings = SMPMetaManager.getSettings();
                    if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
                        // Notify PD server: add
                        PDClientProvider.getInstance().getPDClient().addServiceGroupToIndex(aBusinessCard.getParticipantIdentifier());
                    }
                }

                public void onSMPBusinessCardDeleted(@Nonnull final ISMPBusinessCard aBusinessCard) {
                    final ISMPSettings aSettings = SMPMetaManager.getSettings();
                    if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
                        // Notify PD server: delete
                        PDClientProvider.getInstance().getPDClient().deleteServiceGroupFromIndex(aBusinessCard.getParticipantIdentifier());
                    }
                }
            });
            // If a service information is create, updated or deleted, also update
            // Business Card at PD
            SMPMetaManager.getServiceInformationMgr().serviceInformationCallbacks().add(new ISMPServiceInformationCallback() {

                @Override
                public void onSMPServiceInformationCreated(@Nonnull final ISMPServiceInformation aServiceInformation) {
                    final ISMPSettings aSettings = SMPMetaManager.getSettings();
                    if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
                        // Only if a business card is present
                        if (aBusinessCardMgr.containsSMPBusinessCardOfServiceGroup(aServiceInformation.getServiceGroup())) {
                            // Notify PD server: update
                            PDClientProvider.getInstance().getPDClient().addServiceGroupToIndex(aServiceInformation.getServiceGroup().getParticipantIdentifier());
                        }
                    }
                }

                @Override
                public void onSMPServiceInformationUpdated(@Nonnull final ISMPServiceInformation aServiceInformation) {
                    onSMPServiceInformationCreated(aServiceInformation);
                }

                @Override
                public void onSMPServiceInformationDeleted(@Nonnull final ISMPServiceInformation aServiceInformation) {
                    onSMPServiceInformationCreated(aServiceInformation);
                }
            });
        }
    }
    {
        LOGGER.info("Init of HTTP and Proxy settings");
        // Register global proxy servers
        ProxySelectorProxySettingsManager.setAsDefault(true);
        final IProxySettings aProxyHttp = SMPServerConfiguration.getAsHttpProxySettings();
        if (aProxyHttp != null) {
            // Register a handler that returns the "http" proxy, if an "http" URL is
            // requested
            ProxySettingsManager.registerProvider((sProtocol, sHost, nPort) -> "http".equals(sProtocol) ? new CommonsArrayList<>(aProxyHttp) : null);
        }
        final IProxySettings aProxyHttps = SMPServerConfiguration.getAsHttpsProxySettings();
        if (aProxyHttps != null) {
            // Register a handler that returns the "https" proxy, if an "https" URL
            // is
            // requested
            ProxySettingsManager.registerProvider((sProtocol, sHost, nPort) -> "https".equals(sProtocol) ? new CommonsArrayList<>(aProxyHttps) : null);
        }
    }
    // Special http client config
    BasePageUtilsHttpClient.HttpClientConfigRegistry.register(new HttpClientConfig("directoryclient", "Directory client settings", PDHttpClientSettings::new));
    LOGGER.info("Finished init of managers");
}
Also used : CSMPServer(com.helger.phoss.smp.CSMPServer) PDClientProvider(com.helger.phoss.smp.app.PDClientProvider) PDTConfig(com.helger.commons.datetime.PDTConfig) ILocaleManager(com.helger.photon.core.locale.ILocaleManager) ProxySelectorProxySettingsManager(com.helger.network.proxy.ProxySelectorProxySettingsManager) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) LoggerFactory(org.slf4j.LoggerFactory) PDClientConfiguration(com.helger.pd.client.PDClientConfiguration) SLF4JBridgeHandler(org.slf4j.bridge.SLF4JBridgeHandler) CApplicationID(com.helger.photon.core.appid.CApplicationID) PDTFactory(com.helger.commons.datetime.PDTFactory) SMPCommonUI(com.helger.phoss.smp.ui.SMPCommonUI) UnifiedResponseDefaultSettings(com.helger.servlet.response.UnifiedResponseDefaultSettings) TimeZone(java.util.TimeZone) ConfigurationFile(com.helger.photon.core.configfile.ConfigurationFile) IReadableResource(com.helger.commons.io.resource.IReadableResource) OffsetDateTime(java.time.OffsetDateTime) IProxySettings(com.helger.network.proxy.settings.IProxySettings) InitializationException(com.helger.commons.exception.InitializationException) IAjaxRegistry(com.helger.photon.ajax.IAjaxRegistry) RegExHelper(com.helger.commons.regex.RegExHelper) RequestTrackerSettings(com.helger.xservlet.requesttrack.RequestTrackerSettings) SMPWebAppConfiguration(com.helger.phoss.smp.app.SMPWebAppConfiguration) WSHelper(com.helger.wsclient.WSHelper) ProxySettingsManager(com.helger.network.proxy.settings.ProxySettingsManager) ServletContextPathHolder(com.helger.servlet.ServletContextPathHolder) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) MenuPublic(com.helger.phoss.smp.ui.pub.MenuPublic) PhotonGlobalState(com.helger.photon.core.appid.PhotonGlobalState) SMPSecurity(com.helger.phoss.smp.app.SMPSecurity) RequestParameterManager(com.helger.photon.core.requestparam.RequestParameterManager) WebAppListenerBootstrap(com.helger.photon.bootstrap4.servlet.WebAppListenerBootstrap) IPrivilegedAction(com.helger.commons.lang.priviledged.IPrivilegedAction) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) GlobalDebug(com.helger.commons.debug.GlobalDebug) Nonnull(javax.annotation.Nonnull) ConfigurationFileManager(com.helger.photon.core.configfile.ConfigurationFileManager) Nullable(javax.annotation.Nullable) ArrayHelper(com.helger.commons.collection.ArrayHelper) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) BasePageUtilsHttpClient(com.helger.photon.bootstrap4.pages.utils.BasePageUtilsHttpClient) StringHelper(com.helger.commons.string.StringHelper) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) MenuSecure(com.helger.phoss.smp.ui.secure.MenuSecure) RequestParameterHandlerURLPathNamed(com.helger.photon.core.requestparam.RequestParameterHandlerURLPathNamed) CAjax(com.helger.phoss.smp.ui.ajax.CAjax) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) PDHttpClientSettings(com.helger.pd.client.PDHttpClientSettings) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) SMPServerConfiguration(com.helger.phoss.smp.SMPServerConfiguration) ISMPBusinessCardCallback(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardCallback) HttpClientConfig(com.helger.photon.bootstrap4.pages.utils.BasePageUtilsHttpClient.HttpClientConfig) ServletContext(javax.servlet.ServletContext) EConfigurationFileSyntax(com.helger.photon.core.configfile.EConfigurationFileSyntax) MenuTree(com.helger.photon.core.menu.MenuTree) ISMPBusinessCardCallback(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardCallback) HttpClientConfig(com.helger.photon.bootstrap4.pages.utils.BasePageUtilsHttpClient.HttpClientConfig) ConfigurationFileManager(com.helger.photon.core.configfile.ConfigurationFileManager) Nonnull(javax.annotation.Nonnull) IReadableResource(com.helger.commons.io.resource.IReadableResource) ISMPServiceInformationCallback(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationCallback) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) ISMPBusinessCard(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCard) IProxySettings(com.helger.network.proxy.settings.IProxySettings) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) ISMPSettings(com.helger.phoss.smp.settings.ISMPSettings) ConfigurationFile(com.helger.photon.core.configfile.ConfigurationFile)

Aggregations

IProxySettings (com.helger.network.proxy.settings.IProxySettings)5 ProxySettings (com.helger.network.proxy.settings.ProxySettings)3 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)2 IReadableResource (com.helger.commons.io.resource.IReadableResource)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 ArrayHelper (com.helger.commons.collection.ArrayHelper)1 PDTConfig (com.helger.commons.datetime.PDTConfig)1 PDTFactory (com.helger.commons.datetime.PDTFactory)1 GlobalDebug (com.helger.commons.debug.GlobalDebug)1 InitializationException (com.helger.commons.exception.InitializationException)1 IPrivilegedAction (com.helger.commons.lang.priviledged.IPrivilegedAction)1 RegExHelper (com.helger.commons.regex.RegExHelper)1 StringHelper (com.helger.commons.string.StringHelper)1 ProxySelectorProxySettingsManager (com.helger.network.proxy.ProxySelectorProxySettingsManager)1 ProxySettingsManager (com.helger.network.proxy.settings.ProxySettingsManager)1 PDClientConfiguration (com.helger.pd.client.PDClientConfiguration)1 PDHttpClientSettings (com.helger.pd.client.PDHttpClientSettings)1 CSMPServer (com.helger.phoss.smp.CSMPServer)1