security配置

import com.yineng.corpsysland.security.*;
import com.yineng.corpsysland.web.filter.AuthorizationActiveFilter;
import com.yineng.corpsysland.web.filter.AuthorizationExpiredFilter;
import com.yineng.corpsysland.web.filter.CsrfCookieGeneratorFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.security.web.csrf.CsrfFilter; import javax.inject.Inject;
import javax.servlet.Filter; @Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Inject
private Environment env; @Inject
private AjaxAuthenticationSuccessHandler ajaxAuthenticationSuccessHandler; @Inject
private AjaxLogoutSuccessHandler ajaxLogoutSuccessHandler; @Inject
private AuthenticationProvider authenticationProvider; @Inject
private RememberMeServices rememberMeServices; @Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
} @Inject
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider);
} @Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/oauth/**");
} @Override
protected void configure(HttpSecurity http) throws Exception { http
.csrf()
.ignoringAntMatchers("/websocket/**")
.ignoringAntMatchers("/api/authentication/**")
.ignoringAntMatchers("/api/logout/**")
.and()
.addFilterAfter(new CsrfCookieGeneratorFilter(), CsrfFilter.class)
.addFilterBefore(authorizationActiveFilter(), AuthenticationFilter.class)
.addFilterAfter(authorizationExpiredFilter(), AuthenticationFilter.class)
.rememberMe()
.rememberMeServices(rememberMeServices)
.rememberMeParameter("remember-me")
.key(env.getProperty("jhipster.security.rememberme.key"))
.and()
.formLogin().loginPage("/login.html")
.loginProcessingUrl("/api/authentication")
.successHandler(ajaxAuthenticationSuccessHandler)
.failureHandler(authenticationFailureHandler())
.usernameParameter("j_username")
.passwordParameter("j_password")
.permitAll()
.and()
.logout()
.logoutUrl("/api/logout")
.logoutSuccessHandler(ajaxLogoutSuccessHandler)
.deleteCookies("JSESSIONID")
.permitAll()
.and()
.headers()
.frameOptions()
.disable()
.and()
.authorizeRequests().anyRequest().authenticated()
.antMatchers("/activeSystem").permitAll()
.antMatchers("/api/register").permitAll()
.antMatchers("/api/activate").permitAll()
.antMatchers("/api/authenticate").permitAll()
.antMatchers("/api/account/reset_password/init").permitAll()
.antMatchers("/api/account/reset_password/finish").permitAll()
.antMatchers("/api/logs/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/api/**").authenticated()
.antMatchers("/metrics/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/health/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/trace/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/dump/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/shutdown/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/beans/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/configprops/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/info/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/autoconfig/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/env/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/trace/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/api-docs/**").hasAuthority(AuthoritiesConstants.ADMIN)
.antMatchers("/protected/**").authenticated();
} @Bean
public SecurityEvaluationContextExtension securityEvaluationContextExtension() {
return new SecurityEvaluationContextExtension();
} @Bean
public AuthenticationFailureHandler authenticationFailureHandler() {
return new AjaxAuthenticationFailureHandler("/activeSystem");
} @Bean
public Filter authorizationActiveFilter() {
return new AuthorizationActiveFilter(authenticationFailureHandler());
} @Bean
public Filter authorizationExpiredFilter() {
return new AuthorizationExpiredFilter(authenticationFailureHandler());
} }

配置拦截器

import com.yineng.corpsysland.config.locale.AngularCookieLocaleResolver;
import com.yineng.corpsysland.security.TokenAuthHandler;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; @Configuration
public class MyConfiguration extends WebMvcConfigurerAdapter{ @Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new TokenAuthHandler()).addPathPatterns("/third/**");
}
}
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

SpringBoot使用的心得记录的更多相关文章

  1. SpringBoot使用logback日志记录

    在resources里的配置文件: logback-spring.xml <?xml version="1.0" encoding="UTF-8" ?&g ...

  2. Spring-Boot + MyBatis-Plus 踩坑记录

    这两天在学SpringBoot+MyBatis的开发,配置开发环境和DEMO的过程中踩了很多坑,在这里记录一下. 我的开发环境是idea + JDK 1.8.0.211. 首先展示一下demo的项目整 ...

  3. SpringBoot学习(学习过程记录)

    关于微服务和SOA 这,仅是我学习过程中记录的笔记.确定了一个待研究的主题,对这个主题进行全方面的剖析.笔记是用来方便我回顾与学习的,欢迎大家与我进行交流沟通,共同成长.不止是技术. 官网教程学习ht ...

  4. 会议管理心得记录(非markdown版)

    前提 本文说的会议特指有开发团队成员参与的会议, 包括但不限于开发.设计.测试.运维.管理岗位的成员. 因为不同工种和行业都有其特殊性,我是一名程序员,并不太了解其他工种和行业的具体情况,不敢妄言. ...

  5. ANE接入平台心得记录(安卓)

    开发环境:FlashBuilder4.7 AIR13.0 Eclipse 由于我懒得陪安卓的开发环境所以我下载了包含安卓SDK Manager的Eclipse,其实直接用FlashBuilder开发A ...

  6. iOS关于TableViewController和CollectionViewController中self.view心得记录

    之前写代码,不喜欢记录,导致很多做过的功能,时间久了都遗忘了. 以后要勤记录~~~ 一丶首先说一下TableViewController 大家都知道,如果直接创建一个继承于TableViewContr ...

  7. pymysql使用心得记录

    -----------更新日志 16.7.29------------- (该记录对应文章<豆瓣电影Top250基本信息抓取  >) 折腾了将近两天才把mysql数据库功能给实现了. 经过 ...

  8. springboot添加fluent日志记录

    istio默认会进行日志的记录,但是仅仅记录到服务.以及服务之间调用的信息,不记录业务日志. 如: 所以需要添加业务日志记录. 1.引入依赖 <dependency>     <gr ...

  9. springBoot的搭建使用记录

    一: 首次搭建:https://blog.csdn.net/u013187139/article/details/68944972 整合mybatis: https://www.jianshu.com ...

随机推荐

  1. POJ1185炮兵阵地(状态压缩 + dp)

    题目链接 题意:给出一张n * m的地图,其中 有的地方能放大炮,有的地方不能,大炮与上下左右两个单位范围内会相互攻击,问最多能放几个大炮 能放大炮为1不能放大炮为0,把每一行看做一个状态,要除去同一 ...

  2. VS2012 error C2664: “std::make_pair”:无法将左值绑定到右值引用

    在vs2012(c++)make_pair()改动: C++: template <class T1, class T2> pair<V1, V2> make_pair(T1& ...

  3. _mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h':问题的解决 mysql安装python

    在win7下安装了Python后,想安装python-MySQL,使用pip安装出现如下问题: >pip install MySQL-python _mysql.c(42) : fatal er ...

  4. extjs 兼容性问题解决方案

    首先明确一点,extjs是没有所谓的兼容性的问题的.那为什么总是出现不同浏览器兼容性的问题呢?而且很多人把这作为了extjs一个缺点. 解决方法,看看写的代码是不是多了  英文逗号 , 或 中文的逗号 ...

  5. Spring MVC学习笔记——给Controller和视图传值

    一.给Controller传值,值将显示在控制台 1.第一种:使用@RequestParam,改HelloController.java //RequestMapping表示用哪一个url来对应 @R ...

  6. Random类

    Random类是随机数产生类,可以指定一个随机数的范围,然后任意产生在此范围中的数字. //================================================= // F ...

  7. PHP 弹出文件下载

    /** * @author default7<default7@zbphp.com> * @description 演示PHP弹出下载的原理 * * @param $file_name * ...

  8. macbook pro的usb串口失效的的处理方法

    macbook pro的usb串口失效的的处理方法 2011-08-24 12:14:32|  分类: mac|举报|字号 订阅     今天开电脑,无端端一个usb的串口失效了,接入鼠标 iphon ...

  9. vnc服务器配置实例

    系统环境为CentOS.RHEL. 临时需要远程连接,参考:http://www.centoscn.com/CentOS/Intermediate/2013/0917/1641.html 一.安装.启 ...

  10. Windows下安装Tomcat服务

    startup.bat中添加以下内容 setlocal SET JAVA_HOME=D:\Program Files\Java\jdk1.8.0_05 SET CATALINA_HOME=D:\Pro ...