In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how to solve the problem of access control of springboot+shiro+thymeleaf page-level elements. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Permission control of springboot+shiro+thymeleaf page-level elements
I use the springboot2.1 version.
Learned a lot of God's summary, basically the same, shiro permissions framework, front-end verification is designed for jsp, in which tag can only be used in the jsp series of template engines.
Using thymeleaf as the front-end template engine and using HTML files, it is impossible to introduce tag lib of shiro. At this time, if you want to use shiro, you can introduce thymeleaf-extras-shiro.jar as an extension package to realize the front-end verification of shiro.
Add the following dependencies to pom.xml:
Com.github.theborakompanioni thymeleaf-extras-shiro 1.2.1
Then, when configuring configuration for shiro, add
@ Beanpublic ShiroDialect shiroDialect () {return new ShiroDialect ();}
Then add xmlns to the page header of the page element you want to control:
Add user add interface has permission
No permission
The other configurations are the same as those used by shiro for background access control, and then that's fine. In fact, I did the same thing, but there was a problem.
Keep reporting this exception.
Org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'shiroDialect' defined in class path resource [com/gaox/config/ShiroConfig.class]: Bean instantiation via factory methodfailed; nested exception is org.springframework.beans.BeanInstantiationException:Failed to instantiate [at.pollux.thymeleaf.shiro.dialect.ShiroDialect]: Factorymethod' shiroDialect' threw exception; nested exception isjava.lang.NoClassDefFoundError:org/thymeleaf/processor/attr/AbstractTextChildModifierAttrProcessor
Atorg.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod (ConstructorResolver.java:587) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod (AbstractAutowireCapableBeanFactory.java:1250) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance (AbstractAutowireCapableBeanFactory.java:1099) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:541) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:501) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0 (AbstractBeanFactory.java:317) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:228) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java:315) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:199) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons (DefaultListableBeanFactory.java:760) ~ [spring-beans-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization (AbstractApplicationContext.java:869) ~ [spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:550) ~ [spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]
Atorg.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh (ServletWebServerApplicationContext.java:140) ~ [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Atorg.springframework.boot.SpringApplication.refresh (SpringApplication.java:759) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Atorg.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:395) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Atorg.springframework.boot.SpringApplication.run (SpringApplication.java:327) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Atorg.springframework.boot.SpringApplication.run (SpringApplication.java:1255) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Atorg.springframework.boot.SpringApplication.run (SpringApplication.java:1243) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Atcom.gaox.ShiroDemoApplication.main (ShiroDemoApplication.java:10) [classes/:na]
This exception means that the class AbstractTextChildModifierAttrProcessor can not be found. In fact, there is this class, but it can be found when compiling, so there is no exception, and this class cannot be found at run time, so it is abnormal. I checked it carefully many times. Finally, I changed the version of springboot, and then I did not report an error. At first, I used the latest version 2.0, and changed it to 1.5.
Here is a post about the package used by shiro
I hope the students who encounter the same problem will get around a hole.
Org.apache.shiro shiro-core 1.3.2 org.apache.shiro shiro-spring 1.4.0 org.apache.shiro shiro-ehcache 1.2.5 com.github.theborakompanioni thymeleaf-extras-shiro 1.2.1shiro Integration thymeleaf Common Rights Control tags
1. Unauthenticated and unremembered users
Please login
2. Users who are not authenticated and remembered.
Please login in order to update your credit card information.
3. Users who have been certified or remembered
Welcome back John! Not John? Click here to login.
4. Users who have passed the authentication and have not been remembered
Hello, how are you today?
Update your contact information
5. Current user information
Hello, how are you today?
6. Verify whether the current user has this role
Administer the system
7. Verify whether the current user does not have this role
Sorry, you are not allowed to developer the system.
Verify that the current user has all of the following roles at the same time
You are a developer and an admin.
9. Verify whether the current user is in any of the following roles
You are an admin, vip, or developer.
10. Verify whether the current user has the specified permissions
Add user
11. Verify whether the current user does not have the specified permissions
Sorry, you are not allowed to delete user accounts.
Verify that the current user has all of the following roles at the same time
You can see or add users.
13. Verify whether the current user has any of the following permissions
You can see or delete users.
These are all the contents of this article entitled "how to solve the problem of access control of springboot+shiro+thymeleaf page-level elements". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.