【问题标题】:How to access/use custom attribute in spring security based CAS client如何在基于 Spring Security 的 CAS 客户端中访问/使用自定义属性
【发布时间】:2010-03-28 16:40:30
【问题描述】:

身份验证成功后,我需要将某些属性(例如,人类可读的用户名)从服务器发送到客户端。服务器部分已完成。现在属性已发送给客户端。从日志中,我可以看到:

2010-03-28 23:48:56,669 调试 Cas20ServiceTicketValidator:185 - 服务器响应:http://www.yale.edu/tp/cas'> a@b.com

        <cas:proxyGrantingTicket>PGTIOU-1-QZgcN61oAZcunsC9aKxj-cas</cas:proxyGrantingTicket>



        <cas:attributes>

                <cas:FullName>Test account 1</cas:FullName>

        </cas:attributes>

</cas:authenticationSuccess> </cas:serviceResponse>

但是,我不知道如何访问客户端中的属性(我使用的是 Spring security 2.0.5)。

在 authenticationProvider 中,一个 userDetailsS​​ervice 被配置为读取经过身份验证的主体的 db。

<bean id="casAuthenticationProvider" class="org.springframework.security.providers.cas.CasAuthenticationProvider">
    <sec:custom-authentication-provider />
    <property name="userDetailsService" ref="clerkManager"/>
    <!-- other stuff goes here -->
</bean>

现在在我的控制器中,我可以轻松做到这一点:

 Clerk currentClerk = (Clerk)SecurityContextHolder.getContext().getAuthentication().getPrincipal();

理想情况下,我可以以某种方式将此 Clerk 对象的属性填充为另一个属性。如何做到这一点?

或者在 CAS 的集中式性质下,在所有应用程序之间共享属性的推荐方法是什么?

【问题讨论】:

  • 这是一个网络服务吗?休息?肥皂?

标签: spring spring-security attributes cas


【解决方案1】:

对于 SpringSecurity - 您需要升级到 3.x 以通过内置支持利用 CAS 属性,请参阅:GrantedAuthorityFromAssertionAttributesUserDetailsS​​ervice.java

它看起来不像 SpringSecurity 2.x 填充基于 CAS 属性 - 如果你看一下:

CasAuthenticationProvider.java at getUserDetailsS​​ervice():

/**
 * Template method for retrieving the UserDetails based on the assertion.  Default is to call configured userDetailsService and pass the username.  Deployers
 * can override this method and retrieve the user based on any criteria they desire.
 * 
 * @param assertion The CAS Assertion.
 * @returns the UserDetails.
 */
protected UserDetails loadUserByAssertion(final Assertion assertion) {
    return this.userDetailsService.loadUserByUsername(assertion.getPrincipal().getName());
}

如果您出于某种原因必须留在 2.x 上,当然可以使用 UserDetails 实现来覆盖它。

【讨论】:

    猜你喜欢
    • 2016-02-27
    • 1970-01-01
    • 2014-08-01
    • 2015-11-07
    • 2019-07-11
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 2019-04-14
    相关资源
    最近更新 更多