我在从 java cas (JA-SIG) 检索属性时遇到问题。它总是返回 null。
下面是我的代码。我猜attributeRepository
是从未调用过bean,因为我将表名更改为错误的,并且它运行了,但它没有给出SQL Exception的运行时错误。
这是我的 deployerConfigContext.xml 文件(仅相关部分)
<bean id="authenticationManager" class="org.jasig.cas.authentication.AuthenticationManagerImpl">
<property name="credentialsToPrincipalResolvers">
<list>
<bean class="org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver">
<property name="attributeRepository">
<ref bean="attributeRepository"/>
</property>
</bean>
</list>
</property>
</bean>
<bean id="attributeRepository" class="org.jasig.services.persondir.support.jdbc.SingleRowJdbcPersonAttributeDao">
<constructor-arg index="0" ref="dataSource"/>
<constructor-arg index="1" value="SELECT id,is_admin,screen_name FROM user WHERE {0}"/>
<property name="queryAttributeMapping">
<map>
<entry key="login" value="eroshan@rcapl.com" />
</map>
</property>
<property name="resultAttributeMapping">
<map>
<entry key="id" value="150" />
<entry key="is_admin" value="0" />
<entry key="screen_name" value="xxxx.." />
</map>
</property>
</bean>
下面是我检索属性的客户端代码。org.jasig.cas.client.authentication.Saml11AuthenticationFilter
用于获取数据。
<h1>CAS Attribute Test</h1>
<p>User Id: <%= request.getRemoteUser() %></p>
<%
if (request.getUserPrincipal() != null) {
AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
Map attributes = principal.getAttributes();
out.println("attribute :"+attributes.size());
if (attributes != null) {
Iterator attributeNames = attributes.keySet().iterator();
out.println("Received attributes: <b>" + (attributeNames.hasNext() ? "YES!" : "No") + "</b>");
out.println("<hr><table border='3pt' width='100%'>");
out.println("<th colspan='2'>Attributes</th>");
out.println("<tr><td><b>Key</b></td><td><b>Value</b></td></tr>");
for (; attributeNames.hasNext();) {
out.println("<tr><td>");
String attributeName = (String) attributeNames.next();
out.println(attributeName);
out.println("</td><td>");
Object attributeValue = attributes.get(attributeName);
out.println(attributeValue);
out.println("</td></tr>");
}
out.println("</table>");
} else {
out.println("<pre>The attribute map is empty. Review your CAS filter configurations.</pre>");
}
} else {
out.println("<pre>The user principal is empty from the request object. Review the wrapper filter configuration.</pre>");
}
%>
当我打印属性大小时,它显示为 0。我的代码有什么问题?我在整理这个问题时遇到了很大的麻烦。有很多资源可用于从 Ldap 获取属性,但我需要从我的数据库中获取属性。