`
liuzhiyi7288
  • 浏览: 31247 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

CAS 返回多个信息为空

    博客分类:
  • SSO
 
阅读更多
CAS client 端使用Filter 获得server端传回的信息,如果多个信息使用:
assertion.getPrincipal().getAttributes()
来获得一个Map,但是有的时候Map中没有数据为null;
解决方案:配置deployerConfigContext.xml中名称为serviceRegistryDao的bean,如下
<bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">
			<property name="registeredServices">
					<list>
							<bean class="org.jasig.cas.services.RegisteredServiceImpl" 
                    p:id="1"
                    p:description="test"
                    p:serviceId="http://192.168.104.101:8080/*"
                    p:enabled="true" 
                    p:ssoEnabled="true" 
                    p:anonymousAccess="false">
                    <property name="allowedAttributes" value="key1,key2,key3"/>
               </bean>					</list>
			</property>
,其中最重要的配置为:<property name="allowedAttributes" value="key1,key2,key3"/>
这个属性决定了我们在client端获得map是否为null,如果不配置该属性则为null,该属性配置我们返回多个信息对应的key;
此处对应CAS SERVER端源码如下 CentralAuthenticationServiceImpl.java:
// 获得deployerConfigContext.xml中serviceRegistryDao配置的registeredServices
        final RegisteredService registeredService = this.servicesManager
            .findServiceBy(service);

allowwedAttributes配置对应的代码如下:
/**
             * 从principal.getAttributes()获得map后,获取registeredService的allowedAttributes属性,
             * 可以对应的key存入返回客户端信息的中map中
             */
            for (final String attribute : registeredService
                .getAllowedAttributes()) {
                final Object value = principal.getAttributes().get(
                    attribute);
                if (value != null) {
                    attributes.put(attribute, value);
                }
            }

            final Principal modifiedPrincipal = new SimplePrincipal(
                principalId, attributes);
            
            final MutableAuthentication mutableAuthentication = new MutableAuthentication(
                modifiedPrincipal);

希望对大家有所帮助
分享到:
评论
1 楼 solomon 2011-10-31  
  不错,雪中送炭。 

相关推荐

Global site tag (gtag.js) - Google Analytics