<p dir="ltr">Hi all,<br>
I am seeing some unpredicatble behavior from KC 1.9.3, leading to the following exception (see line comment BOOM!) in the code. Do you see anything that I am doing wrong?<br>
The problem with this issue is that it sometimes work, sometimes not. It almost feels like timing issue with the KC internals (cache?) and there is no<br>
guaranateed way to reproduce it. Usually restarting the WF10 server or redeploying the app fixes it.<br>
Also, can the exception be a bit more helpfull (like what resource is not found?)<br><br></p>
<p dir="ltr">12:03:50,354 ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-81) RESTEASY002010: Failed to execute: javax.ws.rs.NotFoundException: HTTP 404 Not Found<br>
        at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:201)<br>
        at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:174)<br>
        at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:59)<br>
        at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)<br>
        at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:64)<br>
        at com.sun.proxy.$Proxy296.toRepresentation(Unknown Source)<br>
        at com.xxxxx.web.server.UserManagerService.updateKeycloakRoles(UserManagerService.java:86)<br>
        at com.xxxxx.web.server.UserManagerService.changeSubscription(UserManagerService.java:67)<br><br></p>
<p dir="ltr">==========================RealmAdmin.java================================<br>
@ApplicationScoped<br>
public class RealmAdmin {<br>
<br>
        ... //Use JNDI resources to inject adminUser, adminPassword into this producer bean <br>
        <br>
@Produces<br>
Keycloak getKeycloak() {<br>
return Keycloak.getInstance(adminUrl, REALM_NAME, adminUser, adminPassword, CLIENT_ID);<br>
}<br>
}<br>
===========================UserManagerService.java===========================<br>
@Stateless<br>
@SecurityDomain("keycloak")<br>
public class UserManagerService implements UserManager {</p>
<p dir="ltr"> @Inject<br>
private Keycloak admin; //Producer above is used</p>
<p dir="ltr"> @Context<br>
private HttpServletRequest httpRequest;<br>
        <br>
        @Inject<br>
private StripeService stripeService;</p>
<p dir="ltr"> @Override<br>
@RolesAllowed({Roles.ACTIVE})<br>
public void changeSubscription(final UserPlanRequest request) {<br>
final String userId = httpRequest.getUserPrincipal().getName();<br>
RealmResource realm = admin.realm(RealmAdmin.REALM_NAME);<br>
UserResource userResource = realm.users().get(userId);<br>
UserRepresentation userRepresentation = userResource.toRepresentation();<br>
Map<String, List<String>> userAttributes = userRepresentation.getAttributesAsListValues();<br>
final String customerId = extractKeycloakAttribute(userAttributes, StripeService.STRIPE_ID);<br>
final String subscriptionId = extractKeycloakAttribute(userAttributes, StripeService.STRIPE_SUBSCRIPTION_ID);<br>
stripeService.changeSubscription(customerId, subscriptionId, JNDIUtils.getPlanStripeKey(request.plan));<br>
updateKeycloakRoles(request.plan, userResource, realm); <br>
}</p>
<p dir="ltr"> private static void updateKeycloakRoles(Plan newPlan, UserResource user, RealmResource realm) {<br>
RoleRepresentation newPlanRole = realm.roles().get(newPlan.role.getName()).toRepresentation();//BOOM!<br>
RoleScopeResource userRoles = user.roles().realmLevel();<br>
userRoles.remove(userRoles.listAll()<br>
.stream()<br>
.filter(r -> Roles.isActiveOrExpiredPlanRole(r.getName()))<br>
.collect(Collectors.toList()));<br>
userRoles.add(Collections.singletonList(newPlanRole));<br>
}</p>
<p dir="ltr">}</p>
<p dir="ltr">/Hristo Stoyanov</p>