Using Shiro as the basis for application permissions 4: Shiro configuration instructions

Source: Internet
Author: User

The configuration of Apache Shiro is mainly divided into four parts:

  • Securitymanager Configuration
  • Url filter configuration
  • Static User Configuration
  • Static role configuration

Among them, because the user and role are generally dynamic data operated by the background, for example, using the @ requiresroles annotation to control access to a method, Shiro configuration generally only contains the first two configurations.

 

 

SecuritymanagerOfConfiguration: 

[HTML]View plaincopy
  1. <Span style = "font-size: 18px"> <! -- Shiro securitymanager -->
  2. <! -- Shiro uses the Session of the servlet container by default. The native session of Shiro can be specified through the sessionmode attribute -->
  3. <! -- <Propertyname = "sessionmode" value = "native"/>. For more information, see the official documentation. -->
  4. <! -- Here we mainly set up a custom single realm application. If multiple realm applications exist, you can use the 'realms' attribute instead. -->
  5. <Beanidbeanid = "securitymanager"
  6. Class = "org. Apache. Shiro. Web. Mgt. defaultwebsecuritymanager">
  7. <Propertynamepropertyname = "Realm" ref = "shirodbrealm"/>
  8. <! -- <Property name = "cachemanager" ref = "myshiroehcachemanager"/> -->
  9. <! -- <Property name = "sessionmode" value = "native"/>
  10. <Property name = "sessionmanager" ref = "sessionmanager"/>
  11. -->
  12. </Bean>
  13. <! -- User authorization information cache, using ehcache -->
  14. <Beanidbeanid = "myshiroehcachemanager" class = "org. Apache. Shiro. cache. ehcache. ehcachemanager">
  15. <Propertynamepropertyname = "cachemanagerconfigfile" value = "classpath: ehcache-shiro.xml"/>
  16. </Bean>
  17. <! -- Inherit the custom realm from authorizingrealm, that is, specify Shiro to authenticate and authorize the user -->
  18. <Bean id = "shirodbrealm" class = "org. Shiro. Demo. Service. realm. shirodbrealm" depends-on = "baseservice">
  19. <Propertynamepropertyname = "userservice" ref = "userservice"/>
  20. </Bean> </span>

 

 

URLFilter configuration 

Shiro mainly performs security management through URL filtering. The configuration here is to specify specific authentication and authorization rules.

 

[HTML]View plaincopy
    1. <! -- The shiro primary filter has powerful functions. Its powerful feature is that it supports the execution of any URL-based, custom filter. -->
    2. <! -- Shiro filter -->
    3. <Bean id = "shirofilter"
    4. Class = "org. Apache. Shiro. Spring. Web. shirofilterfactorybean">
    5. <! -- This attribute is required for Shiro's core security interface -->
    6. <Property name = "securitymanager" ref = "securitymanager"/>
    7. <! -- The link required for logon is not a required attribute. By default, the "/login. jsp" page under the root directory of the web project is automatically searched. -->
    8. <Property name = "loginurl" value = "/"/>
    9. <! -- Connection to be redirected after Successful Logon (in this example, this attribute is not used, because the processing logic after successful logon is hard coded as main. jsp in logincontroller) -->
    10. <Property name = "successurl" value = "/system/main"/>
    11. <! -- Connection displayed when a user accesses resources that are not authorized to him -->
    12. <Property name = "unauthorizedurl" value = "/system/error"/>
    13. <! -- Shiro filter chain definition -->
    14. <! -- Here can be used with this article to understand the function of each filter connection http://blog.csdn.net/jadyer/article/details/12172839 -->
    15. <! -- The First '/' of the following value indicates the path relative to the value of httpservletrequest. getcontextpath () -->
    16. <! -- Anon: The corresponding filter is empty, and nothing is done. Here, the * parameter after. Do and. jsp, for example, login. jsp? Main -->
    17. <! -- Authc: The page under the filter must be verified before access. It is a built-in interceptor org. Apache. Shiro. Web. Filter. authc. formauthenticationfilter. -->
    18. <Property name = "filterchaindefinitions">
    19. <Value>
    20. /Login = Anon
    21. /Validatecode = Anon
    22. /** = Authc
    23. </Value>
    24. </Property>
    25. </Bean>
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.