Showing posts with label FND. Show all posts
Showing posts with label FND. Show all posts

Tuesday, October 30, 2012

Validate Existing OAF Session in JSP/Servlet

One way to validate OAF session in custom jsp/servlet in Oracle applications. Method will return "INVALID" if the current session is invalid, "EXPIRED" if current session is expired and "VALID" if current session is valid.
You can also create new session if current session is invalid, wiill post detail in some other post. But, usually if Functionality is part of existing oracle application module, then you will just want to validate if current session is valid or not. If not, you may want to redirect to /OA_HTML/AppsLocalLogin.jsp page.

public static String validateOAFSession(HttpServletRequest request, HttpServletResponse response) {
    WebAppsContext appsContext = null;
    try {
        appsContext = WebRequestUtil.createWebAppsContext(request, response);
        if (appsContext != null) {
            String sessionCookie = WebRequestUtil.getSessionCookie(request, response, appsContext);
            if (sessionCookie == null) {
                return "INVALID";
            }
            if (!appsContext.validateSession(sessionCookie, true)) {
                return "EXPIRED";
            }
        }
    } catch (IOException ioe) {
        return "INVALID";
    } finally {
        if (appsContext != null) {
            appsContext.freeWebAppsContext();
        }
    }
    return "VALID";
}

Tuesday, September 18, 2012

FND: Create and Validate ICX Session Ticket

Following plsql block will create icx session ticket based on logged in user and his responsibility. If there is an existing session ticket, we can validate using API used in the block.

DECLARE
  l_user_name   VARCHAR2(50) := 'PANKAJ_MANDALIYA';
  l_resp_name  VARCHAR2(100) := 'Oracle Configurator Developer';
  l_user_id    NUMBER;
  l_resp_id    NUMBER;
  l_appl_id    NUMBER;
  l_icx_ticket  VARCHAR2(50);
  l_session_id VARCHAR2(50);
  l_result     VARCHAR2(50);
BEGIN
  SELECT fnd.user_id
  INTO l_user_id
  FROM fnd_user fnd
  WHERE fnd.user_name = l_user_name;
  
  SELECT DISTINCT fresp.responsibility_id,
    fresp.application_id
  INTO l_resp_id,
    l_appl_id
  FROM fnd_responsibility_tl fresp
  WHERE fresp.responsibility_name = l_resp_name;
  
  dbms_output.put_line('user_id = ' || l_user_id || ', resp_id = ' || l_resp_id || ', appl_id = ' || l_appl_id);
  
  fnd_global.apps_initialize(l_user_id,l_resp_id,l_appl_id);
  
  l_icx_ticket:=cz_cf_api.icx_session_ticket;
  dbms_output.put_line('ICX Ticket = ' || l_icx_ticket);
  
  l_session_id := fnd_session_utilities.XSID_to_SessionID(l_icx_ticket);
  dbms_output.put_line('Session Id = ' || l_session_id);
  
  l_result := fnd_session_management.check_session (p_session_id => l_session_id, p_resp_id => l_resp_id, p_app_resp_id => l_appl_id, p_tickle => 'N');
  dbms_output.put_line('Session validation result = ' || l_result);
END;