[keycloak-user] How to access realms/{realm}/users/{user} with Application

Dean Peterson peterson.dean at gmail.com
Tue Mar 4 14:15:31 EST 2014


Hello,

I am trying to find the best way to access the UsersResource.java Rest
services outside the keycloak admin application to get a user's
information.  How do I make a request using just the client's credentials?

I currently use something like this but I get a 401 because I am using a
user's oauth token and they only have user privileges:
SkeletonKeySession session = (SkeletonKeySession) request
                .getAttribute(SkeletonKeySession.class.getName());
        ResteasyClient client = new ResteasyClientBuilder()
                .trustStore(session.getMetadata().getTruststore())
                .hostnameVerification(

ResteasyClientBuilder.HostnameVerificationPolicy.ANY)
                .build();

        String username = request.getRemoteUser();

        Profile profile = null;

        try {

            Response response = client
                    .target("
http://server:8080/auth/rest/admin/realms/myrealm/users/")
                    .path(username)
                    .request()
                    .header(HttpHeaders.AUTHORIZATION,
                            "Bearer " + session.getTokenString()).get();


            // Get the existing entry if there is one. Otherwise, just
return
            // the regular
            // entity retrieved from the remote system.
            try {
                profile = profileRepository
                        .findByRegistrationId(member.getId());

            } catch (NoResultException e) {
                // ignore
            }

        } finally {
            client.close();
        }

Is there a way for the application to make a request directly as an admin
without giving the user admin privileges?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20140304/061695ca/attachment.html 


More information about the keycloak-user mailing list