将属性从 CAS 释放到 Spring security

2024-03-21

我在客户端使用 Spring security 3.X,在服务器上使用 CAS 4.0。

当我进行 CAS+Spring 安全集成时,我能够达到票证验证成功的水平,并能够在客户端获得适当的角色。

但我在 casServiceValidationSuccess.jsp 中添加了以下几行,以迭代并发送响应中的属性,因为我的属性未正确发布:

    <cas:attributes>
<cas:user>${fn:escapeXml(assertion.primaryAuthentication.principal.id)}</cas:user>
    <c:forEach var="attr" items="${assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.attributes}">
         <cas:${fn:escapeXml(attr.key)}>${fn:escapeXml(attr.value)}</cas:${fn:escapeXml(attr.key)}>
    </c:forEach>
</cas:attributes>

所以想知道在CAS服务器端的deployerConfigContext.xml中是否还有其他替代更改可以释放特定的属性-“权限”(在我的例子中)并在SPRING客户端中获得相同的属性。

找到现有的deployerConfigContext.xml 尝试释放“authorities”属性的片段:

    <bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager">
        <constructor-arg>
            <map>
                <entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />
                <entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />
            </map>
        </constructor-arg>

    <bean id="primaryAuthenticationHandler" class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
  <property name="dataSource" ref="dataSource" />
  <property name="sql" value="SELECT EMAIL FROM USER_DATA WHERE UserID = ?" />
</bean>
   <bean id="primaryPrincipalResolver"
          class="org.jasig.cas.authentication.principal.PersonDirectoryPrincipalResolver" >
        <property name="attributeRepository" ref="attributeRepository" />
    </bean>
   <bean id="attributeRepository"
    class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao">
    <constructor-arg index="0" ref="dataSource" />
    <constructor-arg index="1" value="SELECT UserID, UserROLES FROM USER_DATA WHERE {0}" />
    <property name="queryAttributeMapping">
        <map>
            <entry key="username" value="UserID" />
        </map>
    </property>
    <property name="resultAttributeMapping">
        <map>
            <entry key="UserID" value="username" />
            <entry key="UserROLES" value="UserROLES" />
        </map>
</property>     
</bean>
    <bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">
        <property name="registeredServices">
            <list>
                <bean class="org.jasig.cas.services.RegisteredServiceImpl">
                    <property name="id" value="0"></property>
                    <property name="name" value="HTTP"></property>
                    <property name="description" value="Only Allows HTTP Urls"></property>
                    <property name="serviceId" value="http://**" />
                    <property name="usernameAttribute" value="username" />
                    <property name="ignoreAttributes" value="false" />
                    <property name="allowedAttributes">
                        <list>
                            <value>UserROLES</value>
                        </list>
                    </property>
                </bean>

            </list>
        </property>
    </bean>

还可以在spring客户端找到security-context.xml:

    <security:http use-expressions="true" entry-point-ref="casAuthenticationEntryPoint"
        auto-config="true">     
        <security:custom-filter position="CAS_FILTER"
            ref="casAuthenticationFilter"></security:custom-filter>
        <security:intercept-url pattern="/home" access="hasRole('ROLE_TEST')"></security:intercept-url>
        <security:intercept-url pattern="/**" access="hasRole('ROLE_ANONYMOUS')"></security:intercept-url>
    </security:http>

    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider
            ref="casAuthenticationProvider"></security:authentication-provider>
    </security:authentication-manager>

    <bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
        <property name="service"
            value="http://localhost:7080/test/j_spring_cas_security_check"></property>
        <property name="sendRenew" value="false"></property>
    </bean>

    <bean id="casAuthenticationFilter"
        class="org.springframework.security.cas.web.CasAuthenticationFilter">
        <property name="authenticationManager" ref="authenticationManager"></property>
        <property name="authenticationFailureHandler">
        <bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
            <property name="defaultFailureUrl" value="http://localhost:8090/cas-server-webapp-4.0.0/login"/>
        </bean>
    </property>
    <property name="authenticationSuccessHandler">
        <bean class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
            <property name="defaultTargetUrl" value="/home.jsp"/>
        </bean>
    </property>
    </bean>

    <bean id="casAuthenticationEntryPoint"
        class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
        <property name="loginUrl"
            value="http://localhost:8090/cas-server-webapp-4.0.0/login"></property>
        <property name="serviceProperties" ref="serviceProperties"></property>
    </bean>

    <!-- Handles the CAS ticket processing. -->
    <bean id="casAuthenticationProvider"
        class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
        <!-- <property name="userDetailsService" ref="userService"></property>  -->
    <property name="authenticationUserDetailsService" ref="authenticationUserDetailsService" />
        <property name="serviceProperties" ref="serviceProperties"></property>
        <property name="ticketValidator">
            <bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
                <constructor-arg index="0"
                    value="http://localhost:8090/cas-server-webapp-4.0.0">
                </constructor-arg>
            </bean>
        </property>
        <property name="key" value="cas"></property>
    </bean>

    <bean id="authenticationUserDetailsService"
        class="org.springframework.security.cas.userdetails.GrantedAuthorityFromAssertionAttributesUserDetailsService">
        <constructor-arg>
            <list>
                <value>UserROLES</value>
            </list>
        </constructor-arg>
    </bean>
</beans>

免责声明:我是 CAS 主席,也是 CAS 云创始人(https://www.casinthecloud.com https://www.casinthecloud.com).

您的身份验证处理程序是否引用了您的属性 person DAO?如果没有 Spring security 进行手动服务票证验证,它是否可以工作?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将属性从 CAS 释放到 Spring security 的相关文章

随机推荐

  • 尝试将 AWS DynamoDB 与 Swift 3 结合使用时出现很多错误

    我是快速开发的新手 正在尝试合并后端 我认为 AWS 将是实现我想要完成的任务的好方法 我目前只是想获取他们为您创建的示例项目文件 它有很多错误 令人难以置信 我意识到 AWS 在 Swift 2 中创建文件 因此在 Swift 3 中运行
  • 如何使输入和选择字段的宽度相等

    在表单上 我有一个选择字段和两个输入字段 这些元素垂直对齐 不幸的是 我无法获得这些元素的相同宽度 这是我的代码
  • 在 ASP.Net MVC 中设置 Access-Control-Allow-Origin - 最简单的方法

    我有一个简单的操作方法 它返回一些 json 它在 ajax example com 上运行 我需要从另一个网站 someothersite com 访问该网站 如果我尝试调用它 我会得到预期的 Origin http someothers
  • Pybind11 - 返回指向 unique_ptr 容器的指针

    我一直在使用优秀的 pybind11 库 但遇到了困难 我需要向 Python 返回一个指向不可复制对象的指针 因为该对象包含 unique ptrs 一般来说 这在使用 return value policy reference 的警告下
  • Delphi 和 NoSQL

    有人曾经将 Delphi 与 NoSQL 数据库 如 Mongo CouchDB 或其他数据库 一起使用过吗 您会推荐哪一款 对于 Mongo 有TMongoWire https github com stijnsanders TMongo
  • .NET 和 Lotus Notes 互操作

    我在某个位置有 Lotus Notes 数据库文件 nsf 比方说 http intranet mycompany com somewhere data nsf http intranet mycompany com somewhere d
  • Excel 按名称将工作表数据拆分到新的 Excel 工作簿中[重复]

    这个问题在这里已经有答案了 Model Place model23 35372 model23 35372 model54 31034 model24 31034 model54 31034 model24 31034 我有这个Excel数
  • 如何转储哈希映射的内容?

    如何转储 Java HashMap 或任何其他 的内容 例如转储到 STDOUT 举个例子 假设我有一个具有以下结构的复杂 HashMap student1 gt Map name gt Tim Scores gt Map math gt
  • 如何更改 Treeview 的背景颜色

    我来这里是想问你如何更改树视图的背景 我尝试过 ttk Style configure Treeview background 383838 它仅适用于单元格 但树视图的其余部分保持白色 我尝试更改窗口的背景和框架 但它不起作用 那么 如何
  • 如何根据python中的条件组合或保留列表中的字符串?

    我有三个清单 li1 a a a a b b a a b li2 a a a b a b a a li3 b b a a b 我想通过以下方式 切片和粘贴 元素 b 结果应该是这样的 li1 aaaa b b aa b li2 aaa b
  • 将样式应用于特定类型的所有子元素

    我想为 wpf 编写一个样式 其中 StatusBar 中的所有按钮 具有定义的样式 都具有相同的样式 例如宽度 这是我的风格 以及元素的 xaml
  • 使用java进行服务器端推送

    有没有更简单的方法cometd http cometd org作为java的长轮询框架 因为我需要的是客户端指定一些参数并将它们发送到服务器 服务器处理它们并开始连续将消息推送回客户端 看起来 就像每个服务的线程 客户端接收消息并显示它们
  • 为多个客户管理多个 git 发布分支

    我的公司有一款软件出售给多个客户 但每个客户都有一些不同的要求 不仅仅是 把我们的标志放在这里 它们的核心都是相同的 但有些不需要某些模块 有些则需要所有模块 包括修改 我想在一个 git 存储库中管理所有这些 这样我对它们都有相同的核心
  • 从paleoView导入R中的netcdf时只有正纬度和经度可能是错误的投影

    我用的是古景 https onlinelibrary wiley com doi full 10 1111 ecog 03031软件用于下载过去气候的一些变量 包括 15000BP 10000BP 的平均温度 我可以根据要求上传文件 但至少
  • Android studio 找不到:com.getbase:floatingactionbutton:1.3.0

    我正在尝试使用现有的 android 项目运行我的 gradle 文件 我对这个应用程序的唯一错误是Failed to find com getbase floatingactionbutton 1 3 0 下面是我的 gradle 文件
  • 从 Angular Material 复选框更改 CSS

    有人可以告诉我 当您单击角度材质复选框时 如何更改圆形的颜色 如下图所示 粉色圆圈 这是官方网页的链接 https material angular io components checkbox overview https materia
  • Google 喜欢 Delphi 的编辑/组合控件吗?

    每个人可能都知道我的意思 但要澄清控制需要 当用户编辑文本时触发事件 该事件将提供一个 SuggestionList TStrings 您可以在其中填充匹配 建议 如果 SuggestionList 不为空 则会出现一个下拉菜单 与组合不同
  • Task.WhenAll 是否在后台线程并行运行任务

    以下2个代码片段的作用相同吗 1 var producer Task Run async gt await bar ReadDataAsync var consumer Task Run async gt await bar WriteDa
  • 如何使用 URL 打开应用程序?

    我已经实施了所有必需的事情 但没有成功 我想从浏览器打开应用程序 但不仅仅是网址架构就像 回调 一样 我有类似的东西 http 11 11 21 114 8081 signup callback signupCode 123 id 20 h
  • 将属性从 CAS 释放到 Spring security

    我在客户端使用 Spring security 3 X 在服务器上使用 CAS 4 0 当我进行 CAS Spring 安全集成时 我能够达到票证验证成功的水平 并能够在客户端获得适当的角色 但我在 casServiceValidation