如何注销 oracle APEX 中的会话?

How to logout sessions in oracle APEX?

我试图避免用户在不同的计算机上登录。

我想创建一个登录视图,如果用户已经登录并且您尝试使用该用户登录,该应用程序将显示一条消息 "user already logged" 并可以选择关闭打开的会话link 或按钮。

编辑: Apex 版本 5.1.1.00.08,无法更新此版本。

我已经尝试了多种方法来关闭会话,但 none 到目前为止都有效。

第一步:

创建 url 以注销。

我从 table apex_workspace_sessions[=17 中取出 APEX_SESSION_ID =]

http://xxxxxxxx.com/apex/apex_authentication.logout?p_app_id=100&p_session_id=APEX_SESSION_ID

但是当我打开 link 时,它不会注销 APEX_SESSION_ID

的用户

第二个动作:

我试图创建一个函数来注销从 tableapex_workspace_sessions[中提取 APEX_SESSION_ID 的会话=86=] 但生成此错误也无法正常工作:

ORA-06550:第 2 行,第 11 列:PLS-00328:必须为 DELETE_SESSION 的前向声明定义子程序主体。 ORA-06550:第 6 行,第 16 列:PLS-00302:必须声明组件 'DELETE_SESSION' ORA-06550:第 6 行,第 3 列:PL/SQL:语句被忽略

代码:

declare 

procedure delete_session (p_session_id in number default wwv_flow.g_instance );

begin
    apex_session.delete_session (
    p_session_id => APEX_SESSION_ID );
end;

图中的p_session_id是table中已经存在的APEX_SESSION_ID apex_workspace_sessions

第三个动作:

我尝试运行查询

DELETE FROM APEX_050000.wwv_flow_sessions$ WHERE ID = APEX_SESSION_ID;

显示错误:ORA-00942:table 或视图不存在

和查询

DELETE FROM apex_workspace_sessions WHERE APEX_SESSION_ID = APEX_SESSION_ID;

显示错误:ORA-01031:权限不足

第四个动作:

我尝试使用官方 oracle 文档中的 LOGOUT PROCEDURE,但也没有用

apex_authentication.logout(APEX_SESSION_ID, :APP_ID);

没有错误或任何可显示的内容。

有谁知道如何从另一台计算机注销用户?

谢谢

您使用的是什么版本的 apex?如果您使用的是 18.1 或更高版本,则可以使用 apex_session.delete_session 为您完成所有工作。

这是一个使用自定义 table 的示例。

创建 table

create table most_recent_logins (
  id         number generated by default on null as identity  
             constraint most_recent_logins_id_pk primary key,
  username   varchar2(255) not null,
  app_id     number not null,
  session_id number not null
             constraint most_recent_log_session_id_unq unique,
  login_date date not null,
  constraint most_recent_log_user_app_unq unique (username, app_id)
);

创建post-auth 进程

转到共享组件 > 身份验证方案和 select 当前方案。在 PL/SQL 代码字段中输入以下内容:

procedure post_auth
is

  cursor mrl_cur
  is
    select *
    from most_recent_logins
    where app_id = :app_id
      and username = :app_user
    for update;

  mrl_rec mrl_cur%rowtype;

begin

  open mrl_cur;
  fetch mrl_cur into mrl_rec;

  if mrl_cur%notfound
  then
    insert into most_recent_logins (
      username,
      app_id,
      session_id,
      login_date
    ) values (
      :app_user,
      :app_id,
      :app_session,
      sysdate
    );
  else
    update most_recent_logins
    set session_id = :app_session,
      login_date = sysdate
    where current of mrl_cur;
  end if;

  close mrl_cur;

end;

创建应用进程

转到共享组件 > 应用程序并单击 创建 >。将名称设置为检查最近登录,然后单击下一步>。在PL/SQL代码中输入以下代码,点击下一步 >:

declare

  l_mr_session_id number;

begin

  select session_id
  into l_mr_session_id
  from most_recent_logins
  where username = :app_user
    and app_id = :app_id;

  if l_mr_session_id != :app_session
  then
    apex_util.redirect_url('f?p=' || :app_id || ':9999');
  end if;

end;

配置条件使进程不在登录页面运行,然后单击创建进程

应该这样做。