CAS:CAS客户端不显示属性

问题描述:

我无法获取CAS客户端的属性。 我做了一些研究,并试图找出如何将属性转发给CAS客户端。CAS:CAS客户端不显示属性

cas.properties我设置:

cas.principal.resolver.persondir.return.null=false 

我添加了这个依赖:

<dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-collections4</artifactId> 
     <version>4.1</version> 
    </dependency> 

这是我servicesRegistry.conf

{ 
    "services":[ 
     { 
      "id":1, 
      "serviceId":"https://localhost:8743/**", 
      "name":"HELLO_WORLD", 
      "description":"WEBAPP FOR TESTS", 
      "theme":"my_example_webapp", 
      "allowedToProxy":true, 
      "enabled":true, 
      "ssoEnabled":true, 
      "anonymousAccess":false, 
      "evaluationOrder":1, 
      "attributeReleasePolicy" : { 
       "@class" : "org.jasig.cas.services.ReturnAllowedAttributeReleasePolicy", 
       "principalAttributesRepository" : { 
        "@class" : "org.jasig.cas.authentication.principal.DefaultPrincipalAttributesRepository" 
       }, 
       "allowedAttributes" : [ "java.util.ArrayList", [ "cn", "description", "telephoneNumber" ] ] 
      } 
     }, 

     { 
      "id":2, 
      "serviceId":"https://yahoo.com", 
      "name":"YAHOO", 
      "description":"Test service with exact match on its serviceId and optional extra attributes", 
      "extraAttributes":{ 
       "someCustomAttribute":"Custom attribute value" 
      }, 
      "evaluationOrder":2 
     } 
    ] 
} 

ldapAuthenticationHandler看起来是这样的:

<bean id="ldapAuthenticationHandler" 
     class="org.jasig.cas.authentication.LdapAuthenticationHandler" 
       p:principalIdAttribute="cn" 
       c:authenticator-ref="authenticator"> 
      <property name="principalAttributeMap"> 
       <map> 
        <entry key="cn" value="cn" /> 
        <entry key="description" value="description" /> 
        <entry key="telephoneNumber" value="telephoneNumber" /> 
       </map> 
      </property> 
    </bean> 

而且我authenticationHandlersResolvers这样的:

<util:map id="authenticationHandlersResolvers"> 
    <entry key-ref="ldapAuthenticationHandler" value="#{null}" /> 
</util:map> 

这里是我的attributeRepository

<bean id="attributeRepository" class="org.jasig.services.persondir.support.NamedStubPersonAttributeDao" 
      p:backingMap-ref="attrRepoBackingMap" /> 

<util:map id="attrRepoBackingMap"> 
     <entry key="cn" value="cn" /> 
     <entry key="description" value="description" /> 
     <entry key="telephoneNumber" value="telephoneNumber" /> 
     <entry> 
      <key><value>memberOf</value></key> 
      <list> 
       <value>faculty</value> 
       <value>staff</value> 
       <value>org</value> 
      </list> 
     </entry> 
    </util:map> 

,并在客户端我做这个(编辑版本出来null检查等):

AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal(); 
final Map attributes = principal.getAttributes(); 
Iterator attributeNames = attributes.keySet().iterator(); 
String attributeName = (String) attributeNames.next(); 

但是,我没有得到任何属性。我错过了什么?

编辑:

我在另一个线程,我不得不改变Cas20ProxyReceivingTicketValidationFilterCas30ProxyReceivingTicketValidationFilter阅读,但这并没有改变什么:

<filter> 
     <filter-name>CAS Validation Filter</filter-name> 
      <filter-class>org.jasig.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter</filter-class> 

     <init-param> 
      <param-name>casServerUrlPrefix</param-name> 
      <param-value>https://localhost:8943/cas</param-value> 
     </init-param> 
     <init-param> 
      <param-name>serverName</param-name> 
      <param-value>https://localhost:8743</param-value> 
     </init-param> 
     <init-param> 
      <param-name>redirectAfterValidation</param-name> 
      <param-value>true</param-value> 
     </init-param> 
     <init-param> 
      <param-name>useSession</param-name> 
      <param-value>true</param-value> 
     </init-param> 
    </filter> 

我的问题是servicesRegistry.conf。它出于某种原因没有工作,我不明白为什么。

如果您在使用servicesRegistry.conf文件的问题,我建议你使用这个你deployerConfigContext.xml内:

<bean id="serviceRegistryDao" class="org.jasig.cas.services.InMemoryServiceRegistryDaoImpl"> 
     <property name="registeredServices"> 
      <list> 
       <bean class="org.jasig.cas.services.RegexRegisteredService" 
         p:id="5" p:name="https.all" p:description="Allow HTTPS connection" 
         p:serviceId="^https://.*" p:evaluationOrder="5" > 

        <property name="attributeReleasePolicy"> 
         <bean class="org.jasig.cas.services.ReturnAllAttributeReleasePolicy" /> 
        </property> 
       </bean> 
      </list> 
     </property> 
    </bean> 

这将允许具有适合的正则表达式^https://.*的URL的所有服务。