【问题标题】:Birt/tomcat: set session variable after j_security_checkBirt/tomcat:在 j_security_check 之后设置会话变量
【发布时间】:2014-08-15 22:09:32
【问题描述】:

我在 tomcat 中使用基于表单的身份验证,实际上我正在使用 j_security_check。代码如下

<form method="POST" action="j_security_check">
<table>
    <tr>
        <td colspan="2">Login to the Tomcat-Demo application:</td>
    </tr>
    <tr>
        <td>Name:</td>
        <td><input type="text" name="j_username" /></td>
    </tr>
    <tr>
        <td>Password:</td>
        <td><input type="password" name="j_password"/ ></td>
    </tr>
    <tr>
        <td colspan="2"><input type="submit" value="Go" /></td>
    </tr>
</table>
</form>

我想使用已登录报告的用户。我想从会话中捕获已登录的用户。我的想法是使用下面的jsp语法来设置变量

<%
        session.setAttribute("myName",request.getParameter("user"));
%>

但是,我不确定如何设置会话变量,因为在身份验证后不久,它会被重定向到请求的 URL

有人可以帮忙

问候 阿里夫

【问题讨论】:

  • 您想将该名称输入您的登录表单吗?还是在通过身份验证后获取用户名?
  • 两种方式都可以,只要我能得到登录的用户名。在报告中我想显示允许用户查看的数据。为此,我需要检索已登录的用户

标签: jsp tomcat j-security-check


【解决方案1】:

通常通过过滤器解决。 检查 tomcat 文档中的过滤器,并应用您的过滤器(可能匹配每个请求,因为您无法应用它。google 关键字 session、filter、principal。

dofilter() {
    getSession;
    if(session->user is not set) {
        session->user = request->getPrincipal->getUsername() //something like that
    }
}

【讨论】:

    【解决方案2】:

    通过身份验证后,您可以通过调用从请求中获取相应的用户名:

    request.getRemoteUser()
    

    您还可以通过调用来测试用户是否具有特定角色

    request.isUserInRole()
    

    这可以在您可以访问 HttpServletRequest 的任何地方完成

    有关详细信息,请参阅 servlet API。

    【讨论】:

      猜你喜欢
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2011-05-14
      • 2023-01-23
      • 2013-01-27
      • 2014-12-11
      • 1970-01-01
      相关资源
      最近更新 更多