<div dir="ltr">Yes, I already have created it. I&#39;m using Jboss EAP 6.3. I have installed the adapter. But I have found a difference between adapter installation in Keycloak 1.0.4.Final and 1.1.0.beta2.<div><br></div><div>I&#39;m using 1.0.4.Final and I add this line (as described at for Jboss EAP at <a href="http://docs.jboss.org/keycloak/docs/1.0.4.Final/userguide/html/ch07.html#jboss-adapter-installation">http://docs.jboss.org/keycloak/docs/1.0.4.Final/userguide/html/ch07.html#jboss-adapter-installation</a> ):</div><div>&lt;extension module=&quot;org.keycloak.keycloak-as7-subsystem&quot;/&gt;</div><div><br></div><div>In 1.1.0.beta2 this configuration seems to be only for AS7. Should I use this? If I try it, I get an error (JBAS014674 module cannot be loaded)</div><div>&lt;extension module=&quot;org.keycloak.keycloak-subsystem&quot;/&gt;</div><div><br></div><div>All changes made at my standalone.xml are:<br></div><div><div><br></div><div>&lt;extensions&gt;</div><div><span class="" style="white-space:pre">        </span>&lt;extension module=&quot;org.keycloak.keycloak-as7-subsystem&quot;/&gt;</div><div><span class="" style="white-space:pre">        </span>...</div><div>&lt;/extensions&gt;</div><div>...</div><div>&lt;security-domains&gt;</div><div><span class="" style="white-space:pre">        </span>&lt;security-domain name=&quot;keycloak&quot;&gt;</div><div><span class="" style="white-space:pre">                </span>&lt;authentication&gt;</div><div><span class="" style="white-space:pre">                        </span>&lt;login-module code=&quot;org.keycloak.adapters.jboss.KeycloakLoginModule&quot; flag=&quot;required&quot;/&gt;</div><div><span class="" style="white-space:pre">                </span>&lt;/authentication&gt;</div><div><span class="" style="white-space:pre">        </span>&lt;/security-domain&gt;</div><div><span class="" style="white-space:pre">        </span>...</div><div>&lt;/security-domains&gt;<span class="" style="white-space:pre">        </span></div></div><div><span class="" style="white-space:pre"><br></span></div><div><span class="" style="white-space:pre">Do you think is a configuration problem? Do any of my attemps to get user information should work? Which one?</span></div><div><br></div><div><span style="white-space:pre">Regards,</span></div><div><span style="white-space:pre">Juan Escot</span></div><div><br></div><div><br></div><div><br><div class="gmail_extra"><br><div class="gmail_quote">2015-01-20 12:41 GMT+01:00 Stian Thorgersen <span dir="ltr">&lt;<a href="mailto:stian@redhat.com" target="_blank">stian@redhat.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">For the security context to propagate to EJBs you need to create a shared security domain, see <a href="http://docs.jboss.org/keycloak/docs/1.1.0.Beta2/userguide/html/ch07.html#jboss-adapter-installation" target="_blank">http://docs.jboss.org/keycloak/docs/1.1.0.Beta2/userguide/html/ch07.html#jboss-adapter-installation</a><br>
<br>
----- Original Message -----<br>
&gt; From: &quot;Juan Escot&quot; &lt;<a href="mailto:juan.escot@cdtec.es">juan.escot@cdtec.es</a>&gt;<br>
&gt; To: <a href="mailto:keycloak-dev@lists.jboss.org">keycloak-dev@lists.jboss.org</a><br>
&gt; Sent: Tuesday, 20 January, 2015 11:46:36 AM<br>
&gt; Subject: [keycloak-dev] Rest Service authentication.<br>
&gt;<br>
&gt; Hi,<br>
&gt; I&#39;m developing an application with AngularJS and Rest Services. I&#39;m using<br>
&gt; Keycloak for authentication and role management.<br>
&gt;<br>
&gt; Mi Angular project is registered as &#39;confidential&#39; and work&#39;s fine. It<br>
&gt; refresh tokens and sends it on header like this: &#39;Authorization:Bearer<br>
&gt; eyJhbGciOiJSUzI1Ni...&#39;<br>
&gt;<br>
&gt; Mi java project is defined as &#39;bearer only&#39; and it&#39;s developed with Java EJBs<br>
&gt; as Rest Services. I need more control over permissions and roles, so I don&#39;t<br>
&gt; want to secure my project with security-contraints at web.xml. I&#39;d like to<br>
&gt; get user info and roles inside my Rest methods from token received. I have<br>
&gt; checked I received the token with this line:<br>
&gt;<br>
&gt; String token = request.getHeader(&quot;authorization&quot;);<br>
&gt;<br>
&gt; But, I can&#39;t get any additional information about user. I have tried<br>
&gt; different approaches but I can&#39;t fin a solution. Could I have a Keycloak<br>
&gt; object with user info?.<br>
&gt;<br>
&gt; This is a fragment of my code with all my attemps:<br>
&gt;<br>
&gt; @Stateless<br>
&gt; @LocalBean<br>
&gt; @Path(&quot;/promociones&quot;)<br>
&gt; @SecurityDomain(&quot;keycloak&quot;)<br>
&gt; public class PromocionRest {<br>
&gt; @Context<br>
&gt; HttpServletRequest request;<br>
&gt; @Context<br>
&gt; SecurityContext securityContext;<br>
&gt; @Resource<br>
&gt; SessionContext sc;<br>
&gt; @GET<br>
&gt; @Produces(&quot;application/json&quot;)<br>
&gt; @Path(&quot;/list&quot;)<br>
&gt; //@RolesAllowed({ &quot;user&quot; }) &lt;-- If I use this annotation y get an error.<br>
&gt; @PermitAll<br>
&gt; public RespuestaListaBase&lt;Promocion&gt; listadoPromociones(...){<br>
&gt; KeycloakPrincipal principal =<br>
&gt; (KeycloakPrincipal)securityContext.getUserPrincipal();<br>
&gt; KeycloakSecurityContext session = (KeycloakSecurityContext)<br>
&gt; request.getAttribute(KeycloakSecurityContext.class.getName());<br>
&gt; if (sc!=null &amp;&amp; sc.getCallerPrincipal()!=null){<br>
&gt; System.out.println(&quot;Principal&#39;s name according to EJB: &quot; +<br>
&gt; sc.getCallerPrincipal().getName());<br>
&gt; }<br>
&gt;<br>
&gt; System.out.println(&quot;Is user in role &#39;user&#39;? &quot; +<br>
&gt; request.isUserInRole(&quot;user&quot;));<br>
&gt;<br>
&gt; String token = request.getHeader(&quot;authorization&quot;);<br>
&gt; HttpClient client = new HttpClientBuilder().disableTrustManager().build();<br>
&gt; try {<br>
&gt; String url = request.getRequestURL().toString();<br>
&gt; url = url.substring(0, url.indexOf(&#39;/&#39;, 8));<br>
&gt; HttpGet get = new HttpGet(url + &quot;/auth/admin/realms/demo/roles&quot;);<br>
&gt; get.addHeader(&quot;Authorization&quot;, &quot;Bearer &quot; + token);<br>
&gt; try {<br>
&gt; HttpResponse response = client.execute(get);<br>
&gt; if (response.getStatusLine().getStatusCode() != 200) {<br>
&gt; //throw new Failure(response.getStatusLine().getStatusCode());<br>
&gt; }<br>
&gt; HttpEntity entity = response.getEntity();<br>
&gt; InputStream is = entity.getContent();<br>
&gt;<br>
&gt; } catch (IOException e) {<br>
&gt; throw new RuntimeException(e);<br>
&gt; }<br>
&gt; } finally {<br>
&gt; client.getConnectionManager().shutdown();<br>
&gt; }<br>
&gt; }<br>
&gt; }<br>
&gt;<br>
&gt; I also have configured jboss-web.xml like this:<br>
&gt; &lt;jboss-web&gt;<br>
&gt; &lt;security-domain&gt;keycloak&lt;/security-domain&gt;<br>
&gt; &lt;/jboss-web&gt;<br>
&gt;<br>
&gt; And web.xml like this:<br>
&gt; &lt;login-config&gt;<br>
&gt; &lt;auth-method&gt;KEYCLOAK&lt;/auth-method&gt;<br>
&gt; &lt;realm-name&gt;demo&lt;/realm-name&gt;<br>
&gt; &lt;/login-config&gt;<br>
&gt;<br>
&gt; &lt;security-role&gt;<br>
&gt; &lt;role-name&gt;user&lt;/role-name&gt;<br>
&gt; &lt;/security-role&gt;<br>
&gt;<br>
&gt; Some notes about the code:<br>
&gt; - KeycloakPrincipal principal =<br>
&gt; (KeycloakPrincipal)securityContext.getUserPrincipal(); &lt;-- principal is<br>
&gt; always null<br>
&gt; - KeycloakSecurityContext session = (KeycloakSecurityContext)<br>
&gt; request.getAttribute(KeycloakSecurityContext.class.getName()); &lt;-- session<br>
&gt; is always null<br>
&gt; - sc.getCallerPrincipal().getName() &lt;-- returns &#39;anonymous&#39;, so it seems it<br>
&gt; isn&#39;t taking security-domain?<br>
&gt; - request.isUserInRole(&quot;user&quot;) &lt;-- returns null<br>
&gt; - HttpResponse response = client.execute(get) &lt;-- throws an exception:<br>
&gt; org.jboss.resteasy.spi.UnauthorizedException: Bearer<br>
&gt; - If I use @RolesAllowed({ &quot;user&quot; }) annotation I get this error: JBAS014502:<br>
&gt; The invocation is not allowed in the method<br>
&gt; - String token = request.getHeader(&quot;authorization&quot;); &lt;-- I get<br>
&gt; &#39;Authorization:Bearer eyJhbGciOiJSUzI1Ni...&#39;<br>
&gt;<br>
&gt; I suppose i&#39;m doing it wrong, but I don&#39;t know what is the correct form.<br>
&gt; Could I get user information from token received?<br>
&gt;<br>
&gt; Thanks in advance,<br>
&gt; Juan Escot<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; keycloak-dev mailing list<br>
&gt; <a href="mailto:keycloak-dev@lists.jboss.org">keycloak-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-dev</a><br>
</blockquote></div><br></div></div></div>