<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 16px; font-family: Calibri, sans-serif; ">
<div>
<div>
<div>Hi I just saw your response asking me to open a Jira.</div>
<div><br>
</div>
<div>I have just opened now.</div>
<div><a href="https://issues.jboss.org/browse/KEYCLOAK-2518">https://issues.jboss.org/browse/KEYCLOAK-2518</a></div>
<div><br>
</div>
<div>This is very important for us to continue the project to put Keycloak into production at our company.</div>
<div><br>
</div>
<div>Thank you.</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div>
<div>--&nbsp;</div>
<div><br>
</div>
</div>
<div>
<div>Att,</div>
<div><b>Leonardo Nunes</b></div>
<div>Analista de Sistemas</div>
<div><a href="mailto:leo.nunes@gjccorp.com.br">leo.nunes@gjccorp.com.br</a></div>
<div>Skype: leonardo.puc</div>
<div>&#43;55 (62) 3250-1462</div>
<div><br>
</div>
<div><b>Grupo Jaime Câmara</b></div>
<div><a href="applewebdata://B0E38BB5-8499-4F51-929B-00F21C9F6683/www.gjccorp.com.br">www.gjccorp.com.br</a></div>
</div>
</div>
</div>
</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>Leonardo Nunes &lt;<a href="mailto:leo.nunes@gjccorp.com.br">leo.nunes@gjccorp.com.br</a>&gt;<br>
<span style="font-weight:bold">Date: </span>segunda-feira, 22 de fevereiro de 2016 10:44<br>
<span style="font-weight:bold">To: </span>&quot;<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>&quot; &lt;<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>&gt;<br>
<span style="font-weight:bold">Subject: </span>Re: KeycloakSecurityContext returns NULL using Tomcat Adapter<br>
</div>
<div><br>
</div>
<div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 16px; font-family: Calibri, sans-serif; ">
<div>
<div>
<div>Hi everyone,</div>
<div><br>
</div>
<div>This problem might stop me from using Keycloak, it's been a week since i'm trying to find a way to make it work but I couldn't find any.</div>
<div>If it's a container issue, is there another way to make it work?</div>
<div><br>
</div>
<div>What can I do to access information from the current logged in user at a page that is not secured at the security-contraints at web.xml?</div>
<div>The code below returns null at pages that is not&nbsp;secured, even when the user is logged in.</div>
<div>If the application is deployed to Wildfly it works, but it doesn't work at Jboss EAP and Apache Tomcat.</div>
<div><br>
</div>
<div>(KeycloakPrincipal) req.getUserPrincipal()</div>
<div>Or</div>
<div>(KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName())</div>
<div><br>
</div>
<div><br>
</div>
<div>All of our applications is deployed to Jboss EAP and Apache Tomcat.</div>
</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div>
<div>--&nbsp;</div>
<div>Leonardo</div>
</div>
</div>
</div>
<div><br>
</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>Stian Thorgersen &lt;<a href="mailto:sthorger@redhat.com">sthorger@redhat.com</a>&gt;<br>
<span style="font-weight:bold">Reply-To: </span>&quot;<a href="mailto:stian@redhat.com">stian@redhat.com</a>&quot; &lt;<a href="mailto:stian@redhat.com">stian@redhat.com</a>&gt;<br>
<span style="font-weight:bold">Date: </span>quinta-feira, 18 de fevereiro de 2016 11:12<br>
<span style="font-weight:bold">To: </span>Leonardo Nunes &lt;<a href="mailto:leo.nunes@gjccorp.com.br">leo.nunes@gjccorp.com.br</a>&gt;<br>
<span style="font-weight:bold">Cc: </span>&quot;<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>&quot; &lt;<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>&gt;<br>
<span style="font-weight:bold">Subject: </span>Re: KeycloakSecurityContext returns NULL using Tomcat Adapter<br>
</div>
<div><br>
</div>
<div>
<div>
<div dir="ltr">This is down to the fact that there are differences between different containers. In reality you can only guarantee that&nbsp;KeycloakSecurityContext as long as the request requires authentication. Add a security-constraint for movies and you're fine.</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On 18 February 2016 at 12:50, LEONARDO NUNES <span dir="ltr">
&lt;<a href="mailto:leo.nunes@gjccorp.com.br" target="_blank">leo.nunes@gjccorp.com.br</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;color:rgb(0,0,0);font-size:16px;font-family:Calibri,sans-serif">
<div>
<div>Stian,</div>
<div><br>
</div>
<div>I have an application deployed on Tomcat 7 using the Tomcat Adapter.</div>
<div>When i'm logged in and I go to a non-secured URL, KeycloakSecurityContext returns null.</div>
<div>I deployed the same application to the Keycloak Standalone Server, there I don't have this problem.</div>
<div><br>
</div>
<div>At Tomcat the code below returns null when called from /movies/, and works when called from /article/</div>
<div>At Keycloak Standalone Server&nbsp;/movies/ and /article/ works fine.</div>
<div>(KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName());</div>
<div><br>
</div>
<div>Why is this happening?</div>
<div><br>
</div>
<div>In my web.xml I have only one security-constraint securing /article/*</div>
<div><br>
</div>
<div>WEB.XML:</div>
<div>&lt;security-constraint&gt;</div>
<div>&nbsp; &nbsp; &lt;web-resource-collection&gt;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;web-resource-name&gt;Articles&lt;/web-resource-name&gt;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;url-pattern&gt;/article/*&lt;/url-pattern&gt;</div>
<div>&nbsp; &nbsp; &lt;/web-resource-collection&gt;</div>
<div>&nbsp; &nbsp; &lt;auth-constraint&gt;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &lt;role-name&gt;user&lt;/role-name&gt;</div>
<div>&nbsp; &nbsp; &lt;/auth-constraint&gt;</div>
<div>&lt;/security-constraint&gt;</div>
<span class="HOEnZb"><font color="#888888"></font></span></div>
<span class="HOEnZb"><font color="#888888">
<div><br>
</div>
<div><br>
</div>
<div>
<div>
<div>--&nbsp;</div>
<div>Leonardo Nunes</div>
</div>
</div>
<hr style="min-height:1px;color:#c4c4c4">
<div style="font-family:Arial;color:#848484;font-size:11px"><i>Esta mensagem pode conter informação confidencial e/ou privilegiada. Se você não for o destinatário ou a pessoa autorizada a receber esta mensagem, não poderá usar, copiar ou divulgar as informações
 nela contidas ou tomar qualquer ação baseada nessas informações. Se você recebeu esta mensagem por engano, por favor avise imediatamente o remetente, respondendo o e-mail e em seguida apague-o. Agradecemos sua cooperação.
<br>
<br>
This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have
 received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation<i></i></i></div>
</font></span></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</span></div>
</div>
</span>
</body>
</html>