0
我在Spring-MVC應用程序中使用Spring安全框架。我必須在數據庫中檢查用戶名和密碼是否匹配,當然使用spring security。在多個網站上,我找到了角色的使用。我的程序或數據庫中沒有這樣的屬性角色。我可以排除這種情況,或者在使用Spring-Security時是否有必要使用角色。我張貼一些代碼。請看看。春季安全認證,其中的角色的一部分?
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource" users-by-username-query="select username,password from users where username=?" authorities-by-username-query="select u.username, r.authority from users u, roles r where u.userid = r.userid and u.username =?" />
</authentication-provider>
的LoginController:
@Controller
@PreAuthorize("hasRole('ROLE_USER')")
public class LoginController {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(){
return "login";
}
}
用戶等級:
@Entity
@Table(name="registration")
public class User {
private String Username;
private String password;
}
哪裏作用,這一切進來的畫面。 P.S:我根據我的例子添加了預授權。謝謝。
謝謝。我是Spring安全新手。所以我想我需要在表格中創建一個角色。 PreAuthorize語句應該在哪裏?在userController中? – 2014-09-26 14:19:47
你應該能夠在網上找到很多很好的例子和代碼庫。做一點研究!出於各種原因,我喜歡在服務層保留PreAuthorize註釋。 – proulxs 2014-09-26 14:30:24
好吧,我會,但不幸的是現在我想讓這個東西工作。我現在應該在UserController中使用它嗎? – 2014-09-26 14:37:19