define multiple fragments to apply to "guest" based on attribute values


Below demonstrates the configuration required to allow multiple virtual hosts to serve a different layout per serverName value. 

Step 1: Modify the userContext.xml file

  • Modify uportal-war/src/main/resources/properties/contexts/userContext.xml by first uncommenting out the default bean personManager and add this bean definition

 

<!--
     | Use this bean to extend guest user properties with attributes from the request set by the requestAttributeSourceFilter
-->

     <bean id="personManager" class="org.esco.portal.security.provider.ExtendedPersonManager" >
       <property name="merger">
            <bean class="org.jasig.services.persondir.support.merger.ReplacingAttributeAdder" />
        </property>
       <property name="descriptors" ref="requestAdditionalDescriptors" />
     </bean> 

 

  •  Adapt the subMappers property under the profileMapper bean. This action will place cache in different layouts of the guest user depending on the profiles created. Each profile carries a different value of the attribute which will map to it's corresponding fragment. See the example below.  

 

  <bean id="profileMapper" class="org.jasig.portal.layout.ChainingProfileMapperImpl">
        <property name="defaultProfileName" value="default" />
        <property name="subMappers">
            <util:list>
                <ref bean="sessionAttributeProfileMapper" />
                <ref bean="userAgentProfileMapper" />
                 <!--
                 | Define a profileMapper for user guest associated to the serverName attribute,
                 | This example configuration is applied only if user-agent isn't a mobile.
                 | You need to define and import a new profile for each entry on default users
                 | Add "guest-[server name]-" prefix to the subfname found
                 +-->
                
                <bean class="org.esco.portal.layout.ServerNameGuestChainingProfileMapper">
                	<property name="authorizedServerNames">
                		<util:map>
                			<!-- Only server names listed here are authorized ! (the value replace the server name) -->
                			<entry key="www.univ1.fr" value="univ1" />
                			<entry key="www.univ2.fr" value="univ2" />
                		</util:map>
                	</property>
                	<property name="subMappers">
                		<util:list>
                			<!-- Move here the mappers you want to customize for each server name guest. -->
                		</util:list>
                	</property>
                </bean>
                
            </util:list>
        </property>
    </bean>

 

Step 2: Create Profiles

 

Important

The profile FNAME is important, it must match with the profileMapper definition for the guest user for each serverName.
Example:
  • guest[-serverName]-[ProfileName]
    • where [-serverName] = concat("-", $value_serverName), where $value_serverName is the value of the entry key in the list of authorizedServerNames in bean profileMapper 
    • where [ProfileName] is the value of the profile name define in the example with the property defaultProfileName in the bean profileMapper
 
  • In the bean definition we declared two server names, so we must declare one profile per serverName value and one profile for the default value for all other serverName values. Below demonstrates the three different profiles per guest layout:
Ex. guest-univ1-default.profile.xml
<profile script="classpath://org/jasig/portal/io/import-profile_v3-2.crn" username="defaultTemplateUser">
	<name>ServerName www.univ1.fr HTML browser profile</name>
	<fname>guest-univ1-default</fname>
	<description>A sample profile for common web browsers which requesting www.univ1.fr</description>
	<structure name="DLMTabsColumns"/>
	<theme name="DLMXHTML"/>
</profile>
Ex. guest-univ2-default.profile.xml
<profile script="classpath://org/jasig/portal/io/import-profile_v3-2.crn" username="defaultTemplateUser">
	<name>ServerName www.univ2.fr HTML browser profile</name>
	<fname>guest-univ2-default</fname>
	<description>A sample profile for common web browsers which requesting www.univ2.fr</description>
	<structure name="DLMTabsColumns"/>
	<theme name="DLMXHTML"/>
</profile>
Ex. guest-default.profile.xml
<profile script="classpath://org/jasig/portal/io/import-profile_v3-2.crn" username="defaultTemplateUser">
	<name>ServerName others HTML browser profile</name>
	<fname>guest-default</fname>
	<description>A sample profile for common web browsers which requesting others domains</description>
	<structure name="DLMTabsColumns"/>
	<theme name="DLMXHTML"/>
</profile>

 

Step 3: Define your Fragment Definitions

  • Define your fragment-definition per serverName value and keep the default fragment definition. See the example fragment definitions below:
guestuniv1-lo
<fragment-definition xmlns:dlm="http://org.jasig.portal.layout.dlm.config" script="classpath://org/jasig/portal/io/import-fragment-definition_v3-1.crn">
<dlm:fragment name="GuestsUniv1" ownerID="guestuniv1-lo" precedence="80">
<dlm:audience evaluatorFactory="org.jasig.portal.layout.dlm.providers.PersonEvaluatorFactory">
  <paren mode="AND">
    <attribute name="username" mode="equals" value="guest"/>
    <attribute name="serverName" mode="equals" value="www.univ1.fr"/>
  </paren>
</dlm:audience>
</dlm:fragment>
</fragment-definition>


guestuniv2-lo
<fragment-definition xmlns:dlm="http://org.jasig.portal.layout.dlm.config" script="classpath://org/jasig/portal/io/import-fragment-definition_v3-1.crn">
<dlm:fragment name="GuestsUniv2" ownerID="guestuniv2-lo" precedence="80">
<dlm:audience evaluatorFactory="org.jasig.portal.layout.dlm.providers.PersonEvaluatorFactory">
  <paren mode="AND">
    <attribute name="username" mode="equals" value="guest"/>
    <attribute name="serverName" mode="equals" value="www.univ2.fr"/>
  </paren>
</dlm:audience>
</dlm:fragment>
</fragment-definition>
guest-lo
<fragment-definition xmlns:dlm="http://org.jasig.portal.layout.dlm.config" script="classpath://org/jasig/portal/io/import-fragment-definition_v3-1.crn">
<dlm:fragment name="Guests" ownerID="guest-lo" precedence="80">
<dlm:audience evaluatorFactory="org.jasig.portal.layout.dlm.providers.PersonEvaluatorFactory">
  <paren mode="AND">
    <attribute name="username" mode="equals" value="guest"/>
    <paren mode="NOT">
      <attribute name="serverName" mode="equals" value="www.univ1.fr"/>
    </paren>
    <paren mode="NOT">
      <attribute name="serverName" mode="equals" value="www.univ2.fr"/>
    </paren>
  </paren>
</dlm:audience>
</dlm:fragment>
</fragment-definition>


Step 4: Import profiles and fragment definitions

  • Import each of your newly created profiles and fragment definitions by running the data-import command. See command syntax below:
ant data-import -Dfile=<enter path to file>

 

Step 5: Rebuild/Redeploy uPortal

  • Run the command below to rebuild and deploy your portal changes. After running the command restart tomcat 
ant clean deploy-war


Step 6: Restart Tomcat

Restart your tomcat instance

NOTE: Next, setup layouts per profile. See setup a fragment layout for details.

 

Additional References

Having problems with these instructions?

Please send us feedback at uportal-user@lists.ja-sig.org