Java Code Examples for org.eclipse.jgit.transport.URIish#getScheme()

The following examples show how to use org.eclipse.jgit.transport.URIish#getScheme() . 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: GitUtils.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns whether or not the git repository URI is forbidden. If a scheme of the URI is matched, check if the scheme is a supported protocol. Otherwise,
 * match for a scp-like ssh URI: [user@]host.xz:path/to/repo.git/ and ensure the URI does not represent a local file path.
 * 
 * @param uri
 *            A git repository URI
 * @return a boolean of whether or not the git repository URI is forbidden.
 */
public static boolean isForbiddenGitUri(URIish uri) {
	String scheme = uri.getScheme();
	String host = uri.getHost();
	String path = uri.getPath();
	boolean isForbidden = false;

	if (scheme != null) {
		isForbidden = !uriSchemeWhitelist.contains(scheme);
	} else {
		// match for a scp-like ssh URI
		if (host != null) {
			isForbidden = host.length() == 1 || path == null;
		} else {
			isForbidden = true;
		}
	}

	return isForbidden;
}
 
Example 2
Source File: SshPropertyValidator.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
protected static boolean isSshUri(Object uri) {
	if (uri != null) {
		try {
			URIish urIish = new URIish(uri.toString());
			String scheme = urIish.getScheme();
			if (scheme == null && hasText(urIish.getHost())
					&& hasText(urIish.getUser())) {
				// JGit returns null if using SCP URI but user and host will be
				// populated
				return true;
			}
			return scheme != null && !scheme.matches("^(http|https)$");

		}
		catch (URISyntaxException e) {
			return false;
		}
	}
	return false;
}
 
Example 3
Source File: GitRepository.java    From CardinalPGM with MIT License 6 votes vote down vote up
private static String format(URIish uri) {
    StringBuilder r = new StringBuilder();

    if (uri.getScheme() != null) r.append(uri.getScheme()).append("://");

    if (uri.getHost() != null) {
        r.append(uri.getHost());
        if (uri.getScheme() != null && uri.getPort() > 0) r.append(':').append(uri.getPort());
    }

    if (uri.getPath() != null) {
        if (uri.getScheme() != null) {
            if (!uri.getPath().startsWith("/") && !uri.getPath().isEmpty()) r.append('/');
        } else if(uri.getHost() != null) r.append(':');

        if (uri.getScheme() != null) r.append(uri.getRawPath());
        else r.append(uri.getPath());
    }

    return r.toString();
}
 
Example 4
Source File: GitTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
protected void assertRepositoryInfo(URIish uri, JSONObject result) throws JSONException {
	assertEquals(uri.toString(), result.getJSONObject("JsonData").get("Url"));
	if (uri.getUser() != null)
		assertEquals(uri.getUser(), result.getJSONObject("JsonData").get("User"));
	if (uri.getHost() != null)
		assertEquals(uri.getHost(), result.getJSONObject("JsonData").get("Host"));
	if (uri.getHumanishName() != null)
		assertEquals(uri.getHumanishName(), result.getJSONObject("JsonData").get("HumanishName"));
	if (uri.getPass() != null)
		assertEquals(uri.getPass(), result.getJSONObject("JsonData").get("Password"));
	if (uri.getPort() > 0)
		assertEquals(uri.getPort(), result.getJSONObject("JsonData").get("Port"));
	if (uri.getScheme() != null)
		assertEquals(uri.getScheme(), result.getJSONObject("JsonData").get("Scheme"));
}
 
Example 5
Source File: HttpDelegatingCredentialsProvider.java    From gitflow-incremental-builder with MIT License 5 votes vote down vote up
@Override
public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {

    // only handle HTTP(s)
    if (uri.getScheme() != null && !uri.getScheme().startsWith("http")) {
        return false;
    }

    CredentialsPair credentialsPair = credentials.computeIfAbsent(uri, u -> {
        try {
            return lookupCredentials(uri);
        } catch (IOException | InterruptedException | RuntimeException e) {
            logger.warn("Failed to look up credentials via 'git credential fill' for: " + uri, e);
            return null;
        }
    });
    if (credentialsPair == null) {
        return false;
    }

    // map extracted credentials to CredentialItems, see also: org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
    for (CredentialItem item : items) {
        if (item instanceof CredentialItem.Username) {
            ((CredentialItem.Username) item).setValue(credentialsPair.username);
        } else if (item instanceof CredentialItem.Password) {
            ((CredentialItem.Password) item).setValue(credentialsPair.password);
        } else if (item instanceof CredentialItem.StringType && item.getPromptText().equals("Password: ")) {
            ((CredentialItem.StringType) item).setValue(new String(credentialsPair.password));
        } else {
            throw new UnsupportedCredentialItem(uri, item.getClass().getName() + ":" + item.getPromptText());
        }
    }

    return true;
}
 
Example 6
Source File: GoogleCloudSourceSupport.java    From spring-cloud-config with Apache License 2.0 4 votes vote down vote up
private static boolean isHttpScheme(URIish uri) {
	final String scheme = uri.getScheme();
	return Objects.equals(scheme, "http") || Objects.equals(scheme, "https");
}