Adding Battle Validation
…client
from starting a battle with a Programmer that they do not own? Right now - nothing,
besides karma and trusting that humankind will do the right thing. Unfortunately,
that doesn't usually pass a security audit. Let's be heros and fix this security hole!
EntityType Validation: Restrict Invalid programmerId
…the custom query builder. Now, if someone passes a programmer id that we
do not own, the EntityType will automatically cause a validation error. Security
is built-in.
Head back to the terminal to try it!
Awesome! Well, it failed - but look! It's just…
Exposing more Error Details
…client, but we absolutely don’t want to expose any of our
internals. Make sure whatever logic you use here is very solid. #security
Even our logic is a bit loose. For example, if we go to a URL that just
doesn’t exist, the…
Complex Symfony2 Examples: Users, Menus, CMS Features
…Depending on your preference, you will
probably either use the popular FOSUserBundle or implement this yourself
by following our How to load Security Users from the Database cookbook entry.
In either case, creating a system with “groups” and “permissions” is very possible,
where a user…
Saving Users
…strange, but stay with me. First, we ask Symfony for a
special “encoder” object that knows how to encrypt our passwords. Remember
the bcrypt config we put in security.yml? Yep, this object will use that.
After we grab the encoder, we just call encodePassword()…
Adding Dynamic Roles to each User
…exists, but it’s not actually used during login.
To make this work, change the User class to implement
AdvancedUserInterface
instead of UserInterface:
// src/Yoda/UserBundle/Entity/User.php
// ...
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
class User implements AdvancedUserInterface
{
}
Tip
For the OO geeks…
User Serialization
…
Clearly that’s not the case: Symfony’s security system is smart enough to
take the id and query for a full fresh copy of the User object on each
request.
We can see this right in the web debug toolbar: once a user is…
Validation Constraints
…s no Flex alias for this. So instead, install the actual package
symfony/security-csrf:
As soon as that package is installed, CSRF protection is enabled for
all Symfony forms by default making your forms more secure out of the box.
You can see this…
React Admin
…things are going
to empower you no matter what API you're building. In the next tutorial, we'll talk
about users, security, custom validation, user-specific fields and other wild stuff.
Let us know what you're building and, if you have any questions…
New PUT Behavior
…security standpoint as we now need to worry about objects
being edited or created via the same PUT operation. For that reason, as we go
along, you'll see me remove the PUT operation in some cases.
Next: let's get more complex with security…
Global vs CRUD-Specific Configuration
…day, the actions in our controller are real
actions that are called like any normal action. And second, this is important for
security. Because if we had only put the IsGranted above index() and not
added the access_control, that would not have been enough…
Strategy Part 2: Benefits & In the Wild
…I'm on the Symfony repository. Hit "t"
and search for JsonLoginAuthenticator. This is the code behind the json_login
security authenticator. One common need with the JsonLoginAuthenticator
is to use it like normal... but then take control of what happens on success: for
example…
Checkout Products
…paste... and we can use any future expiration date for
now. I'll say "12/25", and use any three numbers for the security code. This
also requires us to enter a billing address. If we try to click "Buy" without
one, we get a…
404 On Unpublished Items
…if you're allowed to edit or delete a
treasure... that means you've already passed a security check... so we don't
necessarily need to lock things down via this query extension.
The other solution is to change the query to allow owners to…
Validating how Values Change
…Oh, and though I didn't do
it, we could also inject the Security service to allow admin users to do
whatever they want.
Up next: when we create a DragonTreasure, we must send the owner field.
Let's finally make that optional. If we…
Other Conditional Field Strategies
…you would need to turn
it into a UserApiRead and return that.
Anyway, that's definitely more advanced, but if it's interesting, and you try it,
let me know!
Next up: Let's polish our new API resource by re-adding validation and security.
MicroMapper: Central DTO Mapping
…your browser, refresh this page, and... oh...
Full authentication is required to access this resource.
Of course. That's because we added security! Head back over to the homepage,
click this username and password shortcut... boop... and now try to refresh
that page. It works…
Dtos, Mapping & Max Depth of Relations
…getValues() and refresh the page... perfect! We're
back to a regular array of items.
Next: We can read from our new DragonTreasureApi resource, but we can't write to
it yet. Let's create a DragonTreasureApiToEntityMapper and re-add things like
security and validation.
Post-Rector Cleanups & Tweaks
…we need to call ->hashPassword() instead of ->encodePassword().
Done!
Just one more spot where we need this same change:
src/Security/LoginFormAuthenticator.php. We're going to refactor this class later
to use the new security system... but let's at least get it working…
Verifying the Signed Confirm Email URL
…prevent the user from logging in until they've
verified their email. To do that, we first need to learn about the events that happen
inside of the security system. And to show off those, we'll leverage a really
cool new feature: login throttling…
x
1000+