sap.ui.define([
"sap/m/routing/Router"
], function (Router) {
"use strict";
return Router.extend("be.canoas.fiori.RoutingPathObfuscation.util.customRouter", {
// redefine constructor, to initialize private attribute(s)
constructor: function (oRoutes, oConfig, oOwner, oTargetsConfig) {
// initialize private attribute _bRoutingPathObfuscation
// _bRoutingPathObfuscation is only to be used in demo app (not needed in real project)
this.setRoutingPathObfuscation(false);
// define _obfuscate/_deobfuscate methods as properties of private attribute _oParameterHandler
this._oParameterHandler = {};
this._oParameterHandler._obfuscate = function (sString) {
if (!this._bState) {
this._bState = true;
// base64 encoding; alternative: perform ajax call to achieve stronger encryption
return window.btoa(sString);
} else {
return sString;
}
};
this._oParameterHandler._deobfuscate = function (sString) {
if (this._bState) {
this._bState = false;
// base64 decoding; alternative: perform ajax call to achieve stronger decryption
return window.atob(sString);
} else {
return sString;
}
};
// call super
Router.prototype.constructor.call(this, oRoutes, oConfig, oOwner, oTargetsConfig);
},
// getter method for private attribute _bRoutingPathObfuscation
// _bRoutingPathObfuscation is only to be used in demo app (not needed in real project)
getRoutingPathObfuscation: function () {
return this._bRoutingPathObfuscation;
},
// setter method for private attribute _bRoutingPathObfuscation
// _bRoutingPathObfuscation is only to be used in demo app (not needed in real project)
setRoutingPathObfuscation: function (bState) {
this._bRoutingPathObfuscation = bState;
},
// method to process parameters
_processParameters: function (oParameters, sFunctionName) {
// _bRoutingPathObfuscation is only to be used in demo app (not needed in real project)
if (this._bRoutingPathObfuscation) {
for (var name in oParameters) {
if ({}.hasOwnProperty.call(oParameters, name)) {
oParameters[name] = this._oParameterHandler[sFunctionName](oParameters[name]);
}
}
}
return oParameters;
},
// redefine navTo method, for outbound part of navigation
navTo: function (sName, oParameters, bReplace) {
// obfuscate parameters
var oChangedParameters = this._processParameters(oParameters, "_obfuscate");
// call super
Router.prototype.navTo.call(this, sName, oChangedParameters, bReplace);
},
// redefine fireBeforeRouteMatched method, for inbound part of navigation
// (called only if target needs to be loaded and placed)
fireBeforeRouteMatched: function (oEventData) {
// deobfuscate parameters
var oChangedParameters = this._processParameters(oEventData.arguments, "_deobfuscate");
oEventData.arguments = oChangedParameters;
// call super
Router.prototype.fireBeforeRouteMatched.call(this, oEventData);
},
// redefine fireRouteMatched method, for inbound part of navigation
// (called in any case if a route matches the URL hash)
fireRouteMatched: function (oEventData) {
// deobfuscate parameters
var oChangedParameters = this._processParameters(oEventData.arguments, "_deobfuscate");
oEventData.arguments = oChangedParameters;
// call super
Router.prototype.fireRouteMatched.call(this, oEventData);
}
// don't need to redefine fireRoutePatternMatched method, as it is expected to always be triggered
// after either fireBeforeRouteMatched or fireRouteMatched, which means that at this point
// deobfuscation of parameters has already occurred
// don't need to redefine fireBypassed method, as it is not expected to be triggered
// after a call of navTo method, but rather after a manual change of the URL hash (without a
// route being associated to it)
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |