Automatic 404 on Unpublished Items
…worries, let's add the same admin "exception" that we've added to a few other
places. Start with public function __construct() so we can autowire the Security
service. I'll hit Alt + Enter and click "Initialized fields" to create that property
and set it…
Logout & Passing API Data to JS on Page Load
…see
that we're currently logged in. And now... gone! We are anonymous.
Before we keep going with all this API & security goodness, our app has a bug.
If we log in... as soon as the AJAX call finishes, we've made our Vue.js…
ACL & previousObject
…the owner,
access denied! We assert that in our test.
Now... I'm going to trick the security system! We're logged in as
user2@example.com but the CheeseListing we're trying to update is owned by
user1@example.com... which is why we…
Data Persister: Encoding the Plain Password
…for now: the Doctrine data persister. After deserializing
the data into a User object, running security checks and executing validation,
API Platform finally says:
It's time to save this resource!
To figure out how to save the object, it loops over all of its…
Context Builder: Dynamic Fields/Groups
…to check whether
or not a user has a role.
But wait... when we needed to do that in our voter, we autowired a different
service via the Security type-hint. Well... these are both ways to do the
exact same thing: use whichever you…
Logging in Inside the Test
…First, it deserializes the JSON into whatever resource object we're
working with - like a CheeseListing object. Second, it applies the
security access controls. And third it applies our validation rules.
Do you see the problem? It's subtle. If API Platform has any problems…
Symfony's Branching Strategy & Pull Requests
…more level of difficulty: it's time to contribute new
code with a pull request. Let's look at an issue I found:
#27835.
This comes from the Security component. Let me give you some background: if you try
to access a protected page as…
Services, Autowiring & Pushing To GitHub
…
Inside SecurityBundle, look at DependencyInjection and open SecurityExtension.php.
This class loads several XML files that provide all of the services for this bundle.
Inside the Resources/config/ directory, open security.xml. Around line 136...
yep! You'll see the services that our new service…
Symfony Flex & Aliases
…so let's demystify something else, something
that's already been happening behind the scenes. First commit everything, with a
nice message:
Let's install a new feature called the Symfony Security Checker. This is a great
tool.... but... full disclosure: we're mostly installing…
Full Mock Example
…ways... an even better and more common example.
Here's the setup: we're going to need a lot of dinosaurs, a lot of enclosures and
even more security. Instead of creating these by hand each time a new batch of
adorable dinosaurs arrives, let…
FOSUserBundle <3's Guard Authenticators
…The bundle does not provide any authentication. Open app/config/security.yml.
The form_login authentication mechanism we're using is core to Symfony itself,
not this bundle.
So, one of the questions we get a lot is: how can I use Guard authentication with…
Autowiring Deprecations
…supported in version 4.0. You should rename or
alias security.user_password_encoder.generic to ... long class name...
UserPasswordEncoder instead.
Um... what?????
This is saying that somewhere, we are type-hinting an argument with
Symfony\Component\Security\Core\Encoder\UserPasswordEncoder... but there is no…
Conditional Actions
…let's lock down the actual controller action. How? Now we know two ways:
by overriding the editAction() in UserController and adding a security check
or by adding a PRE_EDIT event listener. Let's use events!
Subscribe to a second event: EasyAdminEvents::PRE_EDIT…
Multiple Entries / Pages
…login
page... which has just a little bit of its own JavaScript: a toggleable message
and an error if you get crazy and type a super-long username.
Open up the template: app/Resources/FOSUserBundle/views/Security/login.html.twig.
Yep, it has a script…
Force HTTPS ... please
…token to our server. If that submit happens
over a non-https connection, that's a security risk: there could be somebody
in the middle reading that token. Regardless of what they might or might not be able
to do with that, we need to…
The new Voter Class
…unless I'm an
admin... who can view anyone's page. This is a classic situation where security
isn't global, it's dependent on the object being accessed. I can see my user page
but not your user page.
This is the perfect case…
Dependency Injection Extensions
…I just make something up, like journey and put a
dino_count of 10 under it:
When we refresh, we get a huge error!
And it says it found valid namespaces for framework, security, twig,
monolog, blah blah blah. Hey, those are the root keys…
After-dinner Mint
…let’s
relax a little and have some fun. In this last part, we’ll check out some
cool things related to forms and security.
Form Field Guessing¶
Remember when we disabled HTML5 validation earlier. Let’s add it back temporarily.
Remove the novalidate attribute…
Whitelisting: Securing all Pages, except a few
…
To fix this, add a new access_control entry above this for any page
starting with /login. For the role, type IS_AUTHENTICATED_ANONYMOUSLY:
# app/config/security.yml
security:
Refresh again. It works! We’re missing our styles, but we’ll fix that next.
The…
Accessing the User
…in a Controller¶
From a controller, it’s just as easy. Go to the controller function for the
homepage and grab an object called the security context. Then call getToken()
and getUser():
public function indexAction()
{
}
Actually, since this is a bit long, the Symfony base…
x
1000+