博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
与servlet Api 的集成
阅读量:6969 次
发布时间:2019-06-27

本文共 2104 字,大约阅读时间需要 7 分钟。

hot3.png

Servlet APi 集成

Servlet 2.5+ Integration

15.1.1 HttpServletRequest.getRemoteUser()得到用户名.

15.1.2 HttpServletRequest.getUserPrincipal()

HttpServletRequest.getUserPrincipal()得到SecurityContextHolder.getContext().getAuthentication()的信息.

Authentication auth = httpServletRequest.getUserPrincipal();// assume integrated custom UserDetails called MyCustomUserDetails// by default, typically instance of UserDetailsMyCustomUserDetails userDetails = (MyCustomUserDetails) auth.getPrincipal();String firstName = userDetails.getFirstName();String lastName = userDetails.getLastName();

15.1.3 HttpServletRequest.isUserInRole(String)

是否有角色

boolean isAdmin = httpServletRequest.isUserInRole("ADMIN");

15.2 Servlet 3+ Integration

15.2.1 HttpServletRequest.authenticate(HttpServletRequest,HttpServletResponse)

HttpServletRequest.authenticate(HttpServletRequest,HttpServletResponse) 可以保证用户被认证.如果用户没被认证,AuthenticaitonEntryPoint触发认证.

15.2.2 HttpServletRequest.login(String,String)

登陆

try {httpServletRequest.login("user","password");} catch(ServletException e) {// fail to authenticate}

15.2.3 HttpServletRequest.logout()

登出

AsyncContext.start(Runnable)

异步操作

final AsyncContext async = httpServletRequest.startAsync();async.start(new Runnable() {	public void run() {		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();		try {			final HttpServletResponse asyncResponse = (HttpServletResponse) async.getResponse();			asyncResponse.setStatus(HttpServletResponse.SC_OK);			asyncResponse.getWriter().write(String.valueOf(authentication));			async.complete();		} catch(Exception e) {			throw new RuntimeException(e);		}	}});

异步输出用户信息

Async Servlet Support

servlet至少是3.0

下一步添加DelegatingFilterProxy的异步支持

filter>
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
true
springSecurityFilterChain
/*
REQUEST
ASYNC

15.3 Servlet 3.1+ Integration

15.3.1 HttpServletRequest#changeSessionId()

可以用来对抗session固定攻击.

转载于:https://my.oschina.net/u/1590027/blog/913448

你可能感兴趣的文章
application内置对象
查看>>
iphone5手机端内容超出iphone6没问题且超出内容为http://.....网址
查看>>
Oracle 11g OEM登录后提示“出现内部错误”
查看>>
十一种通用滤波算法(转)~~~非常有用!
查看>>
JMeter中的读取json数据---JSON Extractor插件
查看>>
编译原理作业
查看>>
进程和多线程的概念及线程的优点
查看>>
SpringMVC (四)MultiActionController
查看>>
Linux服务器上搭建Centos7.0+Apache+php+Mysql网站
查看>>
HDOJ 1308.Is It A Tree?
查看>>
CentOS7 yum方式安装 MongoDB 3.4 复制集
查看>>
BP expects to restart drilling in Gulf in H2
查看>>
python通过range函数计算一组数的和的代码
查看>>
获取Android控件的宽和高
查看>>
2013-12-04(datePicker插件的使用)
查看>>
我的友情链接
查看>>
好记性不如烂笔头,今天起坚持每周一篇博文
查看>>
Linux面试题1
查看>>
Hadoop问题汇总
查看>>
初识Hibernate框架
查看>>