下面列出了java.net.URI#getRawUserInfo ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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;
}
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;
}
@Nullable
private String getProfile(URI cdmUri) {
String profile = null;
if (cdmUri.getAuthority() != null) {
profile = cdmUri.getRawUserInfo();
}
return profile;
}
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};
}
ImplicitResponseUrl(URI uri) {
this(uri.getScheme(),
uri.getHost(),
uri.getPort(),
uri.getRawPath(),
uri.getRawFragment(),
uri.getRawQuery(),
uri.getRawUserInfo());
}
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();
}
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;
}
ImplicitResponseUrl(URI uri) {
this(uri.getScheme(),
uri.getHost(),
uri.getPort(),
uri.getRawPath(),
uri.getRawFragment(),
uri.getRawQuery(),
uri.getRawUserInfo());
}
/**
* 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);
}
/**
* {@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();
}
}
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();
}
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 : ""));
}
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 : ""));
}
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};
}
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();
}
/**
*
* @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();
}
@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;
}
/**
* 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());
}
/**
* 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);
}