Getting a custom cookie in my RememberMeAuthenticationProvider

Hi Team,

A need to use a custom cookie on my application.
What’s the best way to load a cookie saved in the browser, on my RememberMeAuthenticationProvider implementation?

Thanks,
Rafael Ratacheski

Hi,

Instance of com.haulmont.cuba.web.sys.AppCookies class can be used to save and load cookies. It has simple methods:

  • getCookieValue
  • addCookie
  • removeCookie

Regards,
Gleb

Hi,

I can’t instantiate com.haulmont.cuba.web.sys.AppCookies class, because RememberMeAuthenticationProvider is in the core module.

Regards,
Rafael Ratacheski

You’re right, from the core module the AppCookies class isn’t accessible because cookies are client-specific functionality and the core module is not. In this case, I would recommend extending LoginScreenAuthDelegate (in the web module) and provide custom cookies in the overridden setRememberMeCookies method:

import com.haulmont.cuba.web.security.LoginScreenAuthDelegate;

public class CustomLoginScreenAuthDelegate extends LoginScreenAuthDelegate {
    @Override
    public void setRememberMeCookies(String login) {
        super.setRememberMeCookies(login);

        // provide custom cookies
        // app.addCookie(...);
    }
}

In LoginScreenAuthDelegate inheritor you don’t need to instantiate AppCookies, instead app.addCookie(...) and app.removeCookie(...) methods can be used.

Register it in the web-spring.xml:

<bean id="cuba_LoginScreenAuthDelegate"
          class="com.company.demo.web.security.CustomLoginScreenAuthDelegate"
          scope="vaadin"/>

Regards,
Gleb