<div dir="ltr">Hello Jeremy,<div><br></div><div>try adding: "principal-attribute": "preferred_username" to your keycloak.json.</div><div><br></div><div>See:</div><div><a href="http://keycloak.github.io/docs/userguide/keycloak-server/html/ch08.html#adapter-config">http://keycloak.github.io/docs/userguide/keycloak-server/html/ch08.html#adapter-config</a><br></div><div><br></div><div>Cheers,</div><div>Thomas</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-09 20:47 GMT+01:00 Jeremy Simon <span dir="ltr"><<a href="mailto:jeremy@jeremysimon.com" target="_blank">jeremy@jeremysimon.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I can't seem to get my user's name using the keycloak adaptor for<br>
spring security. I have a rest controller that i'm trying this chunk<br>
of code:<br>
<br>
...<br>
Authentication KeyCloakAuth =<br>
SecurityContextHolder.getContext().getAuthentication();<br>
KeycloakAccount keyAccount = ((KeycloakAuthenticationToken)<br>
KeyCloakAuth).getAccount();<br>
<br>
String username1 = keyAccount.getPrincipal().getName()<br>
String username2 =<br>
SecurityContextHolder.getContext().getAuthentication().getName()<br>
<br>
KeycloakPrincipal<?> prince = (KeycloakPrincipal<?>)<br>
((KeycloakAuthenticationToken) KeyCloakAuth).getPrincipal();<br>
String username3 = prince.getName();<br>
<br>
...<br>
<br>
<br>
username1, username2, username3 will have something like this:<br>
aa5f6e42-9463-4862-a750-bd0c092daf11<br>
<br>
<br>
I gleaned this from some stackoverflow examples that claimed these<br>
approached worked... There something I don't have set right?<br>
<br>
<br>
jeremy<br>
<a href="mailto:jeremy@jeremysimon.com">jeremy@jeremysimon.com</a><br>
<a href="http://www.JeremySimon.com" rel="noreferrer" target="_blank">www.JeremySimon.com</a><br>
_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
</blockquote></div><br></div>