<div dir="ltr">Hi, <div>I&#39;m trying to add a user pro grammatically to keycloak server like this :</div><div><div> Keycloak kc = KeycloakBuilder</div><div>                .builder()</div><div>                .serverUrl(&quot;<a href="http://localhost:8080/auth/">http://localhost:8080/auth/</a>&quot;)</div><div>                .realm(&quot;myApp&quot;)</div><div>                .username(&quot;admin&quot;)</div><div>                .password(&quot;123&quot;)</div><div>                .clientId(&quot;admin-cli&quot;)</div><div>                .clientSecret(&quot;acce91b1-53ad-467e-8895-5ef8630a3295&quot;)</div><div>                .clientId(&quot;Frontend&quot;)</div><div>                .resteasyClient(</div><div>                        new ResteasyClientBuilder().connectionPoolSize(10)</div><div>                                .build()).build();</div><div>        CredentialRepresentation credential = new CredentialRepresentation();</div><div>        credential.setType(CredentialRepresentation.PASSWORD);</div><div>        credential.setValue(&quot;test123&quot;);</div><div>        UserRepresentation user = new UserRepresentation();</div><div>        user.setUsername(&quot;testuser&quot;);</div><div>        user.setFirstName(&quot;Test&quot;);</div><div>        user.setLastName(&quot;User&quot;);</div><div>        user.setEnabled(true);</div><div>        user.setCredentials(Arrays.asList(credential));</div><div>        kc.realm(&quot;myApp&quot;).users().create(user);</div></div><div><br></div><div>but I get this error :</div><div><br></div><div><br></div><div><div>15:46:51,412 WARN  [org.jboss.resteasy.core.ExceptionHandler] (default task-22) Failed executing POST /admin/realms/myApp/users: org.keycloak.services.ForbiddenException</div><div><span class="" style="white-space:pre">        </span>at org.keycloak.services.resources.admin.RealmAuth.requireManage(RealmAuth.java:59)</div><div><span class="" style="white-space:pre">        </span>at org.keycloak.services.resources.admin.UsersResource.createUser(UsersResource.java:181)</div><div><span class="" style="white-space:pre">        </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)</div><div><span class="" style="white-space:pre">        </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)</div><div><span class="" style="white-space:pre">        </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</div><div><span class="" style="white-space:pre">        </span>at java.lang.reflect.Method.invoke(Method.java:606)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:140)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:109)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:135)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:109)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.ResourceLocatorInvoker.invokeOnTargetObject(ResourceLocatorInvoker.java:135)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.ResourceLocatorInvoker.invoke(ResourceLocatorInvoker.java:103)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)</div><div><span class="" style="white-space:pre">        </span>at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)</div><div><span class="" style="white-space:pre">        </span>at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)</div><div><span class="" style="white-space:pre">        </span>at org.keycloak.services.filters.KeycloakSessionServletFilter.doFilter(KeycloakSessionServletFilter.java:61)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)</div><div><span class="" style="white-space:pre">        </span>at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div><span class="" style="white-space:pre">        </span>at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)</div><div><span class="" style="white-space:pre">        </span>at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)</div><div><span class="" style="white-space:pre">        </span>at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)</div><div><span class="" style="white-space:pre">        </span>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)</div><div><span class="" style="white-space:pre">        </span>at java.lang.Thread.run(Thread.java:744)</div></div><div><br></div><div>I think that the problem come from user role so I tried to grant the admin role to that user but it doesn&#39;t work .</div><div>I&#39;m working with keycloka 1.6</div><div><br></div></div>