Spring Security provides @Secured Annotations to implement method-based authorization control.
@Secured Annotations You can specify a string array parameter as A value that indicates that the current user has any one of these roles to satisfy the authorization criteria.
(1) enabled @Secured annotations.
<secured-annotations= "Enabled" />
(2) Use Secured annotations.
//the Getuserbyname () method can be accessed by users with Role_admin or role_user roles. @Secured ({"Role_admin", "Role_user"}) PublicUserBean getuserbyname (String name) {UserBean user=NewUserBean (name,1001); System.out.println ("Getuserbyname");returnuser;} @Secured ("Role_admin") Public voidAddUser () {System.out.println ("AddUser");} @Secured ("Role_admin") Public voidRemoveuser () {System.out.println ("Removeuser");
} @Secured ("Role_admin") Public voidUpdateUser () {System.out.println ("UpdateUser");}
@Secured Annotations are used in the same way as users who @RolesAllowed annotations, please refer to the introduction of the blog about @RolesAllowed annotations.
Spring Security Application Development (21) method-based authorization (v) using @secured annotations