Skip Navigation

Retrieve information from the authorization header

The final portion of the SampleController.java sample is used to retrieve information about the authenticated user (username and first name) and tenant (SRP ID) from the authorization header and return it as a JSON payload. The following URL path is used for this purpose: https://localhost:8095/{
tenantGuid
}/ext/sample/authInfo
The sample comments also explain another way to retrieve this information using methods of the AuthenticationUtil class.
As in the previous sections,
@Suspended asyncResponse
is the object that returns a response to the client.

SampleController.java

@GET @Path("/authInfo") public void authInfo(@Suspended final AsyncResponse asyncResponse) { // Log the request LOGGER.debug("{}/sample/authInfo", AbstractController.PATH_PREFIX); // Retrieve the authenticated user and tenant from the base class IUser authenticatedUser = getUser(); ITenant authenticatedTenant = getTenant(); // This can also be done elsewhere using the AuthenticationUtil // IUser authenticatedUser = authenticationUtil.getUser(); // ITenant authenticatedTenant = authenticationUtil.getTenant(); // Create a simple return payload. This will get converted to JSON. HashMap<String, String> info = new HashMap<String, String>(); info.put("username", authenticatedUser.getUsername()); info.put("firstName", authenticatedUser.getFirstName()); info.put("externalTenantId", authenticatedTenant.getExternalTenantId()); // Return the response asyncResponse.resume(Response.ok(info).build()); }