用户复制粘贴链接时如何将用户限制为“主页”。

时间:2012-10-12 17:38:11

标签: java jsp

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

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

将它粘贴在chrome..i中,希望用户被限制在主页..

4 个答案:

答案 0 :(得分:1)

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


另见

答案 1 :(得分:1)

如果您使用配置了用于身份验证的登录的​​任何应用服务器,只需保护Login文件中除web.xml页之外的所有网址格式。 如果用户在未经身份验证的情况下尝试访问“登录”页面以外的任何网址(或更多不安全的网址),则默认情况下会显示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

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

答案 2 :(得分:1)

在用户登录后的每个jsp页面中,我在会话中保存用户名,我在每个页面都显示用户名,如...

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

现在我已使用该用户名会话并检查用户名是否为空或空。 如果它为null(即链接被复制并粘贴到其他浏览器..)然后重定向到登录页面

if(ss.getAttribute("username")==null || ss.getAttribute("username")=="")
{
    response.sendRedirect("loginpage.jsp");
}

答案 3 :(得分:0)

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

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

相关问题