package com.ibm.ws.hcare;

import java.io.IOException;
import java.io.PrintWriter;
import java.security.Principal;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.json.java.JSONObject;

/**
 * Servlet implementation class HCareIdentity
 */
@WebServlet("/HCareIdentity")
public class HCareIdentity extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Principal principal = request.getUserPrincipal();
		
		if (principal != null){
			System.out.println ("HCareIdentity: doGet: user name = " + principal.getName());
			
			JSONObject messageObject = new JSONObject();
			messageObject.put("userid", principal.getName());
	
			response.setContentType("application/javascript");
			response.setCharacterEncoding( "UTF-8" );
			PrintWriter out = response.getWriter();
			out.write(messageObject.serialize());
		    out.close();
		}
		else{
			System.out.println ("HCareIdentity: doGet: ERROR: user name = null");
		}
	}
}

@@ -192,32 +192,67 @@
 on.WebServlet;%0D%0A
+import javax.servlet.http.Cookie;%0D%0A
 import javax.ser
@@ -267,32 +267,32 @@
 p.HttpServlet;%0D%0A
-
 import javax.ser
@@ -409,16 +409,74 @@
 Object;%0D
+%0Aimport com.ibm.websphere.security.web.WebSecurityHelper;%0D
 %0A%0D%0A/**%0D%0A
@@ -1089,16 +1089,98 @@
 ));%0D%0A%09%09%09
+System.out.println (%22HCareIdentity: doGet: token = %22 + getSecurityTokenLiberty());
 %0D%0A%09%09%09JSO
@@ -1277,16 +1277,76 @@
 e());%0D%0A%09
+%09%09messageObject.put(%22ltpaToken%22, getSecurityTokenLiberty());
 %0D%0A%09%09%09res
@@ -1639,15 +1639,476 @@
 ;%0D%0A%09%09%7D%0D%0A
-
 %09%7D%0D%0A
+%09%0D%0A%09/*%0D%0A%09*  Sample code to retrieve LTPA token on the IBM WebSphere Liberty Profile */%0D%0A%09/* @return an LTPA token */%0D%0A%09public  String getSecurityTokenLiberty() %7B%0D%0A%09%09Cookie cookie = null;%0D%0A%09%09String token = null;%0D%0A%09%09try %7B%0D%0A%09%09%09cookie = WebSecurityHelper.getSSOCookieFromSSOToken();%0D%0A%09%09%09if (cookie != null) %7B%0D%0A%09%09%09%09token = cookie.getValue();%0D%0A%09%09%09%7D%0D%0A%09%09%7D catch (Exception e) %7B%0D%0A%09%09%09token = %22no token found%22;%0D%0A%09%09%09e.printStackTrace();%0D%0A%09%09%7D%0D%0A%09%09return token;%0D%0A%09%7D%0D%0A%09%0D%0A%09%0D%0A%09%0D%0A
 %7D%0D%0A

Add logging of LTPA Token