Spring Security Application Development (21) method-based authorization (v) using @secured annotations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.