2014-09-04 44 views
0

通過一些鏈接彈簧安全性後,我瞭解它是如何工作的。儘管如此,我仍然對我應該在spring-security.xml中提供的用戶名和密碼感到困惑,因爲我正在使用JSON。我所有的數據都存儲在服務器上。如果我登錄頁面,它將檢查服務器是否存在數據,如果有,那麼它應該進行如何使用spring security和authentication來做到這一點..?對此有任何幫助..?這是我的彈簧security.xml文件彈簧安全,其中數據存儲在服務器上

<http use-expressions="true"> 
    <intercept-url pattern="/signin*" access="isAnonymous()" /> 
    <intercept-url pattern="/**" access="isAuthenticated()"/> 

    <form-login 
    login-page='/signin' 
    default-target-url="/home" 
    authentication-failure-url="/signin?error=true" 
    login-processing-url="/security/j_spring_security_check" 
    /> 
    <logout logout-success-url="/signin" /> 

</http> and may be i have to add some ref in the authentication manager so that it will check the username and password which are present in the remote server.. 


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

如果一些鏈接在那裏或某些info..then請幫助我在這個服務器

回答

0

您可以配置(如用戶名和passwprd存儲在數據庫)

<authentication-manager> 
    <authentication-provider> 
     <jdbc-user-service data-source-ref="dataSource" 

     users-by-username-query=" 
     SELECT USERNAME, PASSWORD, CASE ENABLED WHEN 1 THEN 'true' ELSE 'false' END 'ENABLED' 
     FROM TBL_USERS 
     WHERE USERNAME=?;" 

     authorities-by-username-query=" 
     SELECT u.USERNAME, r.ROLENAME 
     FROM TBL_USERS u, TBL_USER_ROLE r 
     WHERE u.ID = r.USERID 
     AND u.USERNAME=?;" 

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

<authentication-manager> 
    <authentication-provider> 
     <user-service> 
      <user name="user" password="123456" authorities="ROLE_USER" /> 
      <user name="admin" password="123456" authorities="ROLE_ADMIN" /> 
      <user name="dba" password="123456" authorities="ROLE_DBA" /> 
     </user-service> 
    </authentication-provider> 
</authentication-manager> 

形式登錄

<form name='loginForm' action="<c:url value='/j_spring_security_check' />" method='POST'> 
     <table> 
      <tr> 
       <td>User:</td> 
       <td><input type='text' name='username'></td> 
      </tr> 
      <tr> 
       <td>Password:</td> 
       <td><input type='password' name='password' /></td> 
      </tr> 

      <tr> 
       <td></td> 
       <td> 
        <input name="submit" type="submit" value="Login"/> 
       </td> 
      </tr> 
     </table> 
    </form> 

認爲它可以幫助

+0

u能告訴我應該在我的控制器寫的authentiation ..?給我一些提示或鏈接哪些是有用的 – ghhhhhhhh 2014-09-04 11:19:22