DBA Data[Home] [Help]

PACKAGE BODY: APPS.ORACLESSWA

Source


1 package body OracleSSWA as
2 /* $Header: ICXSSWAB.pls 120.1 2007/12/28 09:56:26 stadepal ship $ */
3 
4     procedure bookmarkthis (icxtoken in varchar2,
5                             p        in varchar2) is
6 
7     l_session_id number;
8     l_text varchar2(2000);
9     l_parameters    icx_on_utilities.v80_table;
10     l_resp_appl_id number;
11     l_responsibility_id number;
12     l_security_group_id number;
13     l_function_id number;
14     l_url varchar2(4000);
15 
16 /*
17     l_function_type varchar2(30);
18     l_menu_id number;
19 l_validate          boolean;
20 l_error_message varchar2(2000);
21 err_mesg varchar2(240);
22 err_num number;
23 l_user_id               number;
24 l_org_id                number;
25 l_multi_org_flag        varchar2(30);
26 l_profile_defined       boolean;
27 e_session_invalid       exception;
28 */
29 
30     begin
31 
32       l_session_id := icx_portlet.validateSessionPart1;
33 
34       l_text := icx_call.decrypt4(icxtoken, l_session_id);
35 
36       icx_on_utilities.unpack_parameters(l_text,l_parameters);
37 
38       l_resp_appl_id := nvl(l_parameters(1),178);
39       l_responsibility_id := l_parameters(2);
40       l_security_group_id := l_parameters(3);
41       l_function_id := l_parameters(4);
42 
43       if P is null
44       then
45         l_text := null;
46       else
47         l_text := icx_call.decrypt4(P,l_session_id);
48       end if;
49 
50   -- 2802333 nlbarlow
51   l_url := icx_portlet.createExecLink(p_application_id => l_resp_appl_id,
52                        p_responsibility_id => l_responsibility_id,
53                        p_security_group_id => l_security_group_id,
54                        p_function_id => l_function_id,
55                        p_parameters => P,
56                        p_url_only => 'Y');
57 
58   owa_util.mime_header('text/html', FALSE);
59 
60   owa_util.redirect_url(l_url);
61 
62   owa_util.http_header_close;
63 
64 /*
65       select TYPE
66       into   l_function_type
67       from   FND_FORM_FUNCTIONS
68       where  FUNCTION_ID = l_function_id;
69 
70       l_menu_id := l_parameters(5);
71 
72       select multi_org_flag
73       into   l_multi_org_flag
74       from   fnd_product_groups
75       where  rownum < 2;
76 
77       if l_multi_org_flag = 'Y'
78       then
79           fnd_profile.get_specific(
80               name_z                  => 'ORG_ID',
81               responsibility_id_z     => l_responsibility_id,
82               application_id_z        => l_resp_appl_id,
83               val_z                   => l_org_id,
84               defined_z               => l_profile_defined);
85       end if;
86 
87       update ICX_SESSIONS
88       set    RESPONSIBILITY_APPLICATION_ID = l_resp_appl_id,
89              RESPONSIBILITY_ID = l_responsibility_id,
90              SECURITY_GROUP_ID = l_security_group_id,
91              ORG_ID = l_org_id,
92              FUNCTION_ID = l_function_id,
93              FUNCTION_TYPE = l_function_type,
94              MENU_ID = l_menu_id
95       where SESSION_ID = l_session_id;
96 
97       commit;
98 
99       l_validate := icx_sec.validateSessionPrivate
100                             (c_session_id => l_session_id,
101                              c_resp_appl_id => l_resp_appl_id,
102                              c_security_group_id => l_security_group_id,
103                              c_responsibility_id => l_responsibility_id,
104                              c_function_id => l_function_id,
105                              c_update => FALSE);
106 
107       icx_sec.g_validateSession_flag := false;
108 
109       OracleApps.runFunction
110                  (c_function_id => l_function_id,
111                   n_session_id => l_session_id,
112                   c_parameters => l_text,
113                   p_resp_appl_id => l_resp_appl_id,
114                   p_responsibility_id => l_responsibility_id,
115                   p_security_group_id => l_security_group_id,
116                   p_menu_id => l_menu_id,
117                   p_function_type => l_function_type);
118 
119       icx_sec.g_validateSession_flag := true;
120 */
121 
122     exception
123     when others then
124       icx_sec.g_validateSession_flag := true;
125       htp.p('User does not have access to this function');
126       htp.nl;
127       --NEED TO DO!::
128       --if this is portal/sso, send to oraclesswa.convertsession
129       --if this is php, send to oracleapps.convertsession with encrypted param string
130 --      htp.p(SQLERRM);
131         htp.p(dbms_utility.format_error_stack);
132 
133     end;
134 
135     -- OA Framework version of bookmarkthis which can do some really
136     -- neat stuff for the current responsibility portlet - blow away
137     -- every cached version for the current user!
138 
139     procedure FwkBookmarkThis (icxtoken in varchar2,
140                                p        in varchar2)
141     is
142 
143         l_session_id        number;
144         l_text              varchar2(2000);
145         l_parameters        icx_on_utilities.v80_table;
146         l_resp_appl_id      number;
147         l_responsibility_id number;
148         l_security_group_id number;
149         l_user_id           number;
150 
151     begin
152         -- Get the responsibility information for the bookmark being
153         -- launched
154         l_session_id := icx_portlet.validateSessionPart1;
155         l_text := icx_call.decrypt4(icxtoken, l_session_id);
156         icx_on_utilities.unpack_parameters(l_text,l_parameters);
157         l_resp_appl_id := nvl(l_parameters(1),178);
158         l_responsibility_id := l_parameters(2);
159         l_security_group_id := l_parameters(3);
160 
161         -- Get the current user's user_id
162         select user_id
163         into l_user_id
164         from icx_sessions
165         where session_id = l_session_id;
166 
167         -- Update the caching key for every 'Current responsibility
168         -- pages' portlet belonging to the current user
169         update icx_portlet_customizations
170         set responsibility_id = l_responsibility_id,
171             application_id    = l_resp_appl_id,
172             security_group_id = l_security_group_id,
173             caching_key       = caching_key + 1
174         where plug_id in (select function_id
175                           from fnd_form_functions
176                           where function_name = 'FND_NAVIGATE_SCTX_PORTLET')
177         and user_id = l_user_id;
178 
179         -- Do whatever the BookmarkThis
180         OracleSSWA.BookmarkThis(icxtoken, p);
181     end;
182 
183 
184     procedure switchpage (pagename in varchar2) is
185 
186     l_url varchar2(2000);
187     l_end number;
188 
189     begin
190 
191       fnd_profile.get(name => 'APPS_PORTAL',
192                       val => l_url);
193 
194       if l_url IS NULL Then
195         htp.p ('Please contact System Administrator. ');
196         htp.p ('Profile - APPS_PORTAL is null') ;
197       end If ;
198 
199       l_end := instrb(l_url,'/',-1,1);
200       l_url := substrb(l_url,1,l_end);
201       l_url := l_url||'url/page/'||pagename;
202 
203       owa_util.redirect_url(l_url);
204 
205     exception
206       when others then
207 --        htp.p(SQLERRM);
208      htp.p(dbms_utility.format_error_stack);
209     end;
210 
211     function listener_token return varchar2 is
212 
213     l_listener_token      VARCHAR2(240);
214     l_profile_defined     boolean;
215     l_server              VARCHAR2(240);
216 
217     begin
218 
219      fnd_profile.get_specific(
220         name_z                  => 'APPS_SSO_LISTENER_TOKEN',
221         val_z                   => l_listener_token,
222         defined_z               => l_profile_defined);
223 
224      if l_listener_token is null
225 
226     then
227 
228       -- bug 2712473
229       fnd_profile.get_specific(
230         name_z                  => 'APPS_DATABASE_ID',
231         val_z                   => l_listener_token,
232         defined_z               => l_profile_defined);
233       if l_listener_token is null
234       then
235         l_listener_token := FND_WEB_CONFIG.DATABASE_ID;
236       end if;
237 
238   end if;
239 
240       return l_listener_token;
241 
242     end;
243 
244     procedure sign_on (urlc in varchar2) is
245 
246     l_listener_token      VARCHAR2(240);
247     l_sso_user_name       VARCHAR2(1000);
248     l_ip_address          VARCHAR2(1000);
249     l_sso_time_remaining  VARCHAR2(1000);
250     l_site_time_stamp     VARCHAR2(1000);
251     l_url_requested       VARCHAR2(32000);
252     l_unused_param        VARCHAR2(1000);
253     u                     fnd_user%rowtype;
254     l_user_id             number;
255     l_session_id          number;
256     l_return              VARCHAR2(240);
257     l_session_status      VARCHAR2(10);
258     c_user_id             NUMBER;
259     l_anon_id             NUMBER;
260     l_anon_name           VARCHAR2(350);
261     l_return              VARCHAR2(240);
262     l_procedure_call      varchar2(32000);
263     l_call                integer;
264     l_dummy               integer;
265     l_apps_sso            VARCHAR2(30);
266     l_profile_defined     BOOLEAN;
267     l_mode                VARCHAR2(10);
268     l_language              varchar2(80);
269     l_language_code         varchar2(30);
270     l_date_format           varchar2(150);
271     l_date_language         varchar2(30);
272     l_numeric_characters    varchar2(30);
273     l_nls_sort              varchar2(30);
274     l_nls_territory         varchar2(30);
275     l_limit_time            number;
276     l_limit_connects        number;
277     l_org_id                varchar2(50);
278     portalUrl               VARCHAR2(4000);
279     portalUrlBase           VARCHAR2(4000);
280     l_exception             VARCHAR2(30);
281     l_timeout		    NUMBER;
282 
283     begin
284 
285       icx_sec.ServerLevel;
286 
287       l_listener_token := OracleSSWA.listener_token;
288         fnd_profile.get_specific(
289                 name_z                  => 'APPS_SSO',
290                 user_id_z               => l_user_id,
291                 val_z                   => l_apps_sso,
292                 defined_z               => l_profile_defined);
293 
294 -- Wait SSO
295 
296       IF (nvl(l_apps_sso,'SSWA')='SSO_SDK') OR
297          (nvl(l_apps_sso,'SSWA')='SSWA_SSO') THEN
298 
299       l_call := dbms_sql.open_cursor;
300 
301       l_procedure_call := 'wwsec_sso_enabler.parse_url_cookie'||
302                         '(p_lsnr_token => :l_listener_token'||
303                         ',p_enc_url_cookie => :urlc'||
304                         ',p_sso_username => :l_sso_user_name'||
305                         ',p_ipaddr => :l_ip_address'||
306                         ',p_sso_timeremaining => :l_sso_time_remaining'||
307                         ',p_site_timestamp => :l_site_time_stamp'||
308                         ',p_url_requested => :l_url_requested)';
309 
310       icx_sec.g_window_cookie_name := 'Y';
311 
312       dbms_sql.parse(l_call,'begin '||l_procedure_call||'; exception when wwsec_sso_enabler.COOKIE_EXPIRED_EXCEPTION then icx_sec.g_window_cookie_name := ''X''; raise; when others then raise; end;' ,dbms_sql.native);
313 
314       l_sso_user_name := '1234567890123456789012345678901234567890';
315       l_ip_address := '123.456.678.901';
316       l_sso_time_remaining := 1234567890;
317       l_site_time_stamp := sysdate;
318       l_url_requested := '';
319 
320       for i in 1..100 loop -- set l_url_requested to 2000 characters
321         l_url_requested := l_url_requested||'12345678901234567890';
322       end loop;
323 
324       dbms_sql.bind_variable(l_call,'l_listener_token',l_listener_token);
325       dbms_sql.bind_variable(l_call,'urlc',urlc);
326       dbms_sql.bind_variable(l_call,'l_sso_user_name',l_sso_user_name);
327       dbms_sql.bind_variable(l_call,'l_ip_address',l_ip_address);
328       dbms_sql.bind_variable(l_call,'l_sso_time_remaining',l_sso_time_remaining);
329       dbms_sql.bind_variable(l_call,'l_site_time_stamp',l_site_time_stamp);
330       dbms_sql.bind_variable(l_call,'l_url_requested',l_url_requested);
331 
332       l_dummy := dbms_sql.execute(l_call);
333 
334       dbms_sql.variable_value(l_call,'l_sso_user_name',l_sso_user_name);
335       dbms_sql.variable_value(l_call,'l_url_requested',l_url_requested);
336 
337       dbms_sql.close_cursor(l_call);
338 
339    END IF;--apps_sso profile option
340 
341 portalUrl := fnd_profile.value('APPS_PORTAL');
342 portalUrlBase := substr(portalUrl, 0, length(portalUrl) - 4);
343 
344 if (l_url_requested = 'APPSHOMEPAGE') then
345     if(fnd_profile.value('APPS_SSO') = 'SSO_SDK') then
346      l_url_requested :=
347 portalUrlBase||'wwsec_app_priv.login?p_requested_url='||wfa_html.conv_special_url_chars(portalUrl)||'&p_cancel_url='||wfa_html.conv_special_url_chars(portalUrl);
348     else
349      l_url_requested := FND_WEB_CONFIG.PLSQL_AGENT||'OracleMyPage.Home';
350     end if;
351 end if;
352 
353       l_sso_user_name := upper(l_sso_user_name);
354 
355       -- Set application cookie
356 -- Bug 3801219
357 --  Bug 4151179 : remove those extra parentesis
358       select user_id
359       into   l_user_id
360       from   fnd_user
361       where  user_name = l_sso_user_name
362       and (END_DATE is NULL or END_DATE > sysdate);
363 
364 
365       --begin code for preservation of session_id when switching from anonymous user to authenticated user.
366       l_session_id := icx_sec.getsessioncookie; -- get the cookie if there is one.
367       l_session_status := icx_sec.check_session(l_session_id); -- check to see if cookie is for valid session
368       BEGIN
369         SELECT user_id
370                INTO c_user_id
371                FROM icx_sessions
372                WHERE session_id=l_session_id; -- use cookie value to get user_id, defaults to -999 if bogus cookie/user_id.
373       EXCEPTION
374          WHEN no_data_found THEN
375          c_user_id := -999;
376       END;
377         -- fnd_profile.get(name    => 'GUEST_USER_PWD',
378                         -- val     => l_anon_name);
379         -- Using new api to retrieve GUEST credentials.
380         l_anon_name := fnd_web_sec.get_guest_username_pwd;
381 
382         IF l_anon_name IS NOT NULL THEN
383           l_anon_name  := SUBSTR(l_anon_name, 1, INSTR(l_anon_name, '/') -1); -- profile is stored as user/passwd
384           BEGIN
385            SELECT user_id
386              INTO l_anon_id
387              FROM fnd_user
388              WHERE user_name=l_anon_name;
389           EXCEPTION
390            WHEN OTHERS THEN
391             l_anon_id := -999;
392           END;
393         ELSE
394          l_anon_id := -999;
395         --END;
396         END IF;
397 
398       --test to see if we are switching from an anonymous session to authenticated session
399       -- if it is a valid session, and the users are difference, and the original user is the anonymous user then
400       IF l_session_status <> 'INVALID' and l_user_id <> l_anon_id and c_user_id = l_user_id THEN
401         -- Reuse expired session
402         UPDATE icx_sessions
403         SET last_connect  = sysdate,
404             first_connect = SYSDATE,
405             counter = 1
406         WHERE session_id = l_session_id;
407         owa_util.mime_header('text/html', FALSE);
408         owa_util.redirect_url(l_url_requested);
409         owa_util.http_header_close;
410       ELSIF ((l_session_status<>'INVALID') AND (c_user_id = l_anon_id) AND (l_anon_id <> -999) AND (c_user_id <> l_user_id)) THEN
411 
412       icx_sec.setUserNLS
416                l_date_format,
413               (l_user_id,
414                l_language,
415                l_language_code,
417                l_date_language,
418                l_numeric_characters,
419                l_nls_sort,
420                l_nls_territory,
421                l_limit_time,
422                l_limit_connects,
423                l_org_id,
424                l_timeout);
425 
426       --preserve the existing session durring switch from anon user.
427         UPDATE icx_sessions
428             SET user_id = l_user_id,
429                 nls_language = l_language,
430                 language_code = l_language_code,
431                 date_format_mask = l_date_format,
432                 nls_date_language = l_date_language,
433                 nls_numeric_characters = l_numeric_characters,
434                 nls_sort = l_nls_sort,
435                 nls_territory = l_nls_territory,
436                 limit_time = l_limit_time,
437                 limit_connects = l_limit_connects,
438                 org_id = l_org_id,
439                 last_connect  = sysdate,
440                 first_connect = SYSDATE,
441                 counter = 1
442             WHERE session_id = l_session_id;
443         owa_util.mime_header('text/html', FALSE);
444         owa_util.redirect_url(l_url_requested);
445         owa_util.http_header_close;
446         --end code for preservation of session_id when switching from anonymous user to authenticated user
447       ELSE
448 
449         --this is not an anonymous session conversion.. create a new session and send a new cookie!
450         --Need to check apps_sso profile and determine if we are Portal or PHP and set mode accordingly
451         IF (nvl(l_apps_sso,'SSWA')='SSWA')
452         THEN
453            l_mode := '115P';
454         ELSIF l_apps_sso='SSWA_SSO'
455         THEN
456            l_mode := '115J';
457         ELSE
458            l_mode := '115X';
459         END IF;
460         l_session_id :=  icx_sec.createSession
461                          (p_user_id     => l_user_id,
462                           c_mode_code   => l_mode);
463         owa_util.mime_header('text/html', FALSE);
464         owa_cookie.send(name=>'DEBUG_COOKIE', value=>'-1', expires=>'', path=>'/');
465         owa_cookie.send(name=>'WF_WORKLIST_MODE', value=>'-1', expires=>'', path=>'/');-- mputman added for 1903545
466         icx_sec.sendsessioncookie(l_session_id);
467         owa_util.redirect_url(l_url_requested);
468         owa_util.http_header_close;
469 
470       END IF;
471 
472     exception
473       when others then
474         IF ((nvl(l_apps_sso,'SSWA')='SSO_SDK') OR
475            (nvl(l_apps_sso,'SSWA')='SSWA_SSO')) AND
476            (icx_sec.g_window_cookie_name = 'X')
477         THEN
478           l_url_requested := fnd_sso_manager.getLoginUrl;
479           owa_util.mime_header('text/html', FALSE);
480           owa_util.redirect_url(l_url_requested);
481           owa_util.http_header_close;
482         ELSE
483           raise;
484         END IF;
485     end sign_on;
486 
487 procedure navigate is
488 
489 l_function_id number;
490 l_session_id  number;
491 
492 begin
493 
494 select FUNCTION_ID
495 into   l_function_id
496 from   FND_FORM_FUNCTIONS
497 where  FUNCTION_NAME = 'FND_NAVIGATE_PAGE';
498 
499 if icx_sec.validateSession
500 then
501   l_session_id := icx_sec.getID(icx_sec.pv_session_id);
502 
503   OracleApps.runFunction(c_function_id => l_function_id,
504                          n_session_id  => l_session_id);
505 end if;
506 
507 end;
508 
509 PROCEDURE convertSession
510   IS
511 --this should only be called from VSP when validate_only='N'
512 
513 
514 l_gen_redirect_url      varchar2(32000);
515 l_urlrequested          varchar2(32000);
516 l_urlcancel             varchar2(32000);
517 l_procedure_call        varchar2(32000);
518 l_call                  integer;
519 l_dummy                 integer;
520 l_defined               boolean;
521 l_listener_token        VARCHAR2(240);
522 l_apps_sso              VARCHAR2(30);
523 
524 
525 begin
526 --lower(owa_util.get_cgi_env('REQUEST_PROTOCOL'))||'://'||
527     l_urlrequested :=
528       FND_WEB_CONFIG.PROTOCOL||'//'||
529       owa_util.get_cgi_env('SERVER_NAME')||':'||
530       owa_util.get_cgi_env('SERVER_PORT')||
531       owa_util.get_cgi_env('SCRIPT_NAME')||
532       owa_util.get_cgi_env('PATH_INFO')||'?'||
533       owa_util.get_cgi_env('QUERY_STRING');
534 
535         fnd_profile.get(name    => 'APPS_SSO',
536                         val     => l_apps_sso);
537 -- Wait SSO
538       IF ((nvl(l_apps_sso,'SSWA')='SSO_SDK') OR (nvl(l_apps_sso,'SSWA')='SSWA_SSO')) THEN
539 
540     l_listener_token := OracleSSWA.listener_token;
541 
542     l_call := dbms_sql.open_cursor;
543   --  l_gen_redirect_url:= wwsec_sso_enabler.generate_redirect(p_lsnr_token => l_listener_token,
544   --                                                           p_url_requested => l_urlrequested,
545   --                                                           p_url_cancel  => l_urlcancel);
549                         ',p_url_cancel  => :l_urlcancel)';
546     l_procedure_call := ':l_gen_redirect_url := wwsec_sso_enabler.generate_redirect'||
547                         '(p_lsnr_token => :l_listener_token'||
548                         ',p_url_requested => :l_urlrequested'||
550 
551     dbms_sql.parse(l_call,'declare l_gen_redirect_url varchar2(32000); begin '||l_procedure_call||'; end;',dbms_sql.native);
552 
553     l_gen_redirect_url := '';
554     for i in 1..100 loop -- set l_gen_redirect_url to 2000 characters
555       l_gen_redirect_url := l_gen_redirect_url||'12345678901234567890';
556     end loop;
557 
558     dbms_sql.bind_variable(l_call,'l_gen_redirect_url',l_gen_redirect_url);
559     dbms_sql.bind_variable(l_call,'l_listener_token',l_listener_token);
560     dbms_sql.bind_variable(l_call,'l_urlrequested',l_urlrequested);
561     dbms_sql.bind_variable(l_call,'l_urlcancel',l_urlcancel);
562 
563     l_dummy := dbms_sql.execute(l_call);
564 
565     dbms_sql.variable_value(l_call,'l_gen_redirect_url',l_gen_redirect_url);
566 
567     dbms_sql.close_cursor(l_call);
568 
569       END IF;--apps_sso profile
570     owa_util.redirect_url(l_gen_redirect_url);
571 
572 exception
573   when others then
574 --    htp.p(SQLERRM);
575       htp.p(dbms_utility.format_error_stack);
576 
577 end;
578 
579 procedure execute (F IN VARCHAR2,
580                    E in VARCHAR2,
581                    P IN VARCHAR2,
582                    L IN VARCHAR2) is
583 
584                    --f = function_name                --mutually exclusive
585                    --e = encrypted parameter string   --mutually exclusive
586                    --p = parameters (encrypted)
587                    --l = lanaguage code
588 
589     l_session_id            number;
590     l_text                  varchar2(2000);
591     l_parameters            icx_on_utilities.v80_table;
592     l_resp_appl_id          number;
593     l_responsibility_id     number;
594     l_security_group_id     number;
595     l_function_id           number;
596     l_function_type         varchar2(30);
597     l_menu_id               number;
598     l_validate              boolean;
599     l_error_message         varchar2(2000);
600     err_mesg                varchar2(240);
601     err_num                 number;
602     l_user_id               number;
603     l_user_name             varchar2(100);
604     l_org_id                number;
605     l_multi_org_flag        varchar2(30);
606     l_profile_defined       boolean;
607     e_session_invalid       exception;
608     e_invalid_function      exception;
609     e_refresh_4_cookie       EXCEPTION;
610     l_guest_profile_value   varchar2(80);
611     l_guest_name            varchar2(80);
612     l_guest_pwd             varchar2(80);
613     c_anchor                varchar2(2000);
614     l_url                   varchar2(2000);
615     l_apps_agent            varchar2(2000);
616     new_encrypted_string    varchar2(2000);
617     l_apps_sso            VARCHAR2(100);
618     l_params                VARCHAR2(2000);
619     C_LOGIN_MSG             VARCHAR2(400);
620     C_ERROR_MSG             VARCHAR2(400);
621     l_exeurl                VARCHAR2(2000);
622     l_mode                VARCHAR2(10);
623     l_language             varchar2(30);
624     l_lang_code            varchar2(30);
625     f_type                 VARCHAR2(30);
626     l_servlet_agent        VARCHAR2(800);
627     l_dbc                  VARCHAR2(70);
628     nls_base_lang          varchar2(30);
629     l_apps_web_agent       VARCHAR2(2000);
630     l_recreate_code        varchar2(240);
631 
632 begin
633 
634   icx_sec.ServerLevel;
635 
636 --add parameter for sgid and init it here.
637 
638 IF e IS NOT NULL THEN
639   l_text := icx_call.decrypt(E);
640   icx_on_utilities.unpack_parameters(l_text,l_parameters);
641        l_resp_appl_id := nvl(l_parameters(1),178);
642        l_responsibility_id := l_parameters(2);
643        l_security_group_id := l_parameters(3);
644        l_function_id := l_parameters(4);
645        --verify that this is all we need to call to get the selects to work in hosted env.
646        fnd_global.SET_SECURITY_GROUP_ID_CONTEXT(l_security_group_id);
647 ELSIF f IS NOT NULL THEN
648     --We dont have a secgrpid set here!!!!!
649 
650     --get function_id.
651     BEGIN
652     SELECT function_id
653       INTO l_function_id
654       FROM fnd_form_functions
655       WHERE function_name = F;
656        l_resp_appl_id := NULL;
657        l_responsibility_id :=NULL;
658        l_security_group_id := NULL;
659 
660       EXCEPTION
661        WHEN OTHERS THEN
662        RAISE e_invalid_function;
663     END;
664 ELSIF ((E IS NULL) AND (F IS NULL)) THEN
665    raise e_invalid_function;
666 
667 END IF;--e is null
668 -- function identified
669         fnd_profile.get_specific(
670                 name_z                  => 'APPS_SSO',
671                 user_id_z               => l_user_id,
672                 val_z                   => l_apps_sso,
673                 defined_z               => l_profile_defined);
674 
675 
676 
677    --Bug 2545562/2667712
681 BEGIN
678    select nls_language into nls_base_lang from fnd_languages_vl
679    where installed_flag = 'B';
680 
682 
683     	if L is not null
684 	then
685  	 select nls_language into l_language from fnd_languages_vl
686 	where LANGUAGE_CODE = L and installed_flag in ('B', 'I');
687         end if;
688          exception
689 		 when NO_DATA_FOUND
690     			then
691        		          l_language := nls_base_lang;
692 
693 END;
694 
695  FND_GLOBAL.set_nls_context(
696       p_nls_language => l_language);
697 --     p_nls_territory =>'AMERICA');
698 --     l_language := L;
699 
700   l_session_id := icx_sec.getsessioncookie;
701 
702 --IF (icx_sec.validatesession(c_validate_only=>'Y')) THEN  --there is a session cookie
703 
704 IF (l_session_id >0 AND l_session_id IS NOT NULL) THEN  --there is a session cookie
705 
706   select multi_org_flag
707   into   l_multi_org_flag
708   from   fnd_product_groups
709   where  rownum < 2;
710 
711   if l_multi_org_flag = 'Y'
712   then
713       fnd_profile.get_specific(
714           name_z                  => 'ORG_ID',
715           responsibility_id_z     => l_responsibility_id,
716           application_id_z        => l_resp_appl_id,
717           val_z                   => l_org_id,
718           defined_z               => l_profile_defined);
719   end if;
720 
721 
722 -- 2646577, nvl(l_language,NLS_LANGUAGE)
723 
724   update ICX_SESSIONS
725   set 	 RESPONSIBILITY_APPLICATION_ID = l_resp_appl_id,
726          RESPONSIBILITY_ID = l_responsibility_id,
727          SECURITY_GROUP_ID = l_security_group_id,
728          ORG_ID = l_org_id,
729          FUNCTION_ID = l_function_id,
730          FUNCTION_TYPE = l_function_type,
731          MENU_ID = l_menu_id,
732          NLS_LANGUAGE = nvl(l_language,NLS_LANGUAGE),
733          LANGUAGE_CODE = nvl(L,LANGUAGE_CODE)
734          where	SESSION_ID = l_session_id;
735   --where	SESSION_ID = icx_sec.getsessioncookie;
736 
737   commit;
738 
739 ELSE
740      --get anonymous user info
741      -- fnd_profile.get(name    => 'GUEST_USER_PWD',
742                 -- val     => l_guest_profile_value);
743      -- Using new api to retrieve GUEST credentials.
744      l_guest_profile_value := fnd_web_sec.get_guest_username_pwd;
745      l_guest_name  := SUBSTR(l_guest_profile_value, 1, INSTR(l_guest_profile_value, '/') -1);
746      --l_guest_pwd := SUBSTR(l_guest_profile_value, INSTR(l_guest_profile_value, '/') + 1);
747      l_guest_name := upper(l_guest_name);
748      SELECT user_id
749        into l_user_id
750        from  fnd_user
751        where user_name = l_guest_name;
752 
753        --create anonymous session
754 
755         --Need to check apps_sso profile and determine if we are Portal or PHP and set mode accordingly
756         IF (nvl(l_apps_sso,'SSWA')='SSWA')
757         THEN
758            l_mode := '115P';
759         ELSIF l_apps_sso='SSWA_SSO'
760         THEN
761            l_mode := '115J';
762         ELSE
763            l_mode := '115X';
764         END IF;
765        l_session_id:=icx_sec.CREATESession(l_user_id, l_mode);
766 /*
767        fnd_profile.get_specific(
768           name_z                  => 'APPS_WEB_AGENT',
769           responsibility_id_z     => l_responsibility_id,
770           application_id_z        => l_resp_appl_id,
771           val_z                   => l_apps_web_agent,
772           defined_z               => l_profile_defined);
773 */
774        fnd_profile.get(name  => 'APPS_WEB_AGENT',
775                        val    => l_apps_web_agent);
776 
777        l_url := FND_WEB_CONFIG.TRAIL_SLASH(l_apps_web_agent);
778 
779        --c_anchor := 'OracleSSWA.Execute?E='||wfa_html.conv_special_url_chars(icx_call.encrypt(l_resp_appl_id||'*'||l_responsibility_id||'*'||l_security_group_id||'*'||l_function_id||'*'||'**]'));
780 
781 --bug 267712 added L parm to anchor
782        c_anchor := 'OracleSSWA.Execute?F='||F||'&E='||E||'&P='||P||'&L='||L;
783 
784        owa_util.mime_header('text/html', FALSE);
785        owa_cookie.send(name=>'WF_WORKLIST_MODE', value=>'-1', expires=>'', path=>'/');-- mputman added for 1903545
786        icx_sec.sendSessionCookie(l_session_id);
787        owa_util.http_header_close;
788 
789        RAISE e_refresh_4_cookie;
790 
791 END IF;--cookie
792 
793    --need to do validate_only so if fails, we can still run if public
794    --set a global to -999 to fnd_global will verify user-resp relationship
795    icx_sec.g_prog_appl_id := -999;
796   IF icx_sec.VALIDATESession(c_validate_only => 'Y') THEN
797   icx_sec.g_prog_appl_id := -1;
798 
799 --    IF (fnd_function.test_id(l_function_id))
800 --    THEN
801         --either current user or anonymous user has access to this function.. run it.
802         IF E IS NOT NULL and icx_sec.g_login_id is not null THEN
803            fnd_signon.audit_web_responsibility(icx_sec.g_login_id,
804                                                l_responsibility_id,
805                                                l_resp_appl_id,
806                                                l_responsibility_id); -- mputman added for 1941776
807         END IF;
808 
809         SELECT TYPE
810         INTO f_type
811         FROM fnd_form_functions
815 
812         WHERE function_id = l_function_id;
813 
814         IF f_type = 'FORM' THEN
816             /* 3220523 Replace hard coded RF.jsp
817             fnd_profile.get_specific(
818                 name_z                  => 'APPS_SERVLET_AGENT',
819                 val_z                   => l_servlet_agent,
820                 defined_z               => l_profile_defined);
821             l_servlet_agent:=FND_WEB_CONFIG.TRAIL_SLASH(replace(upper(l_servlet_agent),'OA_SERVLETS','OA_HTML'));
822 
823             fnd_profile.get(name => 'APPS_DATABASE_ID',
824                             val => l_dbc);
825 
826             if l_dbc is null
827               then
828               l_dbc := FND_WEB_CONFIG.DATABASE_ID;
829             end if;
830 
831             l_servlet_agent:=l_servlet_agent||'jsp/fnd/RF.jsp?dbc='||l_dbc||
832                              '&function_id='|| l_function_id ||
833                              '&resp_id=' || l_responsibility_id ||
834                              '&resp_appl_id=' || l_resp_appl_id ||
835                              '&security_group_id=' || nvl(l_security_group_id,'0');
836             */
837 
838             l_servlet_agent:= FND_RUN_FUNCTION.GET_RUN_FUNCTION_URL
839               (P_FUNCTION_ID => l_function_id,
840                P_RESP_APPL_ID => l_resp_appl_id,
841                P_RESP_ID => l_responsibility_id,
842                P_SECURITY_GROUP_ID => nvl(l_security_group_id,'0'));
843 
844             owa_util.redirect_url(l_servlet_agent);
845 
846         ELSE
847           IF p IS NOT NULL THEN
848            l_params := icx_call.decrypt(P);
849            --p_resp_appl_id,p_responsibility_id,p_security_group_id,
850          --p_menu_id,c_function_id,p_function_type,p_page_id
851            OracleApps.runfunction(p_resp_appl_id => l_resp_appl_id,
852                                   p_responsibility_id => l_responsibility_id,
853                                   p_security_group_id => nvl(l_security_group_id,'0'),
854                                   p_function_type => f_type,
855                                   c_function_id => l_function_id,
856                                   n_session_id => icx_Sec.g_session_id,
857                                   c_parameters => l_params);
858           ELSE
859             OracleApps.runfunction(p_resp_appl_id => l_resp_appl_id,
860                                    p_responsibility_id => l_responsibility_id,
861                                    p_security_group_id => nvl(l_security_group_id,'0'),
862                                    p_function_type => f_type,
863                                    c_function_id => l_function_id,
864                                    n_session_id => icx_Sec.g_session_id);
865           END IF;
866         END IF;
867 
868     icx_sec.g_prog_appl_id := -1; --set global back to -1
869 
870   ELSIF icx_sec.check_session(p_session_id => l_session_id) = 'EXPIRED'
871   THEN
872   icx_sec.g_prog_appl_id := -1;
873 
874     select USER_NAME
875     into   l_user_name
876     from   FND_USER fu,
877            ICX_SESSIONS i
878     where  i.SESSION_ID = l_session_id
879     and    i.USER_ID = fu.USER_ID;
880 
881     l_recreate_code := icx_call.encrypt(l_session_id||'*'||l_user_name||'**]');
882 
883     fnd_profile.get_specific(
884           name_z                  => 'APPS_WEB_AGENT',
885           responsibility_id_z     => l_responsibility_id,
886           application_id_z        => l_resp_appl_id,
887           val_z                   => l_apps_web_agent,
888           defined_z               => l_profile_defined);
889     l_url := FND_WEB_CONFIG.TRAIL_SLASH(l_apps_web_agent);
890     l_url := l_url||'OracleSSWA.Execute?E='||icx_call.encrypt(l_resp_appl_id||'*'||l_responsibility_id||'*'||l_security_group_id||'*'||l_function_id||'*'||'**]')||'&'||'P='||P||'&'||'L='||L;
891 
892     OracleApps.displayLogin(i_direct => l_url,
893                             recreate => l_recreate_code);
894 
895     --function available to current or anonymous with a valid session
896   ELSIF (fnd_function.test_id(l_function_id)) -- OR (l_function_id=2594)
897   THEN -- VS Failed.. if function is public, create session and go!
898   icx_sec.g_prog_appl_id := -1;
899      --get anonymous user info
900      -- fnd_profile.get(name    => 'GUEST_USER_PWD',
901                 -- val     => l_guest_profile_value);
902      -- Using new api to retrieve GUEST credentials.
903      l_guest_profile_value := fnd_web_sec.get_guest_username_pwd;
904      l_guest_name  := SUBSTR(l_guest_profile_value, 1, INSTR(l_guest_profile_value, '/') -1);
905      --l_guest_pwd := SUBSTR(l_guest_profile_value, INSTR(l_guest_profile_value, '/') + 1);
906      l_guest_name := upper(l_guest_name);
907      SELECT user_id
908        into l_user_id
909        from  fnd_user
910        where user_name = l_guest_name;
911 
912        --create anonymous session
913 
914         --Need to check apps_sso profile and determine if we are Portal or PHP and set mode accordingly
915         IF (nvl(l_apps_sso,'SSWA')='SSWA')
916         THEN
917            l_mode := '115P';
918         ELSIF l_apps_sso='SSWA_SSO'
919         THEN
920            l_mode := '115J';
921         ELSE
922            l_mode := '115X';
923         END IF;
924        l_session_id:=icx_sec.CREATESession(l_user_id, l_mode);
925        fnd_profile.get_specific(
926           name_z                  => 'APPS_WEB_AGENT',
930           defined_z               => l_profile_defined);
927           responsibility_id_z     => l_responsibility_id,
928           application_id_z        => l_resp_appl_id,
929           val_z                   => l_apps_web_agent,
931        l_url := FND_WEB_CONFIG.TRAIL_SLASH(l_apps_web_agent);
932        c_anchor := 'OracleSSWA.Execute?E='||wfa_html.conv_special_url_chars(icx_call.encrypt(l_resp_appl_id||'*'||l_responsibility_id||'*'||l_security_group_id||'*'||l_function_id||'*'||'**]'));
933 
934        owa_util.mime_header('text/html', FALSE);
935        owa_cookie.send(name=>'WF_WORKLIST_MODE', value=>'-1', expires=>'', path=>'/');-- mputman added for 1903545
936        icx_sec.sendSessionCookie(l_session_id);
937        owa_util.http_header_close;
938 
939        select multi_org_flag
940          into   l_multi_org_flag
941          from   fnd_product_groups
942          where  rownum < 2;
943        if l_multi_org_flag = 'Y' THEN
944        fnd_profile.get_specific(name_z                  => 'ORG_ID',
945                                 responsibility_id_z     => l_responsibility_id,
946                                 application_id_z        => l_resp_appl_id,
947                                 val_z                   => l_org_id,
948                                 defined_z               => l_profile_defined);
949        end if;
950        update ICX_SESSIONS
951           set    RESPONSIBILITY_APPLICATION_ID = l_resp_appl_id,
952                  RESPONSIBILITY_ID = l_responsibility_id,
953                  SECURITY_GROUP_ID = l_security_group_id,
954                  ORG_ID = l_org_id,
955                  FUNCTION_ID = l_function_id,
956                  FUNCTION_TYPE = l_function_type
957           where SESSION_ID = l_session_id;
958          commit;
959          htp.p('<META HTTP-EQUIV=Refresh CONTENT="1; URL='||l_url||c_anchor||'">');
960 
961   ELSE
962    icx_sec.g_prog_appl_id := -1;
963          -- session not valid... or current user cannot access function
964          -- function is not public... need to login.
965          IF ((nvl(l_apps_sso,'SSWA')='SSO_SDK') OR
966              (nvl(l_apps_sso,'SSWA')='SSWA_SSO'))THEN
967              OracleSSWA.convertSession;
968          ELSE
969 
970      --need a session for convertsession to work
971      --get anonymous user info
972      -- fnd_profile.get(name    => 'GUEST_USER_PWD',
973                 -- val     => l_guest_profile_value);
974      -- Using new api to retrieve GUEST credentials.
975      l_guest_profile_value := fnd_web_sec.get_guest_username_pwd;
976      l_guest_name  := SUBSTR(l_guest_profile_value, 1, INSTR(l_guest_profile_value, '/') -1);
977      --l_guest_pwd := SUBSTR(l_guest_profile_value, INSTR(l_guest_profile_value, '/') + 1);
978      l_guest_name := upper(l_guest_name);
979      SELECT user_id
980        into l_user_id
981        from  fnd_user
982        where user_name = l_guest_name;
983        ----
984        l_session_id:=icx_sec.getsessioncookie;
985        IF ((l_user_id <> icx_sec.g_user_id) OR (icx_sec.check_session(icx_sec.getsessioncookie) = 'INVALID')) THEN
986        --create anonymous session
987 
988         --Need to check apps_sso profile and determine if we are Portal or PHP and set mode accordingly
989         IF (nvl(l_apps_sso,'SSWA')='SSWA')
990         THEN
991            l_mode := '115P';
992         ELSIF l_apps_sso='SSWA_SSO'
993         THEN
994            l_mode := '115J';
995         ELSE
996            l_mode := '115X';
997         END IF;
998        l_session_id:=icx_sec.CREATESession(l_user_id, l_mode);
999   --     l_url := FND_WEB_CONFIG.TRAIL_SLASH(fnd_profile.value('APPS_WEB_AGENT'));
1000   --     c_anchor := 'OracleSSWA.Execute?E='||wfa_html.conv_special_url_chars(icx_call.encrypt(l_resp_appl_id||'*'||l_responsibility_id||'*'||l_security_group_id||'*'||l_function_id||'*'||'**]'));
1001 
1002        owa_util.mime_header('text/html', FALSE);
1003        owa_cookie.send(name=>'WF_WORKLIST_MODE', value=>'-1', expires=>'', path=>'/');-- mputman added for 1903545
1004        icx_sec.sendSessionCookie(l_session_id);
1005        owa_util.http_header_close;
1006        --- end create new session
1007 
1008        END IF;
1009 
1010        select multi_org_flag
1011          into   l_multi_org_flag
1012          from   fnd_product_groups
1013          where  rownum < 2;
1014        if l_multi_org_flag = 'Y' THEN
1015        fnd_profile.get_specific(name_z                  => 'ORG_ID',
1016                                 responsibility_id_z     => l_responsibility_id,
1017                                 application_id_z        => l_resp_appl_id,
1018                                 val_z                   => l_org_id,
1019                                 defined_z               => l_profile_defined);
1020        end if;
1021        update ICX_SESSIONS
1022           set    RESPONSIBILITY_APPLICATION_ID = l_resp_appl_id,
1023                  RESPONSIBILITY_ID = l_responsibility_id,
1024                  SECURITY_GROUP_ID = l_security_group_id,
1025                  ORG_ID = l_org_id,
1026                  FUNCTION_ID = l_function_id,
1027                  FUNCTION_TYPE = l_function_type
1028           where SESSION_ID = l_session_id;
1029          commit;
1030 
1031 
1032            new_encrypted_string := icx_call.encrypt(l_session_id||'*'||
1033                                                     l_resp_appl_id||'*'||
1034                                                     l_responsibility_id||'*'||
1035                                                     l_security_group_id||'*'||
1039 
1036                                                     l_function_id||'*'||
1037                                                     p||'**]');
1038            OracleApps.convertSession(new_encrypted_String);
1040          END IF;
1041   END IF;
1042 
1043 EXCEPTION
1044    WHEN e_refresh_4_cookie THEN
1045          htp.p('<META HTTP-EQUIV=Refresh CONTENT="1; URL='||l_url||c_anchor||'">');
1046 
1047    WHEN e_invalid_function THEN
1048 
1049       fnd_message.set_name('ICX','ICX_INVALID_FUNCTION');
1050       c_error_msg := fnd_message.get;
1051       fnd_message.set_name('ICX','ICX_SIGNIN_AGAIN');
1052       c_login_msg := fnd_message.get;
1053       OracleApps.displayLogin(c_error_msg||' '||c_login_msg,'IC','Y');
1054 
1055    WHEN OTHERS THEN
1056         icx_sec.g_prog_appl_id := -1;
1057 
1058 --      fnd_message.set_name('ICX','ICX_SESSION_FAILED');
1059 --      c_error_msg := fnd_message.get;
1060 --      fnd_message.set_name('ICX','ICX_SIGNIN_AGAIN');
1061 --      c_login_msg := fnd_message.get;
1062 
1063         fnd_message.set_name('ICX','ICX_CONTACT_WEBMASTER');
1064         c_error_msg := fnd_message.get;
1065         c_login_msg := dbms_utility.format_error_stack;
1066 
1067       OracleApps.displayLogin(c_error_msg||' '||c_login_msg,'IC','Y');
1068 END;
1069 
1070 FUNCTION SSORedirect (p_req_url IN VARCHAR2,
1071                       p_cancel_url IN VARCHAR2)
1072 RETURN VARCHAR2
1073 IS
1074 
1075   l_gen_redirect_url      varchar2(2024);
1076   l_urlrequested          varchar2(2024);
1077   l_urlcancel             varchar2(2024);
1078   l_listener_token        varchar2(240);
1079   l_procedure_call        varchar2(32000);
1080   l_call                  integer;
1081   l_dummy                 integer;
1082   l_defined               boolean;
1083 
1084 BEGIN
1085 
1086     IF p_req_url IS NULL THEN
1087        fnd_profile.get_specific(name_z    => 'APPS_PORTAL',
1088                                 val_z     => l_urlrequested,
1089                                 defined_z => l_defined );
1090     ELSE
1091     l_urlrequested :=p_req_url;
1092     END IF;
1093     IF p_cancel_url IS NULL THEN
1094        fnd_profile.get_specific(name_z    => 'APPS_PORTAL',
1095                                 val_z     => l_urlcancel,
1096                                 defined_z => l_defined );
1097     ELSE
1098        l_urlcancel:=p_cancel_url;
1099     END IF;
1100 
1101 -- Wait SSO
1102 
1103     l_listener_token := OracleSSWA.listener_token;
1104     -- l_gen_redirect_url := wwsec_sso_enabler.generate_redirect(p_lsnr_token => l_listener_token,
1105     --                                                           p_url_requested => l_urlrequested,
1106     --                                                           p_url_cancel  => l_urlcancel);
1107 
1108 
1109     l_call := dbms_sql.open_cursor;
1110 
1111     l_procedure_call := ':l_gen_redirect_url := wwsec_sso_enabler.generate_redirect'||
1112                         '(p_lsnr_token => :l_listener_token'||
1113                         ',p_url_requested => :l_urlrequested'||
1114                         ',p_url_cancel  => :l_urlcancel)';
1115 
1116     dbms_sql.parse(l_call,'declare l_gen_redirect_url varchar2(32000); begin '||l_procedure_call||'; end;',dbms_sql.native);
1117 
1118     l_gen_redirect_url := '';
1119     for i in 1..100 loop -- set l_gen_redirect_url to 2000 characters
1120       l_gen_redirect_url := l_gen_redirect_url||'12345678901234567890';
1121     end loop;
1122 
1123     dbms_sql.bind_variable(l_call,'l_gen_redirect_url',l_gen_redirect_url);
1124     dbms_sql.bind_variable(l_call,'l_listener_token',l_listener_token);
1125     dbms_sql.bind_variable(l_call,'l_urlrequested',l_urlrequested);
1126     dbms_sql.bind_variable(l_call,'l_urlcancel',l_urlcancel);
1127     l_dummy := dbms_sql.execute(l_call);
1128     dbms_sql.variable_value(l_call,'l_gen_redirect_url',l_gen_redirect_url);
1129 
1130     dbms_sql.close_cursor(l_call);
1131 
1132    RETURN l_gen_redirect_url;
1133 END;
1134 
1135 
1136 
1137 PROCEDURE logout
1138   IS
1139 --using static image from fwk UI media.
1140   -- hextoraw to store a value in a blob wont work in 8i
1141   -- cant use a raw bacause wpg_docload cant accept a raw.
1142 
1143 --    l_img RAW(1000);
1144   BEGIN
1145 
1146 --    l_img:= hextoraw('4749463839610D000D00B30F'||
1147 --                     '000000008000000080008080'||
1148 --                     '00000080800080008080C0C0'||
1149 --                     'C0808080FF000000FF00FFFF'||
1150 --                     '000000FFFF00FF00FFFFFFFF'||
1151 --                     'FF21F9040100000F002C0000'||
1152 --                     '00000D000D0040041FF0C949'||
1153 --                     '2B618CD4C92AD65B2872DF73'||
1154 --                     '4965088EEC8865CF4BAE64AA'||
1155 --                     'D2ED1601003B');
1156       owa_util.mime_header('image/gif', FALSE);
1157     -- Reset cookie
1158      owa_cookie.send
1159       (
1160           name    => icx_sec.getsessioncookiename,
1161           value   => '-1',
1162           path    => '/',
1163           domain  => icx_sec.getsessioncookiedomain
1164       );
1165      --htp.p('Content-Length: ' || length(l_img));
1166      htp.p('Expires: Thu, 29 Oct 1970 17:04:19 GMT');
1167      htp.p('Pragma: no-cache');
1171      --wpg_docload.download_file(l_img);
1168      htp.p('Cache-Control: no-cache');
1169      owa_util.redirect_url('/OA_MEDIA/completeind_status.gif');
1170      owa_util.http_header_close;
1172   EXCEPTION
1173     WHEN OTHERS THEN
1174 --     htp.p(sqlerrm);
1175    htp.p(dbms_utility.format_error_stack);
1176   END logout;
1177 
1178 end OracleSSWA;