예제 #1
0
 /// <summary>
 /// Valida que la informacion proveniente de la solitud tenga todos los parametros obligatorios:
 /// AuthenticationData => Username, Password
 /// DeviceType
 /// </summary>
 /// <param name="request">Base request object</param>
 /// <returns><c>true</c> si es una petición válida, <c>false</c> en caso contrario</returns>
 private bool ValidSecureApiRequest(ASecuredApiRequest request)
 {
     return(request != null &&
            request.AuthenticationData != null &&
            !string.IsNullOrEmpty(request.AuthenticationData.Username) &&
            !string.IsNullOrEmpty(request.AuthenticationData.Password) &&
            request.DeviceType >= 0);
 }
예제 #2
0
        /// <summary>
        /// Realiza la autenticacion en la plataforma y retorna el SessionId
        /// </summary>
        /// <param name="request">Objeto que contiene las credenciales del usuario</param>
        /// <param name="response">Objeto base de respuesta</param>
        /// <param name="returnCode">Codigo de error en caso de que algo falle (-1 = OK, >-1 = Error)</param>
        /// <returns>Un <c>String</c> que contiene el <c>SessionId</c> del usuario autenticado</returns>
        protected string GetSessionId(ASecuredApiRequest request, AGenericApiResponse response, out ErrorMessagesMnemonics returnCode)
        {
            returnCode = ErrorMessagesMnemonics.None;

            string sessionId = this.GetSessionId(request, out returnCode);

            if (returnCode != ErrorMessagesMnemonics.None)
            {
                response.ResponseCode    = (int)returnCode;
                response.ResponseMessage = returnCode.ToDescription();
            }

            return(sessionId);
        }
예제 #3
0
        /// <summary>
        /// Realiza la autenticacion en la plataforma y retorna el SessionId
        /// </summary>
        /// <param name="request">Objeto que contiene las credenciales del usuario</param>
        /// <param name="returnCode">Codigo de error en caso de que algo falle (-1 = OK, >-1 = Error)</param>
        /// <returns>Un <c>string</c> que contiene el <c>SessionId</c> del usuario autenticado</returns>
        protected string GetSessionId(ASecuredApiRequest request, out ErrorMessagesMnemonics returnCode)
        {
            string methodName = string.Format("{0}", System.Reflection.MethodBase.GetCurrentMethod().Name);

            returnCode = ErrorMessagesMnemonics.None;

            this.ProviderLogger.InfoLow(() => TagValue.New()
                                        .MethodName(methodName)
                                        .Message("Obteniendo sesion ...")
                                        .Tag("Login").Value((request.AuthenticationData != null && request.AuthenticationData.Username != null) ? request.AuthenticationData.Username : "******")
                                        .Tag("DeviceType").Value(request.DeviceType)
                                        .Tag("RequestPlatformId").Value(string.IsNullOrEmpty(request.Platform) ? string.Empty : request.Platform));

            if (!this.ValidSecureApiRequest(request))
            {
                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("Imposible obtener sesion")
                                            .Tag("Login").Value((request.AuthenticationData != null && request.AuthenticationData.Username != null) ? request.AuthenticationData.Username : "******")
                                            .Tag("DeviceType").Value(request.DeviceType)
                                            .Tag("RequestPlatformId").Value(string.IsNullOrEmpty(request.Platform) ? string.Empty : request.Platform));

                returnCode = ErrorMessagesMnemonics.MissingAuthenticationInformation;
                return(string.Empty);
            }

            GetSessionResponseBody sessionResponse = new ServiceExecutionDelegator <GetSessionResponseBody, GetSessionRequestBody>()
                                                     .ResolveRequest(
                new GetSessionRequestBody()
            {
                Username   = request.AuthenticationData.Username,
                Password   = request.AuthenticationData.Password,
                DeviceType = request.DeviceType
            },
                request.Platform ?? string.Empty,
                ApiServiceName.GetSession);

            if (sessionResponse == null ||
                string.IsNullOrEmpty(sessionResponse.SessionID) ||
                sessionResponse.SessionID.Equals("0") ||
                sessionResponse.SessionID.Equals("error"))
            {
                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("Imposible obtener sesion")
                                            .Tag("Login").Value((request.AuthenticationData != null && request.AuthenticationData.Username != null) ? request.AuthenticationData.Username : "******")
                                            .Tag("DeviceType").Value(request.DeviceType)
                                            .Tag("RequestPlatformId").Value(string.IsNullOrEmpty(request.Platform) ? string.Empty : request.Platform));

                returnCode = this.MapAuthenticationErrorMessageToErrorMnemonic(sessionResponse != null ? sessionResponse.ResponseMessage : null);
                return(string.Empty);
            }
            else
            {
                this.ProviderLogger.InfoLow(() => TagValue.New()
                                            .MethodName(methodName)
                                            .Message("[" + sessionResponse.SessionID + "] " + "Sesion obtenida")
                                            .Tag("SessionId").Value(sessionResponse.SessionID));
            }

            return(sessionResponse.SessionID);
        }