Given that it’s the day after Thanksgiving, most of the team is still dusting off a turkey hangover and because of that we’re a bit short on links.
We hope everyone had a great Thanksgiving and we’ll be back next week!
Given that it’s the day after Thanksgiving, most of the team is still dusting off a turkey hangover and because of that we’re a bit short on links.
We hope everyone had a great Thanksgiving and we’ll be back next week!
With Symfony2 the firewall comes with a built in feature: impersonate a user. We’ve been using impersonation as an admin tool for about 5 years as it is very effective for troubleshooting. When a user files a support ticket saying something isn’t showing properly to them or they are getting random errors it is very easy to just quickly switch to that user and see what they are seeing. As with all features, this one may not be appropriate for your application if your user expects no administrative staff to have access to his or her account.
While Symfony’s built in impersonation feature is a great step up from having to build it by hand, it still can be a bit more friendly. We’ve seen two additional functions we wanted the impersonation to handle. First, we wanted it to on exit from impersonating the user returns the user to where the user first started to impersonating. Currently it just brings you back to wherever you link the user. Second, if already impersonating a user and trying to start to impersonate another, we didn’t want it to throw an error but to quietly switch you. This functionality could lead to unwanted circumstances if an impersonating user believes they can impersonate another user, and then slowly just keep exiting impersonation of each user and go back up the chain they went down. However, in our situation the time admins hit this was when they’d impersonate one user, realize they clicked the wrong one, click back and try to impersonate a different user. As the browser uses it’s cached page when the user hits back they see the list of users as if they were an admin and can click on the correct user. If they do this they are hit with a 500 error, “You are already switched to X user”.
For both of our goals we overrode the built in switch user class. It is really easy to override, as all you need to do is specify in your parameters.yml “security.authentication.switchuser_listener.class: My\AppBundle\Listener\SwitchUser”. We used the built in class as our starting template: https://github.com/symfony/symfony/blob/2.5/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php Our final class ended looking like:
Here are the specifics on what everything we did and why.
First feature: Redirecting the user on exiting impersonating a user to where they originally started impersonating them. As we didn’t want to go around our entire application updating logic for the exit impersonation links if we decided to later change the behavior, we decided to build the redirect into the class itself. We didn’t want to rely on the user’s browser referrer header, so instead we decided to on the links to impersonate a user to include a “returnTo” parameter. This parameter is set to the current URI (app.request.uri). At line 97 we save the returnTo parameter to the session, for later use. On line 93, as a user is switching (in this case exiting) a user, if the session has a stored “returnTo” URL, we assign it to the “$overrideURI” variable. On line 107 we have a bit of logic on if we redirect them to the default route or the “returnTo” URL. The reason for the additional “$this->useOverrideURI” variable on this line is for our second feature of switching between users when you are already impersonating one. As the logic all runs through the same routine, if you are simply switching to a new user from an already impersonated one, we don’t want to redirect you back to your original URL when you started all the impersonating, so we disregard the redirect in this case and redirect to the default route. An example of this is admin impersonates user A, then wants to impersonate user B. Upon impersonating user B, the admin does not want to be redirected back to the admin dashboard (the sessions returnTo URL), but to where the impersonate user link is pointing to (User B homepage).
Second feature: Allow users to impersonate a different user while already impersonating another. One Line 134 is where the original SwitchUserListener would usually throw a 500 error as you are already impersonating a user. Instead, we make sure that the original token has the appropriate permissions, if so it will not throw an exception. Line 159 is the other main update for this feature. If you are already impersonating a user and try to impersonate another user, upon exiting you want to go back to your original user. Now if a original impersonation token (user) exists, we keep that as the user you’ll be switched to when you exit the impersonation.
It’s Friday and we have links! Grab some coffee (or a beer) because some of these are going to be a time sink.
Enliven your creative projects with millions of unlimited downloadable content at the touch of a mouse on VideoBlocks.com. Check it out >
A small command-line program, youtube-dl lets users download videos from Youtube and other sites. The only requirement though is Python interpreter. Grab it now >
At the re:Invent conference in Las Vegas this year, James Hamilton, vice president and distinguished engineer for Amazon Web Services (AWS), gave conference attendees a broad but insightful glimpse at the size and scope of AWS cloud. For example, Hamilton goes into detail on the ins and outs of the network AWS built from scratch. For more on the story, keep reading >
In October of this year, the World Wide Web Consortium (W3C) officially recommended HTML5. For citizens of the Internet who aren’t familiar with the matter and want to know more about it, this article goes back in time, providing an in-depth history on how the Web, the W3C, and HTML5 came to exist. Keep reading >
Last week, Firefox announced that it will be changing its strategy for Firefox search partnerships. In the announcement, it will no longer have a single global default search provider which was formerly held by Google. Instead, Firefox has chosen to promote choice and innovation on the Internet by partnering with local search providers, becoming the default search experience rather than Google, in every country. Keep reading >
Based on conversations we’ve had with one of our consulting clients, Datapoint Media, who are very familiar with the online advertising industry, it became quickly apparent that there really isn’t a good automated solution currently out there. When a buyer asks for “proofs” of their banner ads on the main sites that they will appear in, Ad Operations personnel are faced with two less than thrilling (and quite time intensive) options:
Imagine having to do this every day week in and week out for hundreds of client orders.
Given the strong demand for a tool and a lack of automated solutions, we worked with Datapoint Media to build a tool as part of their existing Audience Extension platform .
If you have any questions or are interested in gaining access to the tool, feel free to contact the guys over at http://www.datapointmedia.com.
In case you missed some, we’ve got a run down of some of the crazy stuff from last week! The Europeans landed on a comet, Microsoft is open sourcing .NET, and there’s a new variety of Firefox just for developers. Oh and we found an awesome list of UI kits!
For the first time in history a lander, called Philae, successfully landed on the surface of P67, a 2.5-mile-wide comet, on Wednesday (November 12) at approximately 11:00 A.M. EST. For more details on this historic landing keep reading >
.NET has announced that .NET Core stack will be open sourced on GitHub, which includes the runtime and framework libraries. To learn the reasoning behind this decision and what it will entail keep reading >
Firefox recently turned 10 this week and as a birthday present to the world, Mozilla has launched the Firefox Developer Edition. A new version of Firefox, the developer edition is of course designed for developers and places all the browser’s developer tools in front instead of previously being available only as add-ons. To check out the tools available in this edition keep reading >