Shiro: Authorization Control and shiro Authorization Control

Source: Internet
Author: User

Shiro: Authorization Control and shiro Authorization Control

PairEasy to ignoreThe local records are as follows:

1. The following two dependencies need to be introduced. The specific version is modified according to the environment:

<dependency>          <groupId>org.apache.geronimo.bundles</groupId>          <artifactId>aspectjweaver</artifactId>          <version>1.6.8_2</version></dependency><dependency>          <groupId>org.aspectj</groupId>          <artifactId>aspectjrt</artifactId>          <version>1.8.10</version></dependency>

2. Inject the two beans:

/*** Annotation dynamic interception of Access authorization, otherwise doGetAuthenticationInfo ** @ param securityManager * @ return */@ Bean public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor (SecurityManager securityManager) will not be executed) {AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor (); authorizationAttributeSourceAdvisor. setSecurityManager (securityManager); return authorizationAttributeSourceAdvisor;}/*** handle an error when the authorization is not passed (403, without this, the system will not jump to the 403 page ** @ return */@ Bean public SimpleMappingExceptionResolver extends () {SimpleMappingExceptionResolver simpleMappingExceptionResolver (); Properties mappings = new Properties (); mappings. setProperty ("org. apache. shiro. authz. unauthorizedException ","/error/403 "); simpleMappingExceptionResolver. setExceptionMappings (mappings); return simpleMappingExceptionResolver ;}

Finished!

When the following code is executed, the 403 page is displayed:

@RequiresPermissions("user:test")@GetMapping("/test")
public String test() {  String strResult = "/test";  return strResult;}

Related Article

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.