List of usage examples for org.apache.commons.httpclient.contrib.ssl EasySSLProtocolSocketFactory EasySSLProtocolSocketFactory
public EasySSLProtocolSocketFactory()
From source file:org.helios.collector.url.URLCollector.java
/** * This method does the following:/*from w ww .j a v a2 s . co m*/ * 1. Creates a new and unique protocol for each SSL URL that is secured by client certificate * 2. Bind keyStore related information to this protocol * 3. Registers it with HTTP Protocol object * 4. Stores the local reference for this custom protocol for use during furture collect calls * * @throws Exception */ public void registerProtocolCertificate() throws Exception { EasySSLProtocolSocketFactory easySSLPSFactory = new EasySSLProtocolSocketFactory(); easySSLPSFactory.setKeyMaterial(createKeyMaterial()); myProtocolPrefix = (HTTPS_PROTOCOL + uniqueCounter.incrementAndGet()); Protocol httpsProtocol = new Protocol(myProtocolPrefix, (ProtocolSocketFactory) easySSLPSFactory, port); Protocol.registerProtocol(myProtocolPrefix, httpsProtocol); trace("Protocol [ " + myProtocolPrefix + " ] registered for the first time"); }
From source file:org.jaggeryjs2.xhr.XMLHttpRequest.java
public XMLHttpRequest() { try {// www . j a v a 2 s. c om // To ignore the hostname verification in http client side when org.wso2.ignoreHostnameVerification is set // This system variable should not be set in product environment due to security reasons String ignoreHostnameVerification = System.getProperty("org.wso2.ignoreHostnameVerification"); if (ignoreHostnameVerification != null && "true".equalsIgnoreCase(ignoreHostnameVerification)) { Protocol protocolWithoutHostNameVerification = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), HTTPS_DEFAULT_PORT); Protocol.registerProtocol("https", protocolWithoutHostNameVerification); } httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); ProxyHost proxyConfig = getProxyConfig(); if (proxyConfig != null) { httpClient.getHostConfiguration().setProxyHost(proxyConfig); } } catch (IOException e) { log.error(e); } catch (GeneralSecurityException e) { log.error(e); } xhr = new XMLHttpRequest(httpClient); }
From source file:org.kalypso.commons.net.SSLUtilities.java
/** * This function will register the https protocol, which will accept all certificates.<br> * This setting will apply, as long as your application is running. *///w ww. jav a 2 s. co m public static void acceptSelfSignedCertificatesSSL() { final ProtocolSocketFactory easyfactory = new EasySSLProtocolSocketFactory(); final Protocol easyhttps = new Protocol("https", easyfactory, 443); //$NON-NLS-1$ Protocol.registerProtocol("https", easyhttps); //$NON-NLS-1$ }
From source file:org.kuali.rice.ksb.messaging.config.KSBConfigurer.java
@Override public List<Lifecycle> loadLifecycles() throws Exception { List<Lifecycle> lifecycles = new LinkedList<Lifecycle>(); // this validation of our service list needs to happen after we've // loaded our configs so it's a lifecycle lifecycles.add(new BaseLifecycle() { @Override//from w ww. j ava 2 s. c o m public void start() throws Exception { // first check if we want to allow self-signed certificates for SSL communication if (Boolean.valueOf(ConfigContext.getCurrentContextConfig() .getProperty(KSBConstants.Config.KSB_ALLOW_SELF_SIGNED_SSL)).booleanValue()) { Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443)); } super.start(); } }); return lifecycles; }
From source file:org.na.WebHelper.java
public WebHelper() throws GeneralSecurityException, IOException { Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", easyhttps); httpClient = new HttpClient(); }
From source file:org.openmrs.module.sync.server.ServerConnection.java
public static ConnectionResponse sendExportedData(String url, String username, String password, String content, boolean isResponse) { // Default response - default constructor instantiates contains error codes ConnectionResponse syncResponse = new ConnectionResponse(); HttpClient client = new HttpClient(); url = url + SyncConstants.DATA_IMPORT_SERVLET; log.info("POST multipart request to " + url); if (url.startsWith("https")) { try {/* w w w . j a v a2 s . c om*/ if (Boolean.parseBoolean(Context.getAdministrationService() .getGlobalProperty(SyncConstants.PROPERTY_ALLOW_SELFSIGNED_CERTS))) { // It is necessary to provide a relative url (from the host name and port to the right) String relativeUrl; URI uri = new URI(url, true); String host = uri.getHost(); int port = uri.getPort(); // URI.getPort() returns -1 if port is not explicitly set if (port <= 0) { port = SyncConstants.DEFAULT_HTTPS_PORT; relativeUrl = url.split(host, 2)[1]; } else { relativeUrl = url.split(host + ":" + port, 2)[1]; } Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), port); client.getHostConfiguration().setHost(host, port, easyhttps); url = relativeUrl; } } catch (IOException ioe) { log.error("Unable to configure SSL to accept self-signed certificates"); } catch (GeneralSecurityException e) { log.error("Unable to configure SSL to accept self-signed certificates"); } } PostMethod method = new PostMethod(url); try { boolean useCompression = Boolean.parseBoolean(Context.getAdministrationService() .getGlobalProperty(SyncConstants.PROPERTY_ENABLE_COMPRESSION, "true")); log.info("use compression: " + useCompression); // Compress content ConnectionRequest request = new ConnectionRequest(content, useCompression); // Create up multipart request Part[] parts = { new FilePart("syncDataFile", new ByteArrayPartSource("syncDataFile", request.getBytes())), new StringPart("username", username), new StringPart("password", password), new StringPart("compressed", String.valueOf(useCompression)), new StringPart("isResponse", String.valueOf(isResponse)), new StringPart("checksum", String.valueOf(request.getChecksum())) }; method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); // Open a connection to the server and post the data client.getHttpConnectionManager().getParams().setSoTimeout(ServerConnection.getTimeout().intValue()); client.getHttpConnectionManager().getParams() .setConnectionTimeout(ServerConnection.getTimeout().intValue()); int status = client.executeMethod(method); // As long as the response is OK (200) if (status == HttpStatus.SC_OK) { // Decompress the response from the server //log.info("Response from server:" + method.getResponseBodyAsString()); // Check to see if the child/parent sent back a compressed response Header compressionHeader = method.getResponseHeader("Enable-Compression"); useCompression = (compressionHeader != null) ? new Boolean(compressionHeader.getValue()) : false; log.info("Response header Enable-Compression: " + useCompression); // Decompress the data received (if compression is enabled) syncResponse = new ConnectionResponse(method.getResponseBodyAsStream(), useCompression); // Now we want to validate the checksum Header checksumHeader = method.getResponseHeader("Content-Checksum"); long checksumReceived = (checksumHeader != null) ? new Long(checksumHeader.getValue()) : 0; log.info("Response header Content-Checksum: " + checksumReceived); log.info("checksum value received in response header: " + checksumReceived); log.info("checksum of payload: " + syncResponse.getChecksum()); // TODO Need to figure out what to do with this response if (checksumReceived > 0 && (checksumReceived != syncResponse.getChecksum())) { log.error("ERROR: FAILED CHECKSUM!"); syncResponse.setState(ServerConnectionState.CONNECTION_FAILED); // contains error message } } // if there's an error response code we should set the tran else { // HTTP error response code syncResponse .setResponsePayload("HTTP " + status + " Error Code: " + method.getResponseBodyAsString()); syncResponse.setState(ServerConnectionState.CONNECTION_FAILED); // contains error message } } catch (MalformedURLException mue) { log.error("Malformed URL " + url, mue); syncResponse.setState(ServerConnectionState.MALFORMED_URL); } catch (Exception e) { // all other exceptions really just mean that the connection was bad log.error("Error occurred while sending/receiving data ", e); syncResponse.setState(ServerConnectionState.CONNECTION_FAILED); } finally { method.releaseConnection(); } return syncResponse; }
From source file:org.sipfoundry.openfire.ws.WebSocketPlugin.java
public void trustAllCerts() { ProtocolSocketFactory sf;//from w w w .jav a 2s. c o m try { sf = new EasySSLProtocolSocketFactory(); Protocol p = new Protocol("https", sf, 443); Protocol.registerProtocol("https", p); } catch (GeneralSecurityException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.switchyard.quickstarts.demo.policy.security.basic.WorkServiceMain.java
public static void main(String... args) throws Exception { Set<String> policies = new HashSet<String>(); for (String arg : args) { arg = Strings.trimToNull(arg);/*from ww w. ja va 2 s . co m*/ if (arg != null) { if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) { policies.add(arg); } else { LOGGER.error(MAVEN_USAGE); throw new Exception(MAVEN_USAGE); } } } if (policies.contains(HELP)) { LOGGER.info(MAVEN_USAGE); } else { final String scheme; final int port; if (policies.contains(CONFIDENTIALITY)) { scheme = "https"; port = 8443; Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) (new EasySSLProtocolSocketFactory()), port)); } else { scheme = "http"; port = 8080; } String[] userPass = policies.contains(CLIENT_AUTHENTICATION) ? new String[] { "kermit", "thefrog" } : null; invokeWorkService(scheme, port, userPass); } }
From source file:org.switchyard.quickstarts.demo.policy.security.cert.WorkServiceMain.java
public static void main(String... args) throws Exception { Set<String> policies = new HashSet<String>(); for (String arg : args) { arg = Strings.trimToNull(arg);/* ww w.j a va 2s . c o m*/ if (arg != null) { if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) { policies.add(arg); } else { LOGGER.error(MAVEN_USAGE); throw new Exception(MAVEN_USAGE); } } } if (policies.contains(HELP)) { LOGGER.info(MAVEN_USAGE); } else { final String scheme; final int port; if (policies.contains(CONFIDENTIALITY)) { scheme = "https"; port = 8443; Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) (new EasySSLProtocolSocketFactory()), port)); } else { scheme = "http"; port = 8080; } String binarySecurityToken = policies.contains(CLIENT_AUTHENTICATION) ? new StringPuller().pull("/xml/BinarySecurityToken.xml") : null; invokeWorkService(scheme, port, binarySecurityToken); } }
From source file:org.switchyard.quickstarts.demo.policy.security.saml.WorkServiceMain.java
public static void main(String... args) throws Exception { Set<String> policies = new HashSet<String>(); for (String arg : args) { arg = Strings.trimToNull(arg);//from w ww . jav a 2s .c o m if (arg != null) { if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) { policies.add(arg); } else { LOGGER.error(MAVEN_USAGE); throw new Exception(MAVEN_USAGE); } } } if (policies.contains(HELP)) { LOGGER.info(MAVEN_USAGE); } else { final String scheme; final int port; if (policies.contains(CONFIDENTIALITY)) { scheme = "https"; port = 8443; Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) (new EasySSLProtocolSocketFactory()), port)); } else { scheme = "http"; port = 8080; } Element assertion = policies.contains(CLIENT_AUTHENTICATION) ? getAssertion() : null; invokeWorkService(scheme, port, assertion); } }