Skip to content

Commit

Permalink
Update validation and policies
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyaray committed Jun 2, 2018
1 parent 7c9eb12 commit a61d08e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Follow the activities below as the semester progresses.
- [F: User Authentication and Sessions](descriptions/050_authenticate_sessions.md)
- [G: Secure Session](descriptions/055_secure_sessions.md)
- [H: Token Based Authorization](descriptions/060_token_authorization.md)
- [I: Policies and Validation](descriptions/070_policies_validation_ssl.md)
- [I: Policies and Validation](descriptions/070_policies_validation.md)
- [J: OAuth Protocol and Single-Table Inheritance](descriptions/090_oauth_protocol.md)
- [K: Signed Clients and XSS Prevention](descriptions/100_client_side_security.md)
- [L: Final Presentations](descriptions/110_final_presentation.md)
50 changes: 25 additions & 25 deletions descriptions/070_policies_validation.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# Policies and Validation

This week we will create centralized resource policies, and validate user input coming from web forms. See the latest version of our demo project:
- [Web API: auth_policy](https://github.com/ISS-Security/configshare-api/tree/6_auth_policy)
- [Web App: authorized_access](https://github.com/ISS-Security/configshare-app/tree/4_policy_validation)

1. Web App: Start creating "models" in your web application
- The `models/` folder can hold objects that convert incoming API data (arrays/hashes) back into native objects
- The demo app in class creates models for `Project`, `Projects`, `Document`, `User`, and `Session`
1. Web App: Validating Form input
- Use the `dry-validation` gem to create validation schema for your views
- Every view should have a unique schema defined by a *form object* in a new `/forms` directory
- Create custom rules if you need to compare two or more input fields
- Choose between using `dry-validation`'s messages and creating custom error messages
- Use form objects in your controllers
- Pass your `params` directly to your form objects
- Check if form validation is a `success?`
- Pass form object (not params) to service object if needed
1. Formal Policies
- API: Create policy objects in a `/policies` folder of your API
- Create at least one policy object per resource (e.g., 'ProjectPolicy', 'ConfigFilePolicy', etc.)
- Initialize policy objects with appropriate model objects (e.g., account seeking to access resource, particular resource)
- Create true/false predicate methods check for key actions (creation/deletion/updating/viewing, etc.)
- Make your predicate methods readable by using descriptive private helper methods
- Use your policy objects in each API resource route to check authorization of agent
- API: Create policy scope objects
- Scope objects should return lists of all relevant objects for a given action (e.g., `viewable`) and agents (e.g., `current_account`)
- Scope objects could evaluate permission of account requesting access
- Use your policy scope objects to retrieve list of objects to return on index routes (e.g., `/api/v1/accounts/:id/projects`)
- API + Web App: Policy summaries
- API: Create a `summary` method for each policy object that returns a hash of all predicate names and results
- API: Routes that return a resource should return a jsonified summary of its policy for the given account
- Web App: Forms should determine authorization to show links/buttons/resources based on policy summaries returned by API
3. Web App: Validating Form input
- Use the `dry-validation` gem to create validation schema for your views
- Every view should have a unique schema defined by a *form object*
- Put your form objects in a new `/forms` directory
- Create custom rules for rules that use multiple input fields
- Choose between using `dry-validation`'s messages and creating custom error messages
- Use form objects in your controllers
- Pass your `params` directly to your form objects
- See that your controllers are now using only form objects and service objects to handle all non-routing logic
- API: Create policy objects in a `/policies`
- Create at least one policy object per resource (e.g., 'ProjectPolicy', 'DocumentPolicy', etc.)
- Initialize policy objects with appropriate models (subject and object of policy)
- Create true/false predicate methods check for key actions (creation/deletion/updating/viewing, etc.)
- Make your predicate methods readable by using descriptive private predictes
- Use your policy objects in resource request routes to check authorization of account and resource
- API: Create policy scope objects
- Scope objects should return lists of all relevant objects for a given action (e.g., `viewable`) and agents (e.g., `current_account`)
- Use your policy scopes to retrieve lists of objects to return on index routes (e.g., `/api/v1/projects`)
- API + Web App: Policy summaries
- API: Create a `summary` method for each policy object that returns a hash of all predicate names and results
- API: Routes that return a resource should return a jsonified summary of its policy for the given account
- Web App: Forms should determine authorization to show links/buttons/resources based on policy summaries returned by API

0 comments on commit a61d08e

Please sign in to comment.