)}
- { me.isTypeAvailable('prod') && (
+ {me.isTypeAvailable('prod') && (
-
{me.setType('prod')}}>
+
{ me.setType('prod') }}>
-
+
Production Metadata
@@ -40,28 +40,28 @@ function view(me) {
Please choice if you want to continue a previous report or start a new one...
-
{me.startContinue()}}>
+
{ me.startContinue() }}>
-
Continue
+
Continue
Continue to work on the report from the previous session keeping all the stored test results
{me.startNew()}}>
+ onClick={(e) => { me.startNew() }}>
-
Start New
+
Start New
Start a new session to work on a blank report resetting all the previous stored results
- );
+ );
}
export default view;
diff --git a/src/server/api/info.js b/src/server/api/info.js
index 903f18a..9cf3675 100644
--- a/src/server/api/info.js
+++ b/src/server/api/info.js
@@ -1,11 +1,12 @@
const fs = require("fs-extra");
const Utility = require("../lib/utils");
const config_dir = require("../../config/dir.json");
+const config_op = require("../../config/op.json");
module.exports = function(app, checkAuthorisation) {
// get info from session
- app.get("/api/info", function(req, res) {
+ app.get(config_op.basepath+"api/info", function(req, res) {
// check if apikey is correct
if(!checkAuthorisation(req)) {
diff --git a/src/server/api/metadata.js b/src/server/api/metadata.js
index 3dadba0..dbcccc6 100644
--- a/src/server/api/metadata.js
+++ b/src/server/api/metadata.js
@@ -6,7 +6,7 @@ const jwt_decode = require('jwt-decode');
const Utility = require('../lib/utils');
const config_dir = require('../../config/dir.json');
const config_test = require("../../config/test.json");
-
+const config_op = require("../../config/op.json");
module.exports = function(app, checkAuthorisation, database) {
@@ -81,7 +81,7 @@ module.exports = function(app, checkAuthorisation, database) {
*/
// download metadata
- app.post("/api/metadata/:type/download", function(req, res) {
+ app.post(config_op.basepath+"api/metadata/:type/download", function(req, res) {
// check if apikey is correct
let authorisation = checkAuthorisation(req);
@@ -181,7 +181,7 @@ module.exports = function(app, checkAuthorisation, database) {
});
// execute test for metadata
- app.get("/api/metadata/check/:testcase", async function(req, res) {
+ app.get(config_op.basepath+"api/metadata/check/:testcase", async function(req, res) {
// check if apikey is correct
let authorisation = checkAuthorisation(req);
@@ -244,7 +244,7 @@ module.exports = function(app, checkAuthorisation, database) {
});
// return last validation from store
- app.get("/api/metadata/lastcheck/:testcase", function(req, res) {
+ app.get(config_op.basepath+"api/metadata/lastcheck/:testcase", function(req, res) {
// check if apikey is correct
let authorisation = checkAuthorisation(req);
@@ -328,7 +328,7 @@ module.exports = function(app, checkAuthorisation, database) {
*/
// set test for metadata
- app.patch("/api/metadata/:testcase/:test", async function(req, res) {
+ app.patch(config_op.basepath+"api/metadata/:testcase/:test", async function(req, res) {
// check if apikey is correct
let authorisation = checkAuthorisation(req);
diff --git a/src/server/api/store.js b/src/server/api/store.js
index 1c6366b..3161b9f 100644
--- a/src/server/api/store.js
+++ b/src/server/api/store.js
@@ -1,12 +1,12 @@
const fs = require("fs-extra");
const Utility = require("../lib/utils");
const config_dir = require("../../config/dir.json");
-
+const config_op = require("../../config/op.json");
module.exports = function(app, checkAuthorisation, database) {
// list all workspace for user and, maybe, requested store type
//this not saves store to session, use GET /api/store to recover a store instead
- app.get("/api/stores", function(req, res) {
+ app.get(config_op.basepath+"api/stores", function(req, res) {
// check if apikey is correct
if(!checkAuthorisation(req)) {
@@ -34,7 +34,7 @@ module.exports = function(app, checkAuthorisation, database) {
// recover workspace from store cache
// this RECOVER store from cache and SAVE it to session
- app.get("/api/store", function(req, res) {
+ app.get(config_op.basepath+"api/store", function(req, res) {
// check if apikey is correct
if(!checkAuthorisation(req)) {
@@ -71,7 +71,7 @@ module.exports = function(app, checkAuthorisation, database) {
});
// save workspace to store cache
- app.post("/api/store", function(req, res) {
+ app.post(config_op.basepath+"api/store", function(req, res) {
// check if apikey is correct
if(!checkAuthorisation(req)) {
@@ -95,7 +95,7 @@ module.exports = function(app, checkAuthorisation, database) {
});
// delete workspace from store cache
- app.delete("/api/store", function(req, res) {
+ app.delete(config_op.basepath+"api/store", function(req, res) {
// check if apikey is correct
if(!checkAuthorisation(req)) {
diff --git a/src/server/app/auth.js b/src/server/app/auth.js
index 764da42..5623287 100644
--- a/src/server/app/auth.js
+++ b/src/server/app/auth.js
@@ -1,81 +1,81 @@
const fs = require("fs-extra");
const path = require('path');
const sha256 = require("sha256");
-const moment = require("moment");
+const moment = require("moment");
const Utility = require("../lib/utils");
const config_op = require("../../config/op.json");
-module.exports = function(app, checkAuthorisation, authenticator) {
+module.exports = function (app, checkAuthorisation, authenticator) {
// local authentication
- app.get("/login", (req, res)=> {
-
- if(config_op.agidloginAuthentication) {
+ app.get(config_op.basepath+"login", (req, res) => {
+
+ if (config_op.agidloginAuthentication) {
res.redirect(authenticator.getAuthURL());
-
+
} else {
- let user = req.query.user;
- let password = req.query.password;
-
- if((user==config_op.localloginUser && password==config_op.localloginPasswordHash)) {
+ let user = req.query.user;
+ let password = req.query.password;
+
+ if ((user == config_op.localloginUser && password == config_op.localloginPasswordHash)) {
let apikey = recLocalLoginSession(req);
res.status(200).send({ apikey: apikey });
-
+
} else {
- error = {code: 401, msg: "Unauthorized"}
+ error = { code: 401, msg: "Unauthorized" }
console.log("ERROR /auth/local : " + error.msg + " (" + user + " : " + password + ")");
res.status(error.code).send(error.msg);
- return null;
+ return null;
}
}
});
// assert if local authentication apikey or AgID Login authentication
- app.get("/login/assert", (req, res)=> {
+ app.get(config_op.basepath+"login/assert", (req, res) => {
// if autoLogin autologin with localloginUser
- if(config_op.autoLogin) recLocalLoginSession(req);
+ if (config_op.autoLogin) recLocalLoginSession(req);
- if(req.session!=null && req.session.apikey!=null && req.session.apikey!='') {
+ if (req.session != null && req.session.apikey != null && req.session.apikey != '') {
res.status(200).send({
remote: config_op.agidloginAuthentication,
apikey: req.session.apikey
});
} else {
- error = {code: 401, data: {msg: "Unauthorized", remote: config_op.agidloginAuthentication}};
+ error = { code: 401, data: { msg: "Unauthorized", remote: config_op.agidloginAuthentication } };
res.status(error.code).send(error.data);
return null;
}
});
// AgID Login authentication
- app.post("/", function(req, res, next) {
+ app.post("/", function (req, res, next) {
let state = req.body.state;
- authenticator.getUserInfo(req.body, state, (userinfo)=> {
-
+ authenticator.getUserInfo(req.body, state, (userinfo) => {
+
let userpolicy = userinfo.user_policy[0];
let entity = userpolicy.entity_id;
let policy = userpolicy.policy;
-
+
let now = moment();
- let validfrom = (userpolicy.valid_from)? moment(userpolicy.valid_from) : moment();
- let validto = (userpolicy.valid_to)? moment(userpolicy.valid_to) : moment();
+ let validfrom = (userpolicy.valid_from) ? moment(userpolicy.valid_from) : moment();
+ let validto = (userpolicy.valid_to) ? moment(userpolicy.valid_to) : moment();
let fromnow = now.diff(validfrom, 'days');
let nowto = validto.diff(now, 'days');
-
+
console.log("AgID Login USER", userinfo);
-
+
req.session.user = userinfo.email;
let apikey = sha256(userinfo.sub).toString();
req.session.apikey = apikey;
let basepath = config_op.basepath;
- if(!basepath.endsWith('/')) basepath += '/';
+ if (!basepath.endsWith('/')) basepath += '/';
res.redirect(basepath + "worksave");
-
-
- }, (error)=> {
+
+
+ }, (error) => {
Utility.log("Error", error);
res.status(500).send(error);
//res.sendFile(path.resolve(__dirname, "../..", "client/view", "error.html"));
@@ -84,23 +84,23 @@ module.exports = function(app, checkAuthorisation, authenticator) {
});
// session logout and AgID Login global logout
- app.get("/logout", (req, res)=> {
+ app.get(config_op.basepath+"logout", (req, res) => {
req.session.destroy();
- if(config_op.agidloginAuthentication) {
+ if (config_op.agidloginAuthentication) {
res.redirect(authenticator.getLogoutURL());
} else {
let basepath = config_op.basepath;
- if(!basepath.endsWith('/')) basepath += '/';
+ if (!basepath.endsWith('/')) basepath += '/';
res.redirect(basepath);
}
});
// session logout and AgID Login global logout
- app.get("/switch/:user", (req, res)=> {
+ app.get(config_op.basepath+"switch/:user", (req, res) => {
// check if apikey is correct
let authorisation = checkAuthorisation(req);
- if(!authorisation) {
- error = {code: 401, msg: "Unauthorized"};
+ if (!authorisation) {
+ error = { code: 401, msg: "Unauthorized" };
res.status(error.code).send(error.msg);
return null;
}
@@ -108,17 +108,16 @@ module.exports = function(app, checkAuthorisation, authenticator) {
let user = req.params.user;
req.session.user = user;
let basepath = config_op.basepath;
- if(!basepath.endsWith('/')) basepath += '/';
+ if (!basepath.endsWith('/')) basepath += '/';
+ res.redirect(basepath + "worksave");
- res.redirect(basepath + "/worksave");
-
});
-
+
function recLocalLoginSession(req) {
let user = config_op.localloginUser;
let passwordHash = config_op.localloginPasswordHash;
- let apikey = sha256(user + passwordHash).toString();
+ let apikey = sha256(user + passwordHash).toString();
console.log("SUCCESS /auth/local : APIKEY " + apikey);
req.session.user = user;
req.session.apikey = apikey;
diff --git a/src/server/spid-oidc-check-rp.js b/src/server/spid-oidc-check-rp.js
index 51aef00..7847eb1 100644
--- a/src/server/spid-oidc-check-rp.js
+++ b/src/server/spid-oidc-check-rp.js
@@ -29,36 +29,53 @@ let httpsCredentials;
if (useHttps) {
https = require('https');
- httpsPrivateKey = fs.readFileSync(config_server.httpsPrivateKey, 'utf8');
+ httpsPrivateKey = fs.readFileSync(config_server.httpsPrivateKey, 'utf8');
httpsCertificate = fs.readFileSync(config_server.httpsCertificate, 'utf8');
- httpsCredentials = {key: httpsPrivateKey, cert: httpsCertificate};
+ httpsCredentials = { key: httpsPrivateKey, cert: httpsCertificate };
}
var app = express();
app.use(helmet());
-app.use((req, res, next)=> {
+app.use((req, res, next) => {
console.log(".\n.\n.");
Utility.log(moment().format("YYYY-MM-DD HH:mm:ss") + " - " + req.method + " [" + req.ips.join(' - ') + "] " + req.path);
next();
});
-app.get("/", function (req, res, next) {
- if(useProxy || !config_server.basepath) {
+app.get("/", function (req, res, next) {
+ if (useProxy || !config_server.basepath) {
console.log('root base path');
return next();
}
-
let url = config_server.host;
- url += (!useProxy && httpPort)? ':' + httpPort : '';
- url += '/';
+ url += (!useProxy && config_server.port)? ':' + config_server.port : '';
+ if (config_server.basepath) {
+ if (config_server.basepath == '/') {
+ console.log('root base path');
+ return next();
+ }
+ else {
+ let basepath = config_server.basepath;
+ if (!basepath.endsWith('/')) basepath += '/';
+ url += basepath;
+ }
+ } else {
+ url += '/';
+ }
res.redirect(url);
});
-app.use(bodyParser.json({limit: '3mb', extended: true}));
-app.use(bodyParser.urlencoded({limit: '3mb', extended: true}));
-app.use(express.static(path.resolve(__dirname, "..", "client/build")));
+app.use(bodyParser.json({ limit: '3mb', extended: true }));
+app.use(bodyParser.urlencoded({ limit: '3mb', extended: true }));
+let basepath = config_server.basepath;
+if (basepath) {
+ if (!basepath.endsWith('/')) basepath += '/';
+} else {
+ basepath='/';
+}
+app.use(basepath,express.static(path.resolve(__dirname, "..", "client/build")));
app.set('trust proxy', 1);
app.use(session({
@@ -66,9 +83,9 @@ app.use(session({
secret: "OIDC CHECK RP",
resave: false,
saveUninitialized: false,
- cookie: {
- secure: config_server.useHttps? true : false,
- maxAge: 60*60000
+ cookie: {
+ secure: config_server.useHttps ? true : false,
+ maxAge: 60 * 60000
} //30*60000: 30min
}));
@@ -77,21 +94,21 @@ app.use(session({
var database = new Database().connect().setup();
// create authenticator
-var authenticator = config_op.agidloginAuthentication? new Authenticator("validator") : null;
+var authenticator = config_op.agidloginAuthentication ? new Authenticator("validator") : null;
// Private Funcs
-var checkAuth = function(req) {
+var checkAuth = function (req) {
// 'API' if checkBasicAuth = true
// true if checkSessionAuth = true
// else false
return checkBasicAuth(req) || checkSessionAuth(req);
}
-var checkSessionAuth = function(req) {
+var checkSessionAuth = function (req) {
let authorised = false;
let apikey = req.query.apikey;
- if(apikey!=null && apikey == req.session.apikey) {
+ if (apikey != null && apikey == req.session.apikey) {
authorised = true;
} else {
Utility.log("Authorisation", "ERROR check authorisation : " + apikey);
@@ -100,50 +117,50 @@ var checkSessionAuth = function(req) {
return authorised;
}
-var checkBasicAuth = function(req) {
+var checkBasicAuth = function (req) {
let authorised = false;
- if(req.headers.authorization
- && req.headers.authorization.substr(0,5)=="Basic") {
+ if (req.headers.authorization
+ && req.headers.authorization.substr(0, 5) == "Basic") {
let authorization = req.headers.authorization.substr(6);
let authorization_buffer = new Buffer(authorization, 'base64');
let authorization_plain = authorization_buffer.toString('ascii');
let user = authorization_plain.split(":")[0];
let pass = authorization_plain.split(":")[1];
- if(config_api[user]==pass) authorised = 'API';
+ if (config_api[user] == pass) authorised = 'API';
Utility.log("Authorisation API", authorization_plain);
}
return authorised;
}
/* Authentication */
-require('./app/auth') (app, checkAuth, authenticator);
+require('./app/auth')(app, checkAuth, authenticator);
/* OIDC Provider Validator */
-if(config_op.enabled) require('./app/op') (app, checkAuth, database);
+if (config_op.enabled) require('./app/op')(app, checkAuth, database);
/* OIDC Provider Demo */
//if(config_op_demo.enabled) require('./app/op_demo') (app, checkAuth, database);
/* API Validator */
-require('./api/test') (app, checkAuth);
-require('./api/metadata') (app, checkAuth, database);
-require('./api/oidc') (app, checkAuth, database);
-require('./api/store') (app, checkAuth, database);
-require('./api/info') (app, checkAuth);
-require('./api/server-info') (app);
+require('./api/test')(app, checkAuth);
+require('./api/metadata')(app, checkAuth, database);
+require('./api/oidc')(app, checkAuth, database);
+require('./api/store')(app, checkAuth, database);
+require('./api/info')(app, checkAuth);
+require('./api/server-info')(app);
// routes all to React Router
-app.get('*', (req, res)=> {
+app.get('*', (req, res) => {
console.log("Route to front-end");
- res.sendFile(path.resolve(__dirname + '/../client/build/index.html'));
+ res.sendFile(path.resolve(__dirname + '/../client/build/index.html'));
});
// start
-if(useHttps) app = https.createServer(httpsCredentials, app);
+if (useHttps) app = https.createServer(httpsCredentials, app);
app.listen(httpPort, () => {
console.log("\n" + p.name + "\nversion: " + p.version);