当前位置: 首页 > news >正文

哪个网站做高中的题好房99西安房产网

哪个网站做高中的题好,房99西安房产网,网站显示搜索框,广州制作网站企业web如何取得用户信息 之前说过SecurityContextHolder默认使用的是ThreadLocal来进行存储的,而且每次都会清除,但是web每次请求都会验证用户权限,这是如何做到的呢? 这是通过SecurityContextPersistenceFilter来实现的&#xff0…

web如何取得用户信息

之前说过SecurityContextHolder默认使用的是ThreadLocal来进行存储的,而且每次都会清除,但是web每次请求都会验证用户权限,这是如何做到的呢?

这是通过SecurityContextPersistenceFilter来实现的,每次请求过来都会session中来获取SecurityContext,然后设置到SecurityContextHolder中,请求结束后再清除掉

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest) req;HttpServletResponse response = (HttpServletResponse) res;if (request.getAttribute(FILTER_APPLIED) != null) {// ensure that filter is only applied once per requestchain.doFilter(request, response);return;}request.setAttribute(FILTER_APPLIED, Boolean.TRUE);HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request,response);// 从session获取SecurityContextSecurityContext contextBeforeChainExecution = repo.loadContext(holder);try {// 将SecurityContext存入SecurityContextHolderSecurityContextHolder.setContext(contextBeforeChainExecution);chain.doFilter(holder.getRequest(), holder.getResponse());}finally {SecurityContext contextAfterChainExecution = SecurityContextHolder.getContext();// Crucial removal of SecurityContextHolder contents - do this before anything// else.SecurityContextHolder.clearContext();// 存储SecurityContextrepo.saveContext(contextAfterChainExecution, holder.getRequest(),holder.getResponse());request.removeAttribute(FILTER_APPLIED);}
}

loadContext获取SecurityContext

使用HttpSessionSecurityContextRepository

public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) {HttpServletRequest request = requestResponseHolder.getRequest();HttpServletResponse response = requestResponseHolder.getResponse();HttpSession httpSession = request.getSession(false);// 从session中获取SecurityContextSecurityContext context = readSecurityContextFromSession(httpSession);if (context == null) {context = generateNewContext();}SaveToSessionResponseWrapper wrappedResponse = new SaveToSessionResponseWrapper(response, request, httpSession != null, context);requestResponseHolder.setResponse(wrappedResponse);return context;
}

从session中获取SecurityContext

private SecurityContext readSecurityContextFromSession(HttpSession httpSession) {final boolean debug = logger.isDebugEnabled();if (httpSession == null) {return null;}// Session exists, so try to obtain a context from it.Object contextFromSession = httpSession.getAttribute(springSecurityContextKey);if (contextFromSession == null) {return null;}// Everything OK. The only non-null return from this method.return (SecurityContext) contextFromSession;
}

存储SecurityContext

public void saveContext(SecurityContext context, HttpServletRequest request,HttpServletResponse response) {SaveContextOnUpdateOrErrorResponseWrapper responseWrapper = WebUtils.getNativeResponse(response,SaveContextOnUpdateOrErrorResponseWrapper.class);if (!responseWrapper.isContextSaved()) {responseWrapper.saveContext(context);}
}
protected void saveContext(SecurityContext context) {final Authentication authentication = context.getAuthentication();HttpSession httpSession = request.getSession(false);// See SEC-776if (authentication == null || trustResolver.isAnonymous(authentication)) {if (httpSession != null && authBeforeExecution != null) {// SEC-1587 A non-anonymous context may still be in the session// SEC-1735 remove if the contextBeforeExecution was not anonymoushttpSession.removeAttribute(springSecurityContextKey);}return;}if (httpSession == null) {httpSession = createNewSessionIfAllowed(context);}// If HttpSession exists, store current SecurityContext but only if it has// actually changed in this thread (see SEC-37, SEC-1307, SEC-1528)if (httpSession != null) {// We may have a new session, so check also whether the context attribute// is set SEC-1561if (contextChanged(context)|| httpSession.getAttribute(springSecurityContextKey) == null) {// 存到session中httpSession.setAttribute(springSecurityContextKey, context);}}
}

https://zhhll.icu/2024/框架/springSecurity/7.web如何取得用户信息/

http://www.sczhlp.com/news/102642/

相关文章:

  • 怎么搭建网站视频教程营销型企业网站系统模板下载
  • 优秀网站做ssp用什么建网站
  • FTP替代工具哪个产品好,高效安全之选
  • c++之内存对齐模板类aligned_storage
  • ABC 423先慢慢改吧题解
  • 汇聚层交换机的替换要考虑到的因素
  • 沈阳网站提示网站建设中
  • 单页面的网站模板微信公众号 手机网站
  • 鹤岗手机网站建设销售管理crm
  • 宝塔网站建设html5响应式网站开发教程
  • 宁波网站建设工作物流网站建设可行性分析
  • 专做商品折扣的网站做网站的企业有哪些
  • 网群企业网站管理系统企业互联网营销推广方案
  • 做百度网站好吗计算机网站建设方向
  • 女生做网站运营代理网址怎么用
  • git 常见使用
  • python UV 包管理工具安装
  • 什么是网络分区
  • 完整教程:《驾驭云原生复杂性:隐性Bug的全链路防御体系构建》
  • 网站建设学习浩森宇特wordpress相册瀑布
  • 网站死链接查询画册设计步骤
  • wordpress私密文章权限设置学seo推广
  • thinkphp网站模板下载百度网做网站吗
  • 从机器的角度来说ECS为何性能好
  • 人生最幸福的时刻也就几个瞬间
  • 实用指南:经典动态规划题解
  • 郑州做品牌网站的公司济南室内设计学校
  • 响应式装饰设计公司网站源码为推广网站做的宣传活动
  • 英文免费注册网站中国最好的网站器域名统一
  • 深圳微商城网站设计电话给医院做网站赚钱吗