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

哪个网站做高中的题好网页制作素材动漫

哪个网站做高中的题好,网页制作素材动漫,html5单页面网站建设,知名网站排名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.yayakq.cn/news/924952/

相关文章:

  • 网站建设论文任务书哪些网站教做生物实验
  • 宝安中心做网站wordpress ajax不支持ie
  • 国外的有趣设计网站百度搜索竞价
  • 上传网站视频要怎么做才清楚教如何做帐哪个网站好
  • 双阳区住房和城乡建设局网站北京大兴网站建设首选公司
  • 建立自己的网站软件有网站关键词快速排名技术
  • 网站搭建语言佛山新网站建设方案
  • 网站登录系统怎样做域名打不开网站
  • 网匠网站建设有限公司中建人才网
  • 景安网站备案表格wordpress投资主题公园
  • 招聘网站建设工作总结广州互联网
  • wordpress全站静态页面最流行的网站开发框架
  • 珠海斗门建设局官方网站如何做网课网站
  • 电子商务上班干什么seo教程技术整站优化
  • 长春网站建设报价做网站编辑好还是推广好
  • 电子商务网站建设的成本分析牡丹江最新信息网
  • 公司网站制作怎么弄wordpress淘宝客主题
  • 重庆家政公司网站建设从事电子商务的网站建设
  • 泉州做网站的公司黄冈网站建设公司
  • 廊坊网站seo网站建设说明书模板
  • 柯城建设局网站创建全国文明城市方案
  • 宁波市住宅建设集团网站中国设计网网址
  • 加强财政门户网站建设工作查销售数据的网站
  • 河南网站建设公司排名建立自己的WordPress主题
  • 有人拉我做彩票网站网站缩放代码
  • 手机便宜的网站建设在线学习建设网站
  • 辽宁省电力建设网站3d效果图什么网站做的好
  • 图片上传 网站建设教学视频晚上必看正能量网站短视频
  • 免费在线做高考试题的网站wordpress编辑空两格
  • 用vs2010做网站论文郴州网站制作公司电话