SAP-archive/com.sap.openSAP.hana5.example

The predefined session variable cannot be set via SET command: XS_APPLICATIONUSER

Closed this issue · 1 comments

Hello,

I am having the following issue, "

Error: the predefined session variable cannot be set via SET command: XS_APPLICATIONUSER"

When accessing an .xsodata endpoint in my nodeJS app hosted on CF, this is the server.js I am using:

`/eslint no-console: 0, no-unused-vars: 0/
"use strict";
/*
var xsjs = require("@sap/xsjs");
var xsenv = require("@sap/xsenv");
var xsHDBConn = require("@sap/hdbext");
const express = require('express');
const passport = require('passport');
const JWTStrategy = require('@sap/xssec').JWTStrategy;
var port = process.env.PORT || 3000;
var hanaconfig = xsenv.getServices({ hana: {tag: "hana"} }).hana;

const app = express();

const services = xsenv.getServices({ uaa:'my-xsuaa' });
xsHDBConn.middleware(hanaconfig);

passport.use(new JWTStrategy(services.uaa));

app.use(passport.initialize());

app.use(passport.authenticate('JWT', { session: false }));

var options = {
//anonymous : false, // remove to authenticate calls
redirectUrl : "/index.xsjs"
};

// configure HANA
try {
options = Object.assign(options, xsenv.getServices({ hana: {tag: "hana"} }));
} catch (err) {
console.log("[WARN]", err.message);
}

// configure UAA
try {
options = Object.assign(options, xsenv.getServices({ uaa: {tag: "xsuaa"} }));
} catch (err) {
console.log("[WARN]", err.message);
}

// start server
xsjs(options).listen(port);

console.log("Server listening on port %d", port);
*/

"use strict";
var https = require("https");
var xsenv = require("@sap/xsenv");
var port = process.env.PORT || 3000;
var server = require("http").createServer();
https.globalAgent.options.ca = xsenv.loadCertificates();
global.__base = __dirname + "/";

//Initialize Express App for XSA UAA and HDBEXT Middleware
var xsenv = require("@sap/xsenv");
var passport = require("passport");
var xssec = require("@sap/xssec");
var xsHDBConn = require("@sap/hdbext");
var express = require("express");

//logging
var logging = require("@sap/logging");
var appContext = logging.createAppContext();
var logger = appContext.getLogger("/Application");
var tracer = appContext.getTracer(__filename);

//Initialize Express App for XS UAA and HDBEXT Middleware
var app = express();

passport.use("JWT", new xssec.JWTStrategy(xsenv.getServices({
uaa: {
tag: "xsuaa"
}
}).uaa));
app.use(logging.expressMiddleware(appContext));
app.use(passport.initialize());
var hanaOptions = xsenv.getServices({
hana: {
tag: "hana"
}
});
//hanaOptions.hana.rowsWithMetadata = true;
app.use(
passport.authenticate("JWT", {
session: false
}),
xsHDBConn.middleware(hanaOptions.hana)
);

//Setup Routes
//var router = require("/lib")(app, server);

//Start the Server
server.on("request", app);
server.listen(port, function() {
console.info(Logger Level: ${logger.getLevel().toString()});
console.info(Logger Error Enabled: ${logger.isEnabled("error")});
console.info(Tracer Level: ${tracer.getLevel().toString()});
console.info(Tracer Error Enabled: ${tracer.isEnabled("error")});
logger.error(HTTP Server: ${server.address().port});
tracer.info(HTTP Server: ${server.address().port});
console.info(HTTP Server: ${server.address().port});
});`

This is my package.json

{ "dependencies": { "@sap/approuter": "^5.6.4", "@sap/xsenv": "1.2.9", "@sap/xsjs": "3.3.7", "@sap/xssec": "^2.1.15", "@sap/hdbext": "4.7.2", "@sap/hana-client": "~2.3", "express": "^4.16.3", "passport": "^0.4.0" }, "devDependencies": { "@sap/xsjs-test": "2.0.16" }, "files": [], "main": "server.js", "name": "NODE_JS_MODULE", "scripts": { "start": "node server.js", "test": "node testrun.js" }, "engines": { "node": "8.x" }, "version": "1.0.0" }
Anything I am missing? This only fails when I setup the authentication, without it it's possible to call the odata service without issues. I am also able to retrive user authentication scopes from simple JS endpoint s (with authentication on), only with .xsodata (and possible any DB accesses it fails)

Regards,

First this project is not designed nor tested for CF. It is for XSA (HANA on premise). I can't say what you might encounter on CF.

I'd make sure your UAA is getting loaded correctly. Beyond that I can't offer you much advice. This code works as designed in the environment for which it was designed.