Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, you will need create your own user provider and add it as a service your Symfony app. The user provider class you create must implement the UserProviderInterface </p> <p>To get your class started here is an example of my custom class located in Namespace/Bundle/Security/Provider.php:</p> <pre><code>namespace CB\WebsiteBundle\Security; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use CB\WebsiteBundle\Entity\User; class Provider implements UserProviderInterface { protected $user; public function __contsruct (UserInterface $user) { $this-&gt;user = $user; } /** * Loads the user for the given username. * * This method must throw UsernameNotFoundException if the user is not * found. * * @throws UsernameNotFoundException if the user is not found * @param string $username The username * * @return UserInterface */ function loadUserByUsername($username) { $user = User::find(array('username'=&gt;$username)); if(empty($user)){ throw new UsernameNotFoundException('Could not find user. Sorry!'); } $this-&gt;user = $user; return $user; } /** * Refreshes the user for the account interface. * * It is up to the implementation if it decides to reload the user data * from the database, or if it simply merges the passed User into the * identity map of an entity manager. * * @throws UnsupportedUserException if the account is not supported * @param UserInterface $user * * @return UserInterface */ function refreshUser(UserInterface $user) { return $user; } /** * Whether this provider supports the given user class * * @param string $class * * @return Boolean */ function supportsClass($class) { return $class === 'MC\WebsiteBundle\Entity\User'; } } </code></pre> <p>Some key things to note in this class is that it uses a custom User entity that you would define yourself which would facilitate the connection to your Java middleware. In my case, I am connecting to a REST api to get my user information and my user class uses the User::find($criteria) static function to find users by username.</p> <p>Once you have your own User class that interacts with your middleware, and you have your new provider, you need to add the provider as a service in your bundle configuration: YourBundle/Resources/config.xml:</p> <pre><code>&lt;parameters&gt; &lt;parameter key="cb_security_user.class"&gt;CB\WebsiteBundle\Entity\User&lt;/parameter&gt; &lt;parameter key="cb_security_provider.class"&gt;CB\WebsiteBundle\Security\Provider&lt;/parameter&gt; &lt;/parameters&gt; &lt;services&gt; &lt;service id="cb_security_user" class="%cb_security_user.class%" /&gt; &lt;service id="cb_security_provider" class="%cb_security_provider.class%"&gt; &lt;argument type="service" id="cb_security_user" /&gt; &lt;/service&gt; &lt;/services&gt; </code></pre> <p>You can find more details on my blog post here: <a href="http://clintberry.com/2011/custom-user-providers-symfony2/" rel="nofollow">Custom User Providers in Symfony2</a></p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload