internal static GetSessionResponse GetSession(GetSessionRequest getSessionRequest) { LoginRequestInternal loginRequest = new LoginRequestInternal() { User = getSessionRequest.Request.User, Password = getSessionRequest.Request.Password, DeviceType = getSessionRequest.Request.DeviceType }; LoginResponseInternal loginResponse = AuthenticationProvider.LoginInternal(loginRequest); GetSessionResponse getSessionResponse = new GetSessionResponse(); GetSessionResponseBody getSessionResponseBody = new GetSessionResponseBody() { ResponseCode = loginResponse.ResponseCode, ResponseMessage = loginResponse.ResponseMessage, SessionID = loginResponse.SessionID, TransactionID = loginResponse.TransactionID }; getSessionResponse.Response = getSessionResponseBody; return(getSessionResponse); }
public override IMovilwayApiResponse PerformUtibaOperation(IMovilwayApiRequest requestObject, UMarketSCClient utibaClientProxy, String sessionID) { GetSessionRequestBody request = requestObject as GetSessionRequestBody; GetSessionResponseBody response = null; createsessionResponse newSessionResponse = utibaClientProxy.createsession(new createsession()); String PIN = Utils.GenerateHash(newSessionResponse.createsessionReturn.sessionid, request.Username, request.Password); logger.InfoLow("[UTI] " + base.LOG_PREFIX + "[GetSessionProvider] [SEND-DATA] loginRequest {sessionid=" + newSessionResponse.createsessionReturn.sessionid + ",device_type=" + request.DeviceType + ",initiator=" + request.Username + ",pin=" + PIN + "}"); loginResponse loginResponse = utibaClientProxy.login(new login() { loginRequest = new loginRequestType() { sessionid = newSessionResponse.createsessionReturn.sessionid, device_type = request.DeviceType, initiator = request.Username, pin = PIN } }); logger.InfoLow("[UTI] " + base.LOG_PREFIX + "[GetSessionProvider] [RECV-DATA] loginResponse {result=" + loginResponse.loginReturn.result + ",result_namespace=" + loginResponse.loginReturn.result_namespace + "}"); response = new GetSessionResponseBody() { ResponseCode = Utils.BuildResponseCode(loginResponse.loginReturn.result, loginResponse.loginReturn.result_namespace), ResponseMessage = loginResponse.loginReturn.result_message, TransactionID = loginResponse.loginReturn.transid, SessionID = newSessionResponse.createsessionReturn.sessionid }; if (response.ResponseCode == 0) { if (ConfigurationManager.AppSettings["ProcessMigration"].ToLower() == "true") { //logger.InfoHigh("Comienza la migración del usuario: " + request.AuthenticationData.Username); bool migrateAgent = MigrateAgent(request.AuthenticationData.Username); int deviceType = GetDeviceType(request.AuthenticationData.Username); if (migrateAgent) { // Cambio de password Kinacu var changePinResponse = new ServiceExecutionDelegator <ChangePinResponseBody, ChangePinRequestBody>().ResolveRequest( new ChangePinRequestBody() { AuthenticationData = new AuthenticationData() { Username = request.AuthenticationData.Username, Password = ConfigurationManager.AppSettings["StandardOldPin"] }, DeviceType = deviceType, /*int.Parse(ConfigurationManager.AppSettings["StandardNewDeviceType"]),*/ Agent = request.AuthenticationData.Username, OldPin = ConfigurationManager.AppSettings["StandardOldPin"], NewPin = request.AuthenticationData.Password }, ApiTargetPlatform.Kinacu, ApiServiceName.ChangePin); // Login con Kinacu - NOT NOW - La proxima vez que entre va por Kinacu de una //logger.InfoHigh("Resultado del cambio de clave del usuario: " + changePinResponse.ResponseCode); // Save in DB if (changePinResponse.ResponseCode == 0) { //logger.InfoHigh("Se migró exitosamente la clave del usuario: " + request.AuthenticationData.Username); SaveAgentMigrated(request.AuthenticationData.Username); } } } // REPG2013 - esto queda deshabilitado por ahora // For speeding up, I'm caching the session value: //-var couchBaseClient = new CouchbaseClient(); //-couchBaseClient.Store(StoreMode.Set, Utils.GetSessionForUserKey(request.Username, request.Password), response.SessionID, new TimeSpan(0, UtibaUtils.SessionTTL, 0)); // Also caching the //-couchBaseClient.Store(StoreMode.Set, Utils.GetUserForSessionKey(response.SessionID), request.Username, new TimeSpan(0, UtibaUtils.SessionTTL, 0)); } return(response); }
public IMovilwayApiResponse PerformOperation(IMovilwayApiRequest requestObject) { try { //validar una vez la ip //ASecuredApiRequest securityrequest = null; GetSessionResponseBody responseBody = null; switch (_securemode) { case ApiSecurityMode.CREDENTIALS: //securityrequest = Reflection.FactoryObject<ASecuredApiRequest>(typeof(ASecuredApiRequest)); //securityrequest.AuthenticationData = new AuthenticationData(); //securityrequest.AuthenticationData.Username = requestObject.AuthenticationData.Username; //securityrequest.AuthenticationData.Password = requestObject.AuthenticationData.Password; //securityrequest.AuthenticationData.SessionID = requestObject.AuthenticationData.SessionID; //securityrequest.AuthenticationData.Tokken = requestObject.AuthenticationData.Tokken; responseBody = new ServiceExecutionDelegator <GetSessionResponseBody, IMovilwayApiRequest>().ResolveRequest( requestObject , _target, ApiServiceName.GetSession); break; case ApiSecurityMode.USER: //securityrequest = Reflection.FactoryObject<ASecuredApiRequest>(typeof(ASecuredApiRequest)); //securityrequest.AuthenticationData = new AuthenticationData(); //securityrequest.AuthenticationData.Username = requestObject.AuthenticationData.Username; //securityrequest.AuthenticationData.Password = requestObject.AuthenticationData.Password; //securityrequest.AuthenticationData.SessionID = string.Empty; //securityrequest.AuthenticationData.Tokken = string.Empty; responseBody = new ServiceExecutionDelegator <GetSessionResponseBody, IMovilwayApiRequest>().ResolveRequest( requestObject , _target, ApiServiceName.GetSession); break; } if (responseBody.ResponseCode == 0)//&& tokken es valido { // si la validacion es segura return(_serviceImpl.PerformOperation(requestObject)); } else { IMovilwayApiResponse response = Reflection.FactoryObject <IMovilwayApiResponse>(_typeresponse); response.ResponseCode = 90; response.ResponseMessage = responseBody.ResponseMessage; //"ERROR DE SEGURIDAD DATOS ASOCIADOS AL TOKKEN INVALIDO"; return(response); } } catch (Exception ex) { //TODO DESHABILITAR LA EJECUCION DE EST HANDLER IMovilwayApiResponse response = Reflection.FactoryObject <IMovilwayApiResponse>(_typeresponse); response.ResponseCode = 500; response.ResponseMessage = "ERROR INESPERADO EJECUTANDO SECUREPROVIDER"; logger.ErrorHigh(String.Concat(response.ResponseCode, "-", response.ResponseMessage, " ", ex.Message, "-.", ex.StackTrace)); return(response); } }
public override IMovilwayApiResponse PerformKinacuOperation(IMovilwayApiRequest requestObject, SaleInterface kinacuWS, String sessionID) { GetSessionResponseBody response = null; //TODO APLICAR CACHE GetSessionRequestBody request = requestObject as GetSessionRequestBody; response = new GetSessionResponseBody(); if ( request.AuthenticationData == null || ( String.IsNullOrEmpty(request.AuthenticationData.Username) || String.IsNullOrEmpty(request.AuthenticationData.Password) ) ) { response.ResponseCode = 90; response.ResponseMessage = "DATOS DE AUTENTICACIÓN INVALIDOS"; response.TransactionID = 0; response.SessionID = ""; return(response); } string result = ""; #region comentarioanteriores /* * var cacheObj = new LoginDataCache(); * ObjectCache cache = MemoryCache.Default; * var cacheKey = request.AuthenticationData.Username + request.Platform; * * //logger.InfoLow("en el cache tengo " + cache.Count()); * if (cache.Contains(cacheKey)) * { * kinacuWS.LogOff(int.Parse(((LoginDataCache)cache.Get(cacheKey)).Token)); * //logger.InfoLow("ya hicimos logoff de " + ((LoginDataCache)cache.Get(cacheKey)).Token); * cache.Remove(cacheKey); * }*/ #endregion logger.InfoLow("[KIN] " + base.LOG_PREFIX + "[GetSessionProvider] [SEND-DATA] loginParameters {accessId=" + request.AuthenticationData.Username + ",password=******,accessType=" + request.DeviceType + "}"); int newSessionResponse = kinacuWS.Login(request.AuthenticationData.Username, request.AuthenticationData.Password, request.DeviceType, out result); logger.InfoLow("[KIN] " + base.LOG_PREFIX + "[GetSessionProvider] [RECV-DATA] loginResult {response=" + newSessionResponse + ",result=" + result + "}"); var myResponseCode = newSessionResponse != 0 ? 0 : GetResponseCode(result); response = new GetSessionResponseBody() { ResponseCode = myResponseCode, TransactionID = 0, SessionID = myResponseCode.Equals(1013) ? "1013" : newSessionResponse.ToString() }; if (newSessionResponse == 0) { response.ResponseMessage = result; } #region comentarioanteriores //if (response.ResponseCode == 0) //{ // REPG2013 - esto queda deshabilitado por ahora /* * var newCacheObject = new LoginDataCache() * { * UserName = request.AuthenticationData.Username, * Platform = request.Platform, * Token = response.SessionID * }; * // Store data in the cache * var cacheMinutes = ConfigurationManager.AppSettings["UtibaSessionTTL"] ?? "10"; * var cacheItemPolicy = new CacheItemPolicy { AbsoluteExpiration = DateTime.Now.AddSeconds(Convert.ToInt32(cacheMinutes) * 1000) }; * //cache.Add(cacheKey, newCacheObject, cacheItemPolicy); * cacheObj = newCacheObject; * logger.InfoLow("ya guarde en cache"); */ //} #endregion return(response); }