2017-03-10 40 views
0

我爲我的第二個數據庫創建了第二位經理。 在這個基礎上,我創建了一個包含我的用戶的表格。 問題是symfony不會從這個數據庫加載用戶。與第二位經理身份驗證

這裏是我config.yml的摘錄:

學說配置

doctrine: 
dbal: 
    default_connection: default 
    connections: 
     default: 
      driver: pdo_mysql 
      host:  "%database_host%" 
      port:  "%database_port%" 
      dbname: "%database_name%" 
      user:  "%database_user%" 
      password: "%database_password%" 
      charset: UTF8 
     seconddb: 
      driver: pdo_mysql 
      host:  "xx.xx.xx.xx" 
      port:  "3306" 
      dbname: "acme_test" 
      user:  "acmegamestest" 
      password: "mypassword" 
      charset: UTF8 

    # if using pdo_sqlite as your database driver: 
    # 1. add the path in parameters.yml 
    #  e.g. database_path: "%kernel.root_dir%/data/data.db3" 
    # 2. Uncomment database_path in parameters.yml.dist 
    # 3. Uncomment next line: 
    #  path:  "%database_path%" 

orm: 
    default_entity_manager: default 
    auto_generate_proxy_classes: "%kernel.debug%" 
    #naming_strategy: doctrine.orm.naming_strategy.underscore 
    entity_managers: 
     default:  
      connection: default 
      mappings: 
       acmeAdminBundle: ~ 
       acmeBlogBundle: ~ 
       gedmo_translatable: 
        type: annotation 
        alias: GedmoTranslatable 
        prefix: Gedmo\Translatable\Entity 
        is_bundle: false 
        # make sure vendor library location is correct 
        dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity" 
     seconddb: 
      connection: seconddb 
      mappings: 
       acmeJoueurBundle: ~ 

,這裏是我的security.yml的摘錄:

encoders: 
    FOS\UserBundle\Model\UserInterface: sha512 
    Acme\JoueurBundle\Entity\Players: 
     algorithm: sha512 
     encode_as_base64: false 

providers: 
    seconddb: 
     entity: 
      class: Acme\JoueurBundle\Entity\Players 
      property: username  
      manager_name: seconddb 
    fos_userbundle: 
     id: fos_user.user_provider.username 

firewalls: 
    administration: 
     pattern: ^/admin 
     provider: fos_userbundle 
     context: administration 
     form_login: 
      #csrf_provider: security.csrf.token_manager 
      login_path : fos_user_security_login 
      check_path : fos_user_security_check 
      failure_path : null 
      default_target_path : /admin     
     logout:  
      path : fos_user_security_logout 
      target : /connexion 
     anonymous: true  
    frontend: 
     pattern: ^/ 
     provider: acme_joueurbundle 
     context: frontend 
     form_login: 
      #csrf_provider: form.csrf_provider 
      login_path : acme_players_login 
      check_path : acme_players_check 
      failure_path : null 
      default_target_path : acme_players_userprofile      
     logout:  
      path : acme_players_logout 
      target : acme_players_login 
     anonymous: true 

和我的實體實施「 AdvancedUserInterface,\ Serializable「 具有此功能:

//////////////////////////liaison pour symfony//////////////////////////// 

public function getRoles() 
{ 
    return array('ROLE_PLAYERS'); 
} 

public function getSalt(){ 

    return $this->salt; 
} 

public function eraseCredentials(){ 

} 

public function isAccountNonExpired() 
{ 
    return true; 
} 

public function isCredentialsNonExpired() 
{ 
    return true; 
} 

public function isAccountNonLocked() 
{ 

    return !$this->banned; 
} 

public function isEnabled() 
{ 
    return $this->active; 
} 



    /** @see \Serializable::serialize() */ 
public function serialize() 
{ 
    return serialize(array(
     $this->id, 
     $this->username, 
     $this->password, 
     $this->active 
     // see section on salt below 
     // $this->salt, 
    )); 
} 

/** @see \Serializable::unserialize() */ 
public function unserialize($serialized) 
{ 
    list (
     $this->id, 
     $this->username, 
     $this->password, 
     $this->active 
     // see section on salt below 
     // $this->salt 
    ) = unserialize($serialized); 
} 

///////////////////////////////////////////////////////////////////////////// 

然而,當我嘗試連接,我在轉存功能得到這個錯誤:

enter image description here

,並在部分原則我得到這個:

enter image description here

是你知道什麼解決方案? 希望你能幫助我。 感謝

回答

0

編輯

因此,錯誤來自這段代碼在用戶身份驗證提供:

try { 
    $user = $this->retrieveUser($username, $token); 
} catch (UsernameNotFoundException $e) { 
    if ($this->hideUserNotFoundExceptions) { 
     throw new BadCredentialsException('Bad credentials.', 0, $e); 
    } 
    $e->setUsername($username); 
    throw $e; 
} 

的方法retrieveUser失敗,它拋出壞crendentials例外。這解釋了爲什麼沒有連接,因爲它還沒有被調用。

在詢問你的提供者代碼之前,讓我們看看你的security.yml,因爲你創建了一個名爲seconddb的提供者,並且在你的防火牆前端嘗試調用一個不存在的提供者acme_joueurbundle。

所以,你security.yml應該是這樣的:

# app/config/security.yml 

[...] 

providers: 
    seconddb: 
     entity: 
      class: Acme\JoueurBundle\Entity\Players 
      property: username  
      manager_name: seconddb 
    fos_userbundle: 
     id: fos_user.user_provider.username 

firewalls: 
    administration: 
     provider: fos_userbundle 
     [...] 
    frontend: 
     provider: seconddb 
     [...] 
+0

沒有變化!它不工作。很奇怪!! FOSuserbundle,我用它來管理網站和AcmeJoueurBundle,我用它來爲前端的玩家們! – strauss

+0

好吧,我不明白...我以爲你不能連接到第二個數據庫。您的問題與已經似乎正常工作的Doctrine連接無關...您必須添加您的實體(至少是重要的部分),以便我們可以幫助您。也許密碼或鹽字段太小數據庫和字符串被截斷。也許你的樹枝格式不正確。有很多可能的原因。 –

+0

是的,當我嘗試連接表單登錄時,轉儲返回我「不良憑據」,並且我得到了symfony不加載實體玩家的印象,沒有sql查詢在我的第二個管理器中啓動,但配置正確 – strauss