# RealmResourceProvider always returnung error 405

**URL:** <https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397>\
**Category:** Getting advice\
**Created:** [April 4, 2024, 9:05am UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397 "2024-04-04T09:05:21Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ermi](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@ermi](https://forum.keycloak.org/u/ermi)\
**Post date:** [April 4, 2024, 9:05am UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/1 "2024-04-04T09:05:21Z")

</div>

Hello all,

After updating from Version 22 to 24.0.2, none of my custom APIs are working as expected. They are all returning:

```auto
{
    "error": "HTTP 405 Method Not Allowed",
    "error_description": "For more on this error consult the server log at the debug level."
}

```

I already tried all tips that I found from the internet, namely:

- [RealmResourceProvider is not working as expected since version 23.0.0 #25882](https://github.com/keycloak/keycloak/issues/25882)
- [dasniko - keycloak-extensions-demo](https://github.com/dasniko/keycloak-extensions-demo/tree/main/rest-endpoint)
  - connected Forum discussion:` https://forum.keycloak.org/t/creating-a-simple-custom-keycloak-http-rest-endpoint/23773`

- official keycloak rest-api example:`https://github.com/keycloak/keycloak/tree/24.0.2/examples/providers/rest/src/main/java/org/keycloak/examples/rest`

None of which solved my issue, I tried the three solutions from RealmResourceProvider is not working as expected since version 23.0.0 #25882, tested the code from dasniko with the provided docker container (which has keycloak version 23.0.7) and even copied the official example into my project. I still get the 405 error.

Here is a minimal example to test it:

```auto
import org.keycloak.Config;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.services.resource.RealmResourceProvider;
import org.keycloak.services.resource.RealmResourceProviderFactory;

public class testFactory implements RealmResourceProviderFactory {

    @Override
    public RealmResourceProvider create(KeycloakSession keycloakSession) {
        return new testProvider(keycloakSession);
    }

    @Override
    public void init(Config.Scope scope) { }

    @Override
    public void postInit(KeycloakSessionFactory keycloakSessionFactory) { }

    @Override
    public void close() { }

    @Override
    public String getId() {
        return "api-" + "test";
    }
}

```

and

```auto
import org.jboss.logging.Logger;
import org.keycloak.models.KeycloakSession;
import org.keycloak.services.resource.RealmResourceProvider;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

public class testProvider implements RealmResourceProvider {

    private static final Logger logger = Logger.getLogger(
            testProvider.class);

    public testProvider(KeycloakSession session) {
        logger.info("[API::testProvider] constructor");
    }

    @Override
    public void close() {
        logger.info("[API::testProvider] close");
    }

    @Override
    public Object getResource() {
        logger.info("[API::testProvider] get resource");
        return this;
    }

    @GET
    @Path("")
    @Produces("text/plain; charset=utf-8")
    public Response getAlive() {
        logger.info("[API::testProvider] get Alive");
        return Response.status(200).entity("api is working").build();
    }
}

```

The resources/META-INF folder contains an empty beans.xml and the services folder.

The GET request was sent to the URL: `http://localhost:8080/admin/master/api-test/`

Does anyone have an Idea what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [April 4, 2024, 12:38pm UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/2 "2024-04-04T12:38:07Z")

</div>

What’s inside your `META-INF/services` folder?

---

<div class="post-metadata">

**Author:** ![ermi](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@ermi](https://forum.keycloak.org/u/ermi)\
**Post date:** [April 4, 2024, 12:52pm UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/3 "2024-04-04T12:52:04Z")

</div>

My META\_INF looks like this:

- META-INF
  - services
    - org.keycloak.services.resource.RealmResourceProviderFactory (contains the package+FactoryClass name)

  - beans.xml (is empty)

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [April 4, 2024, 7:21pm UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/4 "2024-04-04T19:21:11Z")

</div>

Your example works in my dev environment…

> [@ermi](#):
>
> [http://localhost:8080/admin/master/api-test/](http://localhost:8080/admin/master/api-test/)

This is wrong, your endpoint is not available under the `/admin` path, it’s in the regular `/realms` path and should be `http://localhost:8080/realms/master/api-test/`.  
If I call it with the `admin` path, I get a `404` (expected), but I don’t get ever a `405`.  
So, I don’t know what’s going on in your environment, sorry.

* * *

Two other things, related to general Java development (not related to your 405):

1. Classnames in Java always start with an uppercase letter, so your classes should be `TestFactory` and `TestProvider`
2. Your expression “package+Class name” is called _fully-qualified-class-name_, or _fqcn_

---

<div class="post-metadata">

**Author:** ![ermi](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@ermi](https://forum.keycloak.org/u/ermi)\
**Post date:** [April 5, 2024, 7:51am UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/5 "2024-04-05T07:51:55Z")

</div>

Thanks for the fast answer, I was indeed using the incorrect URL when trying your environment.

But using your API in my code still results in a 405 (using the correct URL), could using multiple Factories be a problem?

It used to work in Version 22 with me adding all Factory classes within the `org.keycloak.services.resource.RealmResourceProviderFactory` File, like `dasniko.keycloak.resource.MyResourceProviderFactory`, with one class per line.

Could this be an error source? Do you know whether I need to change something else when using multiple classes this way?

---

<div class="post-metadata">

**Author:** ![dasniko](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/dasniko/32/2969_2.png) [@dasniko](https://forum.keycloak.org/u/dasniko)\
**Post date:** [April 5, 2024, 8:48am UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/6 "2024-04-05T08:48:41Z")

</div>

Having multiple entries in the services files is the proper approach and way to go. I don’t know of any problems that this won’t work. I do it the same way, there is no other way.

The examples from my repository work as expected, I also just added your classes to my repo, deployed it and it just worked.

---

<div class="post-metadata">

**Author:** ![igdnss](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/igdnss/32/10234_2.png) [@igdnss](https://forum.keycloak.org/u/igdnss)\
**Post date:** [April 16, 2024, 9:33am UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/7 "2024-04-16T09:33:25Z")

</div>

I still encounter the same issue. It works in kc version 22 and it works well in our production. Now I need to upgrade to version 24.0.2, the issue happens. Following is my example.Could you give me some suggestions? Thanks  
**Factory:**

```auto
@AutoService(RealmResourceProviderFactory.class)
// I used to config the factory in the META-INF, it still doesn't work in version 24+
public class TestConfigurationResourceProviderFactory implements RealmResourceProviderFactory {

    @Override
    public RealmResourceProvider create(KeycloakSession session) {
        return new TestConfigurationResourceProvider (session);
    }

    @Override
    public void init(Scope config) {
    }

    @Override
    public void postInit(KeycloakSessionFactory factory) {
    }

    @Override
    public void close() {
    }

    @Override
    public String getId() {
        return "test-configurations";
    }

```

**Provider:**

```auto
@RequiredArgsConstructor
public class TestConfigurationResourceProvider implements RealmResourceProvider {

    private final KeycloakSession session;

    @Override
    public Object getResource() {
        return new TestConfigurationResource (session);
    }
    
    @Override
    public void close() {
    }
}

```

**Resource:**

```auto
@RequiredArgsConstructor
public class TestConfigurationResource {
    
    private final KeycloakSession session;
    
    @GET
    @Path("")
    @Produces(APPLICATION_JSON)
    public Response getTestConfiguration() {
        return Response.ok(Map.of("hello", session.getContext().getRealm().getName())).build();
    }
}

```

---

<div class="post-metadata">

**Author:** ![igdnss](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/igdnss/32/10234_2.png) [@igdnss](https://forum.keycloak.org/u/igdnss)\
**Post date:** [April 17, 2024, 10:19am UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/8 "2024-04-17T10:19:09Z")

</div>

I have tried the solution from this link [https://github.com/keycloak/keycloak/issues/25882](https://github.com/keycloak/keycloak/issues/25882), but it still doesn’t work.  
Besides I have tried clean the mvn repo in my local env, but it still failed, who can help me ??? 😭 😭 😭 😭

---

<div class="post-metadata">

**Author:** ![igdnss](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/igdnss/32/10234_2.png) [@igdnss](https://forum.keycloak.org/u/igdnss)\
**Post date:** [April 18, 2024, 1:58am UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/9 "2024-04-18T01:58:54Z")

</div>

Hello Ermi, have you solved the problem? It blocked me 5 days. I tried all the solutions @dasniko refered, but it failed. Besides, I have cleaned the org.\* folder in local mvn repository, it still doesn’t work. Looking forward you give me some suggestions.

---

<div class="post-metadata">

**Author:** ![ermi](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@ermi](https://forum.keycloak.org/u/ermi)\
**Post date:** [April 18, 2024, 11:27am UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/10 "2024-04-18T11:27:56Z")

</div>

Hello,  
I haven’t found a fix yet. I tried to go back to 22 and update again, but that did not help either.

---

<div class="post-metadata">

**Author:** ![ulftid](https://avatars.discourse-cdn.com/v4/letter/u/919ad9/32.png) [@ulftid](https://forum.keycloak.org/u/ulftid)\
**Post date:** [October 30, 2024, 3:51pm UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/11 "2024-10-30T15:51:14Z")

</div>

@ermi and @igdnss - I have stumbled upon the same issue upgrading from Keycloak 21 to 26. Did any of you ever resolve it?

---

<div class="post-metadata">

**Author:** ![ermi](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@ermi](https://forum.keycloak.org/u/ermi)\
**Post date:** [November 4, 2024, 7:14am UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/12 "2024-11-04T07:14:45Z")

</div>

Hello @ulftid,  
We needed to create a new repo that was based on the tutorials and then just added our existing code. I think there was some error coming from clashing versions of some of the packages.

---

<div class="post-metadata">

**Author:** ![ulftid](https://avatars.discourse-cdn.com/v4/letter/u/919ad9/32.png) [@ulftid](https://forum.keycloak.org/u/ulftid)\
**Post date:** [November 19, 2024, 5:12pm UTC](https://forum.keycloak.org/t/realmresourceprovider-always-returnung-error-405/25397/13 "2024-11-19T17:12:35Z")

</div>

Thanks. We actually solved it eventually - in our case it was as simple as changing the javax package to jakarta for the annotations. For some reason, the old javax annotations were still dragged in via some dependency.
