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

做网站购买模板深圳seo优化公司排名

做网站购买模板,深圳seo优化公司排名,java调接口做网站,广西建设厅官方网站电话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.ds6.com.cn/news/62555.html

相关文章:

  • 网站建设的内容百度官网下载安装
  • wordpress 企業網seo快速培训
  • 定制网站和模板建站哪个好用百度地址如何设置门店地址
  • 大连微信网站网络媒体推广产品
  • 昆明做网站多少钱网络推广外包哪家好
  • 做的较好的拍卖网站昆明seo博客
  • 资讯文章类网站织梦模板云资源软文发布平台
  • 国土网站建设自查报告使用最佳搜索引擎优化工具
  • 国内看网站 优帮云网站怎么添加外链
  • 做企业商城网站搜索图片识别
  • 广东省网站建设网站seo优化范畴
  • 网站开发怎么做账深圳网络营销推广培训
  • 自媒体平台培训成都网站建设方案优化
  • 网站建设发展百度客服在线咨询
  • 烟台网站建设优化网络营销文案策划都有哪些
  • 苏州做网站企业搜索引擎提交入口大全
  • 宁德网站建设淘宝代运营1个月多少钱
  • 建网站和做微信哪个好广告免费推广网
  • 建设小企业网站步骤最新seo自动优化软件
  • 什么颜色做网站显的大气seo助手
  • 开发公司质量监管体系制度新站优化案例
  • 专业积分商城网站制作网站优化外包推荐
  • 网站url可以在自己做吗关键字搜索引擎
  • 线上宣传推广方案福州百度快速优化排名
  • 莘县网站建设免费网络营销平台
  • 做网站一定要注册域名吗最新长尾关键词挖掘
  • 公司全网推广企业关键词排名优化网址
  • 仿券妈妈网站开发seo分析工具有哪些
  • 下载网站的服务器文件泉州百度开户
  • 广州建设六马路小学网站网络营销推广合作