Skip to Content
Technical Articles
Author's profile photo Avinash Raju

Anonymous Call to access XSJS service using SQLCC

     This post focuses on how you can bypass the HANA logon or make an anonymous call for accessing an XSJS service. I would also share the challenge I faced when a XS app was wrapped as an Android app. How to create an Android PhoneGap plugin for UI5 Mobile

     We might come across a situation where we need to bypass the default Form/Basic authentication. In my case, after wrapping the XS App into an .apk I couldn’t navigate to any of my XSJS services unless I logged in with the usual HANA logon authentication. SQLCC helps by enabling us to configure the connection to the database, we can also use specific config for your individual SQL Connections. Below are the steps to achieve this.

Roles you would require:

  1. sap.hana.xs.admin.roles::SQLCCViewer
  2. sap.hana.xs.admin.roles::SQLCCAdministrator

 

The first step would be to create an .xssqlcc file in your XS project or using New -> Other -> Application Development -> SQL Configuration File

{

“description” : “Test SQL connection”

}

Activating this would create an entry in “_SYS_XS”.”SQL_CONNECTIONS”. Note that the USERNAME needs to be updated.

Post_2.jpg

  •      Update the USERNAME using the below URL

               http://hostname:port/sap/hana/xs/sqlcc

Post_3.jpg

 

                   After Update :

Post_4.jpg

  •      You can manage the security for your package from the below link.

              http://hostname:port/sap/hana/xs/admin/

Once the XSSQLCC is created, all you need to do is to use it in your application. We can do this in two ways :

 

          1) Set the parameter in my .xsaccess file

{

   “anonymous_connection”: “SQLCC::testsqlcc”,

   “exposed” : true,

   “authentication” : null

}

          2) Passing the “SQLCC::testsqlcc” as parameter in my $.db.getConnection();

          Note : SQLCC file and the XSJS service SHOULD be in the same package, so that service can access the SQL Connection Configuration file

          Below is a simple snippet of a XS app that calls the SQLCC .

//Open a DB connection

  var conn = $.db.getConnection(“SQLCC::testsqlcc”);

  var oResult = [];

  var sql = “SELECT CUST_ID,CUST_NAME FROM \”TEST\”.\”CUSTOMER\””;

  var pstmt = conn.prepareStatement(sql);

  var rs = pstmt.executeQuery();

  while(rs.next()){

  oResult.push({

  “ID” : rs.getString(1),

  “Name” : rs.getString(1),

  });

  }

  rs.close();

  conn.close();

  $.response.setBody(JSON.stringify(oResult));

Result:

Post_1.jpg

And now I have a service which does not throw a Basic pop up/Form logon. This helped us in navigating to the required service from the XS app which was wrapped as Android App.

Another authentication which you could explore would be OAuth !

 

Hope this post was helpful !

 

Avinash Raju

SAP HANA Consultant

Assigned tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jason Su
      Jason Su

      very cool article.i need to practice according to it.

      Author's profile photo Former Member
      Former Member

      Good information Avinash,

      I'm getting below error when trying to call procedure from xsjs file:

      "dberror(CallableStatement.execute): 2048 - column store error: search table error: [2620] executor: plan operation failed;Can not insert data from temp table into Result_Table"

      I have verified i/p & o/p data types and the same code works fine on studio SQL editor , but facing issue only executing the same from xsjs.

      Please let me know any other suggestions ..

      Thanks & Regards,

      Anup Singh

      Author's profile photo Sreeja Sreekumar
      Sreeja Sreekumar

      Hi

      Thanks for the blog.

      While doing this , i am not able to access the link  http://hostname:port/sap/hana/xs/sqlcc

      Is there a way by which programmatically i can update this table ?

      Thanks in Advance

      Sreeja

      Author's profile photo Former Member
      Former Member

      Hi Sreeja,

      You can locate the .xssqlcc file in the corresponding package in:

      http://hostname:port/sap/hana/xs/admin

      You need the sap.hana.xs.admin.roles::RuntimeConfAdministrator role to be able to locate this file in the XS Applications tab.

      Capture.PNG

      Hope this helps!

      Kind regards,

      Xana

      Author's profile photo Former Member
      Former Member

      Hey! So I am trying to do this and can't seem to find where one would set up the username. I have already granted the RuntimeConfAdministrator role.

       

      I just see a view of the sqlcc object where it says Username is 'Not Set'. What am I missing?

      Author's profile photo Sergio Guerrero
      Sergio Guerrero

      not sure if this still relevant, but.. i am able to follow all these steps... how can i access /sap/hana/xs/admin/ from hcp trial, or can i ?

      Author's profile photo L L
      L L

      You can, just log on to the web based development workbench of your hana mdc created in hcp trial, and in the Editor, follow the path in the directory structure starting from root: /sap/hana/xs/admin/ and you'll find an index.html there which you have to start. But first assign in the Security tool all *xs.admin* roles to e.g. your SYSTEM user.

      Author's profile photo Former Member
      Former Member

      Hey! As I described above, (response to Xana Rasquin's comment) I cant seem to find how to setup username. I have granted to appropriate privileges and everything but I simply don't see a button that would allow me to setup the username.

      Author's profile photo Former Member
      Former Member

      Nice to see this blog, and I also would like to know one more point here - if we implement this then when we run the service will it asks HANA access credentials OR is it suffice that if we give the USERNAME and PASSWORD what we created here?

      Thanks,

      Siva

      Author's profile photo Former Member
      Former Member

      Hi Avinash,

       

      How can I add job scheduler job role using sqlcc? is it possible? a user will have login credentials but won't have job schedule role.

      Thanks

      Nitin

      Author's profile photo Gowthami B
      Gowthami B

      Hi Nitin

      Didn't quite get your question. Please explain.

      Author's profile photo Goga Didebashvili
      Goga Didebashvili

      can anonymous authorization also be used for HAN File Api ? to get XSRF token and make file uploads on vs server using this feature https://help.sap.com/viewer/52715f71adba4aaeb480d946c742d1f6/2.0.02/en-US/c3dd9fded080465cbc194ab7aee650e6.html