Giter VIP home page Giter VIP logo

springboot-shiro's Introduction

springboot-shiro

项目介绍

Springboot + shiro权限管理。这或许是流程最详细、代码最干净、配置最简单的shiro上手项目了。

开发环境

工具 版本或描述
OS Windows 7
JDK 1.7+
IDE IntelliJ IDEA 2017.3
Maven 3.3.1
MySQL 5.6.4

模块划分

模块 释义
shiro-core 核心业务类模块,提供基本的数据操作、工具处理等
shiro-admin 后台管理模块

SQL Model

sql model

使用说明

  1. 使用IDE导入本项目
  2. 新建数据库CREATE DATABASE shiro;
  3. 导入数据库docs/db/shiro.sql
  4. 修改(resources/application.yml)配置文件
    1. 数据库链接属性(可搜索datasource或定位到L.19)
    2. redis配置(可搜索redis或定位到L.69)
  5. 运行项目(三种方式)
    1. 项目根目录下执行mvn -X clean package -Dmaven.test.skip=true编译打包,然后执行java -jar shiro-admin/target/shiro-admin.jar
    2. 项目根目录下执行mvn springboot:run
    3. 直接运行ShiroAdminApplication.java
  6. 浏览器访问http://127.0.0.1:8080

用户密码

超级管理员: 账号:root 密码:123456

普通管理员: 账号:admin 密码:123456

Druid监控

链接http://127.0.0.1:8080/druid/index.html

用户名:zyd-druid 密码:zyd-druid

参与贡献

  1. Fork 本项目
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

参考资料

  1. 本项目部分代码参考自网络文章。查看原文链接
  2. 前端模板来源自开源模板。查看模板链接查看开源项目
  3. 部分js实现参考自本人开源项目。查看开源项目

感谢无私的网友,如果其他问题,欢迎各位朋友指正。

图片预览

首页 资源管理 角色管理 角色分配资源 用户管理 用户分配角色

注:以上图片是以root用户登录,admin用户的界面请参考docs/img下的图片

生命不息,折腾不止! 更多信息,请关注:

  1. 我的博客
  2. 我的微博
  3. 我的头条号
  4. 我的imooc
  5. 我的CSDN

有任何问题可以

微信(备注:加群) 公众号

开源协议

MIT

springboot-shiro's People

Contributors

zhangyd-c avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

springboot-shiro's Issues

大佬,我把你这个项目改成springboot2.0的,我故意输入一个错误的url会出现 UnavailableSecurityManagerException。我想问下你怎么解决的这个问题.下面是我的异常处理

``package com.xiaobu.controller;

import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**

  • @author xiaobu

  • @Version JDK1.8.0_171

  • @Date on 2019/2/21 11:56

  • @description V1.0
    */
    @controller
    public class MyErrorController extends BasicErrorController {
    public MyErrorController() {
    super(new DefaultErrorAttributes(), new ErrorProperties());
    }

    /**

    •     * 定义500的ModelAndView
    •     * @param request
    •     * @param response
    •     * @return
      */
      @RequestMapping(produces = "text/html", value = "/404")
      public ModelAndView errorHtml404(HttpServletRequest request, HttpServletResponse response) {
      response.setStatus(getStatus(request).value());
      Map<String, Object> model = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.TEXT_HTML));
      model.put("msg", "自定义错误信息");
      return new ModelAndView("error/404", model);
      }

    @RequestMapping(produces = "text/html", value = "/500")
    public ModelAndView errorHtml500(HttpServletRequest request, HttpServletResponse response) {
    response.setStatus(getStatus(request).value());
    Map<String, Object> model = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.TEXT_HTML));
    model.put("msg", "自定义错误信息");
    return new ModelAndView("error/500", model);
    }

    /**

    •     * 定义500的错误JSON信息
    •     * @param request
    •     * @return
      */
      @RequestMapping(value = "/500")
      @responsebody
      public ResponseEntity<Map<String, Object>> error500(HttpServletRequest request) {
      Map<String, Object> body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.TEXT_HTML));
      HttpStatus status = getStatus(request);
      return new ResponseEntity<Map<String, Object>>(body, status);
      }

}

package com.xiaobu.config;

import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**

  • 自定义的异常页面配置
    */
    @component
    public class ErrorPagesConfig {

    /**

    • 自定义异常处理路径
      */
      @bean
      public WebServerFactoryCustomizer webServerFactoryCustomizer() {
      //第二种写法:java8 lambda写法
      return (factory -> {
      ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404");
      ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
      ErrorPage errorPage401 = new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/500");
      ErrorPage errorPage403 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
      factory.addErrorPages(errorPage404);
      factory.addErrorPages(errorPage500);
      factory.addErrorPages(errorPage401);
      factory.addErrorPages(errorPage403);
      });

    }

}

我故意输入一个错误的url会出现 UnavailableSecurityManagerException

Caused by: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration. at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123) at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:626) at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56) at com.jagregory.shiro.freemarker.SecureTag.getSubject(SecureTag.java:32) at com.jagregory.shiro.freemarker.UserTag.render(UserTag.java:30) at com.jagregory.shiro.freemarker.SecureTag.execute(SecureTag.java:16) at freemarker.core.Environment.visit(Environment.java:445) at freemarker.core.UnifiedCall.accept(UnifiedCall.java:101) at freemarker.core.Environment.visit(Environment.java:330) at freemarker.core.Environment.visit(Environment.java:336) at freemarker.core.Environment.include(Environment.java:2582) at freemarker.core.Include.accept(Include.java:171) at freemarker.core.Environment.visit(Environment.java:330) at freemarker.core.Environment.visit(Environment.java:336) at freemarker.core.Environment.include(Environment.java:2582) at freemarker.core.Include.accept(Include.java:171) at freemarker.core.Environment.visit(Environment.java:330) at freemarker.core.Environment.visit(Environment.java:336) at freemarker.core.Environment.process(Environment.java:309) at freemarker.template.Template.process(Template.java:384) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:389) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:302) at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:253) at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:178) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ... 26 common frames omitted

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.