0

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

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 的集中式性质下,在所有应用程序之间共享属性的推荐方法是什么?

4

1 回答 1

2

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

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

getUserDetailsS​​ervice() 处的 CasAuthenticationProvider.java:

/**
 * 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 实现来覆盖它。

于 2010-03-30T18:10:01.917 回答