springboot集成shiro权限过程略过
一、添加maven 依赖
<dependency> <groupId>net.mingsoft</groupId> <artifactId>shiro-freemarker-tags</artifactId> <version>0.1</version> </dependency>
二、注入FreeMarkerConfigurer,未指定templateLoaderPath时遇到过跳转到页面404问题
@Bean public FreeMarkerConfigurer freeMarkerConfigurer() throws IOException, TemplateException { FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); freeMarkerConfigurer.setTemplateLoaderPath("classpath:templates/"); freemarker.template.Configuration configuration = freeMarkerConfigurer.createConfiguration(); configuration.setDefaultEncoding("UTF-8"); //这里可以添加其他共享变量 比如sso登录地址 configuration.setSharedVariable("shiro", new ShiroTags()); freeMarkerConfigurer.setConfiguration(configuration); return freeMarkerConfigurer; }
三、shiro标签
1、session中读取登录人信息
<@shiro.principal/>
2、带有loginName属性的对象转换为Prinipal后保存在session
<shiro:principal property="loginName" />
3、带有loginName属性的Json(个人使用的是FashJson对象)转换为Prinipal后保存在session,使用freemarker标签处理Json
<#assign loginInfo><@shiro.principal/></#assign> <#assign data=loginInfo?eval> 用户:${data.loginName!""}
4、其他shiro标签使用
<@shiro.hasPermission name="权限编码"> ... </@shiro.hasPermission>
...