2013-05-11 78 views
0

我想將彈簧安全性集成到我的應用程序中。 用戶的信息保存在Oracle數據庫中,密碼使用md5進行編碼。 我想這在第一,但它沒有工作:將彈簧安全性3.1與現有應用程序集成

<bean id="customjdbcUserService" class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl"> 
      <property name="dataSource" ref="dataSource" /> 
      <property name="enableAuthorities" value="true" /> 
      <property name="usersByUsernameQuery" value="SELECT mail,password,enabled FROM users WHERE mail = ?" /> 
      <property name="authoritiesByUsernameQuery" value="select mail,authority from user_roles where mail = ?" /> 
      </bean> 
    <bean id="dataSource" 
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
      <property name="url" value="jdbc:oracle:thin:@//localhost:8080/ex" /> 
      <property name="username" value="user1" /> 
      <property name="password" value="user1" /> 
     </bean> 
     <bean id="daoAuthenticationProvider" 
       class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"> 
      <property name="userDetailsService" ref="customjdbcUserService"/> 
     </bean> 

     <bean id="authenticationManager" 
      class="org.springframework.security.authentication.ProviderManager"> 
      <property name="providers"> 
       <list> 
        <ref local="daoAuthenticationProvider" /> 
       </list> 
      </property> 
     </bean> 
    <sec:authentication-manager> 
<security:authentication-provider user-service-ref="customjdbcUserService" > 
     <security:password-encoder hash="md5" /> 
    </security:authentication-provider> 
     </sec:authentication-manager> 

我搜索了網,發現了很多關於實現UserDetailsServiceauthenticatioProviderauthenticationManagerFilter。現在我只是困惑:我應該執行哪一個?

+0

你是什麼意思的「它沒有工作」?你有錯誤信息嗎?除此之外:你不應該用md5編碼密碼。 – micha 2013-05-11 17:50:33

+0

@micha當我按下我的表單中的連接按鈕時,它不會進入'default-target-url'頁面,但它會重置我的登錄窗體..以及有關密碼,它們已經在數據庫中編碼我有,這不是我的選擇 – M810 2013-05-11 19:24:20

回答

1

實現UserDetailsS​​ervice的將是巨大的認證用戶,

春季安全XML代碼

<authentication-manager alias="authenticationManager"> 
    <authentication-provider user-service-ref="userDetailService"> 

    </authentication-provider> 
    </authentication-manager> 

服務類實現,org.springframework.security.core.userdetails.UserDetailsS​​ervice

@Service("userDetailsService") 
    public class UserDetailsServiceImpl implements UserDetailsService { 

    public UserDetails loadUserByUsername(String username) 
    { 

    } 
    //methods an your code/logics 

    } 
相關問題