Search in sources :

Example 1 with AuthenticationHeader

use of com.marketo.mktows.AuthenticationHeader in project components by Talend.

the class MarketoSOAPClient method getAuthentificationHeader.

public AuthenticationHeader getAuthentificationHeader() throws NoSuchAlgorithmException, InvalidKeyException {
    // Create Signature
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    String text = df.format(new Date());
    String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
    String encryptString = requestTimestamp + userId;
    SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA1");
    Mac mac = getInstance("HmacSHA1");
    mac.init(secretKeySpec);
    byte[] rawHmac = mac.doFinal(encryptString.getBytes());
    char[] hexChars = encodeHex(rawHmac);
    String signature = new String(hexChars);
    // Set Authentication Header
    AuthenticationHeader hdr = new AuthenticationHeader();
    hdr.setMktowsUserId(userId);
    hdr.setRequestTimestamp(requestTimestamp);
    hdr.setRequestSignature(signature);
    return hdr;
}
Also used : AuthenticationHeader(com.marketo.mktows.AuthenticationHeader) SecretKeySpec(javax.crypto.spec.SecretKeySpec) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ArrayOfString(com.marketo.mktows.ArrayOfString) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Mac(javax.crypto.Mac)

Example 2 with AuthenticationHeader

use of com.marketo.mktows.AuthenticationHeader in project components by Talend.

the class MarketoSOAPClientTest method setUp.

@Before
public void setUp() throws Exception {
    iprops = new TMarketoInputProperties("test");
    iprops.schemaInput.setupProperties();
    iprops.schemaInput.setupLayout();
    iprops.connection.setupProperties();
    iprops.connection.setupLayout();
    iprops.connection.setupProperties();
    iprops.connection.apiMode.setValue(APIMode.SOAP);
    iprops.connection.endpoint.setValue("https://fake.io");
    iprops.connection.clientAccessId.setValue("clientaccess");
    iprops.connection.secretKey.setValue("sekret");
    iprops.setupProperties();
    iprops.setupLayout();
    oprops = new TMarketoOutputProperties("test");
    oprops.schemaInput.setupProperties();
    oprops.schemaInput.setupLayout();
    oprops.connection.setupProperties();
    oprops.connection.setupLayout();
    oprops.connection.setupProperties();
    oprops.connection.apiMode.setValue(APIMode.SOAP);
    oprops.connection.endpoint.setValue("https://fake.io");
    oprops.connection.clientAccessId.setValue("clientaccess");
    oprops.connection.secretKey.setValue("sekret");
    oprops.setupProperties();
    oprops.setupLayout();
    lprops = new TMarketoListOperationProperties("test");
    lprops.schemaInput.setupProperties();
    lprops.schemaInput.setupLayout();
    lprops.connection.setupProperties();
    lprops.connection.setupLayout();
    lprops.connection.setupProperties();
    lprops.connection.apiMode.setValue(APIMode.SOAP);
    lprops.connection.endpoint.setValue("https://fake.io");
    lprops.connection.clientAccessId.setValue("clientaccess");
    lprops.connection.secretKey.setValue("sekret");
    lprops.setupProperties();
    lprops.setupLayout();
    client = spy(new MarketoSOAPClient(iprops.connection));
    port = mock(MktowsPort.class);
    AuthenticationHeader header = mock(AuthenticationHeader.class);
    doReturn(port).when(client).getMktowsApiSoapPort();
    doReturn(header).when(client).getAuthentificationHeader();
    doReturn(null).when(port).listMObjects(any(ParamsListMObjects.class), any(AuthenticationHeader.class));
    client.connect();
    objectFactory = new ObjectFactory();
    factory = DatatypeFactory.newInstance();
    Date dateTest = MarketoUtils.parseDateString(DATE_EXPECTED);
    gcDateTest = new GregorianCalendar();
    gcDateTest.setTime(dateTest);
}
Also used : AuthenticationHeader(com.marketo.mktows.AuthenticationHeader) ObjectFactory(com.marketo.mktows.ObjectFactory) TMarketoOutputProperties(org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties) TMarketoListOperationProperties(org.talend.components.marketo.tmarketolistoperation.TMarketoListOperationProperties) GregorianCalendar(java.util.GregorianCalendar) TMarketoInputProperties(org.talend.components.marketo.tmarketoinput.TMarketoInputProperties) ParamsListMObjects(com.marketo.mktows.ParamsListMObjects) MktowsPort(com.marketo.mktows.MktowsPort) Date(java.util.Date) Before(org.junit.Before)

Aggregations

AuthenticationHeader (com.marketo.mktows.AuthenticationHeader)2 Date (java.util.Date)2 ArrayOfString (com.marketo.mktows.ArrayOfString)1 MktowsPort (com.marketo.mktows.MktowsPort)1 ObjectFactory (com.marketo.mktows.ObjectFactory)1 ParamsListMObjects (com.marketo.mktows.ParamsListMObjects)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 GregorianCalendar (java.util.GregorianCalendar)1 Mac (javax.crypto.Mac)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1 Before (org.junit.Before)1 TMarketoInputProperties (org.talend.components.marketo.tmarketoinput.TMarketoInputProperties)1 TMarketoListOperationProperties (org.talend.components.marketo.tmarketolistoperation.TMarketoListOperationProperties)1 TMarketoOutputProperties (org.talend.components.marketo.tmarketooutput.TMarketoOutputProperties)1