Java Code Examples for java.net.URI#getRawUserInfo()

The following examples show how to use java.net.URI#getRawUserInfo() . 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: KeycloakUriBuilder.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public KeycloakUriBuilder schemeSpecificPart(String ssp) throws IllegalArgumentException {
    if (ssp == null) throw new IllegalArgumentException("schemeSpecificPart was null");

    StringBuilder sb = new StringBuilder();
    if (scheme != null) sb.append(scheme).append(':');
    if (ssp != null)
        sb.append(ssp);
    if (fragment != null && fragment.length() > 0) sb.append('#').append(fragment);
    URI uri = URI.create(sb.toString());

    if (uri.getRawSchemeSpecificPart() != null && uri.getRawPath() == null) {
        this.ssp = uri.getRawSchemeSpecificPart();
    } else {
        this.ssp = null;
        userInfo = uri.getRawUserInfo();
        host = uri.getHost();
        port = uri.getPort();
        path = uri.getRawPath();
        query = uri.getRawQuery();

    }
    return this;

}
 
Example 2
Source File: SourceIdentifiers.java    From es6draft with MIT License 6 votes vote down vote up
private static boolean hasIllegalComponents(URI moduleName) {
    // All components except for 'path' must be empty.
    if (moduleName.getScheme() != null) {
        return true;
    }
    if (moduleName.getRawAuthority() != null) {
        return true;
    }
    if (moduleName.getRawUserInfo() != null) {
        return true;
    }
    if (moduleName.getHost() != null) {
        return true;
    }
    if (moduleName.getPort() != -1) {
        return true;
    }
    if (moduleName.getRawQuery() != null) {
        return true;
    }
    if (moduleName.getRawFragment() != null) {
        return true;
    }
    return false;
}
 
Example 3
Source File: URIBuilder.java    From nano-framework with Apache License 2.0 6 votes vote down vote up
public URIBuilder digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery());
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
    return this;
}
 
Example 4
Source File: RepositoryAddress.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return same as {@link #getURI() getURI().toString()} with obfuscated user info
 */
@Override
@NotNull
public String toString() {
    final URI uri = getURI();
    final String userInfo = uri.getRawUserInfo();
    if (userInfo != null) {
        return uri.toString().replace(userInfo, "******:******");
    } else {
        return uri.toString();
    }
}
 
Example 5
Source File: URIBuilder.java    From RoboZombie with Apache License 2.0 5 votes vote down vote up
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 6
Source File: UriInfo.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
private String[] parseUserinfo(URI uri) {
	String userInfo = uri.getRawUserInfo();

	if (userInfo != null) {
		String[] userPass = userInfo.split(":");
		if (userPass.length == 1) {
			return new String[]{userPass[0], null};
		} else if (userPass.length != 2) {
			throw new IllegalArgumentException("Bad userinfo in URI: " + uri);
		}
		return userPass;
	}

	return new String[]{null, null};
}
 
Example 7
Source File: Url.java    From plugin-socket.io with Apache License 2.0 5 votes vote down vote up
public static URL parse(URI uri) throws MalformedURLException {
    String protocol = uri.getScheme();
    if (protocol == null || !protocol.matches("^https?|wss?$")) {
        protocol = "https";
    }

    int port = uri.getPort();
    if (port == -1) {
        if (PATTERN_HTTP.matcher(protocol).matches()) {
            port = 80;
        } else if (PATTERN_HTTPS.matcher(protocol).matches()) {
            port = 443;
        }
    }

    String path = uri.getRawPath();
    if (path == null || path.length() == 0) {
        path = "/";
    }

    String userInfo = uri.getRawUserInfo();
    String query = uri.getRawQuery();
    String fragment = uri.getRawFragment();
    return new URL(protocol + "://"
            + (userInfo != null ? userInfo + "@" : "")
            + uri.getHost()
            + (port != -1 ? ":" + port : "")
            + path
            + (query != null ? "?" + query : "")
            + (fragment != null ? "#" + fragment : ""));
}
 
Example 8
Source File: Url.java    From plugin-socket.io with Apache License 2.0 5 votes vote down vote up
public static URL parse(URI uri) throws MalformedURLException {
    String protocol = uri.getScheme();
    if (protocol == null || !protocol.matches("^https?|wss?$")) {
        protocol = "https";
    }

    int port = uri.getPort();
    if (port == -1) {
        if (PATTERN_HTTP.matcher(protocol).matches()) {
            port = 80;
        } else if (PATTERN_HTTPS.matcher(protocol).matches()) {
            port = 443;
        }
    }

    String path = uri.getRawPath();
    if (path == null || path.length() == 0) {
        path = "/";
    }

    String userInfo = uri.getRawUserInfo();
    String query = uri.getRawQuery();
    String fragment = uri.getRawFragment();
    return new URL(protocol + "://"
            + (userInfo != null ? userInfo + "@" : "")
            + uri.getHost()
            + (port != -1 ? ":" + port : "")
            + path
            + (query != null ? "?" + query : "")
            + (fragment != null ? "#" + fragment : ""));
}
 
Example 9
Source File: URIBuilder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery());
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 10
Source File: CdmS3Uri.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private String getProfile(URI cdmUri) {
  String profile = null;
  if (cdmUri.getAuthority() != null) {
    profile = cdmUri.getRawUserInfo();
  }
  return profile;
}
 
Example 11
Source File: GenericUrl.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs from a URI.
 *
 * @param uri URI
 * @param verbatim flag, to specify if URL should be used as is (without encoding, decoding and
 *     escaping)
 */
public GenericUrl(URI uri, boolean verbatim) {
  this(
      uri.getScheme(),
      uri.getHost(),
      uri.getPort(),
      uri.getRawPath(),
      uri.getRawFragment(),
      uri.getRawQuery(),
      uri.getRawUserInfo(),
      verbatim);
}
 
Example 12
Source File: ImplicitResponseUrl.java    From android-oauth-client with Apache License 2.0 5 votes vote down vote up
ImplicitResponseUrl(URI uri) {
    this(uri.getScheme(),
            uri.getHost(),
            uri.getPort(),
            uri.getRawPath(),
            uri.getRawFragment(),
            uri.getRawQuery(),
            uri.getRawUserInfo());
}
 
Example 13
Source File: CorsFilter.java    From jrestless with Apache License 2.0 5 votes vote down vote up
private static boolean isValidOrigin(URI origin) {
	return origin != null
			&& origin.getScheme() != null
			&& origin.getHost() != null
			&& isBlank(origin.getRawPath())
			&& origin.getRawQuery() == null
			&& origin.getRawFragment() == null
			&& origin.getRawUserInfo() == null;
}
 
Example 14
Source File: URIBuilder.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery());
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}
 
Example 15
Source File: ImplicitResponseUrl.java    From mirror with Apache License 2.0 5 votes vote down vote up
ImplicitResponseUrl(URI uri) {
    this(uri.getScheme(),
            uri.getHost(),
            uri.getPort(),
            uri.getRawPath(),
            uri.getRawFragment(),
            uri.getRawQuery(),
            uri.getRawUserInfo());
}
 
Example 16
Source File: UriInfo.java    From java-cfenv with Apache License 2.0 5 votes vote down vote up
private String[] parseUserinfo(URI uri) {
	String userInfo = uri.getRawUserInfo();

	if (userInfo != null) {
		String[] userPass = userInfo.split(":");
		if (userPass.length != 2) {
			throw new IllegalArgumentException("Bad userinfo in URI: " + uri);
		}
		return userPass;
	}

	return new String[]{null, null};
}
 
Example 17
Source File: EmoUriBuilder.java    From emodb with Apache License 2.0 4 votes vote down vote up
@Override
public UriBuilder schemeSpecificPart(String ssp) {
    if (ssp == null) {
        throw new IllegalArgumentException("Scheme specific part parameter is null");
    }

    // TODO encode or validate scheme specific part
    // This will not work for template variables present in the spp
    StringBuilder sb = new StringBuilder();
    if (scheme != null) {
        sb.append(scheme).append(':');
    }
    if (ssp != null) {
        sb.append(ssp);
    }
    if (fragment != null && fragment.length() > 0) {
        sb.append('#').append(fragment);
    }
    URI uri = createURI(sb.toString());

    if (uri.getRawSchemeSpecificPart() != null && uri.getRawPath() == null) {
        this.ssp = uri.getRawSchemeSpecificPart();
    } else {
        this.ssp = null;

        if (uri.getRawAuthority() != null) {
            if (uri.getRawUserInfo() == null && uri.getHost() == null && uri.getPort() == -1) {
                authority = uri.getRawAuthority();
                userInfo = null;
                host = null;
                port = -1;
            } else {
                authority = null;
                userInfo = uri.getRawUserInfo();
                host = uri.getHost();
                port = uri.getPort();
            }
        }

        path.setLength(0);
        path.append(replaceNull(uri.getRawPath()));

        query.setLength(0);
        query.append(replaceNull(uri.getRawQuery()));
    }
    return this;
}
 
Example 18
Source File: HgURL.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @param urlString
 * @param username
 * @param password value is cloned, if you want to null the field, call {@link #clearPassword()}
 * @throws URISyntaxException
 */
public HgURL(String urlString, String username, char[] password) throws URISyntaxException {
    URI originalUri;

    if (urlString == null) {
        throw new IllegalArgumentException("<null> URL string");    //NOI18N
    }

    if (urlString.length() == 0) {
        throw new IllegalArgumentException("empty URL string");     //NOI18N
    }

    if (looksLikePlainFilePath(urlString)) {
        originalUri = new File(urlString).toURI();
        scheme = Scheme.FILE;
    } else {
        originalUri = new URI(urlString).parseServerAuthority();
        String originalScheme = originalUri.getScheme();
        scheme = (originalScheme != null) ? determineScheme(originalScheme)
                                          : null;
    }

    if (scheme == null) {
        throw new URISyntaxException(
                urlString,
                NbBundle.getMessage(HgURL.class,
                                    "MSG_UNSUPPORTED_PROTOCOL",     //NOI18N
                                    originalUri.getScheme()));
    }

    verifyUserInfoData(scheme, username, password);

    if (username != null) {
        this.username = username;
        this.password = password == null ? null : (char[])password.clone();
    } else {
        String rawUserInfo = originalUri.getRawUserInfo();
        if (rawUserInfo == null) {
            this.username = null;
            this.password = null;
        } else {
            int colonIndex = rawUserInfo.indexOf(':');
            if (colonIndex == -1) {
                this.username = rawUserInfo;
                this.password = null;
            } else {
                this.username = rawUserInfo.substring(0, colonIndex);
                this.password = rawUserInfo.substring(colonIndex + 1).toCharArray();
            }
        }
    }

    host = originalUri.getHost();
    port = originalUri.getPort();
    rawPath     = originalUri.getRawPath();
    rawQuery    = originalUri.getRawQuery();
    rawFragment = originalUri.getRawFragment();

    path = originalUri.getPath();
}
 
Example 19
Source File: AbstractAuthority.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * use {@link URI#getRawUserInfo()} so the user info is not decoded - connections decode it again, which
 * causes problems with the plus sign, see CLO-8885
 */
public AbstractAuthority(URI uri) {
	this(uri.getScheme(), uri.getRawUserInfo(), uri.getHost(), uri.getPort());
}
 
Example 20
Source File: DefaultAuthority.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * use {@link URI#getRawUserInfo()} so the user info is not decoded - connections decode it again, which
 * causes problems with the plus sign, see CLO-8885
 */
public DefaultAuthority(URI uri, String proxy) {
	this(uri.getScheme(), uri.getRawUserInfo(), uri.getHost(), uri.getPort(), proxy);
}