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

做网站购买模板怎么在百度上投放广告

做网站购买模板,怎么在百度上投放广告,做页面设计的软件,外贸企业论坛网站建设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.tj-hxxt.cn/news/96024.html

相关文章:

  • 徐州网站app开发国产长尾关键词拘挖掘
  • 今日生猪价格表如何优化网络延迟
  • 建设网站明细报价表经典软文案例100例简短
  • 怎么做微信小说网站吗淘宝如何刷关键词增加权重
  • 什么网站没人做吸引人气的营销方案
  • 自己做网站要不要租服务器杭州百度推广优化排名
  • 卢松松的网站最佳搜索引擎磁力王
  • 舒城县建设局网站首页网站排名怎么做
  • 一级a做爰片免费网站 新闻公众号推广接单平台
  • 织梦cms官方网站湘潭关键词优化服务
  • 江苏 网站集约化建设方案seo网络营销推广公司
  • 图片存放网站做链接谷歌外贸平台叫什么
  • 服务器网站过多对排名百度客服电话人工服务热线
  • 唯品会 一家专做特卖的网站运营商大数据精准营销获客
  • 网站开发的实训内容今天重大新闻头条新闻
  • 青岛有做网站的吗网站推广的途径和方法
  • 石家庄网站系统开发电商运营培训班多少钱
  • 网站服务器权限网站优化推广服务
  • 做化妆品的一些网站网站单向外链推广工具
  • 在建项目经理查询做网站怎么优化
  • 做代收的网站有哪些广东seo快速排名
  • 源码网站跟自己做的网站区别全国前十名小程序开发公司
  • 广州网站改版 网站建设建网站设计
  • 手机端怎样做网站建设网站优化排名资源
  • 双桥区网站制作成crm软件
  • 永久免费的ppt网站在线培训平台哪家好
  • 网站建设公司格seo优化培训公司
  • 网站设计什么样风格会高端些网络网站推广选择乐云seo
  • 深圳专业专业网站设计营销网站建设价格
  • 香港网站域名申请产品如何做市场推广