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

com.paypal.core.soap.SignatureSOAPHeaderAuthStrategy 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.soap;

import com.paypal.core.AuthenticationStrategy;
import com.paypal.core.credential.SignatureCredential;
import com.paypal.core.credential.SubjectAuthorization;
import com.paypal.core.credential.ThirdPartyAuthorization;
import com.paypal.core.credential.TokenAuthorization;

/**
 * SignatureSOAPHeaderAuthStrategy is an implementation of
 * {@link AuthenticationStrategy} which acts on {@link SignatureCredential} and
 * retrieves them as SOAP headers
 * 
 */
public class SignatureSOAPHeaderAuthStrategy implements
		AuthenticationStrategy {

	private ThirdPartyAuthorization thirdPartyAuthorization;

	public SignatureSOAPHeaderAuthStrategy() {
	}

	/**
	 * @return the thirdPartyAuthorization
	 */
	public ThirdPartyAuthorization getThirdPartyAuthorization() {
		return thirdPartyAuthorization;
	}

	/**
	 * @param thirdPartyAuthorization
	 *            the thirdPartyAuthorization to set
	 */
	public void setThirdPartyAuthorization(
			ThirdPartyAuthorization thirdPartyAuthorization) {
		this.thirdPartyAuthorization = thirdPartyAuthorization;
	}

	public String generateHeaderStrategy(SignatureCredential credential) {
		String payLoad = null;
		if (thirdPartyAuthorization instanceof TokenAuthorization) {
			payLoad = tokenAuthPayLoad();
		} else if (thirdPartyAuthorization instanceof SubjectAuthorization) {
			payLoad = authPayLoad(credential,
					(SubjectAuthorization) thirdPartyAuthorization);
		} else {
			payLoad = authPayLoad(credential, null);
		}
		return payLoad;
	}

	private String tokenAuthPayLoad() {
		StringBuilder soapMsg = new StringBuilder();
		soapMsg.append("");
		return soapMsg.toString();
	}

	private String authPayLoad(SignatureCredential credential,
			SubjectAuthorization subjectAuth) {
		StringBuilder soapMsg = new StringBuilder();
		soapMsg.append("");
		soapMsg.append("");
		soapMsg.append("" + credential.getUserName()
				+ "");
		soapMsg.append("" + credential.getPassword()
				+ "");
		soapMsg.append("" + credential.getSignature()
				+ "");
		if (subjectAuth != null) {
			soapMsg.append("" + subjectAuth.getSubject()
					+ "");
		}
		soapMsg.append("");
		soapMsg.append("");
		return soapMsg.toString();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy