org.eclipse.jgit.util.Base64 Java Examples

The following examples show how to use org.eclipse.jgit.util.Base64. 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: HerokuDeployApi.java    From heroku-maven-plugin with MIT License 6 votes vote down vote up
public HerokuDeployApi(String client, String clientVersion, String apiKey) {
    Properties pomProperties
            = PropertiesUtils.loadPomPropertiesOrEmptyFromClasspath(this.getClass(), "com.heroku.sdk", "heroku-deploy");

    HashMap<String, String> httpHeaders = new HashMap<>();
    httpHeaders.put("Authorization", Base64.encodeBytes((":" + apiKey).getBytes()));
    httpHeaders.put("Content-Type", "application/json");
    httpHeaders.put("Accept", "application/vnd.heroku+json; version=3");
    httpHeaders.put("User-Agent", String.format(
            "heroku-deploy/%s (%s/%s) Java/%s (%s)",
            pomProperties.getProperty("version", "unknown"),
            client,
            clientVersion,
            System.getProperty("java.version"),
            System.getProperty("java.vendor")));

    this.httpHeaders = httpHeaders;
}
 
Example #2
Source File: PropertyBasedSshSessionFactory.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Override
protected Session createSession(Host hc, String user, String host, int port, FS fs)
		throws JSchException {
	if (this.sshKeysByHostname.containsKey(host)) {
		JGitEnvironmentProperties sshUriProperties = this.sshKeysByHostname.get(host);
		this.jSch.addIdentity(host, sshUriProperties.getPrivateKey().getBytes(), null,
				null);
		if (sshUriProperties.getKnownHostsFile() != null) {
			this.jSch.setKnownHosts(sshUriProperties.getKnownHostsFile());
		}
		if (sshUriProperties.getHostKey() != null) {
			HostKey hostkey = new HostKey(host,
					Base64.decode(sshUriProperties.getHostKey()));
			this.jSch.getHostKeyRepository().add(hostkey, null);
		}
		return this.jSch.getSession(user, host, port);
	}
	throw new JSchException("no keys configured for hostname " + host);
}
 
Example #3
Source File: WebServer.java    From git-as-svn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return current user information.
 *
 * @param authorization HTTP authorization header value.
 * @return Return value:
 * <ul>
 * <li>no authorization header - anonymous user;</li>
 * <li>invalid authorization header - null;</li>
 * <li>valid authorization header - user information.</li>
 * </ul>
 */
@Nullable
public User getAuthInfo(@Nullable final String authorization, int tokenEnsureTime) {
  final UserDB userDB = context.sure(UserDB.class);
  // Check HTTP authorization.
  if (authorization == null) {
    return User.getAnonymous();
  }
  if (authorization.startsWith(AUTH_BASIC)) {
    final String raw = new String(Base64.decode(authorization.substring(AUTH_BASIC.length()).trim()), StandardCharsets.UTF_8);
    final int separator = raw.indexOf(':');
    if (separator > 0) {
      final String username = raw.substring(0, separator);
      final String password = raw.substring(separator + 1);
      try {
        return userDB.check(username, password);
      } catch (SVNException e) {
        log.error("Authorization error: " + e.getMessage(), e);
      }
    }
    return null;
  }
  if (authorization.startsWith(AUTH_TOKEN)) {
    return TokenHelper.parseToken(createEncryption(), authorization.substring(AUTH_TOKEN.length()).trim(), tokenEnsureTime);
  }
  return null;
}
 
Example #4
Source File: GitUserHelper.java    From fabric8-forge with Apache License 2.0 4 votes vote down vote up
public UserDetails createUserDetails(HttpServletRequest request) {
    StopWatch watch = new StopWatch();

    String user = gitUser;
    String password = gitPassword;
    String authorization = null;
    String emailHeader = null;

    // lets try custom headers or request parameters
    if (request != null) {
        authorization = request.getHeader("GogsAuthorization");
        if (Strings.isNullOrEmpty(authorization)) {
            authorization = request.getParameter(Constants.RequestParameters.GOGS_AUTH);
        }
        emailHeader = request.getHeader("GogsEmail");
        if (Strings.isNullOrEmpty(emailHeader)) {
            emailHeader = request.getParameter(Constants.RequestParameters.GOGS_EMAIL);
        }
    }
    if (!Strings.isNullOrEmpty(authorization)) {
        String basicPrefix = "basic";
        String lower = authorization.toLowerCase();
        if (lower.startsWith(basicPrefix)) {
            String base64Credentials = authorization.substring(basicPrefix.length()).trim();
            String credentials = new String(Base64.decode(base64Credentials),
                    Charset.forName("UTF-8"));
            // credentials = username:password
            String[] values = credentials.split(":", 2);
            if (values != null && values.length > 1) {
                user = values[0];
                password = values[1];
            }
        }
    }
    String email = "[email protected]";
    if (!Strings.isNullOrEmpty(emailHeader)) {
        email = emailHeader;
    }
    if (Strings.isNullOrEmpty(address)) {
        address = getGogsURL(true);
        internalAddress = getGogsURL(false);
        if (!address.endsWith("/")) {
            address += "/";
        }
        if (!internalAddress.endsWith("/")) {
            internalAddress += "/";
        }
    }

    LOG.info("createUserDetails took " + watch.taken());
    return new UserDetails(address, internalAddress, user, password, email);
}
 
Example #5
Source File: BitbucketApiService.java    From bitbucket-build-status-notifier-plugin with MIT License 4 votes vote down vote up
private String getHttpBasicAuthHeaderValue() {
    String authStr = config.getApiKey() + ":" + config.getApiSecret();

    return "Basic " + Base64.encodeBytes(authStr.getBytes());
}