Esempio n. 1
0
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new SecurityApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath = "WordProcessing/password-protected.docx"
                };

                var request  = new CheckPasswordRequest(fileInfo.FilePath);
                var response = apiInstance.CheckPassword(request);

                Console.WriteLine("Check password: "******"Exception while calling api: " + e.Message);
            }
        }
        /**
         * Check password.
         */
        public async Task <APIGatewayProxyResponse> CheckPassword(IDataStores dataStores,
                                                                  IDictionary <string, string> requestHeaders,
                                                                  JObject requestBody)
        {
            Debug.Untested();
            Debug.AssertValid(dataStores);
            Debug.AssertValid(requestHeaders);
            Debug.AssertValid(requestBody);

            try {
                // Log call
                LoggingHelper.LogMessage($"UserIdentityService::CheckPassword()");

                // Get the NoSQL DB client
                AmazonDynamoDBClient dbClient = (AmazonDynamoDBClient)dataStores.GetNoSQLDataStore().GetDBClient();
                Debug.AssertValid(dbClient);

                // Check inputs
                CheckPasswordRequest checkPasswordRequest = UserIdentityService_CheckPassword_LogicLayer.CheckValidCheckPasswordRequest(requestBody);
                Debug.AssertValid(checkPasswordRequest);

                // Check authenticated endpoint security
                string loggedInUserId = await APIHelper.CheckLoggedIn(dbClient, requestHeaders);

                Debug.AssertID(loggedInUserId);

                // Perform logic
                await UserIdentityService_CheckPassword_LogicLayer.CheckPassword(dbClient, checkPasswordRequest, loggedInUserId);

                // Respond
                return(new APIGatewayProxyResponse {
                    StatusCode = APIHelper.STATUS_CODE_OK
                });
            } catch (Exception exception) {
                Debug.Tested();
                if ((exception.Message == IdentityServiceLogicLayer.ERROR_INCORRECT_PASSWORD) ||
                    (exception.Message == IdentityServiceLogicLayer.ERROR_USER_BLOCKED) ||
                    (exception.Message == IdentityServiceLogicLayer.ERROR_USER_LOCKED))
                {
                    Debug.Untested();
                    //??--GeneralErrorResponse response = new GeneralErrorResponse();
                    string error = null;
                    if (exception.Message == IdentityServiceLogicLayer.ERROR_INCORRECT_PASSWORD)
                    {
                        Debug.Tested();
                        error = IdentityServiceLogicLayer.INCORRECT_PASSWORD;
                    }
                    else if (exception.Message == IdentityServiceLogicLayer.ERROR_USER_BLOCKED)
                    {
                        Debug.Tested();
                        error = IdentityServiceLogicLayer.USER_BLOCKED;
                    }
                    else if (exception.Message == IdentityServiceLogicLayer.ERROR_USER_LOCKED)
                    {
                        Debug.Tested();
                        error = IdentityServiceLogicLayer.USER_LOCKED;
                    }
                    //??-- ObjectResult result = new ObjectResult(response);
                    // result.StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED;
                    // return result;
                    return(new APIGatewayProxyResponse {
                        StatusCode = APIHelper.STATUS_CODE_UNAUTHORIZED,
                        Body = $"{{ error = \"{error}\"}}"
                    });
                }
                else
                {
                    Debug.Tested();
                    return(APIHelper.ResponseFromException(exception));
                }
            }
        }