Extending Backoffice Login Page

The default login page shipped with the backoffice extension has three predefined fields: Username, Password, and Language. You can extend the login page by adding custom fields.

Prerequisites

For the purpose of the below example, generate two custom backoffice extensions: extensionOne and extensionTwo. Create the dependency between the extensions by the following code phrase in the extensionTwo/extensioninfo.xml:
<requires-extension name="extensionOne"/>

Context

The example shows how to add custom fields to both extensions to extend the Backoffice login page.

Adding New Fields to extensionOne

Extend login page for extensionOne with new fields.

Procedure

  1. Add the following bean to the Spring application context of extensionOne:

    extensionOne/resources/extensionOne-backoffice-spring.xml

    <alias name="extensionOneLoginInformationHandler" alias="loginInformationHandler"/>	
    <bean id="extensionOneLoginInformationHandler" parent="defaultLoginInformationHandler" init-method="init" scope="session">
    	<property name="configuration">
    		<list merge="true">
    			<bean class="com.hybris.cockpitng.handler.login.LoginInformationConfigData">
    				<constructor-arg value="tenant"></constructor-arg>
    				<constructor-arg value="login.tenant.extension.one.label"></constructor-arg>
    				<constructor-arg value="java.lang.String"></constructor-arg>
    				<constructor-arg>
    					<value type="java.lang.Integer">3</value>
    				</constructor-arg>
    			</bean>
    			<bean class="com.hybris.cockpitng.handler.login.LoginInformationConfigData">
    				<constructor-arg value="enumExtensionOne"></constructor-arg>
    				<constructor-arg value="login.enum.extension.one"></constructor-arg>
    				<constructor-arg value="ENUM(val1, val2, val3)"></constructor-arg>
    				<constructor-arg>
    					<value type="java.lang.Integer">4</value>
    				</constructor-arg>
    			</bean>
    		</list>
    	</property>	
    </bean>
  2. Add the following labels for your new fields:

    extensionOne/resources/extensionOne-backoffice-labels/labels.properties

    login.tenant.extension.one.label=Extension One Tenant:
    login.enum.extension.one=Extension One Enum:
  3. Restart the application.

Results

The login page shows the new fields:

Adding New Fields to extensionTwo

Extend login page for extensionTwo with enum and boolean fields.

Procedure

  1. Add the following bean to the Spring application context of extensionTwo:

    extensionTwo/resources/extensionTwo-backoffice-spring.xml

    <alias name="extensionTwoLoginInformationHandler" alias="loginInformationHandler"/>	
    <bean id="extensionTwoLoginInformationHandler" parent="extensionOneLoginInformationHandler" init-method="init" scope="session">
    	<property name="configuration">
    		<list merge="true">
    			<bean class="com.hybris.cockpitng.handler.login.LoginInformationConfigData">
    				<constructor-arg value="enumExtensionTwo"></constructor-arg>
    				<constructor-arg value="login.enum.extension.two"></constructor-arg>
    				<constructor-arg value="ENUM(red, green, blue)"></constructor-arg>
    				<constructor-arg >
    					<value type="java.lang.Integer">5</value>
    				</constructor-arg>
    			</bean>
    			<bean class="com.hybris.cockpitng.handler.login.LoginInformationConfigData">
    				<constructor-arg value="modtwo"></constructor-arg>
    				<constructor-arg value="login.modtwo.boolean"></constructor-arg>
    				<constructor-arg value="java.lang.Boolean"></constructor-arg>
    				<constructor-arg >
    					<value type="java.lang.Integer">6</value>
    				</constructor-arg>
    			</bean>
    		</list>
    	</property>	
    </bean>
  2. Add the following labels for your new fields:

    extensionTwo/resources/myextension-backoffice-labels/labels.properties

    login.enum.extension.two=Extension Two Enum:
    login.modtwo.boolean=Extension Two Boolean:
  3. Restart the application.

Results

The login page contains fields from both custom extensions:

Accessing Login Information

It is possible to access information provided when logging in to Backoffice.

Context

To access information provided while logging in, use the LoginInformationHandler. This handler allows you to define a current login screen configuration, store the login information, and then read the stored login information. See the example.

Procedure

Access the name of the tenant (a field defined in extensionOne) provided by the user on login. Use the following code phrase:
loginInformationHandler.getLoginInformation(“tenant”);