# Override keycloak class

**URL:** <https://forum.keycloak.org/t/override-keycloak-class/17192>\
**Category:** Miscellanaeous\
**Created:** [September 1, 2022, 2:41pm UTC](https://forum.keycloak.org/t/override-keycloak-class/17192 "2022-09-01T14:41:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nelsonVE](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/nelsonve/32/3558_2.png) [@nelsonVE](https://forum.keycloak.org/u/nelsonVE)\
**Post date:** [September 1, 2022, 2:41pm UTC](https://forum.keycloak.org/t/override-keycloak-class/17192/1 "2022-09-01T14:41:44Z")

</div>

Hi! How can i override a keycloak class (i.g: IdentityProviderAuthenticator)?

I have already built the package and created the respective file in META-INF/services but when i execute keycloak, it keeps the original IdentityProviderAuthenticator class. It is possible to override any class of keycloak using this method?

---

<div class="post-metadata">

**Author:** ![weltonrodrigo](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/weltonrodrigo/32/3104_2.png) [@weltonrodrigo](https://forum.keycloak.org/u/weltonrodrigo)\
**Post date:** [September 2, 2022, 1:35pm UTC](https://forum.keycloak.org/t/override-keycloak-class/17192/2 "2022-09-02T13:35:34Z")

</div>

I believe there is no way to remove the default authenticators with an SPI. You would have to generate a custom keycloak build for that.

But you could probably just create your own authenticator, based on a default one and introduce it in the flow you’re interested in.

---

<div class="post-metadata">

**Author:** ![nelsonVE](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/nelsonve/32/3558_2.png) [@nelsonVE](https://forum.keycloak.org/u/nelsonVE)\
**Post date:** [September 2, 2022, 3:26pm UTC](https://forum.keycloak.org/t/override-keycloak-class/17192/3 "2022-09-02T15:26:00Z")

</div>

Thank you! i did something like you have said

If anyone is interested or there are a better approach:

My problem:  
When i login via social authentication, there is no “Remember me” option, and KC creates the “KEYCLOAK\_IDENTITY\_LEGACY” cookie which expires when the browser closes, and then everytime i close and open the browser i need to login.

Possible solution (it works for me, but maybe there will be a better approach):

I override the Identity providers i use (i.g: Google) and in GoogleIdentityProvider.java just made a function that overrides the “authenticationFinished” method:

```auto
@Override
    public void authenticationFinished(AuthenticationSessionModel authSession, BrokeredIdentityContext context) {
        super.authenticationFinished(authSession, context);
        authSession.setAuthNote(Details.REMEMBER_ME, "true");
    }

```

It will add an auth note “Remember me” in true (this auth note is created on UserPasswordForm when the “remember me” checkbox is checked) and voilà! It creates the “KEYCLOAK\_IDENTITY\_LEGACY” with expiration 🙂 (which fix the problem for me)
