List of usage examples for java.net URI getUserInfo
public String getUserInfo()
From source file:com.cloud.hypervisor.vmware.mo.HypervisorHostHelper.java
public static String resolveHostNameInUrl(DatacenterMO dcMo, String url) { s_logger.info("Resolving host name in url through vCenter, url: " + url); URI uri; try {/* w w w . j a v a2s. com*/ uri = new URI(url); } catch (URISyntaxException e) { s_logger.warn("URISyntaxException on url " + url); return url; } String host = uri.getHost(); if (NetUtils.isValidIp(host)) { s_logger.info("host name in url is already in IP address, url: " + url); return url; } try { ManagedObjectReference morHost = dcMo.findHost(host); if (morHost != null) { HostMO hostMo = new HostMO(dcMo.getContext(), morHost); String managementPortGroupName; if (hostMo.getHostType() == VmwareHostType.ESXi) managementPortGroupName = (String) dcMo.getContext().getStockObject("manageportgroup"); else managementPortGroupName = (String) dcMo.getContext().getStockObject("serviceconsole"); VmwareHypervisorHostNetworkSummary summary = hostMo .getHyperHostNetworkSummary(managementPortGroupName); if (summary == null) { s_logger.warn("Unable to resolve host name in url through vSphere, url: " + url); return url; } String hostIp = summary.getHostIp(); try { URI resolvedUri = new URI(uri.getScheme(), uri.getUserInfo(), hostIp, uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); s_logger.info("url " + url + " is resolved to " + resolvedUri.toString() + " through vCenter"); return resolvedUri.toString(); } catch (URISyntaxException e) { assert (false); return url; } } } catch (Exception e) { s_logger.warn("Unexpected exception ", e); } return url; }
From source file:com.fsck.k9.mail.store.webdav.WebDavStore.java
/** * Decodes a WebDavStore URI.//w ww. j av a2 s . c om * * <p>Possible forms:</p> * <pre> * webdav://user:password@server:port ConnectionSecurity.NONE * webdav+ssl+://user:password@server:port ConnectionSecurity.SSL_TLS_REQUIRED * </pre> */ public static WebDavStoreSettings decodeUri(String uri) { String host; int port; ConnectionSecurity connectionSecurity; String username = null; String password = null; String alias = null; String path = null; String authPath = null; String mailboxPath = null; URI webDavUri; try { webDavUri = new URI(uri); } catch (URISyntaxException use) { throw new IllegalArgumentException("Invalid WebDavStore URI", use); } String scheme = webDavUri.getScheme(); /* * Currently available schemes are: * webdav * webdav+ssl+ * * The following are obsolete schemes that may be found in pre-existing * settings from earlier versions or that may be found when imported. We * continue to recognize them and re-map them appropriately: * webdav+tls * webdav+tls+ * webdav+ssl */ if (scheme.equals("webdav")) { connectionSecurity = ConnectionSecurity.NONE; } else if (scheme.startsWith("webdav+")) { connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED; } else { throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")"); } host = webDavUri.getHost(); if (host.startsWith("http")) { String[] hostParts = host.split("://", 2); if (hostParts.length > 1) { host = hostParts[1]; } } port = webDavUri.getPort(); String userInfo = webDavUri.getUserInfo(); if (userInfo != null) { String[] userInfoParts = userInfo.split(":"); username = decodeUtf8(userInfoParts[0]); String userParts[] = username.split("\\\\", 2); if (userParts.length > 1) { alias = userParts[1]; } else { alias = username; } if (userInfoParts.length > 1) { password = decodeUtf8(userInfoParts[1]); } } String[] pathParts = webDavUri.getPath().split("\\|"); for (int i = 0, count = pathParts.length; i < count; i++) { if (i == 0) { if (pathParts[0] != null && pathParts[0].length() > 1) { path = pathParts[0]; } } else if (i == 1) { if (pathParts[1] != null && pathParts[1].length() > 1) { authPath = pathParts[1]; } } else if (i == 2) { if (pathParts[2] != null && pathParts[2].length() > 1) { mailboxPath = pathParts[2]; } } } return new WebDavStoreSettings(host, port, connectionSecurity, null, username, password, null, alias, path, authPath, mailboxPath); }
From source file:com.c0124.k9.mail.store.WebDavStore.java
/** * Decodes a WebDavStore URI.//from w w w . j a v a 2 s. c o m * * <p>Possible forms:</p> * <pre> * webdav://user:password@server:port CONNECTION_SECURITY_NONE * webdav+tls://user:password@server:port CONNECTION_SECURITY_TLS_OPTIONAL * webdav+tls+://user:password@server:port CONNECTION_SECURITY_TLS_REQUIRED * webdav+ssl+://user:password@server:port CONNECTION_SECURITY_SSL_REQUIRED * webdav+ssl://user:password@server:port CONNECTION_SECURITY_SSL_OPTIONAL * </pre> */ public static WebDavStoreSettings decodeUri(String uri) { String host; int port; ConnectionSecurity connectionSecurity; String username = null; String password = null; String alias = null; String path = null; String authPath = null; String mailboxPath = null; URI webDavUri; try { webDavUri = new URI(uri); } catch (URISyntaxException use) { throw new IllegalArgumentException("Invalid WebDavStore URI", use); } String scheme = webDavUri.getScheme(); if (scheme.equals("webdav")) { connectionSecurity = ConnectionSecurity.NONE; } else if (scheme.equals("webdav+ssl")) { connectionSecurity = ConnectionSecurity.SSL_TLS_OPTIONAL; } else if (scheme.equals("webdav+ssl+")) { connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED; } else if (scheme.equals("webdav+tls")) { connectionSecurity = ConnectionSecurity.STARTTLS_OPTIONAL; } else if (scheme.equals("webdav+tls+")) { connectionSecurity = ConnectionSecurity.STARTTLS_REQUIRED; } else { throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")"); } host = webDavUri.getHost(); if (host.startsWith("http")) { String[] hostParts = host.split("://", 2); if (hostParts.length > 1) { host = hostParts[1]; } } port = webDavUri.getPort(); String userInfo = webDavUri.getUserInfo(); if (userInfo != null) { try { String[] userInfoParts = userInfo.split(":"); username = URLDecoder.decode(userInfoParts[0], "UTF-8"); String userParts[] = username.split("\\\\", 2); if (userParts.length > 1) { alias = userParts[1]; } else { alias = username; } if (userInfoParts.length > 1) { password = URLDecoder.decode(userInfoParts[1], "UTF-8"); } } catch (UnsupportedEncodingException enc) { // This shouldn't happen since the encoding is hardcoded to UTF-8 throw new IllegalArgumentException("Couldn't urldecode username or password.", enc); } } String[] pathParts = webDavUri.getPath().split("\\|"); for (int i = 0, count = pathParts.length; i < count; i++) { if (i == 0) { if (pathParts[0] != null && pathParts[0].length() > 1) { path = pathParts[0]; } } else if (i == 1) { if (pathParts[1] != null && pathParts[1].length() > 1) { authPath = pathParts[1]; } } else if (i == 2) { if (pathParts[2] != null && pathParts[2].length() > 1) { mailboxPath = pathParts[2]; } } } return new WebDavStoreSettings(host, port, connectionSecurity, null, username, password, alias, path, authPath, mailboxPath); }
From source file:br.pcfl.up.mail.store.WebDavStore.java
/** * Decodes a WebDavStore URI.// w w w .ja v a2 s .com * * <p>Possible forms:</p> * <pre> * webdav://user:password@server:port ConnectionSecurity.NONE * webdav+ssl+://user:password@server:port ConnectionSecurity.SSL_TLS_REQUIRED * </pre> */ public static WebDavStoreSettings decodeUri(String uri) { String host; int port; ConnectionSecurity connectionSecurity; String username = null; String password = null; String alias = null; String path = null; String authPath = null; String mailboxPath = null; URI webDavUri; try { webDavUri = new URI(uri); } catch (URISyntaxException use) { throw new IllegalArgumentException("Invalid WebDavStore URI", use); } String scheme = webDavUri.getScheme(); /* * Currently available schemes are: * webdav * webdav+ssl+ * * The following are obsolete schemes that may be found in pre-existing * settings from earlier versions or that may be found when imported. We * continue to recognize them and re-map them appropriately: * webdav+tls * webdav+tls+ * webdav+ssl */ if (scheme.equals("webdav")) { connectionSecurity = ConnectionSecurity.NONE; } else if (scheme.startsWith("webdav+")) { connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED; } else { throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")"); } host = webDavUri.getHost(); if (host.startsWith("http")) { String[] hostParts = host.split("://", 2); if (hostParts.length > 1) { host = hostParts[1]; } } port = webDavUri.getPort(); String userInfo = webDavUri.getUserInfo(); if (userInfo != null) { try { String[] userInfoParts = userInfo.split(":"); username = URLDecoder.decode(userInfoParts[0], "UTF-8"); String userParts[] = username.split("\\\\", 2); if (userParts.length > 1) { alias = userParts[1]; } else { alias = username; } if (userInfoParts.length > 1) { password = URLDecoder.decode(userInfoParts[1], "UTF-8"); } } catch (UnsupportedEncodingException enc) { // This shouldn't happen since the encoding is hardcoded to UTF-8 throw new IllegalArgumentException("Couldn't urldecode username or password.", enc); } } String[] pathParts = webDavUri.getPath().split("\\|"); for (int i = 0, count = pathParts.length; i < count; i++) { if (i == 0) { if (pathParts[0] != null && pathParts[0].length() > 1) { path = pathParts[0]; } } else if (i == 1) { if (pathParts[1] != null && pathParts[1].length() > 1) { authPath = pathParts[1]; } } else if (i == 2) { if (pathParts[2] != null && pathParts[2].length() > 1) { mailboxPath = pathParts[2]; } } } return new WebDavStoreSettings(host, port, connectionSecurity, null, username, password, alias, path, authPath, mailboxPath); }
From source file:com.bernard.beaconportal.activities.mail.store.WebDavStore.java
/** * Decodes a WebDavStore URI./*from w w w . jav a 2s .c om*/ * * <p> * Possible forms: * </p> * * <pre> * webdav://user:password@server:port ConnectionSecurity.NONE * webdav+ssl+://user:password@server:port ConnectionSecurity.SSL_TLS_REQUIRED * </pre> */ public static WebDavStoreSettings decodeUri(String uri) { String host; int port; ConnectionSecurity connectionSecurity; String username = null; String password = null; String alias = null; String path = null; String authPath = null; String mailboxPath = null; URI webDavUri; try { webDavUri = new URI(uri); } catch (URISyntaxException use) { throw new IllegalArgumentException("Invalid WebDavStore URI", use); } String scheme = webDavUri.getScheme(); /* * Currently available schemes are: webdav webdav+ssl+ * * The following are obsolete schemes that may be found in pre-existing * settings from earlier versions or that may be found when imported. We * continue to recognize them and re-map them appropriately: webdav+tls * webdav+tls+ webdav+ssl */ if (scheme.equals("webdav")) { connectionSecurity = ConnectionSecurity.NONE; } else if (scheme.startsWith("webdav+")) { connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED; } else { throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")"); } host = webDavUri.getHost(); if (host.startsWith("http")) { String[] hostParts = host.split("://", 2); if (hostParts.length > 1) { host = hostParts[1]; } } port = webDavUri.getPort(); String userInfo = webDavUri.getUserInfo(); if (userInfo != null) { try { String[] userInfoParts = userInfo.split(":"); username = URLDecoder.decode(userInfoParts[0], "UTF-8"); String userParts[] = username.split("\\\\", 2); if (userParts.length > 1) { alias = userParts[1]; } else { alias = username; } if (userInfoParts.length > 1) { password = URLDecoder.decode(userInfoParts[1], "UTF-8"); } } catch (UnsupportedEncodingException enc) { // This shouldn't happen since the encoding is hardcoded to // UTF-8 throw new IllegalArgumentException("Couldn't urldecode username or password.", enc); } } String[] pathParts = webDavUri.getPath().split("\\|"); for (int i = 0, count = pathParts.length; i < count; i++) { if (i == 0) { if (pathParts[0] != null && pathParts[0].length() > 1) { path = pathParts[0]; } } else if (i == 1) { if (pathParts[1] != null && pathParts[1].length() > 1) { authPath = pathParts[1]; } } else if (i == 2) { if (pathParts[2] != null && pathParts[2].length() > 1) { mailboxPath = pathParts[2]; } } } return new WebDavStoreSettings(host, port, connectionSecurity, null, username, password, alias, path, authPath, mailboxPath); }
From source file:cn.mailchat.mail.store.WebDavStore.java
/** * Decodes a WebDavStore URI.//from w w w .j a v a2 s . co m * * <p>Possible forms:</p> * <pre> * webdav://user:password@server:port ConnectionSecurity.NONE * webdav+ssl+://user:password@server:port ConnectionSecurity.SSL_TLS_REQUIRED * </pre> */ public static WebDavStoreSettings decodeUri(String uri) { String host; int port; ConnectionSecurity connectionSecurity; String username = null; String password = null; String alias = null; String path = null; String authPath = null; String mailboxPath = null; URI webDavUri; try { webDavUri = new URI(uri); } catch (URISyntaxException use) { throw new IllegalArgumentException("Invalid WebDavStore URI", use); } String scheme = webDavUri.getScheme(); /* * Currently available schemes are: * webdav * webdav+ssl+ * * The following are obsolete schemes that may be found in pre-existing * settings from earlier versions or that may be found when imported. We * continue to recognize them and re-map them appropriately: * webdav+tls * webdav+tls+ * webdav+ssl */ if (scheme.equals("webdav")) { connectionSecurity = ConnectionSecurity.NONE; } else if (scheme.startsWith("webdav+")) { connectionSecurity = ConnectionSecurity.SSL_TLS_REQUIRED; } else { throw new IllegalArgumentException("Unsupported protocol (" + scheme + ")"); } host = webDavUri.getHost(); if (host.startsWith("http")) { String[] hostParts = host.split("://", 2); if (hostParts.length > 1) { host = hostParts[1]; } } port = webDavUri.getPort(); String userInfo = webDavUri.getUserInfo(); if (userInfo != null) { try { String[] userInfoParts = userInfo.split(":"); username = URLDecoder.decode(userInfoParts[0], "UTF-8"); String userParts[] = username.split("\\\\", 2); if (userParts.length > 1) { alias = userParts[1]; } else { alias = username; } if (userInfoParts.length > 1) { password = URLDecoder.decode(userInfoParts[1], "UTF-8"); } } catch (UnsupportedEncodingException enc) { // This shouldn't happen since the encoding is hardcoded to UTF-8 throw new IllegalArgumentException("Couldn't urldecode username or password.", enc); } } String[] pathParts = webDavUri.getPath().split("\\|"); for (int i = 0, count = pathParts.length; i < count; i++) { if (i == 0) { if (pathParts[0] != null && pathParts[0].length() > 1) { path = pathParts[0]; } } else if (i == 1) { if (pathParts[1] != null && pathParts[1].length() > 1) { authPath = pathParts[1]; } } else if (i == 2) { if (pathParts[2] != null && pathParts[2].length() > 1) { mailboxPath = pathParts[2]; } } } return new WebDavStoreSettings(host, port, connectionSecurity, null, username, password, null, alias, path, authPath, mailboxPath); }
From source file:org.apache.nifi.web.api.ApplicationResource.java
/** * Generate a resource uri based off of the specified parameters. * * @param path path//from ww w . ja va2s. co m * @return resource uri */ protected String generateResourceUri(final String... path) { final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder(); uriBuilder.segment(path); URI uri = uriBuilder.build(); try { // check for proxy settings final String scheme = httpServletRequest.getHeader(PROXY_SCHEME_HTTP_HEADER); final String host = httpServletRequest.getHeader(PROXY_HOST_HTTP_HEADER); final String port = httpServletRequest.getHeader(PROXY_PORT_HTTP_HEADER); String baseContextPath = httpServletRequest.getHeader(PROXY_CONTEXT_PATH_HTTP_HEADER); // if necessary, prepend the context path String resourcePath = uri.getPath(); if (baseContextPath != null) { // normalize context path if (!baseContextPath.startsWith("/")) { baseContextPath = "/" + baseContextPath; } // determine the complete resource path resourcePath = baseContextPath + resourcePath; } // determine the port uri int uriPort = uri.getPort(); if (port != null) { if (StringUtils.isWhitespace(port)) { uriPort = -1; } else { try { uriPort = Integer.parseInt(port); } catch (final NumberFormatException nfe) { logger.warn(String.format( "Unable to parse proxy port HTTP header '%s'. Using port from request URI '%s'.", port, uriPort)); } } } // construct the URI uri = new URI((StringUtils.isBlank(scheme)) ? uri.getScheme() : scheme, uri.getUserInfo(), (StringUtils.isBlank(host)) ? uri.getHost() : host, uriPort, resourcePath, uri.getQuery(), uri.getFragment()); } catch (final URISyntaxException use) { throw new UriBuilderException(use); } return uri.toString(); }
From source file:com.emc.atmos.api.test.AtmosApiClientTest.java
@Test public void testDisableSslValidation() throws Exception { Assume.assumeFalse(isVipr);//from ww w .jav a 2 s .com config.setDisableSslValidation(true); api = new AtmosApiClient(config); List<URI> sslUris = new ArrayList<URI>(); for (URI uri : config.getEndpoints()) { sslUris.add(new URI("https", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment())); } config.setEndpoints(sslUris.toArray(new URI[sslUris.size()])); cleanup.add(api.createObject("Hello SSL!", null)); }
From source file:com.buaa.cfs.fs.FileSystem.java
/** * Canonicalize the given URI./*from w w w.j a va 2s .c om*/ * <p> * This is filesystem-dependent, but may for example consist of canonicalizing the hostname using DNS and adding the * default port if not specified. * <p> * The default implementation simply fills in the default port if not specified and if the filesystem has a default * port. * * @return URI */ protected URI canonicalizeUri(URI uri) { if (uri.getPort() == -1 && getDefaultPort() > 0) { // reconstruct the uri with the default port set try { uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), getDefaultPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { // Should never happen! throw new AssertionError("Valid URI became unparseable: " + uri); } } return uri; }
From source file:jp.co.fttx.rakuphotomail.mail.store.WebDavStore.java
/** * Performs form-based authentication.// w ww.ja v a 2 s. com * * @throws MessagingException */ public void doFBA(ConnectionInfo info) throws IOException, MessagingException { // Clear out cookies from any previous authentication. mAuthCookies.clear(); WebDavHttpClient httpClient = getHttpClient(); String loginUrl; if (info != null) { loginUrl = info.guessedAuthUrl; } else if (mCachedLoginUrl != null && !mCachedLoginUrl.equals("")) { loginUrl = mCachedLoginUrl; } else { throw new MessagingException("No valid login URL available for form-based authentication."); } HttpGeneric request = new HttpGeneric(loginUrl); request.setMethod("POST"); // Build the POST data. ArrayList<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>(); pairs.add(new BasicNameValuePair("destination", mUrl)); pairs.add(new BasicNameValuePair("username", mUsername)); pairs.add(new BasicNameValuePair("password", mPassword)); pairs.add(new BasicNameValuePair("flags", "0")); pairs.add(new BasicNameValuePair("SubmitCreds", "Log+On")); pairs.add(new BasicNameValuePair("forcedownlevel", "0")); pairs.add(new BasicNameValuePair("trusted", "0")); UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(pairs); request.setEntity(formEntity); HttpResponse response = httpClient.executeOverride(request, mContext); boolean authenticated = testAuthenticationResponse(response); if (!authenticated) { // Check the response from the authentication request above for a form action. String formAction = findFormAction(WebDavHttpClient.getUngzippedContent(response.getEntity())); if (formAction == null) { // If there is no form action, try using our redirect URL from the initial connection. if (info != null && info.redirectUrl != null && !info.redirectUrl.equals("")) { loginUrl = info.redirectUrl; request = new HttpGeneric(loginUrl); request.setMethod("GET"); response = httpClient.executeOverride(request, mContext); formAction = findFormAction(WebDavHttpClient.getUngzippedContent(response.getEntity())); } } if (formAction != null) { try { URI formActionUri = new URI(formAction); URI loginUri = new URI(loginUrl); if (formActionUri.isAbsolute()) { // The form action is an absolute URL, just use it. loginUrl = formAction; } else { // Append the form action to our current URL, minus the file name. String urlPath; if (formAction.startsWith("/")) { urlPath = formAction; } else { urlPath = loginUri.getPath(); int lastPathPos = urlPath.lastIndexOf('/'); if (lastPathPos > -1) { urlPath = urlPath.substring(0, lastPathPos + 1); urlPath = urlPath.concat(formAction); } } // Reconstruct the login URL based on the original login URL and the form action. URI finalUri = new URI(loginUri.getScheme(), loginUri.getUserInfo(), loginUri.getHost(), loginUri.getPort(), urlPath, null, null); loginUrl = finalUri.toString(); } // Retry the login using our new URL. request = new HttpGeneric(loginUrl); request.setMethod("POST"); request.setEntity(formEntity); response = httpClient.executeOverride(request, mContext); authenticated = testAuthenticationResponse(response); } catch (URISyntaxException e) { Log.e(RakuPhotoMail.LOG_TAG, "URISyntaxException caught " + e + "\nTrace: " + processException(e)); throw new MessagingException("URISyntaxException caught", e); } } else { throw new MessagingException("A valid URL for Exchange authentication could not be found."); } } if (authenticated) { mAuthentication = AUTH_TYPE_FORM_BASED; mCachedLoginUrl = loginUrl; } else { throw new MessagingException("Invalid credentials provided for authentication."); } }