Grails:Spring Security CAS 在 2.2.3 中工作,但在 2.3.0 中不起作用

2023-12-13

我有一个使用 Groovy 2.0 的 Grails 2.2.3 项目。我使用 Spring Security 将其设置为使用 CAS 进行身份验证,使用 LDAP 进行用户角色。当我运行应用程序时,一切都按预期进行:任何人都允许访问 /appcontext/,并且 /appcontext/admin/ 下的任何内容都由 CAS 和 LDAP 的管理员角色保护。我现在正在尝试使用最新版本的 Grails 和 Groovy。我安装了 GGTS 3.4.0.RELEASE 并使用 Grails 2.3.0 和 Groovy 2.1。我创建了一个新项目,制作了一个简单的域类和控制器,并添加了安全设置。

这是我使用 Grails 2.2.3 和 Groovy 2.0 运行 GGTS 3.3.0.RELEASE 应用程序时的输出:(注意“服务器正在运行”消息的位置)

| Loading Grails 2.2.3
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Running Grails application

Configuring Spring Security Core ...
... finished configuring Spring Security Core

Configuring Spring Security CAS ...
... finished configuring Spring Security CAS

Configuring Spring Security LDAP ...
... finished configuring Spring Security LDAP

| Server running. Browse to http://localhost:8080/appcontext

以下是我使用 Grails 2.3.0 和 Groovy 2.1 运行 GGTS 3.4.0.RELEASE 应用程序时的输出(请注意“服务器正在运行”消息的位置):

| Loading Grails 2.3.0
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 1 source files.....
| Running Grails application
| Server running. Browse to http://localhost:8080/appcontext
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Configuring Spring Security LDAP ...
... finished configuring Spring Security LDAP
Error initializing the application: No bean named 'casAuthenticationProvider' is defined
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'casAuthenticationProvider' is defined
        at SpringSecurityCoreGrailsPlugin$_createBeanList_closure22.doCall(SpringSecurityCoreGrailsPlugin.groovy:686)
        at SpringSecurityCoreGrailsPlugin.createBeanList(SpringSecurityCoreGrailsPlugin.groovy:686)
        at SpringSecurityCoreGrailsPlugin$_closure4.doCall(SpringSecurityCoreGrailsPlugin.groovy:615)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
| Error 2013-10-15 11:33:02,925 [localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing the application: No bean named 'casAuthenticationProvider' is defined
Message: No bean named 'casAuthenticationProvider' is defined
   Line | Method
->> 686 | doCall         in SpringSecurityCoreGrailsPlugin$_createBeanList_closure22
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   615 | doCall         in SpringSecurityCoreGrailsPlugin$_closure4
|   303 | innerRun . . . in java.util.concurrent.FutureTask$Sync
|   138 | run            in java.util.concurrent.FutureTask
|   886 | runTask . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run            in     ''
^   662 | run . . . . .  in java.lang.Thread
schema export unsuccessful
org.h2.jdbc.JdbcSQLException: Database is already closed (to disable automatic closing     at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-170]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:169)
    at org.h2.message.DbException.get(DbException.java:146)
    at org.h2.message.DbException.get(DbException.java:135)
    at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1391)
    at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1366)
    at org.h2.jdbc.JdbcConnection.getAutoCommit(JdbcConnection.java:424)
    at java.lang.Thread.run(Thread.java:662)
| Error 2013-10-15 11:33:03,071 [Thread-9] ERROR hbm2ddl.SchemaExport  - schema export unsuccessful
Message: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-170]
    Line | Method
->>  329 | getJdbcSQLException in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    169 | get                 in     ''
|    146 | get . . . . . . . . in     ''
|    135 | get                 in     ''
|   1391 | checkClosed . . . . in org.h2.jdbc.JdbcConnection
|   1366 | checkClosed         in     ''
|    424 | getAutoCommit . . . in     ''
^    662 | run                 in java.lang.Thread
| Error Forked Grails VM exited with error

这是我的基本安全设置:

conf/spring/resources.groovy

import org.apache.commons.lang.StringEscapeUtils

// Place your Spring DSL code here
beans = {
    // load ldap roles from spring security
    def ldapUrl = StringEscapeUtils.escapeJava('${ldap.defaultUrl}')
    def ldapUser = StringEscapeUtils.escapeJava('${ldap.username}')
    def ldapPassword = StringEscapeUtils.escapeJava('${ldap.password}')
    def ldapBase = StringEscapeUtils.escapeJava('${ldap.base}')
    def ldapRoleSearchBase = StringEscapeUtils.escapeJava('${ldap.roleSearchBase}')

    initialDirContextFactory(org.springframework.security.ldap.DefaultSpringSecurityContextSource, ldapUrl){
        userDn = ldapUser
        password = ldapPassword
    }

    ldapUserSearch(org.springframework.security.ldap.search.FilterBasedLdapUserSearch,
        ldapBase, 'sAMAccountName={0}', initialDirContextFactory){ }

    ldapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator,
        initialDirContextFactory, ldapRoleSearchBase){
            groupRoleAttribute = 'cn'
            groupSearchFilter = 'member={0}'
            searchSubtree = true
            rolePrefix = 'ROLE_'
            convertToUpperCase = true
            ignorePartialResultException = true
        }

    userDetailsService(org.springframework.security.ldap.userdetails.LdapUserDetailsService,ldapUserSearch,ldapAuthoritiesPopulator){ }

}

conf/Config.groovy

def appName = grails.util.Metadata.current.getApplicationName()

environments {
    development {
        grails.logging.jul.usebridge = true

        host.ip = "12.34.56.78"
        host.port = "8080"
        host.securePort = "8080"
        ldap.username = "ldapUsername"
        ldap.password = "ldapPassword"
        ldap.base = "DC=foo,DC=company,DC=com"
        ldap.roleSearchBase = "OU=bar,DC=foo,DC=company,DC=com"
        ldap.defaultUrl = "ldap://123.45.67.89:389"
        ldap.urls = "ldap://123.45.67.89:389 ldap://123.45.67.89:389"

        cas.url = "https://sso.company.com/cas/"
        cas.loginUrl = "https://sso.company.com/cas/login"
        cas.logoutUrl = "https://sso.company.com/cas/logout"

        grails.plugins.springsecurity.cas.serviceUrl = 'http://${host.ip}:${host.securePort}/' + appName +'/j_spring_cas_security_check'
        grails.plugins.springsecurity.cas.proxyCallbackUrl = 'http://${host.ip}:${host.securePort}/' + appName +'/secure/receptor'
    }
    production {
        grails.logging.jul.usebridge = false
        grails.plugins.springsecurity.cas.serviceUrl = 'https://${host.ip}:${host.securePort}/' + appName +'/j_spring_cas_security_check'
        grails.plugins.springsecurity.cas.proxyCallbackUrl = 'https://${host.ip}:${host.securePort}/' + appName +'/secure/receptor'
    }
}

//spring security core config
grails.plugins.springsecurity.providerNames = ['casAuthenticationProvider']
grails.plugins.springsecurity.rejectIfNoRule = true
grails.plugins.springsecurity.securityConfigType = "InterceptUrlMap"
grails.plugins.springsecurity.interceptUrlMap = [
    '/js/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
    '/css/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
    '/images/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
    '/admin/login/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
    '/admin/logout/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
    '/admin/**': ['hasAnyRole("ROLE_ADMIN")'],
    '/**': ['IS_AUTHENTICATED_ANONYMOUSLY']
]

//cas config
grails.plugins.springsecurity.cas.loginUri = 'login'
grails.plugins.springsecurity.cas.serverUrlPrefix = '${cas.url}'
grails.plugins.springsecurity.cas.proxyReceptorUrl = '/secure/receptor'

conf/BuildConfig.groovy

compile ":spring-security-core:1.2.7.3"
compile ":spring-security-cas:1.0.5"
compile ":spring-security-ldap:1.0.6"

EDIT使用下面接受的答案的建议,我能够正确配置 Spring Security CAS,但我的控制器仍然不安全。我认为这与奇怪的加载顺序有关,应用程序服务器说它正在运行,然后加载 Spring Security、LDAP 和 CAS。一位同事建议取出我的 InterceptUrlMap 并使用 @Secured 注释来查看是否是加载顺序(因为在一切启动并运行后 InterceptUrlMap 无法更新)。我摆脱了rejectIfNoRule、securityConfigType 和interceptUrlMap 设置,并向控制器添加了@Secured(['ROLE_ADMIN']) 。该应用程序现在可以按预期工作,并且该控制器已受到保护。

因此,Grails 2.3.0 和 Spring Security 的事件顺序仍然存在问题,但这是一种解决方法。

相关问题:https://stackoverflow.com/questions/19411102/grails-2-3-0-spring-security-ldap-and-cas-load-after-server-starts


我也看到同样的事情。看起来 CAS 插件默认来自DefaultCasSecurityConfig.groovy在 Grails 2.3.0 下没有正确合并。可能值得一个 JIRA。同时,您可以通过将默认值添加到 Config.groovy 来继续前进(覆盖您的环境):

grails.plugins.springsecurity.cas.active = true
grails.plugins.springsecurity.cas.loginUri = null // must be set, e.g. '/login'
grails.plugins.springsecurity.cas.sendRenew = false
grails.plugins.springsecurity.cas.serviceUrl = null // must be set, e.g. 'http://localhost:8080/myapp/j_spring_cas_security_check'
grails.plugins.springsecurity.cas.serverUrlPrefix = null // must be set, e.g. 'http://localhost:9090/cas'
grails.plugins.springsecurity.cas.serverUrlEncoding = 'UTF-8'
grails.plugins.springsecurity.cas.key = 'grails-spring-security-cas'
grails.plugins.springsecurity.cas.artifactParameter = 'ticket'
grails.plugins.springsecurity.cas.serviceParameter = 'service'
grails.plugins.springsecurity.cas.filterProcessesUrl = '/j_spring_cas_security_check'
grails.plugins.springsecurity.cas.proxyCallbackUrl = null // should be set, e.g. 'http://localhost:8080/myapp/secure/receptor'
grails.plugins.springsecurity.cas.proxyReceptorUrl = null // should be set, e.g. '/secure/receptor'
grails.plugins.springsecurity.cas.useSingleSignout = true
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Grails:Spring Security CAS 在 2.2.3 中工作,但在 2.3.0 中不起作用 的相关文章

随机推荐

  • 在 Visual Studio 2017 .NET Core 项目中支持 Roslyn 分析器(.ruleset)

    如何在 Visual Studio 2017 NET Core 项目中添加对 Roslyn 分析器 ruleset 的支持 在 project json 中 它是通过使用配置的buildOptions buildOptions additi
  • Varchar 或 Text 数据类型,字符串长度最多为数千个字符

    我有一个小型社交网站 包含帖子和评论 我决定让用户使用他们想要的任意数量的字符创建帖子 我认为存储此类内容的最佳数据类型是Text 但对于评论 大多数情况下用户只写一行或几行文字 这就是为什么我认为我必须将注释字符串长度限制为最大 3000
  • 从 C# 关闭最小化/图标化进程

    这是我的问题 我需要从 C 程序关闭一个已经运行的进程 问题是该进程现在作为图标运行 最小化到任务栏 除非用户至少打开它一次 这在无人值守的计算机上永远不会发生 否则它永远不会 有一个主窗口 我的另一个要求是应用程序是closed not
  • 尽可能均匀地分配数量

    我们有一定的数量 例如300 单位 该数量应尽可能均匀地分布在 40 个 槽 上 如果每个槽都相同 那就很容易了 所以每个槽都是 7 5 然而 插槽的大小各不相同 我们不能 填充 超过其 大小 允许的范围 例如如果只有 5 个 我们无法 填
  • 有没有直接的方法将 Informix 上的 Unix 时间转换为 YYYY-MM-DD HH:MM:SS?

    我知道使用 PHP 或 Perl 可以轻松完成类似的事情 但我想知道是否有一种方法可以直接在 Informix 上完成 例如函数FROM UNIXTIME 在 MySQL 上 我认为你可以使用 dbinfo 和 utc to datetim
  • 使用php将mysql表列表从mysql导出到csv文件

    我想知道是否有人可以向我展示一个示例 PHP 代码 说明如何将 MySQL 数据库中的大约 50 个表导出到 CSV 文件 我的数据库名称是 samples 该数据库下有大约 49 个表 我希望该数据库下的每个表 大约有 20 00 行 导
  • 使用 Google Sheets 脚本,为什么我的 if 语句在比较单元格值时总是返回 false?

    我需要比较两个单元格值并在它们不同时对其采取行动 然而 在比较单元格内容时 我的 if 语句总是返回 false 我不明白为什么 function onEdit var ss SpreadsheetApp getActiveSpreadsh
  • Haskell 继承、数据、构造函数

    所以我想为我的小行星游戏 作业定义多个数据类 data One One oneVelocity Velocity onePosition Position other properties unique to One data Two Tw
  • 如何在C#中从mysql结果中读取某些数据

    我想从 C 对 mysql 进行某些查询 这样我就可以返回例如姓名和姓氏 我不知道如何在 C 中处理这个问题 我想尽量减少 SQLinjection 这是我的代码 con new MySqlConnection server localho
  • 无法加载实体框架提供程序类型“Oracle.ManagedDataAccess.EntityFramework”

    我正在尝试在 MVC 应用程序中使用 Entity Framework v6 使用 Oracle Data Provider NET ODP NET 连接到 Oracle 我从这里安装了 ODP NET https www nuget or
  • 根据 WooCommerce 中的产品类别自定义“缺货”文本

    每件缺货产品都显示 缺货 有很多functions php覆盖文本的脚本 但我只是尝试覆盖特定于 类别 A 的文本 或者如果我知道类别 id 编号 那也可以工作 我找到了这个脚本 但它只允许您修改每个产品 ID 的 txt add filt
  • 视图内的 Rails 布局名称

    如何打印视图中当前布局的名称 Example puts controller current layout Thx 这适用于 Rails 3 0 7 controller send layout 显然 这是一种私有方法 因此使用时需要您自担
  • VHDL:IEEE std_logic 库中的真值表

    我研究了 IEEE 如何定义其库 当我打开的时候标准逻辑库 我看到了一些被定义为常数的真值表 我不知道真值表是如何运作的 请解释如何使用真值表返回结果 这是我找到的 AND 门 TYPE stdlogic table IS ARRAY st
  • SQL 创建 UDF 计算列

    我尝试创建一个计算列 但由于其中一列位于另一个表中 我知道我需要创建一个 udf 这是 ERD 的链接 以便您可以查看其中的关系 http imageshack us photo my images 23 databaseassignmen
  • 如何使用Androidfragmentmanager传递变量[重复]

    这个问题在这里已经有答案了 我有以下简单的代码可以在内容框架中从一个片段切换到另一个片段 在下面的代码中是否有一种简单的方法来传递变量 FragmentManager fm getActivity getFragmentManager fm
  • 试图理解这个简短的汇编指令,但我不明白

    我们有一个任务 给定的是 2 寻址的汇编指令 机器 mov 202 100 r1 记下替代此的最小汇编指令序列 说明 见上文 where n rx 按后增量索引的寄存器 n 是索引值 rx 是寄存器 x 单个数值 直接寻址 存储 我们应该使
  • 如何在 TypeScript 中设置类型参数的下限?

    在 TypeScript 我的版本 2 1 1 中 可以为类型参数设置上限 如下所示 class Animal class Cat extends Animal class Kitten extends Cat function foo a
  • 存储 bcrypt 哈希值

    根据 PHP 的文档 bcrypt salt 是由 2a 两位数的成本参数 以及字母表中的 22 位数字 0 9A Za z 因此 如果我使用 crypt 函数对我的密码进行哈希处理 则结果输出包括前 7 个字符 2a 10 如果 10 是
  • WindowsFormsHost 上的工具栏覆盖

    我有一个嵌入在 WPF 窗口内的 WindowsFormsHost 控件中的 SWF 对象 我想在 swf 影片上添加一个工具栏 我下面的代码片段的问题是 当新的子控件添加到主机控件时 或者加载电影 我还没有弄清楚是哪一个 工具栏实际上是不
  • Grails:Spring Security CAS 在 2.2.3 中工作,但在 2.3.0 中不起作用

    我有一个使用 Groovy 2 0 的 Grails 2 2 3 项目 我使用 Spring Security 将其设置为使用 CAS 进行身份验证 使用 LDAP 进行用户角色 当我运行应用程序时 一切都按预期进行 任何人都允许访问 ap