2

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 から属性を取得するためのリソースはたくさんありますが、データベースから取得する必要があります。

4

1 に答える 1

3

構成は適切に見えますが、返される属性を CAS サービスに対して定義する必要があり、抽出された構成にこの部分が表示されません。これは、RegisteredServiceImpl Bean、プロパティ「allowedAttributes」の serviceRegistryDao Bean で行われます。

例 :

<bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl">
 <property name="registeredServices">
   <list>
     <bean class="org.jasig.cas.services.RegisteredServiceImpl">
       <property name="id" value="0" />
       <property name="name" value="HTTP" />
       <property name="description" value="Only Allows HTTP Urls" />
       <property name="serviceId" value="http://**" />
       <property name="evaluationOrder" value="10000001" />
       <property name="allowedAttributes">
        <list>
          <value>name</value>
          <value>first_name</value>
          <value>middle_name</value>`
...
于 2012-09-10T07:12:22.723 に答える