用的spring security  做的权限控制, 当  访问没有权限, 跳转 会跳到默认403 页面。不符合当前项目需求。

一下是解决方式:

package com.ycmedia;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import com.ycmedia.service.UserService; @SpringBootApplication
@EnableAutoConfiguration
public class Application extends WebMvcConfigurerAdapter { @Bean
public UserDetailsService userDetailsService() {
return new UserService();
}
/**
* 自定义异常页
*/
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() { return (container -> {
ErrorPage error401Page = new ErrorPage(HttpStatus.FORBIDDEN, "/403.html");
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");
container.addErrorPages(error401Page, error404Page, error500Page);
});
} @Override
public void addViewControllers(ViewControllerRegistry registry) {
} public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

看到网上什么实现AccessDeniedHandler  ,好像不好用。

spring security +spring boot 自定义 403 页面的更多相关文章

  1. spring security 授权方式(自定义)及源码跟踪

    spring security 授权方式(自定义)及源码跟踪 ​ 这节我们来看看spring security的几种授权方式,及简要的源码跟踪.在初步接触spring security时,为了实现它的 ...

  2. Spring Boot自定义错误页面,Whitelabel Error Page处理方式

    我已经是Spring Framework框架的忠实粉丝.对于企业软件开发者来说它提供了对常见问题的通用解决方案,包括那些你在未来开发中没有意识到的问题.但是,它构建的J2EE项目变得比较臃肿,需要被一 ...

  3. (后端)Spring Boot自定义错误页面,Whitelabel Error Page处理方式(转)

    我已经是Spring Framework框架的忠实粉丝.对于企业软件开发者来说它提供了对常见问题的通用解决方案,包括那些你在未来开发中没有意识到的问题.但是,它构建的J2EE项目变得比较臃肿,需要被一 ...

  4. Spring Security学习笔记-自定义Spring Security过滤链

    Spring Security使用一系列过滤器处理用户请求,下面是spring-security.xml配置文件. <?xml version="1.0" encoding= ...

  5. spring boot:swagger3的安全配置(swagger 3.0.0 / spring security / spring boot 2.3.3)

    一,swagger有哪些环节需要注意安全? 1,生产环境中,要关闭swagger application.properties中配置: springfox.documentation.swagger- ...

  6. Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken

    在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Securit ...

  7. Spring Security笔记:自定义登录页

    以下内容参考了 http://www.mkyong.com/spring-security/spring-security-form-login-example/ 接上回,在前面的Hello Worl ...

  8. spring security方法一 自定义数据库表结构

    Spring Security默认提供的表结构太过简单了,其实就算默认提供的表结构很复杂,也无法满足所有企业内部对用户信息和权限信息管理的要求.基本上每个企业内部都有一套自己的用户信息管理结构,同时也 ...

  9. 【JavaEE】SSH+Spring Security+Spring oauth2整合及example

    现在加最后一样,就是oauth2,现在很多网站都有对应的移动版本,那么移动端访问服务端的服务怎么控制权限,我知道的主要是两种方法,第一是模拟浏览器,访问服务的时候会生成session,之后在移动端缓存 ...

随机推荐

  1. Linux(Fedora)下NodeJs升级最新版本(制定版本)

    Linux(Fedora)下NodeJs升级最新版本(制定版本) 首先安装n模块: npm install -g n 升级node.js到最新稳定版 n stable 升级node.js到制定版本 n ...

  2. JavaScript学习心得(六)

    函数 对函数参数没有任何类型检查(弱类型),在必要时在函数内加上类型检查(typeof): JavaScript的函数参数无法设置默认值(可以通过检查参数,当为undefined时设置一个值 func ...

  3. 一些static_cast const_cast

    static_cast:干杂活的,那三个都有各自的专有用途,那三个不做的都由这个转型符来做,只要它能做的,用C语法的强制类型转换运算符也一定能够完成:但话又说回来了,C强制类型转换能做的,它可不一定都 ...

  4. js 中文排序

    /** * 比较函数 * @param {Object} param1 要比较的参数1 * @param {Object} param2 要比较的参数2 * @return {Number} 如果pa ...

  5. WPF扩展标记

    标记扩展和 WPF XAML,标记扩展是 XAML 语言以及 XAML 服务的 .NET 实现的常规功能 XAML 处理器和标记扩展 XAML 分析器可将特性值解释为可转换成基元的文本字符串,或可通过 ...

  6. Window7 下开发php扩展

    一.首先查看phpinfo() 信息PHP Version 5.4.34Zend Extension Build     API220100525,TS,VC9 PHP Extension Build ...

  7. [原创]dm642_HPI调通并boot成功

    一直在折腾前段时间画好的dm642+lpc4357板子,说明下这个板子的结构: 主芯片为DM642,这个片子很老了,但因为对这个片子熟悉,别折腾 没有给DM642加FLASH,配了一片LPC4357, ...

  8. ​? super T ? extends T

    ​? super T ?保存的是  T类型或者T类型的父类 ​ ? extends T ?保存的是  T类型或者T类型的子类

  9. git reset到之前的某一个commit或者恢复之前删除的某一个分支

    一.使用了git reset之后,想要找回某一个commit 1.git log -g  这个命令只能显示少部分的commit 推荐使用git reflog 找到想要恢复的那个commit的hash, ...

  10. Fragment 常见问题

    1. 因为Fragment是在3.0提出的,为了兼容低版本,需要引入一个android-support-v4.jar 2. 需要实例化的activity必须 extends FragmentActiv ...