cancel
Showing results for 
Search instead for 
Did you mean: 

Set Employee lastLogin field on Backoffice Login

0 Kudos

Hi,

I have a requirement where i need to set employee lastLogin field in backoffice on successful login of backoffice users.

Did some digging into it and I am trying to to override ResetConfigurationAuthenticationSuccessHandler/BackofficeAuthenticationSuccessHandler class and its bean backofficeAuthenticationSuccessHandler in my custom extension and set the lastLogin field in the overridden success handler.

But I am getting the following error on server startup:

[Hybris Version:1811]

[BackofficeApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#4' while setting bean property 'sourceList' with key [4]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#4': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [4]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'backofficeAuthenticationSuccessHandler' while setting bean property 'authenticationSuccessHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationAuthenticationSuccessHandler' defined in class path resource [custombackoffice-spring-security-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.hybris.backoffice.cockpitng.user.BackofficeCockpitUserService' to required type 'com.hybris.cockpitng.core.user.CockpitUserService' for property 'cockpitUserService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.hybris.backoffice.cockpitng.user.BackofficeCockpitUserService' to required type 'com.hybris.cockpitng.core.user.CockpitUserService' for property 'cockpitUserService': no matching editors or conversion strategy found

I was able to find a solution to this by customizing the backoffice-spring-security.xml to change the successauthenticationhandler:

authentication-success-handler-ref="testSuccessHandler"

and defined a custom SuccessHandler in backoffice/src folder as:

public class TestAuthSuccessHandler extends BackofficeAuthenticationSuccessHandler{

.....

onAuthenticationSuccess(){
EmployeeModel employee = (EmployeeModel)this.userService.getUserForUID(authentication.getName(), EmployeeModel.class);
        employee.setLastLogin(new Date());
        modelService.save(employee);
        super.onAuthenticationSuccess(request, response, authentication);

}
.....
}

Bean declaration for the above class [in backoffice-spring-security.xml]:

<beans:bean id="testSuccessHandler" parent="defaultBackofficeAuthenticationSuccessHandler">
    <beans:property name="userService" ref="userService" />
    <beans:property name="modelService" ref="modelService" />
</beans:bean>
0 Kudos

Hi Aman,

I am trying to achieve same functionality but unable to do so :

I have few questions -

1. Are you replacing OOB "backoffice-spring-security.xml " with custom xml file via "ant customize" ? If yes, can you please share this custom xml file ?

2. Where your custom class "testSuccessHandler" resides ?

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member817306
Discoverer
0 Kudos

Hi Amit,

The little modification to above solution worked for me , provide alias of "backofficeAuthenticationSuccessHandler" to "testSuccessHandler" in custombackoffice-backoffice-spring.xml file instead customizing the backoffice-spring-security.xml to change the successauthenticationhandler.

<alias name="testSuccessHandler" alias="backofficeAuthenticationSuccessHandler"/>
<beans:bean id="testSuccessHandler" parent="defaultBackofficeAuthenticationSuccessHandler">
    <beans:property name="userService" ref="userService" />
    <beans:property name="modelService" ref="modelService" />
</beans:bean>
former_member817306
Discoverer
0 Kudos

Hi Amit,

The little modification to above solution worked for me , provide alias of "backofficeAuthenticationSuccessHandler" to "testSuccessHandler" in custombackoffice-backoffice-spring.xml file instead customizing the backoffice-spring-security.xml to change the successauthenticationhandler.

<alias name="testSuccessHandler" alias="backofficeAuthenticationSuccessHandler"/>
<beans:bean id="testSuccessHandler" parent="defaultBackofficeAuthenticationSuccessHandler">
    <beans:property name="userService" ref="userService" />
    <beans:property name="modelService" ref="modelService" />
</beans:bean>