[英]how to restrict direct access to url in spring
在Web应用程序中,当用户访问学生列表页面时,屏幕会显示带有超链接的学生姓名列表。 仅显示允许用户看到的那些学生姓名。 当用户单击超链接时,将打开一个新窗口,显示用户的详细信息。 子窗口的地址栏显示网址,如下所示。
为myhost:8080 / studentID = 100
问题在于用户可以更改参数StudentID的值,并获取他/她不符合查看条件的其他一些学生的详细信息(因此未在上一列表屏幕中显示)。 这是一个安全问题-网址处理。
我可以想到一些可以防止这种情况的方法。
使用Spring Framework实现基于角色的安全性
对于教程,您可以参考:
http://www.mkyong.com/spring-security/spring-security-access-control-example/
您需要使用Cookie和唯一的会话ID。 因此,用户登录并获得了唯一的密钥,该密钥与具有这些临时访问令牌或会话ID的数据库表相对应。 通常,这些令牌仅在一段时间内有效。 在服务器端,您可以将cookie值测试到数据库,并重定向不允许访问的用户。 祝你好运,您问正确的问题就继续前进!
您无需打开单独的窗口。 这是一些例子。 我在这里使用jQuery。
<script type='text/javascript' src='http://code.jquery.com/jquery-1.6.4.js'></script>
范例HTML
<div id="blockbox" >
<div class="contents">
<div id="data"></div>
<div class="close">close</div>
</div>
</div>
<div>
<a href="#" stid='1'>Name1</a>
<a href="#" stid='2'>Name2</a>
<a href="#" stid='3'>Name3</a>
<a href="#" stid='4'>Name4</a>
<a href="#" stid='5'>Name5</a>
</div>
CSS
div.contents
{
color:#111;
font-family: "Calibri";
background-color: #eee;
text-align: left;
min-height: 100px;
box-shadow: 0px 0px 7px #000;
position: absolute;
width:200px;
height: 10px;
margin-left:20%;
margin-top:20%;
padding: 16px;
z-index:2000;
display: inline-block;
}
div.contents .close
{
width: 20px;
height: 24px;
position: absolute;
top: 0px;
right: 30px;
cursor: pointer;
}
jQuery的
$(document).ready(function(){
$("#blockbox").fadeOut(0);
$("div a").click(function(e){
e.preventDefault();
$("#blockbox").fadeIn(100);
//$("#data").html($(this).attr("stid"));
//This will sent studentID to relevent page
//and retrieve the result
$.post("myhost:8080",
{
studentID:$(this).attr("stid"),
}
).done(function(data) {
$("#data").html(data);
});
});
$(".close").click(function(e){
$("#blockbox").fadeOut(100);
});
});
您的服务器端脚本捕获$ .post方法发送的studentID。 我在这里使用PHP
<?php
$studentID=$_POST['studentID'];
//echo student details
?>
然后数据变量捕获响应并将其添加到#data id
.done(function(data) {
$("#data").html(data);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.