Anaplan API Authentication service - nuances...

Highlighted
Certified Master Anaplanner

Anaplan API Authentication service - nuances...

Official documentation from Anaplan: https://anaplanauthentication.docs.apiary.io/#

 

In order to successfully connect to the Anaplan Authentication service you will need to:

  1. Generate a CA certificate. with access to both the public certificate and the private key
  2. Add the public cert to the anaplan security site
  3. Generate random byte** string
  4. Sing random byte** string

**the random byte string IS NOT just a random string of characters. the byte referred to is actually a data field type. I have tested using random strings and encoding it and has not worked. The only way i got it to work is following the example of the Java script, and creating the random string and signed random string. An alternative method is to use anaplan's packaged process. This process calls the Anaplan Connect .jar file, which is part of zip file. This call only goes to the authentication value creation.

To use the anaplan process a Java Key Store (JKS) will need to be created. Once created, the .bat file included in the zip file will need to updated with the JKS location, JKS alias and JKS password. Screenshot of the successful process completion is provided below.

 

Here is the zip file of the certificate generator provided by the anaplan support team: certAuthGenerator.7z 

The file: certAuthGenerator.bat needs to be configured to match your JKS (Java Key Store)

anaplanconnect_bat.png


 

OR you can use the code below to create the same result

I have posted some code below. I used Eclipse to execute.

 

import java.util.Random;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.Base64;
import java.util.UUID;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.*;
 
public class anaplan_random_150_string_encoded {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
            System.out.println("The strings are created below");
            char[] password = "password".toCharArray();
            String alias = "alias_name_here";
            String keystoreFilename = "C:/OpenSSL-Win64/bin/<Java_Key_Store_file>";
            SecureRandom random = new SecureRandom();
            random.setSeed(System.currentTimeMillis());
            byte bytes[] = new byte[150];
            random.nextBytes(bytes);
            String encodedData = Base64.getEncoder().encodeToString(bytes);
            //JCEKS
            try {
                KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
                FileInputStream fis = new FileInputStream(keystoreFilename);
                    ks.load(fis, password);
                    PrivateKey key = (PrivateKey)ks.getKey(alias, password);
                    //Use SHA512withRSA with RSA keys, SHA512withDSA for DSA keys,...
                    //See supported algorithm here: <a href="<a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Signature" target="_blank">https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Signature</a>" target="_blank"><a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Signature</a" target="_blank">https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Signature</a</a>>
                    String signatureAlgorithm = "SHA512withRSA";
 
                    //Digital Signature
                    Signature sig = Signature.getInstance(signatureAlgorithm);
                    sig.initSign(key);
//                    sig.update(Files.readAllBytes(Paths.get(file)));
                    sig.update(bytes);
                    byte[] signature_bytes = sig.sign();
                    String encodedData_signed = Base64.getEncoder().encodeToString(signature_bytes);
                    System.out.println("Encoded signed data: " + encodedData_signed);
 
            } catch (KeyStoreException e) {   
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
//            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            //KeyStore keyStore = KeyStore.getInstance("JKS");
 catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (GeneralSecurityException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
 
            System.out.println("Encoded data: " + encodedData);
    }
}

 

random string generation  Expand source