All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.paypal.core.AbstractCertificateHttpHeaderAuthStrategy Maven / Gradle / Ivy

Go to download

PayPal Java SDK Core library base and common to PayPal SDKs. The paypal-core library is a dependency for all PayPal related Java SDKs

There is a newer version: 1.7.2
Show newest version
package com.paypal.core;

import java.util.HashMap;
import java.util.Map;

import com.paypal.core.credential.CertificateCredential;
import com.paypal.core.credential.TokenAuthorization;
import com.paypal.sdk.exceptions.OAuthException;

/**
 * AbstractCertificateHttpHeaderAuthStrategy is an abstract implementation for
 * certificate based {@link ICredential} to be realized as HTTP headers
 */
public abstract class AbstractCertificateHttpHeaderAuthStrategy implements
		AuthenticationStrategy, CertificateCredential> {

	/**
	 * Endpoint url
	 */
	protected String endPointUrl;

	/**
	 * AbstractCertificateHttpHeaderAuthStrategy
	 * 
	 * @param endPointUrl
	 *            Endpoint URL
	 */
	public AbstractCertificateHttpHeaderAuthStrategy(String endPointUrl) {
		this.endPointUrl = endPointUrl;
	}

	/**
	 * Returns {@link CertificateCredential} as HTTP headers
	 */
	public Map generateHeaderStrategy(
			CertificateCredential credential) throws OAuthException {
		Map headers = null;
		if (credential.getThirdPartyAuthorization() instanceof TokenAuthorization) {
			headers = processTokenAuthorization(credential,
					(TokenAuthorization) credential
							.getThirdPartyAuthorization());

		} else {
			headers = new HashMap();
			headers.put(Constants.PAYPAL_SECURITY_USERID_HEADER,
					credential.getUserName());
			headers.put(Constants.PAYPAL_SECURITY_PASSWORD_HEADER,
					credential.getPassword());
		}
		return headers;
	}

	/**
	 * Process TokenAuthorization based on API format
	 * 
	 * @param credential
	 *            Instance of {@link CertificateCredential}
	 * @param tokenAuth
	 *            Instance of {@link TokenAuthorization}
	 * @return Map of HTTP headers
	 * @throws OAuthException
	 */
	protected abstract Map processTokenAuthorization(
			CertificateCredential credential, TokenAuthorization tokenAuth)
			throws OAuthException;

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy