Java Code Examples for java.net.URL#getUserInfo()
The following examples show how to use
java.net.URL#getUserInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FtpURLConnection.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(checkURL(url)); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example 2
Source File: RandomisedUrlService.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Encodes a full URL. * * @param rawUrl the URL to encode. */ private String encodeUrl(String rawUrl) { if (StringUtils.isBlank(rawUrl)) { return null; } String encodedUrl = null; try { URL url = new URL(rawUrl); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); encodedUrl = uri.toASCIIString(); } catch (Exception e) { log.warn("encoding url: " + rawUrl + ", " + e.getMessage(), e); } return encodedUrl; }
Example 3
Source File: FtpURLConnection.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(checkURL(url)); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example 4
Source File: FtpURLConnection.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(checkURL(url)); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example 5
Source File: FtpURLConnection.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(url); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example 6
Source File: FtpURLConnection.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(checkURL(url)); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example 7
Source File: WebdavClientImpl.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
public static String getPassword(URL url) throws UnsupportedEncodingException { String userInfo = url.getUserInfo(); if (userInfo != null) { userInfo = URLDecoder.decode(userInfo, UTF_8); int colon = userInfo.indexOf(':'); if (colon == -1) { return ""; } else { return userInfo.substring(colon+1); } } else { return ""; } }
Example 8
Source File: FtpURLConnection.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Same as FtpURLconnection(URL) with a per connection proxy specified */ FtpURLConnection(URL url, Proxy p) { super(checkURL(url)); instProxy = p; host = url.getHost(); port = url.getPort(); String userInfo = url.getUserInfo(); if (userInfo != null) { // get the user and password int delimiter = userInfo.indexOf(':'); if (delimiter == -1) { user = ParseUtil.decode(userInfo); password = null; } else { user = ParseUtil.decode(userInfo.substring(0, delimiter++)); password = ParseUtil.decode(userInfo.substring(delimiter)); } } }
Example 9
Source File: S3Handler.java From konduit-serving with Apache License 2.0 | 5 votes |
protected URLConnection openConnection(URL url) throws IOException { return new URLConnection(url) { @Override public InputStream getInputStream() throws IOException { String accessKey = null; String secretKey = null; if (url.getUserInfo() != null) { String[] credentials = url.getUserInfo().split("[:]"); accessKey = credentials[0]; secretKey = credentials[1]; } String bucket = url.getHost().substring(0, url.getHost().indexOf(".")); String key = url.getPath().substring(1); /*try { RestS3Service s3Service = new RestS3Service(new AWSCredentials(accessKey, secretKey)); S3Object s3obj = s3Service.getObject(bucket, key); return s3obj.getDataInputStream(); } catch (ServiceException e) { throw new IOException(e); }*/ return null; } @Override public void connect() throws IOException { } }; }
Example 10
Source File: ClientBuilder.java From java-cloudant with Apache License 2.0 | 5 votes |
private ClientBuilder(URL url) { logger.config("URL: " + url); String urlProtocol = url.getProtocol(); String urlHost = url.getHost(); //Check if port exists int urlPort = url.getPort(); if (urlPort < 0) { urlPort = url.getDefaultPort(); } if (url.getUserInfo() != null) { //Get username and password and replace credential variables try { this.username = URLDecoder.decode(url.getUserInfo().substring(0, url .getUserInfo() .indexOf(":")), "UTF-8"); this.password = URLDecoder.decode(url.getUserInfo().substring(url .getUserInfo() .indexOf(":") + 1), "UTF-8"); } catch (UnsupportedEncodingException e) { // Should never happen UTF-8 is required in JVM throw new RuntimeException(e); } } // Check if a path exists and sanitize it by removing whitespace and any trailing / String urlPath = url.getPath().trim(); urlPath = urlPath.endsWith("/") ? urlPath.substring(0, urlPath.length() - 1) : urlPath; // Reconstruct URL without user credentials this.url = convertStringToURL(urlProtocol + "://" + urlHost + ":" + urlPort + urlPath); }
Example 11
Source File: ResourceUploaderURLImpl.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
@Override public PasswordAuthentication getAuthentication( String realm, URL tracker ) { if ( user_name == null || password == null ){ String user_info = tracker.getUserInfo(); if ( user_info == null ){ return( null ); } String user_bit = user_info; String pw_bit = ""; int pos = user_info.indexOf(':'); if ( pos != -1 ){ user_bit = user_info.substring(0,pos); pw_bit = user_info.substring(pos+1); } return( new PasswordAuthentication( user_bit, pw_bit.toCharArray())); } return( new PasswordAuthentication( user_name, password.toCharArray())); }
Example 12
Source File: UrlUtils.java From htmlunit with Apache License 2.0 | 5 votes |
/** * Creates and returns a new URL identical to the specified URL but with a changed user name. * @param u the URL on which to base the returned URL * @param newUserName the new user name * @return a new URL identical to the specified URL; only user name updated * @throws MalformedURLException if there is a problem creating the new URL */ public static URL getUrlWithNewUserName(final URL u, final String newUserName) throws MalformedURLException { String newUserInfo = newUserName; final String userInfo = u.getUserInfo(); if (org.apache.commons.lang3.StringUtils.isNotBlank(userInfo)) { final int colonIdx = userInfo.indexOf(':'); if (colonIdx > -1) { newUserInfo = newUserName + userInfo.substring(colonIdx); } } return createNewUrl(u.getProtocol(), newUserInfo, u.getHost(), u.getPort(), u.getPath(), u.getRef(), u.getQuery()); }
Example 13
Source File: ResolverImpl.java From vertx-stack with Apache License 2.0 | 5 votes |
private static Authentication extractAuth(URL url) { String userInfo = url.getUserInfo(); if (userInfo != null) { AuthenticationBuilder authBuilder = new AuthenticationBuilder(); int sep = userInfo.indexOf(':'); if (sep != -1) { authBuilder.addUsername(userInfo.substring(0, sep)); authBuilder.addPassword(userInfo.substring(sep + 1)); } else { authBuilder.addUsername(userInfo); } return authBuilder.build(); } return null; }
Example 14
Source File: SmbURLStreamHandlerService.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public URLConnection openConnection(URL url) throws IOException{ SingletonContext context = SingletonContext.getInstance(); NtlmPasswordAuthentication ntlmPasswordAuthentication = new NtlmPasswordAuthentication(context, url.getUserInfo()); CIFSContext credentials = SingletonContext.getInstance().withCredentials(ntlmPasswordAuthentication); return new SmbFile(url, credentials); }
Example 15
Source File: GitHubDiscoverer.java From mdw with Apache License 2.0 | 5 votes |
/** * Must be a public repository. */ public GitHubDiscoverer(URL repoUrl) throws IOException { super(repoUrl); String apiBaseUrl = "https://"; if (repoUrl.getUserInfo() != null) { apiBaseUrl += repoUrl.getUserInfo() + "@"; } apiBase = new URL(apiBaseUrl + "api.github.com/repos"); String path = repoUrl.getPath(); repoPath = path.substring(1, path.lastIndexOf('.')); repoName = repoPath.substring(repoPath.lastIndexOf('/') + 1); }
Example 16
Source File: Handler.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
protected boolean equals(URL u1, URL u2) { String userInfo1 = u1.getUserInfo(); String userInfo2 = u2.getUserInfo(); return super.equals(u1, u2) && (userInfo1 == null? userInfo2 == null: userInfo1.equals(userInfo2)); }
Example 17
Source File: Handler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
protected boolean equals(URL u1, URL u2) { String userInfo1 = u1.getUserInfo(); String userInfo2 = u2.getUserInfo(); return super.equals(u1, u2) && (userInfo1 == null? userInfo2 == null: userInfo1.equals(userInfo2)); }
Example 18
Source File: Handler.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
protected boolean equals(URL u1, URL u2) { String userInfo1 = u1.getUserInfo(); String userInfo2 = u2.getUserInfo(); return super.equals(u1, u2) && (userInfo1 == null? userInfo2 == null: userInfo1.equals(userInfo2)); }
Example 19
Source File: Handler.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
protected boolean equals(URL u1, URL u2) { String userInfo1 = u1.getUserInfo(); String userInfo2 = u2.getUserInfo(); return super.equals(u1, u2) && (userInfo1 == null? userInfo2 == null: userInfo1.equals(userInfo2)); }
Example 20
Source File: PacmanUtils.java From pacbot with Apache License 2.0 | 4 votes |
public static List<String> getVolumeIdFromElasticSearch(String id, String esUrl, String attributeName) { JsonParser jsonParser = new JsonParser(); List<String> volList = new ArrayList<>(); try { HttpClient client = HttpClientBuilder.create().build(); URL url = new URL(esUrl); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); // prepare Json pay load for GET query. JsonObject innerJson = new JsonObject(); JsonObject matchPhrase = new JsonObject(); JsonObject must = new JsonObject(); JsonObject bool = new JsonObject(); JsonObject query = new JsonObject(); innerJson.addProperty(attributeName, id); matchPhrase.add(PacmanRuleConstants.MATCH_PHRASE, innerJson); must.add("must", matchPhrase); bool.add("bool", must); query.add(PacmanRuleConstants.QUERY, bool); StringEntity strjson = new StringEntity(query.toString()); // Qurying the ES HttpPost httpPost = new HttpPost(); httpPost.setURI(uri); httpPost.setEntity(strjson); httpPost.setHeader(PacmanRuleConstants.CONTENT_TYPE, PacmanRuleConstants.APPLICATION_JSON); HttpResponse response = client.execute(httpPost); String jsonString = EntityUtils.toString(response.getEntity()); JsonObject resultJson = (JsonObject) jsonParser.parse(jsonString); String hitsJsonString = resultJson.get(PacmanRuleConstants.HITS).toString(); JsonObject hitsJson = (JsonObject) jsonParser.parse(hitsJsonString); JsonArray jsonArray = hitsJson.getAsJsonObject().get(PacmanRuleConstants.HITS).getAsJsonArray(); volList = getVolumeList(jsonArray); } catch (Exception me) { logger.error(me.getMessage()); } return volList; }