2

因为在这个问题中设置端口并没有解决重定向循环问题,所以我创建了一个简单的测试应用程序(grails 2.0,最新的 spring-security-core 1.2.7.1),所以重定向循环问题很容易重现/希望解决:步骤如下:

1-创建了名为 test 的新应用程序,并创建了一个名为 simple 的控制器(也在测试包中),即:

   package test

   class SimpleController {
       def index()  { redirect action: 'start'    }
       def start()  { render "start - not secure" }
       def middle() { render "middle - secure"    }
       def end()    { render "end - not secure"   }
   }  

2- grails 是否安装了 spring-security-core 以及grails s2-quickstart 测试用户角色

3- 在 Config.groovy 中,添加以下几行,然后执行 run-app -https在我的开发机器上进行测试:

   grails.plugins.springsecurity.secureChannel.definition = [
     '/simple/middle/**':    'REQUIRES_SECURE_CHANNEL',
     '/simple/end/**':       'REQUIRES_INSECURE_CHANNEL',
     '/simple/**':           'ANY_CHANNEL'
   ]

结果:全部结帐,可以输入网址../simple/start,然后输入../simple/middle进入SSL/https模式,随意。

4- 在 Config.groovy 中,然后我将端口配置为在 Heroku 上运行(估计,没有找到文档/参考):

  grails.plugins.springsecurity.portMapper.httpPort = '80'
  grails.plugins.springsecurity.portMapper.httpsPort = '443'

5- 完成git init步骤 后,git add 。git commit -m "initial commit"heroku create --stack cedar,我去了 Heroku 并将 PiggyBack SSL 添加到那里新创建的应用程序中。然后我做了一个git push heroku master来部署。

结果:得到常见的“IllegalStateException,未找到线程绑定请求”,此处此处描述的问题。

6- 因此,在 BuildConfig.groovy 中,我对 plugins {} 部分进行了以下 2 处更改:

    //runtime ":resources:1.1.5"
    compile ":webxml:1.4.1"   

结果: IllegalStateException 消失了,我可以访问简单的控制器(和登录控制器)。我可以在这些网址前加上 https,一切都很好。但是,如果我输入 ../simple/middle URL,我会得到重定向循环(类似于此处的跟踪)。

7-出于好奇,我在步骤 6 中注释掉了一半的更改,即//compile: "webxml:1.4.1"

结果:得到相同的 IllegalStateException

8-因为我不确定 Heroku 和云支持插件是如何影响上述基本步骤的,所以我一直等到这一步才添加它们。然后我做了 grails install-plugin cloud-supportgrails install-plugin heroku,并更新了 BuildConfig.groovy 所以它现在看起来像:

   plugins {
     runtime ":hibernate:$grailsVersion"
     runtime ":jquery:1.7.1"

      //runtime ":resources:1.1.5"
      //compile ":webxml:1.4.1"
      compile ':heroku:1.0'
      compile ':cloud-support:1.0.8'

      compile ":tomcat:$grailsVersion"
   }

然后清理并更新了 git 存储库并推送到 heroku。

结果:相同的 IllegalStateException(注意 webxml 依赖项已被注释掉)。

9-然后我取消注释compile ":webxml:1.4.1",并再次推送到heroku:

结果:与第 3 步完全相同。即除了 ../simple/middle 之外,所有 URL 都有效,包括添加 https 前缀。转到 ../simple/middle URL 会导致重定向循环问题。

你能建议如何解决这个问题吗?如果有什么东西让我尝试(即不确定的解决方案),请更新评论部分,我会回复结果。非常感谢。

-------------------------------------------------- --------------------------------------

使用新的 spring-security 1.2.7.2 进行更新。

我的 BuildConfig.groovy 现在是:

 dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
    runtime 'mysql:mysql-connector-java:5.1.16'
}

plugins {
    runtime ":hibernate:$grailsVersion"
    runtime ":jquery:1.7.1"

    runtime ":resources:1.1.6"
    compile ":spring-security-core:1.2.7.2"

    compile ":webxml:1.4.1"

    compile ':heroku:1.0'
    compile ':cloud-support:1.0.8'

    build ":tomcat:$grailsVersion"
}

即使使用 MySql,在部署到 Heroku 时也会出现 PostGres 依赖错误。因此,我删除了 Heroku 上的所有应用程序并清理了我的 git 存储库,并开始使用全新的部署/全新应用程序。

仍然得到这个 PostGres 依赖错误(下)。注意:以前在 MySql 工作时收到“未找到事务管理器 - 如果您的 webapp 需要一个,请配置一个”警告。唔。

  12-02-03T07:18:09+00:00 app[web.1]: 2012-02-03 07:18:09.810:INFO:omjr.Runner:Runner
  12-02-03T07:18:09+00:00 app[web.1]: 2012-02-03 07:18:09.811:WARN:omjr.Runner:No tx manager found
  12-02-03T07:18:09+00:00 app[web.1]: 2012-02-03 07:18:09.852:INFO:omjr.Runner:Deploying  file:/app/target/momentum-0.1.war @ /
  12-02-03T07:18:09+00:00 app[web.1]: 2012-02-03 07:18:09.869:INFO:oejs.Server:jetty-7.x.y-SNAPSHOT
 12-02-03T07:18:09+00:00 app[web.1]: [o.e.j.w.WebAppContext{/,null},file:/app/target/momentum-0.1.war]
 12-02-03T07:18:09+00:00 app[web.1]: 2012-02-03  07:18:09.915:INFO:oejw.WebInfConfiguration:Extract jar:file:/app/target/momentum-0.1.war!/ to   /tmp/jetty-0.0.0.0-43683-momentum-0.1.war-_-any-/webapp
 12-02-03T07:18:14+00:00 app[web.1]: 2012-02-03 07:18:14.500:INFO:oejpw.PlusConfiguration:No Transaction manager found - if your webapp requires one, please configure one.
 12-02-03T07:18:18+00:00 app[web.1]: 2012-02-03 07:18:18.361:INFO:/:Initializing Spring root WebApplicationContext
 12-02-03T07:18:24+00:00 app[web.1]:
 12-02-03T07:18:24+00:00 app[web.1]: Configuring Spring Security Core ...
 12-02-03T07:18:24+00:00 app[web.1]: ... finished configuring Spring Security Core
 12-02-03T07:18:24+00:00 app[web.1]:
 12-02-03T07:18:24+00:00 app[web.1]: 2012-02-03 07:18:24.490:WARN:oejw.WebAppContext:Failed    startup of context o.e.j.w.WebAppContext{/,file:/tmp/jetty-0.0.0.0-43683-momentum-0.1.war-_-any- /webapp/},file:/a
   /target/momentum-0.1.war
   12-02-03T07:18:24+00:00 app[web.1]: org.springframework.beans.factory.BeanCreationException:   Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; 
    ************************************************************   
    nested exception is org.springframework.beans.factory.BeanCreationException: Error  creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while  setting bean property 'lobHandler'; 
      nested exception is org.springframework.beans.factory.BeanCreationException:  Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; 
   nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.postgresql.Driver'
   *************************************************************

  12-02-03T07:18:24+00:00 app[web.1]:   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:126)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:707)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:449)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration.getApplicationContext(DefaultRuntimeSpringConfiguration.java:153)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:124)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:165)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.codehaus.groovy.grails.web.context.GrailsConfigUtils.configureWebApplicationContext(GrailsConfigUtils.java:121)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.codehaus.groovy.grails.web.context.GrailsContextLoader.initWebApplicationContext(GrailsContextLoader.java:104)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:643)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:233)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1213)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:589)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:454)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  12-02-03T07:18:24+00:00 app[web.1]:   at  org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:167)
  12-02-03T07:18:24+00:00 app[web.1]:   at  org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.server.Server.doStart(Server.java:261)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.mortbay.jetty.runner.Runner.run(Runner.java:500)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.mortbay.jetty.runner.Runner.main(Runner.java:639)
  12-02-03T07:18:24+00:00 app[web.1]:   at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
4

1 回答 1

2

如果你不知道它为什么在那里,可能最好不要只是随意破解一些东西:)

IllegalStateException 来自filter-mappingweb.xml 中的元素顺序不正确。spring-security-core 和 resources 都是定位filter-mapping元素并且相互踩踏,所以我们更新了 webxml 插件以按照惯例支持它,并使两个插件都依赖于那个。由于不同依赖插件版本的插件驱逐存在错误,因此使用 spring-security-core 版本和依赖于相同 webxml 版本的资源非常重要。

新的 2.0 应用程序声明了对使用 webxml v1.4 的资源 1.1.5 的依赖,而 spring-security-core 1.2.7+ 使用 1.4.1,因此您需要不使用资源或使用 1.1.6 版本。那么就没有歧义了,将使用正确的版本,并且 web.xml 的顺序将是正确的。您还应该在 BuildConfig 中注册所有插件,而不是使用 install-plugin;这会将所有内容保存在一个地方,并允许您定义排除项等。

然而,这完全独立于 SSL 问题,因此最好一次只关注一个问题。我没有在 Heroku 上使用 SSL,所以我不知道他们使用什么端口。我假设在防火墙内他们使用 443 以外的其他内容,然后请求在 443 上路由。但这与 Grails 和 spring-security-core 插件无关,因此了解 SSL 的配置方式只是一个一般文档问题。

更新

好的,所以基于 James 发布的链接中的解决方法,我发布了一个新版本的 Spring Security 插件(v1.2.7.2),支持 X-Forwarded-Proto。添加grails.plugins.springsecurity.secureChannel.useHeaderCheckChannelSecurity = trueConfig.groovy它,它将使用该方法而不是更简单的安全/不安全检查。IllegalStateException 是由于 Heroku 部署 Grails 2.0 应用程序的方式中的一个错误。构建战争时插件依赖关系没有得到解决,因此您需要明确。所以一定要加

compile ":spring-security-core:1.2.7.2"
compile ':webxml:1.4.1'
compile ":heroku:1.0"
compile ':cloud-support:1.0.8'

确保BuildConfig.groovy安装和部署 webxml(spring-security-core 依赖项)和 cloud-support(heroku 依赖项)。

于 2012-02-02T20:17:29.223 回答