Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Ticket solution for authentication in Qlik sense

Hi ,

I have seen post regarding authentication solution using Ticket solution. I am also  following each step in Ticketing with Qlik Sense and Java - YouTube  but getting attached error.

I have my company internal dashboard, and there i am already login through admin credentials and with same credential i want to access qlik mashup or objects. We dont want to enter qlik server authentication again. Same admin credential should work for qlik. 

Capture.PNG

Kindly guide or provide me some inputs how to achieve the same.

Thanks in advance.

Regards,

Apoorva

4 Replies
konrad_mattheis
Luminary Alumni
Luminary Alumni

Hi,

did you opend the rest api port to fetch the ticket?

I implemeneted already a lot of solution with no issues.

Please attach you sample code.

bye Konrad

Not applicable
Author

Hi Konrad,

Thanks for replying on my query. Below is the code i used to fetch the Ticket :

Also while running this file i am getting the attched error.

public class Ticket

{

  public static void main(String[] args)

  {

  String xrfkey = "7rBHABt65vFflaZ7"; //Xrfkey to prevent cross-site issues

  String host = "Acer-PC"; /*Enter the Qlik Sense Server hostname here  (given the host name which was given in QMC while exporting certificates)*/

  String vproxy = "custom"; //Enter the prefix for the virtual proxy configured in Qlik Sense Steps Step 1

  try

  {

  /************** BEGIN Certificate Acquisition **************/

  String certFolder = "c:\\java\\"; //This is a folder reference to the location of the jks files used for securing ReST communication

  String proxyCert = certFolder + "client.jks"; //Reference to the client jks file which includes the client certificate with private key

  String proxyCertPass="testtest"; //This is the password to access the Java Key Store information

  String rootCert = certFolder + "root.jks"; //Reference to the root certificate for the client cert. Required in this example because Qlik Sense certs are used.

  String rootCertPass = "testtest"; //This is the password to access the Java Key Store information

  /************** END Certificate Acquisition **************/

  /************** BEGIN Certificate configuration for use in connection **************/

  KeyStore ks = KeyStore.getInstance("JKS");

  ks.load(new FileInputStream(new File(proxyCert)), proxyCertPass.toCharArray());

  KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());

  kmf.init(ks, proxyCertPass.toCharArray());

  SSLContext context = SSLContext.getInstance("SSL");

  KeyStore ksTrust = KeyStore.getInstance("JKS");

  ksTrust.load(new FileInputStream(rootCert), rootCertPass.toCharArray());

  TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

  tmf.init(ksTrust);

  context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

  SSLSocketFactory sslSocketFactory = context.getSocketFactory();

  /************** END Certificate configuration for use in connection **************/

  /************** BEGIN HTTPS Connection **************/

  System.out.println("Browsing to: " + "https://" + host + ":4243/qps/" + vproxy + "/ticket?xrfkey=" + xrfkey);

  URL url = new URL("https://" + host + ":4243/qps/" + vproxy + "/ticket?xrfkey=" + xrfkey);

  HttpsURLConnection connection = (HttpsURLConnection ) url.openConnection();

  connection.setSSLSocketFactory(sslSocketFactory);

  connection.setRequestProperty("x-qlik-xrfkey", xrfkey); connection.setDoOutput(true);

  connection.setDoInput(true);

  connection.setRequestProperty("Content-Type","application/json");

  connection.setRequestProperty("Accept", "application/json");

  connection.setRequestMethod("POST");

  /************** BEGIN JSON Message to Qlik Sense Proxy API **************/

  String body = "{ 'UserId':'" + args[0] + "','UserDirectory':'" + args[1] +"',";

  body+= "'Attributes': [],"; body+= "}"; System.out.println("Payload: " + body);

  /************** END JSON Message to Qlik Sense Proxy API **************/

  OutputStreamWriter wr= new OutputStreamWriter(connection.getOutputStream());

  wr.write(body);

  wr.flush(); //Get the response from the QPS BufferedReader

  BufferedReader in1 = new BufferedReader(new InputStreamReader(connection.getInputStream()));

  StringBuilder builder = new StringBuilder();

  String inputLine;

  while ((inputLine = in1.readLine()) != null)

  {

  builder.append(inputLine);

  }

  in1.close();

  String data = builder.toString();

  System.out.println("The response from the server is: " + data);

  /************** END HTTPS Connection **************/

  }

  catch (KeyStoreException e) { e.printStackTrace(); }

  catch (IOException e) { e.printStackTrace(); }

  catch (CertificateException e) { e.printStackTrace(); }

  catch (NoSuchAlgorithmException e) { e.printStackTrace(); }

  catch (UnrecoverableKeyException e) { e.printStackTrace(); }

  catch (KeyManagementException e) { e.printStackTrace(); }

  }

}

Thanks and regards,

Apoorva

santoswg
Contributor II
Contributor II

Hi,

I want to implement a Ticket solution for authentication in Qlik sense.

I'd implement a single sign-on solution. I have a java application that will display a Qlik sense dashboard. I want Qlik Sense use the same login of the java application without needing a new authentication.

Could you please send a sample code for me.

Thank you for your attention.

Wellington

 

StevenJDH
Employee
Employee

Hello all,

For those who are interested, I've created an updated example for how to request a ticket via Java. This version is more adaptable with a number of improvements and has better clarity. The biggest change is that you can now also use the standard certificates that are exported from Qlik Sense without having to convert them to the Java KeyStore (*.jks) format. You can find the code here: https://github.com/StevenJDH/Qlik-Sense-Java-Examples