CAS支持http协议

阅读:392 2019-03-19 14:42:57 来源:新网

前置文章:cas学习教程

前面我们已经知道,cas默认是使用https协议请求验证,https相对于http无疑在安全性是更高的,但是https协议在实际开发中会比较麻烦,首先域名访问,对于企业内网或者专网的应用系统一般都是使用ip访问,这个给cas集成造成了很大的问题,其次https的证书部署也比较麻烦,所以有时会使用http协议部署,当然在能使用https的情况下还是尽量使用https,之前也说了对于单点登录,一旦被攻击,那么你的所有属于cas管理的业务系统都可以被自由访问或者都无法访问了。

所以具体具体采用何种方式还是需要开发团队和客户协商确认,以下说下如何修改配置,可以让cas使用http访问。

1.打开web-inf/spring-configuration/warncookiegenerator.xml文件cookiesecure设置为false

2.打开web-inf/spring-configuration/ticketgrantingticketcookiegenerator.xml文件cookiesecure设置为false

3.打开web-inf/deployerconfigcontext.xml文件requiresecure设置为false

如果我们使用的是基于filter在web.xml中的方式,至此使用http协议就可以单点登录了。

如果我们使用的javacoreobject的方式,那么还需要进行的下面的步骤

4.打开文件secureurl.java

/**copyright(c)2000-2003yaleuniversity.allrightsreserved.**thissoftwareisprovided"asis,"andanyexpressorimplied*warranties,including,butnotlimitedto,theimpliedwarrantiesof*merchantabilityandfitnessforaparticularpurpose,areexpressly*disclaimed.innoeventshallyaleuniversityoritsemployeesbe*liableforanydirect,indirect,incidental,special,exemplary,or*consequentialdamages(including,butnotlimited,thecostsof*procurementofsubstitutegoodsorservices;lossofuse,dataor*profits;orbusinessinterruption)howevercausedandonanytheoryof*liability,whetherincontract,strictliability,ortort(including*negligenceorotherwise)arisinginanywayoutoftheuseofthis*software,evenifadvisedinadvanceofthepossibilityofsuch*damage.**redistributionanduseofthissoftwareinsourceorbinaryforms,*withorwithoutmodification,arepermitted,providedthatthe*followingconditionsaremet:**1.anyredistributionmustincludetheabovecopyrightnoticeand*disclaimerandthislistofconditionsinanyrelateddocumentation*and,iffeasible,intheredistributedsoftware.**2.anyredistributionmustincludetheacknowledgment,"thisproduct*includessoftwaredevelopedbyyaleuniversity,"inanyrelated*documentationand,iffeasible,intheredistributedsoftware.**3.thenames"yale"and"yaleuniversity"mustnotbeusedtoendorse*orpromoteproductsderivedfromthissoftware.*/packageorg.jasig.cas.client.corejavaobject.util;importjava.io.bufferedreader;importjava.io.ioexception;importjava.io.inputstreamreader;importjava.net.url;importjava.net.urlconnection;importorg.apache.commons.logging.log;importorg.apache.commons.logging.logfactory;/***aclasshousingsomeutilityfunctionsexposingsecureurlvalidation*andcontentretrieval.therulesareintendedtobeaboutasrestrictive*asacommonbrowserwithrespecttoserver-certificatevalidation.*/publicclasssecureurl{privatestaticloglog=logfactory.getlog(secureurl.class);/***fortestingonly...*/publicstaticvoidmain(stringargs[])throwsioexception{system.setproperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");system.out.println(secureurl.retrieve(args[0]));}/***retrievethecontentsfromthegivenurlasastring,assumingthe*url'sservermatcheswhatweexpectittomatch.*/publicstaticstringretrieve(stringurl)throwsioexception{if(log.istraceenabled()){log.trace("enteringretrieve("+url+")");}bufferedreaderr=null;try{urlu=newurl(url);if(!u.getprotocol().equals("https")){//ioexceptionmaynotbethebestexceptionwecouldthrowhere//sincetheproblemiswiththeurlargumentwewerepassed,not//io.-awp9log.error("retrieve("+url+")onanillegalurlsinceprotocolwasnothttps.");thrownewioexception("only'https'urlsarevalidforthismethod");}urlconnectionuc=u.openconnection();uc.setrequestproperty("connection","close");r=newbufferedreader(newinputstreamreader(uc.getinputstream()));stringline;stringbufferbuf=newstringbuffer();while((line=r.readline())!=null)buf.append(line+"n");returnbuf.tostring();}finally{try{if(r!=null)r.close();}catch(ioexceptionex){//ignore}}}}

找到下面的部分

if(!u.getprotocol().equals("https")){//ioexceptionmaynotbethebestexceptionwecouldthrowhere//sincetheproblemiswiththeurlargumentwewerepassed,not//io.-awp9log.error("retrieve("+url+")onanillegalurlsinceprotocolwasnothttps.");thrownewioexception("only'https'urlsarevalidforthismethod");}

相信大家应该明白了吧,只需要将此部分注释掉即可。

备注:cookiesecure都修改false,我们来看下其作用是什么?

secure是cookie的一个属性。

如果客户端仅在使用安全超文本传输协议(https)的后继请求中返回cookie,则为true;否则为false。默认为false。

实际上,当此属性为true时,该cookie只能通过https://请求来发送。即使用http协议是无法传递cookie的。

相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>
推荐商标

{{ v.name }}

{{ v.cls }}类

立即购买 联系客服