Skip to content
This repository has been archived by the owner on Nov 3, 2017. It is now read-only.

Dynamic Login View Selector

Dmitriy Kopylenko edited this page Oct 23, 2013 · 6 revisions

There are uses cases where, conditionally, the cas server may have to display and render login pages other than the default view. In such a scenario, the per-service theming feature of CAS is generally not sufficient, in the sense that the adopter would want to drastically alter the structure of a given page for various types of members. An example use case may be that the CAS server may be intended for different types of users where presentation of the login page is drastically different for each. This difference could be text, images, and additional HTML elements, such that it would better require an entirely different page.

Example types of users would be staff, faculty, etc and specially when these users are geographically dispersed. A staff member from UK for instance would want to see a very different page, than a student from Poland. Implementations should allow the CAS server to route the login view to other JSPs other than the default.

Since version 1.9 there's a facility in cas-addons that is able to dynamically decide on the login view to be presented, based on a particular view url parameter. The value of this parameter may be mapped internally to a given view. If no matches are found, the default cas login view is used.

Configuration

  • Declare the bean using custom XML schema element:
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"              
       xmlns:cas="http://unicon.net/schema/cas"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd       
       http://unicon.net/schema/cas http://unicon.net/schema/cas/cas-addons.xsd">

   <cas:request-param-login-view-selector>
        <cas:login-view param="staff" view="casViewForStaff"/>
        <cas:login-view param="faculty" view="casViewForFaculty"/>
    </cas:request-param-login-view-selector>

</beans>

This will create a bean with casLoginViewSelector id, target request parameter name view, default view name casLoginView and a map of view request parameter values to custom login view names.

If you wish to change the request parameter name and/or default login view, use this form:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"              
       xmlns:cas="http://unicon.net/schema/cas"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd       
       http://unicon.net/schema/cas http://unicon.net/schema/cas/cas-addons.xsd">

   <cas:request-param-login-view-selector parameter-name="customViewParam" default-view="customCasLoginView">
        <cas:login-view param="staff" view="casViewForStaff"/>
        <cas:login-view param="faculty" view="casViewForFaculty"/>
    </cas:request-param-login-view-selector>

</beans>

Each view state needs to be separately mapped and constructed in the CAS configuration, much like the default casLoginView.

  • Adjust the login webflow:
<view-state id="viewLoginForm" view="${casLoginViewSelector.selectLoginView(flowRequestContext)}" ...>
  ...
</view>

Custom Selectors

If you wish to design your own selector that routes the login form based on other methods, simply implement the CasLoginViewSelector interface in your Java class and reconfigure the bean appropriately. Extensions should have access to the RequestContext of the webflow to make decisions.

Clone this wiki locally