瀏覽代碼

refactory

Guillermo Espinoza 8 年之前
父節點
當前提交
621cbc8e85

+ 0 - 9
BaseOAuthBundle.php

@@ -1,9 +0,0 @@
-<?php
-
-namespace Base\OAuthBundle;
-
-use Symfony\Component\HttpKernel\Bundle\Bundle;
-
-class BaseOAuthBundle extends Bundle
-{
-}

+ 9 - 0
BaseOAuthServerBundle.php

@@ -0,0 +1,9 @@
+<?php
+
+namespace Base\OAuthServerBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+class BaseOAuthServerBundle extends Bundle
+{
+}

+ 1 - 1
Command/OAuthClientCreateCommand.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\Command;
+namespace Base\OAuthServerBundle\Command;
 
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputInterface;

+ 1 - 1
Controller/OAuthController.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\Controller;
+namespace Base\OAuthServerBundle\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;

+ 2 - 2
Controller/SecurityController.php

@@ -9,7 +9,7 @@
  * file that was distributed with this source code.
  */
 
-namespace Base\OAuthBundle\Controller;
+namespace Base\OAuthServerBundle\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Symfony\Component\HttpFoundation\Request;
@@ -72,7 +72,7 @@ class SecurityController extends Controller
      */
     protected function renderLogin(array $data)
     {
-        return $this->render('@BaseOAuthBundle/Security/login.html.twig', $data);
+        return $this->render('@BaseOAuthServerBundle/Security/login.html.twig', $data);
     }
 
     /**

+ 2 - 2
DependencyInjection/BaseOAuthExtension.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\DependencyInjection;
+namespace Base\OAuthServerBundle\DependencyInjection;
 
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\Config\FileLocator;
@@ -12,7 +12,7 @@ use Symfony\Component\DependencyInjection\Loader;
  *
  * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
  */
-class BaseOAuthExtension extends Extension
+class BaseOAuthServerExtension extends Extension
 {
     /**
      * {@inheritdoc}

+ 2 - 2
DependencyInjection/Configuration.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\DependencyInjection;
+namespace Base\OAuthServerBundle\DependencyInjection;
 
 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
 use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -18,7 +18,7 @@ class Configuration implements ConfigurationInterface
     public function getConfigTreeBuilder()
     {
         $treeBuilder = new TreeBuilder();
-        $rootNode = $treeBuilder->root('base_o_auth');
+        $rootNode = $treeBuilder->root('base_o_auth_server');
 
         // Here you should define the parameters that are allowed to
         // configure your bundle. See the documentation linked above for

+ 1 - 1
Entity/AccessToken.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\Entity;
+namespace Base\OAuthServerBundle\Entity;
 
 use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;
 use Doctrine\ORM\Mapping as ORM;

+ 1 - 1
Entity/AuthCode.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\Entity;
+namespace Base\OAuthServerBundle\Entity;
 
 use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode;
 use Doctrine\ORM\Mapping as ORM;

+ 1 - 1
Entity/OAuthClient.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\Entity;
+namespace Base\OAuthServerBundle\Entity;
 
 use FOS\OAuthServerBundle\Entity\Client as BaseClient;
 use Doctrine\ORM\Mapping as ORM;

+ 1 - 1
Entity/RefreshToken.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\Entity;
+namespace Base\OAuthServerBundle\Entity;
 
 use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken;
 use Doctrine\ORM\Mapping as ORM;

+ 0 - 46
EventListener/DynamicRelationSubscriber.php

@@ -1,46 +0,0 @@
-<?php
-
-namespace Base\OAuthBundle\EventListener;
-
-use Doctrine\ORM\Events;
-use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
-use Doctrine\Common\EventSubscriber;
-
-class DynamicRelationSubscriber implements EventSubscriber
-{
-    /**
-     * {@inheritDoc}
-     */
-    public function getSubscribedEvents()
-    {
-        return array(
-            Events::loadClassMetadata,
-        );
-    }
-
-    /**
-     * @param LoadClassMetadataEventArgs $eventArgs
-     */
-    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
-    {
-        // the $metadata is the whole mapping info for this class
-        $metadata = $eventArgs->getClassMetadata();
-        $classes = array(
-            'Base\OAuthBundle\Entity\AccessToken',
-            'Base\OAuthBundle\Entity\AuthCode',
-            'Base\OAuthBundle\Entity\RefreshToken'
-        );
-        
-        if (!in_array($metadata->getName(), $classes)) {
-            return;
-        }
-        
-        $userClass = 'Base\UserBundle\Entity\User';
-        $OAuthUserClass = '\Base\OAuthBundle\Security\Core\User\CustomOAuthUser';
-        
-        $metadata->mapManyToOne(array(
-            'targetEntity'  => class_exists($userClass) ? $userClass : $OAuthUserClass,
-            'fieldName'     => 'user'
-        ));
-    }
-}

+ 1 - 1
EventListener/OAuthEventListener.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Base\OAuthBundle\EventListener;
+namespace Base\OAuthServerBundle\EventListener;
 
 use FOS\OAuthServerBundle\Event\OAuthEvent;
 

+ 0 - 30
OAuth/Response/PathUserResponse.php

@@ -1,30 +0,0 @@
-<?php
-
-namespace Base\OAuthBundle\OAuth\Response;
-
-class PathUserResponse extends \HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse
-{
-
-    /**
-     * @var array
-     */
-    protected $paths = array(
-        'identifier' => null,
-        'nickname' => null,
-        'firstname' => null,
-        'lastname' => null,
-        'realname' => null,
-        'email' => null,
-        'profilepicture' => null,
-        'roles' => null,
-    );
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getRoles()
-    {
-        return $this->getValueForPath('roles');
-    }
-
-}

+ 5 - 5
Resources/config/fosoauthserverbundle/config.yml

@@ -1,9 +1,9 @@
 fos_oauth_server:
     db_driver: orm       # Drivers available: orm, mongodb, or propel
-    client_class:        Base\OAuthBundle\Entity\OAuthClient
-    access_token_class:  Base\OAuthBundle\Entity\AccessToken
-    refresh_token_class: Base\OAuthBundle\Entity\RefreshToken
-    auth_code_class:     Base\OAuthBundle\Entity\AuthCode
+    client_class:        Base\OAuthServerBundle\Entity\OAuthClient
+    access_token_class:  Base\OAuthServerBundle\Entity\AccessToken
+    refresh_token_class: Base\OAuthServerBundle\Entity\RefreshToken
+    auth_code_class:     Base\OAuthServerBundle\Entity\AuthCode
     service:
         user_provider: fos_user.user_provider.username_email
         options:
@@ -11,4 +11,4 @@ fos_oauth_server:
 
 twig:
     paths:
-        '%kernel.root_dir%/../vendor/base-oauth-bundle/Resources/views': BaseOAuthBundle            
+        '%kernel.root_dir%/../vendor/base-oauth-server-bundle/Resources/views': BaseOAuthServerBundle            

+ 1 - 1
Resources/config/fosoauthserverbundle/services.yml

@@ -1,6 +1,6 @@
 services:
     oauth_event_listener:
-        class:  Base\OAuthBundle\EventListener\OAuthEventListener
+        class:  Base\OAuthServerBundle\EventListener\OAuthEventListener
         tags:
             - { name: kernel.event_listener, event: fos_oauth_server.pre_authorization_process, method: onPreAuthorizationProcess }
             - { name: kernel.event_listener, event: fos_oauth_server.post_authorization_process, method: onPostAuthorizationProcess }

+ 0 - 30
Resources/config/hwioauthbundle/config.yml

@@ -1,30 +0,0 @@
-hwi_oauth:
-    resource_owners:
-        login:
-            type:                oauth2
-            client_id:           "%client_id%"
-            client_secret:       "%client_secret%"
-            access_token_url:    "%access_token_url%"
-            authorization_url:   "%authorization_url%"
-            infos_url:           "%infos_url%"
-            scope:               "user"
-            user_response_class: Base\OAuthBundle\OAuth\Response\PathUserResponse
-            paths:
-                identifier: id
-                nickname: username
-                realname: firstname
-                firstname: firstname
-                lastname: lastname
-                roles: roles
-    firewall_names: [secured_area]
-
-doctrine:
-    orm:
-        entity_managers:
-            default:
-                mappings:
-                    custom_mapping:
-                        type: annotation
-                        prefix: Base\OAuthBundle\Security\Core\User\
-                        dir: "%kernel.root_dir%/../vendor/base-oauth-bundle/Security/Core/User/"
-                        is_bundle: false

+ 0 - 11
Resources/config/hwioauthbundle/routing.yml

@@ -1,11 +0,0 @@
-hwi_oauth_redirect:
-    resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
-    prefix:   /connect
-
-hwi_oauth_connect:
-    resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
-    prefix:   /connect
-
-hwi_oauth_login:
-    resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
-    prefix:   /login

+ 0 - 4
Resources/config/hwioauthbundle/services.yml

@@ -1,4 +0,0 @@
-services:
-    base_oauth_bundle.oauth_user_provider:
-        class: Base\OAuthBundle\Security\Core\User\CustomOAuthUserProvider
-        arguments: ["@security.token_storage"]

+ 2 - 2
Resources/config/routing.yml

@@ -1,4 +1,4 @@
-base_o_auth:
-    resource: "@BaseOAuthBundle/Controller/"
+base_o_auth_server:
+    resource: "@BaseOAuthServerBundle/Controller/"
     type:     annotation    
     prefix:   /

+ 1 - 1
Resources/config/services.yml

@@ -1,5 +1,5 @@
 services:
     oauth.user.mapping.listener:
-        class: Base\OAuthBundle\EventListener\DynamicRelationSubscriber
+        class: Base\OAuthServerBundle\EventListener\DynamicRelationSubscriber
         tags:
             - { name: doctrine.event_listener, event: loadClassMetadata }

+ 0 - 5
Resources/views/Core/oauth_user_block.html.twig

@@ -1,5 +0,0 @@
-{% extends "SonataAdminBundle:Core:user_block.html.twig" %}
-
-{% block user_block %}
-    <li><a href="{{ path('logout') }}">{{ 'link.user_logout'|trans({}, 'BaseUserBundle') }}</a></li>
-{% endblock %}

+ 0 - 33
Resources/views/layout.html.twig

@@ -1,33 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <meta charset="UTF-8" />
-    </head>
-    <body>
-        <div>
-            {% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
-                {{ 'layout.logged_in_as'|trans({'%username%': app.user.username}, 'FOSUserBundle') }} |
-                <a href="{{ path('fos_user_security_logout') }}">
-                    {{ 'layout.logout'|trans({}, 'FOSUserBundle') }}
-                </a>
-            {% else %}
-                <a href="{{ path('fos_user_security_login') }}">{{ 'layout.login'|trans({}, 'FOSUserBundle') }}</a>
-            {% endif %}
-        </div>
-
-        {% if app.request.hasPreviousSession %}
-            {% for type, messages in app.session.flashbag.all() %}
-                {% for message in messages %}
-                    <div class="flash-{{ type }}">
-                        {{ message }}
-                    </div>
-                {% endfor %}
-            {% endfor %}
-        {% endif %}
-
-        <div>
-            {% block fos_user_content %}
-            {% endblock fos_user_content %}
-        </div>
-    </body>
-</html>

+ 0 - 51
Security/Core/User/CustomOAuthUser.php

@@ -1,51 +0,0 @@
-<?php
-
-namespace Base\OAuthBundle\Security\Core\User;
-
-use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUser;
-use Doctrine\ORM\Mapping as ORM;
-
-/**
- * @ORM\Entity
- */
-class CustomOAuthUser extends OAuthUser
-{
-    
-    /**
-     * @ORM\Id
-     * @ORM\Column(type="integer")
-     * @ORM\GeneratedValue(strategy="AUTO")
-     */
-    protected $id;
-
-    /**
-     * @var array
-     */
-    protected $roles = array('ROLE_USER');
-
-    
-    /**
-     * @return int
-     */
-    public function getId()
-    {
-        return $this->id;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getRoles()
-    {
-        return $this->roles;
-    }
-
-    /**
-     * @param array $roles
-     */
-    public function setRoles($roles)
-    {
-        $this->roles = $roles;
-    }
-
-}

+ 0 - 49
Security/Core/User/CustomOAuthUserProvider.php

@@ -1,49 +0,0 @@
-<?php
-
-namespace Base\OAuthBundle\Security\Core\User;
-
-use HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface;
-use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUserProvider;
-use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
-
-class CustomOAuthUserProvider extends OAuthUserProvider
-{
-
-    protected $securityTokenStorage;
-
-    
-    public function __construct($securityTokenStorage)
-    {
-        $this->securityTokenStorage = $securityTokenStorage;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function loadUserByUsername($username)
-    {
-        return new CustomOAuthUser($username);
-    }
-    
-    /**
-     * {@inheritdoc}
-     */
-    public function loadUserByOAuthUserResponse(UserResponseInterface $response)
-    {
-        $user = $this->loadUserByUsername($response->getNickname());
-        $user->setRoles($response->getRoles());
-        $token = new UsernamePasswordToken($user, null, "secured_area", $user->getRoles());
-        $this->securityTokenStorage->setToken($token);
-        
-        return $user;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function supportsClass($class)
-    {
-        return $class === 'Base\\OAuthBundle\\Security\\Core\\User\\CustomOAuthUser';
-    }
-
-}

+ 3 - 4
composer.json

@@ -1,13 +1,12 @@
 {
-    "name": "base-oauth-bundle",
-    "description": "Flowdat 3 Base OAuth Bundle",
+    "name": "base-oauth-server-bundle",
+    "description": "Flowdat 3 Base OAuth Server Bundle",
     "keywords": ["Admin Generator", "admin", "oauth", "bundle"],
     "require": {
-        "hwi/oauth-bundle": "^0.5.3",
         "friendsofsymfony/oauth-server-bundle": "^1.5"
     },
     "autoload": {
-        "psr-4": { "Base\\OAuthBundle\\": "" }
+        "psr-4": { "Base\\OAuthServerBundle\\": "" }
     },
 	"version": "1.0",
   	"minimum-stability": "stable"