public ActionResult <Boolean> Patch([FromRoute] Guid packageId, [FromRoute] String objectType) { // Do the authentication process with the given request and helpers // to determine the result ApiAuthenticationResult authResult = WebAuthHelper.AuthenticateApiRequest( packageId, objectType, SessionHandler.PackageRepository, Request ); // Everything work ok? Then continue to the important bits if (authResult.StatusCode != HttpStatusCode.OK) { return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription)); } // Get the body of the request from the stream String body = HttpRequestHelper.GetBody(Request); if (body == String.Empty) { return(StatusCode((Int32)HttpStatusCode.BadRequest, "Request body contained no data")); } // Got to the end so must be ok return(StatusCode((Int32)HttpStatusCode.OK, "")); }
public AuthenticationResult AuthenticateSpecificUser(Login login) { var authenticationResult = new ApiAuthenticationResult { LoginStatus = UserLoginStatus.NotSupportedLoginType }; if (login.GetType() == typeof(ApiUserLogin)) { authenticationResult.LoginStatus = UserLoginStatus.ValidUser; } return(authenticationResult); }
public ActionResult <Boolean> Get([FromRoute] Guid packageId, [FromRoute] String objectType) { // Do the authentication process with the given request and helpers // to determine the result ApiAuthenticationResult authResult = WebAuthHelper.AuthenticateApiRequest( packageId, objectType, SessionHandler.PackageRepository, Request ); // Everything work ok? Then continue to the important bits if (authResult.StatusCode == HttpStatusCode.OK) { // Use the api definition to get the data connection and // definition from the package and then try to connect IDataProvider provider = providerFactory.Get( authResult.Package, authResult.Package.DataConnection(authResult.ApiDefinition.DataConnection), authResult.Package.DataDefinition(authResult.ApiDefinition.DataDefinition), true); // Are we connected? if (provider.Connected) { // Return the data with the appropriate filter DataTable results = provider.Read(authResult.Permissions.Filter); // Manage any aliases for the results table ManagedApiHelper.HandleAliases(results, authResult.ApiDefinition.Aliases); // Format the data table as Json return(ManagedApiHelper.ToJson(results)); } else { return(StatusCode((Int32)HttpStatusCode.InternalServerError, "Could not connect to the data source")); } } else { return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription)); } }
public override ApiAuthenticationResult Authenticate(LoginParameters LoginParameters) { ApiAuthenticationResult authenticationResult = new ApiAuthenticationResult(); try { if (!LoginParameters.ContainsValue(XafXpoLoginFunction.XafId)) { throw new ArgumentException("Missing XafId on LoginParameters"); } var XafDal = this.XpoInitializerResolver.GetById(XafId); var UoW = XafDal.CreateUnitOfWork(); var User = UoW.FindObject <PermissionPolicyUser>(new BinaryOperator("UserName", LoginParameters.Username)); if (User == null) { authenticationResult.LastError = "User not found"; return(authenticationResult); } if (!User.ComparePassword(LoginParameters["Password"]?.ToString())) { authenticationResult.LastError = "Password do not match"; return(authenticationResult); } authenticationResult.Authenticated = true; authenticationResult.UserId = User.Oid.ToString(); authenticationResult.Username = User.UserName; authenticationResult.Add("Token", this.tokenBuilder.BuildToken(LoginParameters)); return(authenticationResult); } catch (Exception exception) { authenticationResult.LastError = $"{exception.Message}{System.Environment.NewLine}{exception.StackTrace}"; return(authenticationResult); } }
public ActionResult <Boolean> Delete([FromRoute] Guid packageId, [FromRoute] String objectType) { // Do the authentication process with the given request and helpers // to determine the result ApiAuthenticationResult authResult = WebAuthHelper.AuthenticateApiRequest( packageId, objectType, SessionHandler.PackageRepository, Request ); // Everything work ok? Then continue to the important bits if (authResult.StatusCode == HttpStatusCode.OK) { return(StatusCode((Int32)HttpStatusCode.OK, "")); } else { return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription)); } }
public static bool IsInRole(this ApiAuthenticationResult authenticationResult, string roleName) { var roles = authenticationResult.User.FindAll("https://schemas.2wradmin.com/role"); return(roles.Any(r => r.Value == roleName)); }
public ActionResult <Boolean> Post([FromRoute] Guid packageId, [FromRoute] String objectType) { // Do the authentication process with the given request and helpers // to determine the result ApiAuthenticationResult authResult = WebAuthHelper.AuthenticateApiRequest( packageId, objectType, SessionHandler.PackageRepository, Request ); // Everything work ok? Then continue to the important bits if (authResult.StatusCode != HttpStatusCode.OK) { return(StatusCode((Int32)authResult.StatusCode, authResult.StatusDescription)); } // Get the body of the request from the stream String body = HttpRequestHelper.GetBody(Request); if (body == String.Empty) { return(StatusCode((Int32)HttpStatusCode.BadRequest, "Request body contained no data")); } // Translate the body try { DataTable data = null; // Parse the body to a queryable Json Object (bad formatting will fail it) data = ManagedApiHelper.ToDataTable( Request.ContentType.Trim().ToLower(), body, authResult.ApiDefinition, authResult.DataDefinition); // Did we get some data from the conversion (depending on the type format) if (data != null) { // Use the api definition to get the data connection and // definition from the package and then try to connect IDataProvider provider = providerFactory.Get( authResult.Package, authResult.Package.DataConnection(authResult.ApiDefinition.DataConnection), authResult.Package.DataDefinition(authResult.ApiDefinition.DataDefinition), true); // Are we connected? if (provider.Connected) { // Return the data with the appropriate filter // DataTable results = provider.Read(authResult.Permissions.Filter); if (provider.Write(data, "")) { } else { return(StatusCode((Int32)HttpStatusCode.InternalServerError, "Could not write the data")); } } else { return(StatusCode((Int32)HttpStatusCode.InternalServerError, "Could not connect to the data source")); } } else { return(StatusCode((Int32)HttpStatusCode.BadRequest, "Request body contained no valid data or the format was incorrect")); } } catch (Exception ex) { return(StatusCode((Int32)HttpStatusCode.BadRequest, $"Malformed body content in request ({ex.Message})")); } // Got to the end so must be ok return(StatusCode((Int32)HttpStatusCode.OK, "")); }