CAS 返回多个信息为空

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值