Trying to override the username ID

31 views
Skip to first unread message

Ganael Laplanche

unread,
Nov 9, 2018, 2:23:43 AM11/9/18
to CAS Community
Hi,

I am using Cas 4.1.7 and trying to override the returned username ID with an LDAP attribute (uid), following that documentation :


Here is the configuration for the service:

            <bean class="org.jasig.cas.services.RegexRegisteredService"
                 
p:id="1"
                 
p:name="Authentication on XXX"
                 
p:serviceId="XXX"
                 
p:evaluationOrder="1">
               
<property name="attributeReleasePolicy">
                   
<bean class="org.jasig.cas.services.ReturnAllAttributeReleasePolicy" />
               
</property>
               
<property name="usernameAttributeProvider">
                   
<bean class="org.jasig.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider">
                       
<property name="usernameAttribute" value="uid" />
                   
</bean>
               
</property>
           
</bean>

Unfortunately, when rebuilding the application, I get the following error message :

"Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'usernameAttribute' of bean class [org.jasig.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider]: Bean property 'usernameAttribute' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?"

If I explicitly switch back to the default username provider using the following config, it builds fine again:

                <property name="usernameAttributeProvider">
                   
<bean class="org.jasig.cas.services.DefaultRegisteredServiceUsernameProvider" />
               
</property>

I must be missing something... Any hint ?

Best regards,

Ganael.

Ray Bon

unread,
Nov 9, 2018, 12:31:29 PM11/9/18
to cas-...@apereo.org
Ganael,

That error means that the class, PrincipalAttributeRegisteredServiceUsernameProvider, does not have a setter for the property, usernameAttribute.
You can set the 'switch' in the service definition. See further up the same page at https://apereo.github.io/cas/4.1.x/integration/Attribute-Release.html#principalattributeregisteredserviceusernameprovider.

Ray
-- 
Ray Bon
Programmer analyst
Development Services, University Systems
2507218831 | CLE 019 | rb...@uvic.ca

Ganael Laplanche

unread,
Nov 12, 2018, 5:13:16 AM11/12/18
to CAS Community
Hi Ray,

That error means that the class, PrincipalAttributeRegisteredServiceUsernameProvider, does not have a setter for the property, usernameAttribute.
You can set the 'switch' in the service definition. See further up the same page at https://apereo.github.io/cas/4.1.x/integration/Attribute-Release.html#principalattributeregisteredserviceusernameprovider.

Thanks a lot for your answer, it helped me fix the service definition.

Studying the source code of the PrincipalAttributeRegisteredServiceUsernameProvider class shows that there is no setter indeed. The usernameAttribute attribute can only be set through the constructor.

So I changed the declaration that way :

                <property name="usernameAttributeProvider">
                    <bean class="org.jasig.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider"
                        c:usernameAttribute="uid" />
                </property>

and managed to build the application again :)

Best regards,

Ganael.
Reply all
Reply to author
Forward
0 new messages