0

当用户将链接从一个浏览器复制并粘贴到另一个浏览器时,如何将用户限制为“主页”......即

当用户从 Internet Explorer 复制我的项目“localhost:8080/MyJavaProjectV1.0/Admin_GetTokenId.jsp”中的链接时

将其粘贴到 chrome..我希望用户被限制在主页..

4

4 回答 4

1

In every jsp page after the user was logged in, I am saving the username in a session and I am displaying username in every page, like...

hai  <%= ss.getAttribute("username")%>  

now I have used that username session and checking if username is null or empty.. if its null(ie the link is copied and pasted to other browser..) then im redirecting to login page

if(ss.getAttribute("username")==null || ss.getAttribute("username")=="")
{
    response.sendRedirect("loginpage.jsp");
}
于 2012-10-19T12:06:18.117 回答
1

如果您使用的任何应用服务器都配置了登录以进行身份​​验证,只需保护文件中除Login页面之外的所有 URL 模式web.xml如果用户在没有身份验证的情况下尝试访问“登录”页面以外的任何 URL(或更多不安全的 URL),Login则默认情况下会显示页面。. 您的配置如下所示:

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Sample Security Realm</realm-name>
</login-config>

<security-role><role-name>admin</role-name></security-role>
<security-role><role-name>user</role-name></security-role>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Admin</web-resource-name>
        <!-- Mention your URL pattern here for admin access check>
        <url-pattern>/admin/*</url-pattern>  
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>
<security-constraint>
    <web-resource-collection>
        <web-resource-name>User</web-resource-name>
        <!-- Mention your URL pattern here for standard user access check>
        <url-pattern>/user/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>user</role-name>
    </auth-constraint>
</security-constraint>

如果您没有使用任何应用程序服务器,而是使用网络服务器(例如apache前端应用程序),请使用 apache 的安全插件和您的身份验证机制,例如很好的Siteminder凝胶。Apache

如果以上都不适用,请配置请求过滤器,检查用户,如果用户未通过身份验证,则重定向到登录页面。

于 2012-10-12T17:46:10.923 回答
1

添加一个 servlet 过滤器,将每个请求过滤到主页并检查请求是否经过身份验证以提供服务 - 服务,否则限制


另见

于 2012-10-12T17:39:13.703 回答
0

这个问题尚不清楚是否有任何形式的身份验证。假设这与身份验证无关,一种解决方案是查看一个名为referrer http://en.wikipedia.org/wiki/HTTP_referrer的http 标头 ,该referrer 标头包含有关用户先前在哪个页面上的信息。

您可以创建一个 servlet 过滤器来检查引荐来源网址。在访问任何文章时检查引荐来源标题,如果它的任何页面或网站不是您的主页,或者引荐来源为空白,您会将用户转发到主页,否则将用户发送到他请求的页面。

于 2012-10-12T17:48:00.527 回答