English 中文(简体)
如何让同一个会话横跨脆弱地带的子域
原标题:How to get the same session across subdomains in grails

我有一个处理多个子域的单一应用程序, 例如

  • sub1.domain.com
  • sub2.domain.com
  • www.domain.com
  • domain.com

用户在使用应用程序时可以切换这些子域。 发生这种情况时, 会话不会在这些子域之间共享。 我使用Tomcat作为开发和制作的服务器 。

我试图首先让共同会议在发展工作中发挥作用。

<Context sessionCookiePath="/" sessionCookieDomain=".domain.com">

发展环境有没有办法让我用Tomcat来形容?

我在Events.groovy尝试了以下代码,但没有成功:

eventConfigureTomcat = {tomcat ->
    def context = tomcat.addContext("","/")
    context.setSessionCookieDomain(".domain.com")
    context.setSessionCookiePath("/")
}

我理解错误 java. lang. Illaw Argument Exception: 加子:孩子的名字并不独特

我认为我所需要的是相当于以下代码的代码(因为没有 " 通俗 " 方法,该代码无法工作):

eventConfigureTomcat = {tomcat ->
    def context = tomcat.getContext("") //This function does not exist
    context.setSessionCookieDomain(".domain.com")
    context.setSessionCookiePath("/")
}

Any suggestions on how I can get this working in both development and production? Thanks in advance for any help.

问题回答

要访问默认的 Tomcat 上下文, 您可能需要在插件 s TomcatServer. groovy 文件中修补 TomcatServer 创建的方法 。

TomcatServer(String basedir, String webXml, String contextPath, ClassLoader classLoader) {
    tomcat = new Tomcat()
this.buildSettings = BuildSettingsHolder.getSettings()  

    if(contextPath== / ) contextPath =   

    def tomcatDir = new File("${buildSettings.projectWorkDir}/tomcat").absolutePath
    def ant = new AntBuilder()      
    ant.delete(dir:tomcatDir, failonerror:false)        

    tomcat.basedir = tomcatDir

    context = tomcat.addWebapp(contextPath, basedir) 
    // ** do additional context stuff here ** 
    tomcat.enableNaming()       

    // we handle reloading manually
    context.reloadable = false
    context.setAltDDName("${buildSettings.projectWorkDir}/resources/web.xml")

    def aliases = []
    def pluginManager = PluginManagerHolder.getPluginManager()
    def pluginSettings = GPU.getPluginBuildSettings()
    if(pluginManager!=null) {
        for(plugin in pluginManager.userPlugins) {
              def dir = pluginSettings.getPluginDirForName(GrailsNameUtils.getScriptName(plugin.name))
              def webappDir = dir ? new File("${dir.file.absolutePath}/web-app") : null
              if (webappDir?.exists())
                    aliases << "/plugins/${plugin.fileSystemName}=${webappDir.absolutePath}"
    }
}

    if(aliases) {
        context.setAliases(aliases.join( , ))
    }
    TomcatLoader loader = new TomcatLoader(classLoader)

    loader.container = context
    context.loader = loader

    initialize()
}




相关问题
Tomcat´s server.xml dynamic configuration

My web application uses the same database configuration as the application XYZ. I have a resource declaration for a context in server.xml, so I have a duplicated configuration (once for web ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

热门标签