this.name = hash(getCurrentTemplatePath());
//variables.framework = structNew(); //
variables.framework.debugKey = "debug";
variables.framework.reloadKey = "reload";
variables.framework.reloadPassword = "true";
variables.framework.reloadOnEveryRequest = true;
variables.framework.serializer = "taffy.core.nativeJsonSerializer";
//variables.framework.serializer = "JsonUtilSerializer";
variables.framework.dashboardKey = "dashboard";
variables.framework.disableDashboard = false;
variables.framework.unhandledPaths = "/flex2gateway";
variables.framework.allowCrossDomain = true; // соответствующие заголовки, включая Access-Control-Allow-Origin выставляются только при наличии заголовка origin в реквесте
//variables.framework.allowCrossDomain = ""; // перепишем явно, возвращая Origin
variables.framework.globalHeaders = structNew();
variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location";
variables.framework.globalHeaders["Access-Control-Allow-Credentials"] = "true";
variables.framework.globalHeaders["X-Application-Version"] = "0.00.004";
//variables.framework.globalHeaders["Access-Control-Allow-Origin"] = "*"; //*** не знаю, нужно ли - но просили этот заголовок
//variables.framework.globalHeaders["X-MY-HEADER"] = "my header value for example";
//variables.framework.docs={};
variables.framework.docs.APIName="Deck API";
variables.framework.docs.APIVersion="0.004";
request.UNDEFINED_USR_ID=-1;
request.ANONYMOUS_USR_ID=2;
request.GUEST_USR_ID=3;
////////////////////////////////////////////////////////
request.ORCHESTRATOR_AUTH = createObject("java", "java.lang.System").getEnv("ORCHESTRATOR_AUTH");
if (isNull(request.ORCHESTRATOR_AUTH)) {
request.ORCHESTRATOR_AUTH = "Basic c3ZjX2xrdGVzdDoxMTgzZDIyNzc1OWExYjFkZmVjM2M3NTFiMzIyNzdiYTQ3";//*** времянка, дубль из корневого Application.cfm
}
//почему-то scope this ведет себя совершенно не так, как request и variables
// в нем переменная имеет значение Empty:null и можно выполнить writedump, а в других получаем ошибку, что такой переменной нет
--->
--->
function onTaffyRequest(verb, cfc, requestArguments, mimeExt, headers){
/* https://docs.taffy.io/#/3.5.0 */
/*
//allow white-listed requests through
if (cfc == "login"){
return true;
}
//otherwise require a device token
if (!structKeyExists(requestArguments, "deviceToken")){
return newRepresentation().noData().withStatus(401, "Authentication Required");
//and make sure it's valid
}else if (!validateToken(requestArguments.deviceToken)){
return newRepresentation().noData().withStatus(403, "Not Authorized");
}
//return representationOf(requestArguments);
//if a token is included, and valid, allow the request to continue
return true;
*/
////////////////////////////////////////////////
// самым грубым образом получаем данные от IDP, не обрабатывая исключения
//if (variables.framework.allowCrossDomain EQ "") {
//corsHeaders(); // *** нужно, чтобы variables.framework.allowCrossDomain="" иначе задвоятся заголовки
//}
//if (UCase(arguments.verb) EQ 'OPTIONS') return newRepresentation().noData().withStatus("204","No Data").withHeaders({"Content-Type":"application/json;charset=utf-8"});
if (UCase(arguments.verb) EQ 'OPTIONS') return true;
/*
var auth="";
if (structKeyExists(headers,"Authorization")) {
auth=headers.Authorization;
} else {
return representationOf("Authorization header expected").withStatus(401);
}
var httpService = new http(method = "GET", charset = "utf-8", url = "https://personal-cabinet.adl.nubes.ru/api/v1/user", timeout="3");
httpService.addParam(type = "HEADER", name = "Accept", value = "application/json");
httpService.addParam(type = "HEADER", name = "Authorization", value = "#auth#"); //passthrough
var resp = httpService.send();
var result = resp.getPrefix().filecontent;
//writeDump(result); abort;
var idpUserData=deserializeJson(result);
arguments.requestArguments.companyUid=idpUserData.companyId;
arguments.requestArguments.usrUid=idpUserData.contactId;//userId; //GUID!
var usrCustomerInfo=getUsrCustomerInfo(idpUserData.contactId);
if (structIsEmpty(usrCustomerInfo)) return representationOf("Cannot find default specification for current user #result#").withStatus(422);
arguments.requestArguments.usrId=usrCustomerInfo.usrId; //Integer!
arguments.requestArguments.specificationId=usrCustomerInfo.specificationId; //Integer
*/
return true;
////////////////////////////////////////////////////////////////////////////
//ensure https because of basic authentication
if (!lcase(request.config.environment) == "development"){
if (!cgi.server_port_secure) { return newRepresentation().noData().withStatus("403.4", "SSL Required");}
}
request.usr_id=request.UNDEFINED_USR_ID;
if (checkAuth()) {return true;}
//return representationOf(arguments.headers);
//return representationOf(arguments.cfc);
var authToken="";
if (structKeyExists(arguments.headers,"x-auth-token")) {authToken=structFind(arguments.headers,"x-auth-token");}
var issuedFor="";
if (structKeyExists(arguments.headers,"x-issued-for")) {issuedFor=structFind(arguments.headers,"x-issued-for");}
if (validatePin(authToken,issuedFor, arguments.verb, arguments.cfc)) return true; //side effect: sets request.usr_id!
if (!validateCredentials(getBasicAuthCredentials())) {
return newRepresentation().noData().withStatus("401", "Invalid Credentials").withHeaders({"WWW-Authenticate":"Basic realm=mms-api"});
}
return true;
}
//private function validateToken(token){ return false; }
//refactoring required
private function validateCredentials(credentials) {//return true;
if (arguments.credentials.username == "medved" /*AND credentials.password == "ghtdtlrhjcfdxtu!Y"*/) {
request.usr_id=-3;
return true;
}
return false;
}
select creator_id
from auth_token
where auth_token=
AND issued_for=
AND dt_valid_till >
select usr_id from usr where login=
#cfcatch.message# : #cfcatch.detail#
#cfcatch.message# : #cfcatch.detail#
select u.usr_id, s.specification_id
from usr u
join contract c on (u.contragent_id=c.contragent_id)
join specification s on (c.contract_id=s.contract_id)
where idp_usr_uid=
order by specification_id desc limit 1;
#local.resultSerialized#
Request Details: