package zhet.sprintBoot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
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;

/**
* @author sdcuike
* @date 2018/1/28
* @since 2018/1/28
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private CustomUserDetailsService userDetailsService;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder( new PasswordEncoder() {
@Override
public String encode(CharSequence charSequence) {
return charSequence.toString();
}

@Override
public boolean matches(CharSequence charSequence, String s) {
return s.equals(charSequence.toString());
}
});
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// 设置登陆页
.formLogin()

// login22.html 在 static 文件夹下
.loginPage("/login22.html")

//自定义登录页的 action  = "/login"
.loginProcessingUrl("/login") // 自定义的登录接口

// 设置登陆成功页
.defaultSuccessUrl("/home.html")
.failureUrl("/loginFaile.html").permitAll()
.and().authorizeRequests()
// .antMatchers("/login").permitAll()
.anyRequest().authenticated();

// 如果有允许匿名的url,填在下面
// .antMatchers().permitAll()

// 自定义登陆用户名和密码参数,默认为username和password
// .usernameParameter("username")
// .passwordParameter("password")
// .and()
// .logout().permitAll()

// 关闭CSRF跨域
http.csrf().disable();
}

@Override
public void configure(WebSecurity web) throws Exception {
// 设置拦截忽略文件夹,可以对静态资源放行
web.ignoring().antMatchers("/css/**", "/js/**");
}
}

spring boot 下 spring security 自定义登录配置与form-login属性详解的更多相关文章

  1. Spring Boot下Spring Batch入门实例

    一.About Spring Batch是什么能干什么,网上一搜就有,但是就是没有入门实例,能找到的例子也都是2.0的,看文档都是英文无从下手~~~,使用当前最新的版本整合网络上找到的例子. 关于基础 ...

  2. Spring Cloud Alibaba基础教程:Nacos配置的加载规则详解

    前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式(Res ...

  3. Spring Boot 源码分析 数据源 + Mybatis 配置

    公司今年开始使用 Spring Boot 开发,当然使用 Spring Boot 也是大势所趋,尤其是现在微服务的趋向,当然是选择基于Spring Boot 的 Spring Cloud.(所谓的 S ...

  4. Spring Cloud Alibaba与Spring Boot、Spring Cloud之间不得不说的版本关系

    这篇博文是临时增加出来的内容,主要是由于最近连载<Spring Cloud Alibaba基础教程>系列的时候,碰到读者咨询的大量问题中存在一个比较普遍的问题:版本的选择.其实这类问题,在 ...

  5. Spring Security 自定义登录认证(二)

    一.前言 本篇文章将讲述Spring Security自定义登录认证校验用户名.密码,自定义密码加密方式,以及在前后端分离的情况下认证失败或成功处理返回json格式数据 温馨小提示:Spring Se ...

  6. spring boot+freemarker+spring security标签权限判断

    spring boot+freemarker+spring security标签权限判断 SpringBoot+SpringSecurity+Freemarker项目中在页面上使用security标签 ...

  7. spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,guava限流,定时任务案例, 发邮件

    本文介绍spring boot集成swagger,自定义注解,拦截器,xss过滤,异步调用,定时任务案例 集成swagger--对于做前后端分离的项目,后端只需要提供接口访问,swagger提供了接口 ...

  8. Spring Boot (一): Spring Boot starter自定义

    前些日子在公司接触了spring boot和spring cloud,有感于其大大简化了spring的配置过程,十分方便使用者快速构建项目,而且拥有丰富的starter供开发者使用.但是由于其自动化配 ...

  9. 转-Hive/Phoenix + Druid + JdbcTemplate 在 Spring Boot 下的整合

    Hive/Phoenix + Druid + JdbcTemplate 在 Spring Boot 下的整合 http://blog.csdn.net/balabalayi/article/detai ...

随机推荐

  1. 27.【转载】挖洞技巧:如何绕过URL限制

    大家对URL任意跳转都肯定了解,也知道他的危害,这里我就不细说了,过~ 大家遇到的肯定都是很多基于这样的跳转格式:http://www.xxx.xxx/xxx?xxx=http://www.xxx.x ...

  2. 1.浅谈XXE漏洞攻击与防御

    XML基础 在介绍XXE漏洞前,先学习温顾一下XML的基础知识.XML被设计为传输和存储数据,其焦点是数据的内容,其把数据从HTML分离,是独立于软件和硬件的信息传输工具. XML是一种用于标记电子文 ...

  3. 简单Hadoop集群环境搭建

    最近大数据课程需要我们熟悉分布式环境,每组分配了四台服务器,正好熟悉一下hadoop相关的操作. 注:以下带有(master)字样为只需在master机器进行,(ALL)则表示需要在所有master和 ...

  4. hdu1055

    #include<iostream> #include<iomanip> #include<cstdio> #include<cstring> #inc ...

  5. hdu 5147 Sequence II (树状数组 求逆序数)

    题目链接 Sequence II Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. Window Live Writer在Win7下安装提示错误“OnCatalogResult:0x80190194”

    1.在C:\Users\All Users\Microsoft\WLSetup\Logs下(All Users默认是隐藏文件夹),有两个Window Live的安装日记记录文件,打开第一个找到ERRO ...

  7. 【mybatis批量插入】

    mybatis批量插入操作: MySQL:1.INSERT INTO TABLE_NAME(ID,NAME)VALUES(1,'张三'),(2,'李四')                  2.INS ...

  8. [CentOS7] SELinux

    声明:本文主要总结自:鸟哥的Linux私房菜-第十六章.程序管理與 SELinux 初探,如有侵权,请通知博主 SELinux = Security Enhanced Linux 传统的文件权限与账号 ...

  9. Mybatis中文模糊查询,数据库中有数据,但无结果匹配

    1.Mybatis中文模糊查询,数据库中有数据,但无结果匹配 1.1 问题描述: Mybatis采用中文关键字进行模糊查询,sql语句配置无误,数据库有该数据,且无任何报错信息,但无查询结果 1.2 ...

  10. ASP.NET控件之RangeValidator控件

    作用:对Textbox或者输入框进行范围验证: 属性:ControlToValidate:要验证的控件: ErrorMessage:错误提示信息: MaxiMumValue:最大值: MinimumV ...