Example usage for com.liferay.portal.kernel.servlet ProtectedServletRequest getRemoteUser

List of usage examples for com.liferay.portal.kernel.servlet ProtectedServletRequest getRemoteUser

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet ProtectedServletRequest getRemoteUser.

Prototype

@Override
    public String getRemoteUser() 

Source Link

Usage

From source file:com.liferay.whoami.servlet.WhoAmIAuthenticationServlet.java

License:Open Source License

protected void getUser(HttpServletRequest request, HttpServletResponse response) throws Exception {

    ProtectedServletRequest protectedServletRequest = (ProtectedServletRequest) request;

    long userId = GetterUtil.getLong(protectedServletRequest.getRemoteUser());

    User user = UserLocalServiceUtil.getUser(userId);

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject();

    responseJSONObject.put("uuid", user.getUserUuid());
    responseJSONObject.put("fullName", user.getFullName());
    responseJSONObject.put("emailAddress", user.getEmailAddress());
    responseJSONObject.put("avatarURL", StringPool.BLANK);

    String responseJSON = responseJSONObject.toString();

    response.setContentType(ContentTypes.APPLICATION_JSON);

    ServletOutputStream servletOutputStream = response.getOutputStream();

    servletOutputStream.write(responseJSON.getBytes(StringPool.UTF8));
}