CN113805880A - 一种解决https协议在shiro框架下请求失败的方法 - Google Patents

一种解决https协议在shiro框架下请求失败的方法 Download PDF

Info

Publication number
CN113805880A
CN113805880A CN202111036838.2A CN202111036838A CN113805880A CN 113805880 A CN113805880 A CN 113805880A CN 202111036838 A CN202111036838 A CN 202111036838A CN 113805880 A CN113805880 A CN 113805880A
Authority
CN
China
Prior art keywords
shiro
filter
https
realized
http
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111036838.2A
Other languages
English (en)
Inventor
王超
罗义斌
司震
胡明慧
王文波
王�锋
杨涛
宋炜伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nanjing Linkage Information Technology Co ltd
Original Assignee
Nanjing Linkage Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nanjing Linkage Information Technology Co ltd filed Critical Nanjing Linkage Information Technology Co ltd
Priority to CN202111036838.2A priority Critical patent/CN113805880A/zh
Publication of CN113805880A publication Critical patent/CN113805880A/zh
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/36Software reuse
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Storage Device Security (AREA)

Abstract

一种解决HTTPS协议在shiro框架下请求失败的方法。解决HTTPS协议在shiro框架下请求失败的方法,允许用户同时使用http与https协议访问应用,步骤一:需要自己实现一个authc过滤器,并指定使用重新实现的过滤器替换默认的org.apache.shiro.web.filter.authc.FormAuthenticationFilter;步骤二:通过继承默认过滤器FormAuthenticationFilter,步骤三:重新实现redirectToSavedRequest,随着JavaWEB应用的迅猛发展,在Spring框架下集成shiro框架,再使用https请求以后,会跳转到http地址,影响用户使用。Shiro是一个强大的Java安全框架,越来越多的人使用它;本发明的特征在于重新实现了redirectToSavedRequest方法。

Description

一种解决https协议在shiro框架下请求失败的方法
技术领域
本发明涉及https协议应用于Java EE项目中,使用了Spring框架并集成shiro框架的情况下,允许用户同时使用http与https协议访问应用,着重解决默认情况下,用户使用https访问请求,自动转换成http返回的问题。
背景技术
超文本传输协议(Hypertext Transfer Protocol,HTTP)是一个简单的请求-响应协议,它通常运行在TCP之上。它指定了客户端可能发送给服务器什么样的消息以及得到什么样的响应。请求和响应消息的头以ASCII形式给出;而消息内容则具有一个类似MIME的格式。
HTTPS,是以安全为目标的HTTP通道,在HTTP的基础上通过传输加密和身份认证保证了传输过程的安全性。HTTPS在HTTP的基础下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。
Apache Shiro是一个强大且易用的Java安全框架,执行身份验证、授权、密码和会话管理。使用Shiro的易于理解的API,可以快速、轻松地获得任何应用程序,从最小的移动应用程序到最大的网络和企业应用程序。
随着Java WEB应用的迅猛发展,用户对安全性的要求越来越高,越来越多的用户将现有WEB应用的请求方式升级成https。但是在使用过程之中发现,在Spring框架下集成shiro框架,再使用https请求以后,会跳转到http地址,影响用户使用。
发明内容
本发明目的:本发明旨在解决在Java EE项目中使用了Spring框架(JavaEE是一组建立在JavaSE之上的标准,解决企业级开发中的一系列问题。Spring是一个优秀的高可用的JavaEE轻量级开发框架。提供一站式开发解决方案)并集成shiro框架的情况下,在使用https协议请求以后,会跳转http地址的问题。允许用户自由使用http和https协议,解决现有解决方案下使用用户只可以使用某种协议的情况,提供了使用了shiro框架的用户在现使用http协议的情况下,增加https协议请求方式的一种解决方案。
本发明的技术方案是:一种解决https协议在shiro框架下请求失败的方法,允许用户同时使用http与https协议访问应用,包含三个步骤:
步骤一:需要自己实现一个authc过滤器,并指定使用重新实现的过滤器替换默认的org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
authc过滤器,对应的处理器的类是FormAuthenticationFilter;
步骤二:通过继承默认过滤器FormAuthenticationFilter,重新实现过滤器中方法issueSuccessRedirect,不再调用org.apache.shiro.web.util.WebUtils的redirectToSavedRequest方法,跳转时使用重新实现redirectToSavedRequest方法;
步骤三:重新实现redirectToSavedRequest方法中,不再使用原代码中使用issueRedirect(ServletRequest request,ServletResponse response,String url)方法,改用重载后的issueRedirect(ServletRequest request,ServletResponse response,String url,Map queryParams,boolean contextRelative,boolean http10Compatible)方法,通过http10Compatible参数来实现https访问。
所述步骤二具体实现方法为:
重写issueRedirect(ServletRequest request,ServletResponse response)方法来实现兼容http与https协议的情况,在重写的issueRedirect方法最后跳转时调用重新实现的redirect To Saved Request方法。
Java EE项目使用HttpServletResponse.sendRedirect方法,设置的相对路径的地址跳转到了http地址(80端口),而不是https(443端口),需要关闭对http1.0协议的兼容支持以解决该问题,在使用了Spring和shiro框架后,本发明通过设置redirectHttp10Compatible属性来解决该问题。Java EE通过发明的开发语言,http是访问的路径,意思是要解决图4这种情况的问题。
本发明通过继承类FormAuthenticationFilter,重写了issueRedirect(ServletRequest request,ServletResponse response)方法来,在重写的issueRedirect方法最后跳转时调用自己实现的redirectToSavedRequest方法。同时需要实现一个redirectToSavedRequest方法,在实现redirectToSavedRequest方法中加入设置redirectHttp10Compatible属性设置,从而实现用户可以兼容使用http和https协议并跳转到相应路径。
本发明提出一种解决HTTPS协议在shiro框架下请求失败的方法。随着Java WEB应用的迅猛发展,用户对安全性的要求越来越高,越来越多的用户将现有WEB应用的请求方式升级成https。但是在使用过程之中发现,在Spring框架下集成shiro框架,再使用https请求以后,会跳转到http地址,影响用户使用。Shiro是一个强大的Java安全框架,越来越多的人使用它.适用于JavaSE和JavaEE.可以进行认证,授权,加密和会话管理,也支持Web,单点登录,记住我等功能。Shiro属于Apache组织下的项目。在控制权限,保障数据隐私和安全,进行相应的控制。实现权限验证单点登录,记住我,密码加密等,完成过滤器或者***。
本发明在于重新实现了redirect To Saved Request方法,在其中加入了关闭http10Compatible的方法,同时自定义了issue Success Redirect方法,避免现有方案之中需要写死https路径的方法,能允许用户可以自由选择http或者https协议使用。
有益效果:现有技术实现在shiro框架是使用https需要使用https协议是将跳转路径配全,这种方式限制了用户必须选择http或者https协议其中一种,本发明通过重写底层实现方式允许用户同时可以使用http或者https协议访问,并跳转到相对应的路径。
附图说明
下面结合附图和实施例对本发明进一步说明。
图1.重写类FormAuthenticationFilter血缘关系图;
Shiro框架默认使用FormAuthenticationFilter过滤用户信息,本发明改进了该过滤器实现,从而实现同时支持http与https协议的需求。
图2.FormAuthenticationFilter登录验证方法调用逻辑图;
图3.本发明重新实现的Form With Captcha Authentication Filter登录验证方法调用逻辑图
Issue SuccessRedirect。
图4是正常情况和本发明解决的异常情况的示意图。
具体实施方式
步骤一:
需要自己实现一个authc过滤器,并指定使用重新实现的过滤器替换默认的org.apache.shiro.web.filter.authc.FormAuthenticationFilter。如下通过配置指定一个新的过滤器。
Figure BDA0003247521060000041
步骤二:
通过继承默认过滤器FormAuthenticationFilter实现过滤器FormWithCaptchaAuthenticationFilter,重新实现过滤器中方法issueSuccessRedirect,不再调用org.apache.shiro.web.util.WebUtils的redirectToSavedRequest方法,跳转时使用重新实现的redirectToSavedRequest方法。自己重新实现issueSuccessRedirect方法如下:
Figure BDA0003247521060000042
Figure BDA0003247521060000051
步骤三:
实现redirectToSavedRequest方法,不再使用原代码中使用issueRedirect(ServletRequest request,ServletResponse response,String url)方法,改用重载后的issueRedirect(ServletRequest request,ServletResponseresponse,String url,MapqueryParams,boolean contextRelative,booleanhttp10Compatible)方法,通过http10Compatible参数来实现https访问。
Figure BDA0003247521060000052
Figure BDA0003247521060000061

Claims (3)

1.一种解决HTTPS协议在shiro框架下请求失败的方法,其特征在于,允许用户同时使用http与https协议访问应用,包含三个步骤:
步骤一:需要自己实现一个authc过滤器,并指定使用重新实现的过滤器替换默认的org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
authc过滤器,对应的处理器的类是FormAuthenticationFilter;
步骤二:通过继承默认过滤器FormAuthenticationFilter,重新实现过滤器issueSuccessRedirect,不再调用org.apache.shiro.web.util.WebUtils的redirectToSavedRequest,跳转时使用重新实现redirectToSavedRequest;
步骤三:重新实现redirectToSavedRequest方法中,不再使用原代码中使用issueRedirect(ServletRequest request,ServletResponse response,Stringurl),改用重载后的issueRedirect(ServletRequest request,ServletResponse response,Stringurl,Map queryParams,boolean contextRelative,boolean http10Compatible),通过http10Compatible参数来实现https访问。
2.根据权利要求1所述的一种解决HTTPS协议在shiro框架下请求失败的方法,其特征在于:所述步骤二具体实现方法为:
重写issueRedirect(ServletRequest request,ServletResponse response)来实现兼容http与https协议的情况,在重写的issueRedirect最后跳转时调用重新实现redirectTo Saved Request。
3.根据权利要求1所述的一种解决HTTPS协议在shiro框架下请求失败的方法,其特征在于:所述步骤三具体实现方法为:
重新实现一个redirectToSavedRequest,在实现redirectToSavedRequest中加入设置redirectHttp10Compatible属性,从而保证用户能够同时兼容http与https协议。
CN202111036838.2A 2021-09-06 2021-09-06 一种解决https协议在shiro框架下请求失败的方法 Pending CN113805880A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111036838.2A CN113805880A (zh) 2021-09-06 2021-09-06 一种解决https协议在shiro框架下请求失败的方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111036838.2A CN113805880A (zh) 2021-09-06 2021-09-06 一种解决https协议在shiro框架下请求失败的方法

Publications (1)

Publication Number Publication Date
CN113805880A true CN113805880A (zh) 2021-12-17

Family

ID=78894652

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111036838.2A Pending CN113805880A (zh) 2021-09-06 2021-09-06 一种解决https协议在shiro框架下请求失败的方法

Country Status (1)

Country Link
CN (1) CN113805880A (zh)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180109498A1 (en) * 2016-10-17 2018-04-19 Zscaler, Inc. Systems and methods for improving https security
CN108494825A (zh) * 2018-02-24 2018-09-04 深圳市联软科技股份有限公司 一种重定向访问请求的方法、介质及设备
CN108737343A (zh) * 2017-04-20 2018-11-02 苏宁云商集团股份有限公司 一种安全访问网络的实现方法及装置
CN109688127A (zh) * 2018-12-20 2019-04-26 深圳市吉祥腾达科技有限公司 一种支持HTTPS页面跳转的web认证方法
CN110581821A (zh) * 2018-06-07 2019-12-17 珠海横琴盛达兆业科技投资有限公司 一种实现药店***单点登录与本地登录集成的方法
CN111147583A (zh) * 2019-12-27 2020-05-12 杭州迪普科技股份有限公司 一种http重定向重写方法及装置
CN111600837A (zh) * 2020-04-08 2020-08-28 曙光信息产业(北京)有限公司 基于多数据中心云管平台的登录管理***和方法
CN112492055A (zh) * 2020-11-11 2021-03-12 浪潮商用机器有限公司 一种传输协议重定向的方法、装置、设备及可读存储介质

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180109498A1 (en) * 2016-10-17 2018-04-19 Zscaler, Inc. Systems and methods for improving https security
CN108737343A (zh) * 2017-04-20 2018-11-02 苏宁云商集团股份有限公司 一种安全访问网络的实现方法及装置
CN108494825A (zh) * 2018-02-24 2018-09-04 深圳市联软科技股份有限公司 一种重定向访问请求的方法、介质及设备
CN110581821A (zh) * 2018-06-07 2019-12-17 珠海横琴盛达兆业科技投资有限公司 一种实现药店***单点登录与本地登录集成的方法
CN109688127A (zh) * 2018-12-20 2019-04-26 深圳市吉祥腾达科技有限公司 一种支持HTTPS页面跳转的web认证方法
CN111147583A (zh) * 2019-12-27 2020-05-12 杭州迪普科技股份有限公司 一种http重定向重写方法及装置
CN111600837A (zh) * 2020-04-08 2020-08-28 曙光信息产业(北京)有限公司 基于多数据中心云管平台的登录管理***和方法
CN112492055A (zh) * 2020-11-11 2021-03-12 浪潮商用机器有限公司 一种传输协议重定向的方法、装置、设备及可读存储介质

Non-Patent Citations (5)

* Cited by examiner, † Cited by third party
Title
HIVI729061855: "协议升级https后,重定向还是http的问题", 《HTTPS://BLOG.CSDN.NET/HIVI12345/ARTICLE/DETAILS/116525921》 *
徐定强: "如何实现SSL访问", 《福建电脑 》 *
瓜皮猫咪: "shiro认证成功后,没有跳转到配置的successUrl", 《HTTPS://BLOG.CSDN.NET/WEIXIN_42759709/ARTICLE/DETAILS/85007036》 *
范爱平等: "基于Struts构架的Web认证", 《计算机工程》 *
风中凌乱的小森桩: "解决https服务使用shiro跳转登录界面变成http", 《HTTPS://BLOG.CSDN.NET/KANAIJI123/ARTICLE/DETAILS/110679225》 *

Similar Documents

Publication Publication Date Title
CN108901022B (zh) 一种微服务统一鉴权方法及网关
EP3162103B1 (en) Enterprise authentication via third party authentication support
US10349272B2 (en) Virtual SIM card cloud platform
US9607143B2 (en) Provisioning account credentials via a trusted channel
EP3138257B1 (en) Enterprise system authentication and authorization via gateway
US8769063B2 (en) Policy-based application management
US9038138B2 (en) Device token protocol for authorization and persistent authentication shared across applications
EP1233636B1 (en) System and method for over the air configuration security
US11792074B2 (en) Method for secure enrollment of devices in the industrial internet of things
CN107743702B (zh) 托管移动设备的单点登录
US20140040979A1 (en) Policy-Based Application Management
US9344417B2 (en) Authentication method and system
US11303625B2 (en) Industrial automation device and cloud service
EP2978192B1 (en) Peer to peer remote control method between one or more mobile devices
CA3135212A1 (en) Computing system and methods providing session access based upon authentication token with different authentication credentials
EP3326098A1 (en) Anonymous application wrapping
WO2023283499A1 (en) Computing session multi-factor authentication
US11589226B2 (en) Multi-factor authentication for mobile security protocol
CN113805880A (zh) 一种解决https协议在shiro框架下请求失败的方法
JP4972646B2 (ja) 一貫したアプリケーション対応ファイヤウォールトラバーサルの提供
JP2016118930A (ja) 認証システム
US20240056443A1 (en) Secure cross-platform smart hosting, credential sharing, and identity management
JP2013161260A (ja) シンクライアントシステム
JP2024504286A (ja) Esimの作成、生成、配布
JP2023095286A (ja) ネットワークシステムおよびアクセス制御方法

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20211217

RJ01 Rejection of invention patent application after publication