SpringSecurity中自定义过滤器的种类
2015-03-25 10:54
295 查看
配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Security文档的说明:
------------------
auto-config Automatically registers a login form, BASIC authentication, logout services. If set to "true", all of these capabilities are added (although you can still customize the configuration of each by providing the respective element).
------------------
可以理解为:
本文出自:
http://www.cnblogs.com/yjmyzz/p/3888507.html
------------------
auto-config Automatically registers a login form, BASIC authentication, logout services. If set to "true", all of these capabilities are added (although you can still customize the configuration of each by providing the respective element).
------------------
可以理解为:
<http> <form-login /> <http-basic /> <logout /> </http>
package com.cnblogs.yjmyzz; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; //import org.springframework.security.authentication.AuthenticationServiceException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; public class CustomLoginFilter extends UsernamePasswordAuthenticationFilter { public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { // if (!request.getMethod().equals("POST")) { // throw new AuthenticationServiceException( // "Authentication method not supported: " // + request.getMethod()); // } String username = obtainUsername(request).toUpperCase().trim(); String password = obtainPassword(request); UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken( username, password); setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); } }即:从UsernamePasswordAuthenticationFilter继承一个类,然后把关于POST方式判断的代码注释掉即可。默认情况下,Spring Security的用户名是区分大小写,如果觉得没必要,上面的代码同时还演示了如何在Filter中自动将其转换成大写。
本文出自:
http://www.cnblogs.com/yjmyzz/p/3888507.html
相关文章推荐
- SpringSecurity自定义过滤器
- SpringSecurity学习之自定义过滤器
- vue组件化挖矿之旅(三):vue-cli 自定义过滤器的使用
- django “如何”系列4:如何编写自定义模板标签和过滤器
- SSH的自定义登陆过滤器
- “管道和过滤器”模式中管道的种类
- CAS实战のclient自定义过滤器
- 自定义过滤器
- 详解AngularJS中自定义过滤器
- Vue自定义过滤器
- Qt之事件过滤器 截获消息通知 自定义消息处理事件解析.
- 自定义View之RGB颜色变化Paint画笔颜色过滤器setColorFilter,LightingColorFilter光照过滤器
- Angular过滤器 自定义及使用方法
- django中自定义过滤器,自定义标签
- 购物车中自定义过滤器
- 自定义过滤器 将首字母大写 其余字母消息
- Log4j 1.2 使用自定义级别、自定义过滤器、动态路径
- angularJs自定义过滤器
- spring 集成shiro 之 自定义过滤器
- 基于java config的springSecurity(二)--自定义认证