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.docs={};
variables.framework.docs.APIName="Deck API";
variables.framework.docs.APIVersion="0.031";
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"] = variables.framework.docs.APIVersion;
//variables.framework.globalHeaders["Access-Control-Allow-Origin"] = "*";
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";//*** времянка, дубль из deck/Application.cfm
}
//*** почему-то scope this ведет себя совершенно не так, как request и variables
// в нем, когда переменная получает значение Empty:null, можно выполнить writedump, а в других получаем ошибку, что такой переменной нет
request.locateIamService=locateIamService; //for possible debug
//request.IAM_SERVICE_URL=this.iamServiceUrl;
--->
--->
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;
if (lCase(arguments.cfc) EQ 'err') return true;
var auth="";
if (structKeyExists(headers,"Authorization")) {
auth=headers.Authorization;
} else {
return representationOf("Authorization header expected").withStatus(401);
}
try {
var httpService = new http(method = "GET", charset = "utf-8", url = #this.iamServiceUrl#, 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;
if (resp.responseheader.status_code NEQ 200) throw("IDP response not OK");
} catch (e) {
if (fileExists("#GetDirectoryFromPath(GetCurrentTemplatePath())#/etc/local-debug")) { //true for local debug without IDP, etc/* does not go to repository
var result='{"accounts":[{"login":"","type":"telegram"}],"avatar":["d2d2b7ac-50af-432b-b7c4-f7d6561e288a"],"company":"ООО «НУБЕС»","companyId":"8ec70ac0-546d-42a7-8cff-339c8fb51a23","contactId":"983967a3-58c2-4cdd-84a5-8b427ccfac82","email":"smishchuk@nubes.ru","externalUser":false,"fio":{"fullName":"Мищук Сергей ","name":"Сергей","secondName":"","surname":"Мищук"},"groupIds":["94bf5be7-52f4-5c13-87c3-513786934685","ab12b6b8-0265-4683-a5c2-5e1a74a55216","aff008c3-7443-50f6-86e1-ecff3cd3b04d","d6000da0-c9aa-55eb-9882-f118b432730b","d89a33dc-3177-5854-9580-f7f860a5ab7c","ddfe2555-9ef4-42cb-9a2b-7f24e61e7747","df12926f-ecb8-5479-857f-6d291464baad","fda5c295-230a-5025-9797-b8b4e99e08aa","2be9b4b6-94d1-59f9-a649-cab228d82169","64fe6f5c-a91b-5fea-a7ca-d9823701ebd4"],"integration":{"serviceId":""},"login":"smishchuk@nubes.ru","mobilePhone":[],"position":"","userId":"d72530e1-66a4-412f-a046-38153c4e5405"}';}
}
//writeDump(result); abort;
try {
var idpUserData=deserializeJson(result);
arguments.requestArguments.companyUid=idpUserData.companyId;//GUID!
arguments.requestArguments.usrUid=idpUserData.contactId;//userId; //GUID!
} catch (e) {
return representationOf( {"exception"=e, "idpResponse"=result} );
}
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: