【更新】看到很多博客写 shiro权限认证的,都是一半的代码,复制上根本不能使用,依赖文件对于小白来说,更是不知道使用什么依赖,所以我把相应的java文件的包 都一并带上

spring-shiro属于轻量级权限框架,即使spring-security更新换代,市场上大多数企业还是选择shiro

废话不多说  引入pom文件相关依赖

  1. <!--日志管理-->
  2. <dependency>
  3. <groupId>org.slf4j</groupId>
  4. <artifactId>slf4j-api</artifactId>
  5. <version>1.7.16</version>
  6. </dependency>
  7. <!--shiro权限框架-->
  8. <dependency>
  9. <groupId>org.apache.shiro</groupId>
  10. <artifactId>shiro-spring</artifactId>
  11. <version>1.3.2</version>
  12. </dependency>

导入之后 相关依赖包就会自动加载 shiro-core、shiro-spring、shiro-web等等  依赖版本还得根据shiro集成的spring版本进行加载(注意版本号)

设计登录认证,就少不三张表。没做过登录认证的小白    仔细看,我在Shiro配置中,尽量的去加入注释说明

先贴上我的 用户,角色,权限 三张表的 java 对象

需求分析为:用户角色 - 多对多

           角色权限 - 多对多

注意:直接复制的同学,三张表的注解,各位可以忽略删除  也可以学习使用 Spring-Data-Jpa 底层是 Hibernate,建表和查询方便

三个关系告诉你了,其实只需要最后关联的是 : 用户 - 权限  这里不需要 role角色表(实际项目中可以选择需要)

  1. import lombok.Data;
  2. import lombok.ToString;
  3.  
  4. @Data
  5. @ToString
  6. public class User {
  7. /**
  8. *
  9. * This field was generated by MyBatis Generator.
  10. * This field corresponds to the database column tb_users.user_id
  11. *
  12. * @mbg.generated
  13. */
  14. private Integer userId;
  15.  
  16. /**
  17. *
  18. * This field was generated by MyBatis Generator.
  19. * This field corresponds to the database column tb_users.user_name
  20. *
  21. * @mbg.generated
  22. */
  23. private String userName;
  24.  
  25. /**
  26. *
  27. * This field was generated by MyBatis Generator.
  28. * This field corresponds to the database column tb_users.password
  29. *
  30. * @mbg.generated
  31. */
  32. private String password;
  33.  
  34. /**
  35. *
  36. * This field was generated by MyBatis Generator.
  37. * This field corresponds to the database column tb_users.phone
  38. *
  39. * @mbg.generated
  40. */
  41. private String phone;
  42.  
  43. /**
  44. *
  45. * This field was generated by MyBatis Generator.
  46. * This field corresponds to the database column tb_users.email
  47. *
  48. * @mbg.generated
  49. */
  50. private String email;
  51.  
  52. /**
  53. *
  54. * This field was generated by MyBatis Generator.
  55. * This field corresponds to the database column tb_users.status
  56. *
  57. * @mbg.generated
  58. */
  59. private Integer status;
  60.  
  61. private String salt;
  62.  
  63. public String getSalt() {
  64. return salt;
  65. }
  66.  
  67. public void setSalt(String salt) {
  68. this.salt = salt;
  69. }
  70.  
  71. /**
  72. *
  73. * This field was generated by MyBatis Generator.
  74. * This field corresponds to the database column tb_users.note
  75. *
  76. * @mbg.generated
  77. */
  78. private String note;
  79.  
  80. /**
  81. *
  82. * This field was generated by MyBatis Generator.
  83. * This field corresponds to the database column tb_users.create_time
  84. *
  85. * @mbg.generated
  86. */
  87. private String createTime;
  88.  
  89. /**
  90. *
  91. * This field was generated by MyBatis Generator.
  92. * This field corresponds to the database column tb_users.update_time
  93. *
  94. * @mbg.generated
  95. */
  96. private String updateTime;
  97.  
  98. /**
  99. * This method was generated by MyBatis Generator.
  100. * This method returns the value of the database column tb_users.user_id
  101. *
  102. * @return the value of tb_users.user_id
  103. *
  104. * @mbg.generated
  105. */
  106. public Integer getUserId() {
  107. return userId;
  108. }
  109.  
  110. /**
  111. * This method was generated by MyBatis Generator.
  112. * This method sets the value of the database column tb_users.user_id
  113. *
  114. * @param userId the value for tb_users.user_id
  115. *
  116. * @mbg.generated
  117. */
  118. public void setUserId(Integer userId) {
  119. this.userId = userId;
  120. }
  121.  
  122. /**
  123. * This method was generated by MyBatis Generator.
  124. * This method returns the value of the database column tb_users.user_name
  125. *
  126. * @return the value of tb_users.user_name
  127. *
  128. * @mbg.generated
  129. */
  130. public String getUserName() {
  131. return userName;
  132. }
  133.  
  134. /**
  135. * This method was generated by MyBatis Generator.
  136. * This method sets the value of the database column tb_users.user_name
  137. *
  138. * @param userName the value for tb_users.user_name
  139. *
  140. * @mbg.generated
  141. */
  142. public void setUserName(String userName) {
  143. this.userName = userName == null ? null : userName.trim();
  144. }
  145.  
  146. /**
  147. * This method was generated by MyBatis Generator.
  148. * This method returns the value of the database column tb_users.password
  149. *
  150. * @return the value of tb_users.password
  151. *
  152. * @mbg.generated
  153. */
  154. public String getPassword() {
  155. return password;
  156. }
  157.  
  158. /**
  159. * This method was generated by MyBatis Generator.
  160. * This method sets the value of the database column tb_users.password
  161. *
  162. * @param password the value for tb_users.password
  163. *
  164. * @mbg.generated
  165. */
  166. public void setPassword(String password) {
  167. this.password = password == null ? null : password.trim();
  168. }
  169.  
  170. /**
  171. * This method was generated by MyBatis Generator.
  172. * This method returns the value of the database column tb_users.phone
  173. *
  174. * @return the value of tb_users.phone
  175. *
  176. * @mbg.generated
  177. */
  178. public String getPhone() {
  179. return phone;
  180. }
  181.  
  182. /**
  183. * This method was generated by MyBatis Generator.
  184. * This method sets the value of the database column tb_users.phone
  185. *
  186. * @param phone the value for tb_users.phone
  187. *
  188. * @mbg.generated
  189. */
  190. public void setPhone(String phone) {
  191. this.phone = phone == null ? null : phone.trim();
  192. }
  193.  
  194. /**
  195. * This method was generated by MyBatis Generator.
  196. * This method returns the value of the database column tb_users.email
  197. *
  198. * @return the value of tb_users.email
  199. *
  200. * @mbg.generated
  201. */
  202. public String getEmail() {
  203. return email;
  204. }
  205.  
  206. /**
  207. * This method was generated by MyBatis Generator.
  208. * This method sets the value of the database column tb_users.email
  209. *
  210. * @param email the value for tb_users.email
  211. *
  212. * @mbg.generated
  213. */
  214. public void setEmail(String email) {
  215. this.email = email == null ? null : email.trim();
  216. }
  217.  
  218. /**
  219. * This method was generated by MyBatis Generator.
  220. * This method returns the value of the database column tb_users.status
  221. *
  222. * @return the value of tb_users.status
  223. *
  224. * @mbg.generated
  225. */
  226. public Integer getStatus() {
  227. return status;
  228. }
  229.  
  230. /**
  231. * This method was generated by MyBatis Generator.
  232. * This method sets the value of the database column tb_users.status
  233. *
  234. * @param status the value for tb_users.status
  235. *
  236. * @mbg.generated
  237. */
  238. public void setStatus(Integer status) {
  239. this.status = status;
  240. }
  241.  
  242. /**
  243. * This method was generated by MyBatis Generator.
  244. * This method returns the value of the database column tb_users.note
  245. *
  246. * @return the value of tb_users.note
  247. *
  248. * @mbg.generated
  249. */
  250. public String getNote() {
  251. return note;
  252. }
  253.  
  254. /**
  255. * This method was generated by MyBatis Generator.
  256. * This method sets the value of the database column tb_users.note
  257. *
  258. * @param note the value for tb_users.note
  259. *
  260. * @mbg.generated
  261. */
  262. public void setNote(String note) {
  263. this.note = note == null ? null : note.trim();
  264. }
  265.  
  266. /**
  267. * This method was generated by MyBatis Generator.
  268. * This method returns the value of the database column tb_users.create_time
  269. *
  270. * @return the value of tb_users.create_time
  271. *
  272. * @mbg.generated
  273. */
  274. public String getCreateTime() {
  275. return createTime;
  276. }
  277.  
  278. /**
  279. * This method was generated by MyBatis Generator.
  280. * This method sets the value of the database column tb_users.create_time
  281. *
  282. * @param createTime the value for tb_users.create_time
  283. *
  284. * @mbg.generated
  285. */
  286. public void setCreateTime(String createTime) {
  287. this.createTime = createTime;
  288. }
  289.  
  290. /**
  291. * This method was generated by MyBatis Generator.
  292. * This method returns the value of the database column tb_users.update_time
  293. *
  294. * @return the value of tb_users.update_time
  295. *
  296. * @mbg.generated
  297. */
  298. public String getUpdateTime() {
  299. return updateTime;
  300. }
  301.  
  302. /**
  303. * This method was generated by MyBatis Generator.
  304. * This method sets the value of the database column tb_users.update_time
  305. *
  306. * @param updateTime the value for tb_users.update_time
  307. *
  308. * @mbg.generated
  309. */
  310. public void setUpdateTime(String updateTime) {
  311. this.updateTime = updateTime;
  312. }
  313.  
  314. }

User

  1. import lombok.Data;
  2. import lombok.ToString;
  3.  
  4. import java.util.Date;
  5.  
  6. /**
  7. * @author wusiwee
  8. * @date 2020/4/3 10:58
  9. */
  10. @Data
  11. @ToString
  12. public class Permission {
  13.  
  14. /**
  15. *
  16. * This field was generated by MyBatis Generator.
  17. * This field corresponds to the database column tb_functions.func_id
  18. *
  19. * @mbg.generated
  20. */
  21. private Integer funcId;
  22.  
  23. /**
  24. *
  25. * This field was generated by MyBatis Generator.
  26. * This field corresponds to the database column tb_functions.func_name
  27. *
  28. * @mbg.generated
  29. */
  30. private String funcName;
  31.  
  32. /**
  33. *
  34. * This field was generated by MyBatis Generator.
  35. * This field corresponds to the database column tb_functions.func_url
  36. *
  37. * @mbg.generated
  38. */
  39. private String funcUrl;
  40.  
  41. /**
  42. *
  43. * This field was generated by MyBatis Generator.
  44. * This field corresponds to the database column tb_functions.func_code
  45. *
  46. * @mbg.generated
  47. */
  48. private String funcCode;
  49.  
  50. /**
  51. *
  52. * This field was generated by MyBatis Generator.
  53. * This field corresponds to the database column tb_functions.parent_id
  54. *
  55. * @mbg.generated
  56. */
  57. private Integer parentId;
  58.  
  59. /**
  60. *
  61. * This field was generated by MyBatis Generator.
  62. * This field corresponds to the database column tb_functions.func_type
  63. *
  64. * @mbg.generated
  65. */
  66. private Integer funcType;
  67.  
  68. /**
  69. *
  70. * This field was generated by MyBatis Generator.
  71. * This field corresponds to the database column tb_functions.status
  72. *
  73. * @mbg.generated
  74. */
  75. private Integer status;
  76.  
  77. /**
  78. *
  79. * This field was generated by MyBatis Generator.
  80. * This field corresponds to the database column tb_functions.sort_num
  81. *
  82. * @mbg.generated
  83. */
  84. private Integer sortNum;
  85.  
  86. /**
  87. *
  88. * This field was generated by MyBatis Generator.
  89. * This field corresponds to the database column tb_functions.create_time
  90. *
  91. * @mbg.generated
  92. */
  93. private Date createTime;
  94.  
  95. /**
  96. *
  97. * This field was generated by MyBatis Generator.
  98. * This field corresponds to the database column tb_functions.update_time
  99. *
  100. * @mbg.generated
  101. */
  102. private Date updateTime;
  103.  
  104. /**
  105. * This method was generated by MyBatis Generator.
  106. * This method returns the value of the database column tb_functions.func_id
  107. *
  108. * @return the value of tb_functions.func_id
  109. *
  110. * @mbg.generated
  111. */
  112. public Integer getFuncId() {
  113. return funcId;
  114. }
  115.  
  116. /**
  117. * This method was generated by MyBatis Generator.
  118. * This method sets the value of the database column tb_functions.func_id
  119. *
  120. * @param funcId the value for tb_functions.func_id
  121. *
  122. * @mbg.generated
  123. */
  124. public void setFuncId(Integer funcId) {
  125. this.funcId = funcId;
  126. }
  127.  
  128. /**
  129. * This method was generated by MyBatis Generator.
  130. * This method returns the value of the database column tb_functions.func_name
  131. *
  132. * @return the value of tb_functions.func_name
  133. *
  134. * @mbg.generated
  135. */
  136. public String getFuncName() {
  137. return funcName;
  138. }
  139.  
  140. /**
  141. * This method was generated by MyBatis Generator.
  142. * This method sets the value of the database column tb_functions.func_name
  143. *
  144. * @param funcName the value for tb_functions.func_name
  145. *
  146. * @mbg.generated
  147. */
  148. public void setFuncName(String funcName) {
  149. this.funcName = funcName == null ? null : funcName.trim();
  150. }
  151.  
  152. /**
  153. * This method was generated by MyBatis Generator.
  154. * This method returns the value of the database column tb_functions.func_url
  155. *
  156. * @return the value of tb_functions.func_url
  157. *
  158. * @mbg.generated
  159. */
  160. public String getFuncUrl() {
  161. return funcUrl;
  162. }
  163.  
  164. /**
  165. * This method was generated by MyBatis Generator.
  166. * This method sets the value of the database column tb_functions.func_url
  167. *
  168. * @param funcUrl the value for tb_functions.func_url
  169. *
  170. * @mbg.generated
  171. */
  172. public void setFuncUrl(String funcUrl) {
  173. this.funcUrl = funcUrl == null ? null : funcUrl.trim();
  174. }
  175.  
  176. /**
  177. * This method was generated by MyBatis Generator.
  178. * This method returns the value of the database column tb_functions.func_code
  179. *
  180. * @return the value of tb_functions.func_code
  181. *
  182. * @mbg.generated
  183. */
  184. public String getFuncCode() {
  185. return funcCode;
  186. }
  187.  
  188. /**
  189. * This method was generated by MyBatis Generator.
  190. * This method sets the value of the database column tb_functions.func_code
  191. *
  192. * @param funcCode the value for tb_functions.func_code
  193. *
  194. * @mbg.generated
  195. */
  196. public void setFuncCode(String funcCode) {
  197. this.funcCode = funcCode == null ? null : funcCode.trim();
  198. }
  199.  
  200. /**
  201. * This method was generated by MyBatis Generator.
  202. * This method returns the value of the database column tb_functions.parent_id
  203. *
  204. * @return the value of tb_functions.parent_id
  205. *
  206. * @mbg.generated
  207. */
  208. public Integer getParentId() {
  209. return parentId;
  210. }
  211.  
  212. /**
  213. * This method was generated by MyBatis Generator.
  214. * This method sets the value of the database column tb_functions.parent_id
  215. *
  216. * @param parentId the value for tb_functions.parent_id
  217. *
  218. * @mbg.generated
  219. */
  220. public void setParentId(Integer parentId) {
  221. this.parentId = parentId;
  222. }
  223.  
  224. /**
  225. * This method was generated by MyBatis Generator.
  226. * This method returns the value of the database column tb_functions.func_type
  227. *
  228. * @return the value of tb_functions.func_type
  229. *
  230. * @mbg.generated
  231. */
  232. public Integer getFuncType() {
  233. return funcType;
  234. }
  235.  
  236. /**
  237. * This method was generated by MyBatis Generator.
  238. * This method sets the value of the database column tb_functions.func_type
  239. *
  240. * @param funcType the value for tb_functions.func_type
  241. *
  242. * @mbg.generated
  243. */
  244. public void setFuncType(Integer funcType) {
  245. this.funcType = funcType;
  246. }
  247.  
  248. /**
  249. * This method was generated by MyBatis Generator.
  250. * This method returns the value of the database column tb_functions.status
  251. *
  252. * @return the value of tb_functions.status
  253. *
  254. * @mbg.generated
  255. */
  256. public Integer getStatus() {
  257. return status;
  258. }
  259.  
  260. /**
  261. * This method was generated by MyBatis Generator.
  262. * This method sets the value of the database column tb_functions.status
  263. *
  264. * @param status the value for tb_functions.status
  265. *
  266. * @mbg.generated
  267. */
  268. public void setStatus(Integer status) {
  269. this.status = status;
  270. }
  271.  
  272. /**
  273. * This method was generated by MyBatis Generator.
  274. * This method returns the value of the database column tb_functions.sort_num
  275. *
  276. * @return the value of tb_functions.sort_num
  277. *
  278. * @mbg.generated
  279. */
  280. public Integer getSortNum() {
  281. return sortNum;
  282. }
  283.  
  284. /**
  285. * This method was generated by MyBatis Generator.
  286. * This method sets the value of the database column tb_functions.sort_num
  287. *
  288. * @param sortNum the value for tb_functions.sort_num
  289. *
  290. * @mbg.generated
  291. */
  292. public void setSortNum(Integer sortNum) {
  293. this.sortNum = sortNum;
  294. }
  295.  
  296. /**
  297. * This method was generated by MyBatis Generator.
  298. * This method returns the value of the database column tb_functions.create_time
  299. *
  300. * @return the value of tb_functions.create_time
  301. *
  302. * @mbg.generated
  303. */
  304. public Date getCreateTime() {
  305. return createTime;
  306. }
  307.  
  308. /**
  309. * This method was generated by MyBatis Generator.
  310. * This method sets the value of the database column tb_functions.create_time
  311. *
  312. * @param createTime the value for tb_functions.create_time
  313. *
  314. * @mbg.generated
  315. */
  316. public void setCreateTime(Date createTime) {
  317. this.createTime = createTime;
  318. }
  319.  
  320. /**
  321. * This method was generated by MyBatis Generator.
  322. * This method returns the value of the database column tb_functions.update_time
  323. *
  324. * @return the value of tb_functions.update_time
  325. *
  326. * @mbg.generated
  327. */
  328. public Date getUpdateTime() {
  329. return updateTime;
  330. }
  331.  
  332. /**
  333. * This method was generated by MyBatis Generator.
  334. * This method sets the value of the database column tb_functions.update_time
  335. *
  336. * @param updateTime the value for tb_functions.update_time
  337. *
  338. * @mbg.generated
  339. */
  340. public void setUpdateTime(Date updateTime) {
  341. this.updateTime = updateTime;
  342. }
  343. }

Permission

开始进入Shiro篇

一:自定义Reaml域,用于实现自身认证体系,大白话:什么样的认证规则,我都可以来定

    创建Reaml对象 继承 AuthorizingRealm 实现

授权方法

  1. doGetAuthorizationInfo(PrincipalCollection principals){}

认证方法

  1. doGetAuthenticationInfo(AuthenticationToken token){}
  1. import com.bear.entity.Permission;
  2. import com.bear.entity.User;
  3. import com.bear.service.PermissionService;
  4. import com.bear.service.UserService;
  5. import org.apache.shiro.authc.AuthenticationException;
  6. import org.apache.shiro.authc.AuthenticationInfo;
  7. import org.apache.shiro.authc.AuthenticationToken;
  8. import org.apache.shiro.authc.SimpleAuthenticationInfo;
  9. import org.apache.shiro.authz.AuthorizationInfo;
  10. import org.apache.shiro.authz.SimpleAuthorizationInfo;
  11. import org.apache.shiro.realm.AuthorizingRealm;
  12. import org.apache.shiro.subject.PrincipalCollection;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14.  
  15. import java.util.ArrayList;
  16. import java.util.List;
  17.  
  18. /**
  19. * @author wusw
  20. * @version 1.0
  21. * @date 2020/4/2 19:46
  22. */
  23. public class ShiroReaml extends AuthorizingRealm {
  24. /**
  25. * 注入userService 服务层 用户与数据库数据查询
  26. */
  27. @Autowired
  28. private UserService userService;
  29. /**
  30. * 注入permissionService 服务层 用户与数据库数据查询
  31. */
  32. @Autowired
  33. private PermissionService permissionService;
  34.  
  35. /**
  36. * 授权
  37. * @param principalCollection
  38. * @return
  39. */
  40. @Override
  41. protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
  42. //这个User对应下面认证方法的 返回的第一个参数 ew SimpleAuthenticationInfo(user, user.getPassword(), "shiroReaml")
  43. User user = (User)principalCollection.getPrimaryPrincipal();
  44. //查询用户相关权限
  45. List<Permission> permissionList = permissionService.findPermissionByUserId(user.getUserId());
  46. //授权对象
  47. SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
  48. //创建一个List<String> 用于接收权限信息
  49. ArrayList<String> list = new ArrayList<>();
  50. for (Permission permission : permissionList) {
  51. //添加权限String字符串:存值示例: "admin:*","admin:list"...
  52. info.addStringPermission(permission.getFuncCode());
  53. }
  54. return info;
  55. }
  56.  
  57. /**
  58. * 认证
  59. * @param token
  60. * @return
  61. * @throws AuthenticationException
  62. */
  63. @Override
  64. protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
  65. //这一块toString返回 username 是login方法在 newUserNamePassword(username,password)创建的token封装成的
  66. String username = token.getPrincipal().toString();
  67. //打印一下,项目中 尽量不要使用System.out.println(),最好使用log日志进行记录
  68. System.out.println("认证获取的username:"+username);
  69.  
  70. //查询数据库用户是否存在 不存在则抛异常 Shiro会自动认证失败
  71. User user = this.userService.findByUsername(username);
  72. //参数一 可以传 username,user对象 等等 我这里是user对象 对应上面授权方法principalCollection获取的值
  73. //参数二 用户密码
  74. //参数三 shiroReaml 名称要与 shiroConfig配置中的 Reaml 的注入Bean保持一致
  75. SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user, user.getPassword(), "shiroReaml");
  76. return authenticationInfo;
  77. }
  78. }

二:Shiro配置  加上注解 @Configuration 让springboot识别它为一个配置类

注意:打字太多,我把相应规则的 url 贴上,供大家参考

  1. import org.apache.shiro.mgt.SecurityManager;
  2. import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
  3. import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
  4. import org.springframework.beans.factory.annotation.Qualifier;
  5. import org.springframework.context.annotation.Bean;
  6. import org.springframework.context.annotation.Configuration;
  7.  
  8. import java.util.HashMap;
  9.  
  10. /**
  11. * 请注意看每个方法上的注释
  12. * @author wusw
  13. * @version 1.0
  14. * @date 2020/4/2 19:41
  15. */
  16. @Configuration
  17. public class ShiroConfig {
  18.  
  19. /**
  20. * 添加创建 securityMeneger 工厂注入Bean
  21. * @param securityManager 注解Qualifier中的名字 和下面 DefaultWebSecurityManager 的Bean的名字相同
  22. * @return
  23. */
  24. @Bean
  25. public ShiroFilterFactoryBean shiroFilterFactoryBean(@Qualifier("securityManager") SecurityManager securityManager){
  26. ShiroFilterFactoryBean filterFactoryBean = new ShiroFilterFactoryBean();
  27. filterFactoryBean.setSecurityManager(securityManager);
  28. //设置权限过滤器集合 key-value 形式
  29. // key :访问路径 正常/**写在最下面,执行顺序是从上至下,这里是个大坑,一不小心,程序就凉凉了呢~
  30. // value:anon(可以匿名访问),authc(认证后才能访问),logout(退出后自动清除session)
  31. HashMap<String, String> map = new HashMap<>();
  32. map.put("/bear/login","anon");
  33. map.put("/bear/logout","logout");
  34. map.put("/**","authc");
  35.  
  36. filterFactoryBean.setLoginUrl("/bear/toLogin");
  37. filterFactoryBean.setUnauthorizedUrl("/bear/401");
  38. filterFactoryBean.setSuccessUrl("/bear/index");
  39. //将map集合 传给过滤器
  40. filterFactoryBean.setFilterChainDefinitionMap(map);
  41.  
  42. return filterFactoryBean;
  43. }
  44.  
  45. /**
  46. * 创建 securityMeneger 类的注入Bean
  47. * @param shiroReaml 注解Qualifier中的名字 和下面 ShiroReaml的Bean的名字相同
  48. * @return
  49. */
  50. @Bean("securityManager")
  51. public DefaultWebSecurityManager defaultWebSecurityManager(@Qualifier("shiroReaml") ShiroReaml shiroReaml){
  52. DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
  53. securityManager.setRealm(shiroReaml);
  54. return securityManager;
  55. }
  56.  
  57. /**
  58. * 创建自定义域 reaml注入Bean
  59. * @return
  60. */
  61. @Bean("shiroReaml")
  62. public ShiroReaml shiroReaml(){
  63. return new ShiroReaml();
  64. }
  65. }

主要已经搞定,贴上相关service,controller,以及yml配置文件,dao层交互我使用的是mybaties相关pom依赖各位小伙伴自己导入 xml中namespase和type路径请自行导入

  1. # 数据库的配置信息
  2. spring:
  3. datasource:
  4. driver-class-name: com.mysql.cj.jdbc.Driver
  5. url: jdbc:mysql://0.0.0.0/db?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Hongkong&verifyServerCertificate=false
  6. username: ***
  7. password: ***
  8. type: com.alibaba.druid.pool.DruidDataSource
  9. thymeleaf:
  10. mode: HTML5
  11. encoding: UTF-8
  12. servlet:
  13. content-type: text/html
  14. mvc:
  15. static-path-pattern: /**
  16. # mybatis的配置信息
  17. mybatis:
  18. config-location: classpath:mybatis/config/mybatis-config.xml
  19. mapper-locations: classpath:mybatis/mapper/*.xml
  20.  
  21. server:
  22. port: 8081

applicaiton.yml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.bear.dao.IUserMapper">
  5.  
  6. <resultMap id="BaseResultMap" type="com.bear.entity.User">
  7. <!--
  8. WARNING - @mbg.generated
  9. This element is automatically generated by MyBatis Generator, do not modify.
  10. -->
  11. <id column="user_id" jdbcType="INTEGER" property="userId" />
  12. <result column="user_name" jdbcType="VARCHAR" property="userName" />
  13. <result column="password" jdbcType="VARCHAR" property="password" />
  14. <result column="phone" jdbcType="VARCHAR" property="phone" />
  15. <result column="email" jdbcType="VARCHAR" property="email" />
  16. <result column="salt" jdbcType="VARCHAR" property="salt" />
  17. <result column="status" jdbcType="INTEGER" property="status" />
  18. <result column="note" jdbcType="VARCHAR" property="note" />
  19. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  20. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  21. </resultMap>
  22.  
  23. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  24. <!--
  25. WARNING - @mbg.generated
  26. This element is automatically generated by MyBatis Generator, do not modify.
  27. -->
  28. delete from tb_users
  29. where user_id = #{userId,jdbcType=INTEGER}
  30. </delete>
  31. <insert id="insert" parameterType="com.bear.entity.User">
  32. insert into tb_users (user_id, user_name, password,
  33. phone, email, status,
  34. note, create_time, update_time
  35. )
  36. values (#{userId,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
  37. #{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
  38. #{note,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
  39. )
  40. </insert>
  41. <update id="updateByPrimaryKey" parameterType="com.bear.entity.User">
  42. <!--
  43. WARNING - @mbg.generated
  44. This element is automatically generated by MyBatis Generator, do not modify.
  45. -->
  46. update tb_users
  47. set user_name = #{userName,jdbcType=VARCHAR},
  48. password = #{password,jdbcType=VARCHAR},
  49. phone = #{phone,jdbcType=VARCHAR},
  50. email = #{email,jdbcType=VARCHAR},
  51. status = #{status,jdbcType=INTEGER},
  52. note = #{note,jdbcType=VARCHAR},
  53. create_time = #{createTime,jdbcType=TIMESTAMP},
  54. update_time = #{updateTime,jdbcType=TIMESTAMP}
  55. where user_id = #{userId,jdbcType=INTEGER}
  56. </update>
  57. <!-- <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  58. select user_id, user_name, password, phone, email, status, note, create_time, update_time
  59. from tb_users
  60. where user_id = #{userId,jdbcType=INTEGER}
  61. </select>-->
  62. <select id="findAll" resultMap="BaseResultMap">
  63. select user_id, user_name, password, phone, email, status, note, create_time, update_time
  64. from tb_users
  65. </select>
  66.  
  67. <!-- 根据用户名密码查询 -->
  68. <select id="findByUsername" resultMap="BaseResultMap">
  69. select * from tb_users where user_name = #{username}
  70. </select>
  71. <!-- 根据分页查询 -->
  72. <!-- <select id="findByPage" resultMap="BaseResultMap">
  73. select * from tb_users limit #{page},#{rows}
  74. </select>
  75. &lt;!&ndash; 统计总记录数 &ndash;&gt;
  76. <select id="totalCount" resultType="long">
  77. select count(*) from tb_users
  78. </select>
  79. &lt;!&ndash; 根据ID查询 &ndash;&gt;
  80. <select id="findById" resultMap="BaseResultMap">
  81. select * from tb_users where user_id = #{userId}
  82. </select>-->
  83.  
  84. </mapper>

IUserMappler.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.bear.dao.IPermissionMapper">
  4. <resultMap id="BaseResultMap" type="com.bear.entity.Permission">
  5. <!-- WARNING - @mbg.generated This element is automatically generated by
  6. MyBatis Generator, do not modify. -->
  7. <id column="func_id" jdbcType="INTEGER" property="funcId" />
  8. <result column="func_name" jdbcType="VARCHAR" property="funcName" />
  9. <result column="func_url" jdbcType="VARCHAR" property="funcUrl" />
  10. <result column="func_code" jdbcType="VARCHAR" property="funcCode" />
  11. <result column="parent_id" jdbcType="INTEGER" property="parentId" />
  12. <result column="func_type" jdbcType="INTEGER" property="funcType" />
  13. <result column="status" jdbcType="INTEGER" property="status" />
  14. <result column="sort_num" jdbcType="INTEGER" property="sortNum" />
  15. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  16. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  17. </resultMap>
  18. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  19. <!-- WARNING - @mbg.generated This element is automatically generated by
  20. MyBatis Generator, do not modify. -->
  21. delete from tb_functions
  22. where func_id = #{funcId,jdbcType=INTEGER}
  23. </delete>
  24. <insert id="insert" parameterType="com.bear.entity.Permission">
  25. <!-- WARNING - @mbg.generated This element is automatically generated by
  26. MyBatis Generator, do not modify. -->
  27. insert into tb_functions (func_id, func_name, func_url,
  28. func_code,
  29. parent_id, func_type,
  30. status, sort_num, create_time,
  31. update_time)
  32. values
  33. (#{funcId,jdbcType=INTEGER}, #{funcName,jdbcType=VARCHAR},
  34. #{funcUrl,jdbcType=VARCHAR},
  35. #{funcCode,jdbcType=VARCHAR},
  36. #{parentId,jdbcType=INTEGER}, #{funcType,jdbcType=INTEGER},
  37. #{status,jdbcType=INTEGER}, #{sortNum,jdbcType=INTEGER},
  38. #{createTime,jdbcType=TIMESTAMP},
  39. #{updateTime,jdbcType=TIMESTAMP})
  40. </insert>
  41. <update id="updateByPrimaryKey" parameterType="com.bear.entity.Permission">
  42. <!-- WARNING - @mbg.generated This element is automatically generated by
  43. MyBatis Generator, do not modify. -->
  44. update tb_functions
  45. set func_name = #{funcName,jdbcType=VARCHAR},
  46. func_url = #{funcUrl,jdbcType=VARCHAR},
  47. func_code =
  48. #{funcCode,jdbcType=VARCHAR},
  49. parent_id = #{parentId,jdbcType=INTEGER},
  50. func_type = #{funcType,jdbcType=INTEGER},
  51. status =
  52. #{status,jdbcType=INTEGER},
  53. sort_num = #{sortNum,jdbcType=INTEGER},
  54. create_time = #{createTime,jdbcType=TIMESTAMP},
  55. update_time =
  56. #{updateTime,jdbcType=TIMESTAMP}
  57. where func_id =
  58. #{funcId,jdbcType=INTEGER}
  59. </update>
  60. <select id="selectByPrimaryKey" parameterType="java.lang.Integer"
  61. resultMap="BaseResultMap">
  62. <!-- WARNING - @mbg.generated This element is automatically generated by
  63. MyBatis Generator, do not modify. -->
  64. select func_id, func_name, func_url, func_code, parent_id, func_type,
  65. status, sort_num,
  66. create_time, update_time
  67. from tb_functions
  68. where
  69. func_id = #{funcId,jdbcType=INTEGER}
  70. </select>
  71. <select id="selectAll" resultMap="BaseResultMap">
  72. <!-- WARNING - @mbg.generated This element is automatically generated by
  73. MyBatis Generator, do not modify. -->
  74. select func_id, func_name, func_url, func_code, parent_id, func_type,
  75. status, sort_num,
  76. create_time, update_time
  77. from tb_functions
  78. </select>
  79.  
  80. <select id="findByRoleIds" resultMap="BaseResultMap"
  81. parameterType="java.util.List">
  82. select distinct f.* from tb_functions f , tb_role_function rf where
  83. f.func_id = rf.func_id and rf.role_id in
  84. <foreach collection="list" item="id" open="(" close=")"
  85. separator=",">
  86. #{id}
  87. </foreach>
  88. and f.func_type = 0
  89. </select>
  90.  
  91. <select id="findPermissionByUserId" resultMap="BaseResultMap"
  92. parameterType="int">
  93. select
  94. DISTINCT
  95. f.*
  96. from
  97. tb_users u,tb_user_role ur,tb_roles r,tb_functions f,tb_role_function rf
  98. where
  99. u.user_id = ur.user_id and
  100. r.role_id = ur.role_id and
  101. f.func_id = rf.func_id and
  102. r.role_id = rf.role_id and
  103. u.user_id = #{userId}
  104. </select>
  105.  
  106. </mapper>

IPermissionMapper

dao层:

  1. import org.apache.ibatis.annotations.Mapper;
  2.  
  3. import java.util.List;
  4.  
  5. @Mapper
  6. public interface IUserMapper {
  7. /**
  8. * 根据用户名查找用户
  9. * @param username
  10. * @return
  11. */
  12. User findByUsername(String username);
  13.  
  14. /**
  15. * 更新
  16. * @param user
  17. */
  18. void updateByPrimaryKey(User user);
  19.  
  20. /**
  21. * 新增
  22. * @param user
  23. */
  24. void insert(User user);
  25.  
  26. /**
  27. * 根据id删除用户(后期修改为改变状态)
  28. * @param id
  29. */
  30. void deleteByPrimaryKey(Integer id);
  31.  
  32. /**
  33. * 查询所有用户列表
  34. * @return
  35. */
  36. List<User> findAll();
  37. }

IUserMapper

  1. import org.apache.ibatis.annotations.Mapper;
  2.  
  3. import java.util.List;
  4.  
  5. /**
  6. * @author wusiwee
  7. * @date 2020/4/3 11:00
  8. */
  9. @Mapper
  10. public interface IPermissionMapper {
  11.  
  12. /**
  13. * 根据user id查询用户权限
  14. * @param userId
  15. * @return
  16. */
  17. List<Permission> findPermissionByUserId(Integer userId);
  18. }

IPermissionMapper

service层:

  1. import java.util.List;
  2.  
  3. public interface UserService {
  4.  
  5. User findByUsername(String username);
  6.  
  7. List<User> findAll();
  8. }

UserService

  1. import com.bear.dao.IUserMapper;
  2. import com.bear.entity.User;
  3. import com.bear.service.UserService;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6.  
  7. import java.util.List;
  8.  
  9. @Service
  10. public class UserServiceImpl implements UserService {
  11.  
  12. @Autowired
  13. private IUserMapper userMapper;
  14.  
  15. @Override
  16. public User findByUsername(String username) {
  17. User result = null;
  18. if (username != null) {
  19. result = this.userMapper.findByUsername(username);
  20. }
  21. return result;
  22. }
  23.  
  24. @Override
  25. public List<User> findAll() {
  26. return this.userMapper.findAll();
  27. }
  28. }

UserServiceImpl

  1. import com.bear.entity.Permission;
  2.  
  3. import java.util.List;
  4.  
  5. /**
  6. * @author wusiwee
  7. * @date 2020/4/3 11:02
  8. */
  9. public interface PermissionService {
  10.  
  11. List<Permission> findPermissionByUserId(Integer userId);
  12. }

PermissionService

  1. import com.bear.dao.IPermissionMapper;
  2. import com.bear.entity.Permission;
  3. import com.bear.service.PermissionService;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6.  
  7. import java.util.List;
  8.  
  9. /**
  10. * @author wusiwee
  11. * @date 2020/4/3 11:02
  12. */
  13. @Service
  14. public class PermissionServiceImpl implements PermissionService {
  15.  
  16. @Autowired
  17. private IPermissionMapper permissionMapper;
  18.  
  19. @Override
  20. public List<Permission> findPermissionByUserId(Integer userId) {
  21. List<Permission> result = null;
  22. if (userId != null) {
  23. result = this.permissionMapper.findPermissionByUserId(userId);
  24. }
  25. return result;
  26. }
  27. }

PermissionServiceImpl

controller层(注意Login方法的subject为shiro登录使用):

  1. 注解@RequiresPermissions("system:*")为校验用户是否有权限,没有此权限则不允许访问此方法 跳转401
  1. import com.bear.service.UserService;
  2. import org.apache.commons.lang3.StringUtils;
  3. import org.apache.shiro.SecurityUtils;
  4. import org.apache.shiro.authc.UsernamePasswordToken;
  5. import org.apache.shiro.authz.annotation.RequiresPermissions;
  6. import org.apache.shiro.subject.Subject;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.ui.Model;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12.  
  13. @Controller
  14. @RequestMapping("/bear")
  15. public class LoginController {
  16.  
  17. @Autowired
  18. private UserService userService;
  19.  
  20. @GetMapping("toLogin")
  21. public String toLogin(){
  22. return "login";
  23. }
  24.  
  25. @GetMapping("/login")
  26. public String login(String username, String password, Model model){
  27. if (!StringUtils.isEmpty(username) && !StringUtils.isEmpty(password)){
  28. //进行登录验证
  29. Subject subject = SecurityUtils.getSubject();
  30. UsernamePasswordToken token = new UsernamePasswordToken(username, password);
  31. try {
  32. subject.login(token);
  33. //认证
  34. boolean authenticated = subject.isAuthenticated();
  35. if (authenticated){
  36. //获取当前对象,存入session
  37. User user = (User)subject.getPrincipal();
  38. subject.getSession().setAttribute("user",user);
  39. System.out.println("登陆成功");
  40. return "redirect:index";
  41. }else {
  42. model.addAttribute("msg","登录认证失败!");
  43. return "login";
  44. }
  45. }catch (Exception e){
  46. model.addAttribute("msg","登录认证失败!");
  47. return "login";
  48. }
  49.  
  50. }
  51. return "login";
  52. }
  53. @RequestMapping("/index")
  54. public String index(Model model){
  55. model.addAttribute("userList",this.userService.findAll());
  56. return "index";
  57. }
  58.  
  59. @RequestMapping("/logout")
  60. public String index(){
  61. return "redirect:login";
  62. }
  63.  
  64. @RequestMapping("/401")
  65. public String fours(){
  66. return "401";
  67. }
  68.  
  69. @RequiresPermissions("system")
  70. @RequestMapping("/success")
  71. public String success(){
  72. return "success";
  73. }
  74. }

LoginController

html 页面:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>成功页面</title>
  6. </head>
  7. <body>
  8. SUCCESS!
  9. </body>
  10. </html>

success页面

  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>登录页面</title>
  6. </head>
  7. <body>
  8. <h2>欢迎来到登录页面!</h2>
  9. <form action="/bear/login" method="GET" name="loginForm">
  10. 登录用户:<input type="text" name="username" value=""><br/>
  11. 登录密码:<input type="text" name="password" value=""><br/>
  12. <input type="submit" name="log" value="登录">
  13. </form>
  14. <!--/*@thymesVar id="msg" type="at"*/-->
  15. <div th:text="${msg}"></div>
  16. </body>
  17. </html>

login页面

  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>首面</title>
  6. </head>
  7. <style>
  8. table{
  9. border: 1px solid grey;
  10. border-collapse: collapse;
  11. }
  12. table td{
  13. border: 1px solid grey;
  14. border-collapse: collapse;
  15. }
  16. </style>
  17. <body>
  18. <h2>用户列表页面</h2>
  19. <table>
  20. <tr>
  21. <td>用户ID</td>
  22. <td>用户名</td>
  23. <td>手机号</td>
  24. <td>邮箱</td>
  25. <td>状态</td>
  26. <td>创建时间</td>
  27. </tr>
  28. <tr th:each="user:${userList}">
  29. <td th:text="${user.userId}"></td>
  30. <td th:text="${user.userName}"></td>
  31. <td th:text="${user.phone}"></td>
  32. <td th:text="${user.email}"></td>
  33. <td th:text="${user.status == 1?'正常':'失效'}">正常</td>
  34. <td th:text="${user.createTime}"></td>
  35. </tr>
  36. </table>
  37. <form action="/bear/logout" method="get">
  38. <input type="submit" value="退出">
  39. </form>
  40. </body>
  41. </html>

index页面

  1. <!DOCTYPE html>
  2. <html lang="en" xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>401没有认证</title>
  6. </head>
  7. <body>
  8. <h2>抱歉,您的权限不足或认证失败,请重新登录!</h2>
  9. </body>
  10. </html>

401没有权限页面

配置完成

启动运行Applicaiton.java,最后一行,启动成功  

  1. . ____ _ __ _ _
  2.  
  3. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  4. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  5. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  6. ' |____| .__|_| |_|_| |_\__, | / / / /
  7. =========|_|==============|___/=/_/_/_/
  8. :: Spring Boot :: (v2.2.6.RELEASE)
  9.  
  10. 2020-04-07 15:11:42.580 INFO 14672 --- [ main] com.bear.PublicApplication : Starting PublicApplication on shands-siwee with PID 14672 (D:\java\GitProjects\bear-world\target\classes started by Shands-New in D:\java\GitProjects\bear-world)
  11. 2020-04-07 15:11:42.584 INFO 14672 --- [ main] com.bear.PublicApplication : No active profile set, falling back to default profiles: default
  12. 2020-04-07 15:11:43.534 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'shiroConfig' of type [com.bear.shiro.ShiroConfig$$EnhancerBySpringCGLIB$$45102fe0] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  13. 2020-04-07 15:11:43.599 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'mybatis-org.mybatis.spring.boot.autoconfigure.MybatisProperties' of type [org.mybatis.spring.boot.autoconfigure.MybatisProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  14. 2020-04-07 15:11:43.604 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration' of type [org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration$$EnhancerBySpringCGLIB$$6a2f2642] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  15. 2020-04-07 15:11:43.605 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Generic' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Generic] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  16. 2020-04-07 15:11:43.617 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  17. 2020-04-07 15:11:43.665 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSource' of type [com.alibaba.druid.pool.DruidDataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  18. 2020-04-07 15:11:43.677 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  19. 2020-04-07 15:11:43.923 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'sqlSessionFactory' of type [org.apache.ibatis.session.defaults.DefaultSqlSessionFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  20. 2020-04-07 15:11:43.926 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'sqlSessionTemplate' of type [org.mybatis.spring.SqlSessionTemplate] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  21. 2020-04-07 15:11:43.928 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'IUserMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  22. 2020-04-07 15:11:43.929 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'IUserMapper' of type [com.sun.proxy.$Proxy63] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  23. 2020-04-07 15:11:43.929 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'userServiceImpl' of type [com.bear.service.impl.UserServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  24. 2020-04-07 15:11:43.932 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'IPermissionMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  25. 2020-04-07 15:11:43.932 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'IPermissionMapper' of type [com.sun.proxy.$Proxy64] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  26. 2020-04-07 15:11:43.932 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'permissionServiceImpl' of type [com.bear.service.impl.PermissionServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  27. 2020-04-07 15:11:43.933 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'shiroReaml' of type [com.bear.shiro.ShiroReaml] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  28. 2020-04-07 15:11:44.601 INFO 14672 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'securityManager' of type [org.apache.shiro.web.mgt.DefaultWebSecurityManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  29. 2020-04-07 15:11:44.857 INFO 14672 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8081 (http)
  30. 2020-04-07 15:11:44.868 INFO 14672 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
  31. 2020-04-07 15:11:44.868 INFO 14672 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
  32. 2020-04-07 15:11:45.041 INFO 14672 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
  33. 2020-04-07 15:11:45.042 INFO 14672 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2400 ms
  34. 2020-04-07 15:11:45.231 INFO 14672 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
  35. 2020-04-07 15:11:45.301 INFO 14672 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
  36. 2020-04-07 15:11:45.356 WARN 14672 --- [ main] org.thymeleaf.templatemode.TemplateMode : [THYMELEAF][main] Template Mode 'HTML5' is deprecated. Using Template Mode 'HTML' instead.
  37. 2020-04-07 15:11:45.455 INFO 14672 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8081 (http) with context path ''
  38. 2020-04-07 15:11:45.458 INFO 14672 --- [ main] com.bear.PublicApplication : Started PublicApplication in 3.516 seconds (JVM running for 4.842)

启动程序

测试访问 :localhost:8081/bear/index ——>此时是被拦截的,会自动跳转toLogin到登录页面

 

spring-boot整合shiro作权限认证的更多相关文章

  1. Spring Boot 整合 Shiro ,两种方式全总结!

    在 Spring Boot 中做权限管理,一般来说,主流的方案是 Spring Security ,但是,仅仅从技术角度来说,也可以使用 Shiro. 今天松哥就来和大家聊聊 Spring Boot ...

  2. Spring Boot2 系列教程(三十二)Spring Boot 整合 Shiro

    在 Spring Boot 中做权限管理,一般来说,主流的方案是 Spring Security ,但是,仅仅从技术角度来说,也可以使用 Shiro. 今天松哥就来和大家聊聊 Spring Boot ...

  3. Spring Boot 整合 Shiro实现认证及授权管理

    Spring Boot Shiro 本示例要内容 基于RBAC,授权.认证 加密.解密 统一异常处理 redis session支持 介绍 Apache Shiro 是一个功能强大且易于使用的Java ...

  4. Spring boot整合shiro权限管理

    Apache Shiro功能框架: Shiro聚焦与应用程序安全领域的四大基石:认证.授权.会话管理和保密. #,认证,也叫作登录,用于验证用户是不是他自己所说的那个人: #,授权,也就是访问控制,比 ...

  5. spring boot 2 + shiro 实现权限管理

    Shiro是一个功能强大且易于使用的Java安全框架,主要功能有身份验证.授权.加密和会话管理.看了网上一些文章,下面2篇文章写得不错.Springboot2.0 集成shiro权限管理 Spring ...

  6. spring boot整合shiro后,部分注解(Cache缓存、Transaction事务等)失效的问题

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/elonpage/article/details/78965176 前言 整合有缓存.事务的sprin ...

  7. Spring boot整合shiro框架

    ShiroConfiguration package com.energy.common.config; import java.util.LinkedHashMap; import java.uti ...

  8. spring boot整合shiro出现UnavailableSecurityManagerException

    spring boot自带spring security,spring security自然不用说是一个强大的安全框架,但是用惯了shiro,一时半会用不来spring security,所以要在sp ...

  9. 上手spring boot项目(二)之spring boot整合shiro安全框架

    题记:在学习了springboot和thymeleaf之后,想完成一个项目练练手,于是使用springboot+mybatis和thymeleaf完成一个博客系统,在完成的过程中出现的一些问题,将这些 ...

随机推荐

  1. javascript的DI

    学习AngularJS的原因之一就是觉得他的DI很牛叉,为了更好的学习,在研究源码之前,想自己按照自己的思路先实现个DI,希望这个思路能够对学习源码有帮助. (function(){ var conf ...

  2. HTML5-A*寻路算法

    设置起点 设置终点 设置障碍 清除障碍 允许斜向跨越

  3. 9、IPA通路分析相关网页教程

    IPA FAQ: http://ingenuity.force.com/ipa/IPATutorials# ####有各种相关教程和帮助文件. IPA 分析结果展示: http://www.lucid ...

  4. Entity Framework Code-First(13):Configure Many-to-Many

    Configure Many-to-Many relationship: Here, we will learn how to configure Many-to-Many relationship ...

  5. python远程登录Paramiko模块的安装

    最近做云平台的项目,需要使用python来管理所有的主机,我选择了paramiko.它跨平台的,linux和window都可以使用,pssh只支持linux. 1:安装gcc和python-devel ...

  6. OC官方文档翻译-Values-and-Collections-值与集合类型

    查看全部文档翻译,请浏览https://github.com/L1l1thLY/Programming-with-Objective-C-in-Chinese,blog仅收录本人翻译的两章. 简述 O ...

  7. 清北刷题冲刺 11-02 p.m

    函数最值 #include<iostream> #include<cstdio> #include<cstring> #define maxn 100010 usi ...

  8. Android进阶书籍推荐

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/124 Android进阶书籍推荐 端午节前我写了drake ...

  9. 在 CentOS7 安装 ELK【转】

    ELK是一个成熟的日志系统,主要功能有收集.分析.检索,详细见 elastic官网. 本文主要介绍如何在CentOS7下安装最新版本的ELK,当然现在docker已经有完全配置成功的elk容器,安装配 ...

  10. MarkDown基础语法大全

    一.MarkDown是什么? Markdown是一种轻量级的「标记语言」,创始人为约翰·格鲁伯,用简洁的语法代替排版,目前被越来越多的知识工作者.写作爱好者.程序员或研究员广泛使用.其常用的标记符号不 ...