[keycloak-user] spring security getting username

Thomas Darimont thomas.darimont at googlemail.com
Wed Feb 10 09:00:29 EST 2016


Hello Jeremy,

have a look at this issue:
https://issues.jboss.org/browse/KEYCLOAK-2079?jql=project%20%3D%20KEYCLOAK%20AND%20status%20%3D%20Open%20AND%20text%20~%20%22installation%22

Cheers,
Thomas

2016-02-10 14:56 GMT+01:00 Jeremy Simon <jeremy at jeremysimon.com>:

> So, this is nice that it can be fixed by hand.  I'm wondering, is
> there any way to configure these things for a particular client or
> realm so that when you're downloading the keycloak.json from the admin
> console that it's present?
> jeremy
> jeremy at jeremysimon.com
> www.JeremySimon.com
>
>
> On Tue, Feb 9, 2016 at 3:44 PM, Jeremy Simon <jeremy at jeremysimon.com>
> wrote:
> > That's the trick!  Thank you!
> > jeremy
> > jeremy at jeremysimon.com
> > www.JeremySimon.com
> >
> >
> > On Tue, Feb 9, 2016 at 3:25 PM, Thomas Darimont
> > <thomas.darimont at googlemail.com> wrote:
> >> Hello Jeremy,
> >>
> >> try adding: "principal-attribute": "preferred_username" to your
> >> keycloak.json.
> >>
> >> See:
> >>
> http://keycloak.github.io/docs/userguide/keycloak-server/html/ch08.html#adapter-config
> >>
> >> Cheers,
> >> Thomas
> >>
> >> 2016-02-09 20:47 GMT+01:00 Jeremy Simon <jeremy at jeremysimon.com>:
> >>>
> >>> Hi,
> >>>
> >>> I can't seem to get my user's name using the keycloak adaptor for
> >>> spring security.  I have a rest controller that i'm trying this chunk
> >>> of code:
> >>>
> >>> ...
> >>> Authentication KeyCloakAuth =
> >>> SecurityContextHolder.getContext().getAuthentication();
> >>> KeycloakAccount  keyAccount = ((KeycloakAuthenticationToken)
> >>> KeyCloakAuth).getAccount();
> >>>
> >>> String username1 = keyAccount.getPrincipal().getName()
> >>> String username2 =
> >>> SecurityContextHolder.getContext().getAuthentication().getName()
> >>>
> >>> KeycloakPrincipal<?> prince = (KeycloakPrincipal<?>)
> >>> ((KeycloakAuthenticationToken) KeyCloakAuth).getPrincipal();
> >>> String username3 = prince.getName();
> >>>
> >>> ...
> >>>
> >>>
> >>> username1, username2, username3 will have something like this:
> >>> aa5f6e42-9463-4862-a750-bd0c092daf11
> >>>
> >>>
> >>> I gleaned this from some stackoverflow examples that claimed these
> >>> approached worked... There something I don't have set right?
> >>>
> >>>
> >>> jeremy
> >>> jeremy at jeremysimon.com
> >>> www.JeremySimon.com
> >>> _______________________________________________
> >>> keycloak-user mailing list
> >>> keycloak-user at lists.jboss.org
> >>> https://lists.jboss.org/mailman/listinfo/keycloak-user
> >>
> >>
> >>
> >> _______________________________________________
> >> keycloak-user mailing list
> >> keycloak-user at lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/keycloak-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160210/af5f7804/attachment.html 


More information about the keycloak-user mailing list