需求描述如下:
?
2台机器部署了2个web应用,A应用需要访问B应用的URL。为了保证URL不会让任意用户随便粘贴就可以访问,需要在B应用上加上filter拦截请求,并进行权限校验。A应用的URL给用户看来是一个中间跳转页面的URL。在这个中间页面,添加hidden的value,在B应用的filter端进行value的校验。代码如下:
?
? ?<%@ page language="java" contentType="text/html;
charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function init(){
document.getElementById('myForm').action="http://localhost:8080/ext2.2/Filter.jsp"
document.getElementById('myForm').submit();
}
</script>
</head>
<body onload="init()">
<form method="post" id="myForm">
<input type="hidden" name="key" id="key" value="MERKTLTTOR">
</form>
</body>
</html>
?
?
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <title></title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript"> function init (){ <% String key=request.getParameter("key"); if(!"MERKTLTTOR".equals(key)){ %> alert('不允许访问'); <% } %> } </script> </head> <body onload="init()"> <form method="post" id="myForm"> <input type="hidden" name="key" id="key" value="MERKTLTTOR"> </form> </body> </html>
?
?
?
这是filter页面,实际中可以是真正的过滤器filter。
中间页面采用post提交,用户在url中看不到提交的hidden。 ? 中间页面的form的action可以用request.getParamter()获取 ?
当然value可以采用一些加密算法进行加密。
?
?

On site B, in the filter, you should check where the http request comes, and bring the user to a standard error page if the request is not from site A.
Most of application server supports this feature already, it called trusted IP.
Another option is use JMS through a queue or create a web service that used to communicate each other.
至于采用什么策略完全是由需求决定的,而不是你想用什么都可以用的
只是trustedIP不能解决权限认证的问题,只能限制访问的地址是A的服务器IP。
该例子只是个雏形,也就是描述下集成的理路。在实际使用中可能还有不少工作要做。
比如跳转jsp页面,可以改为filter,在fileter responst write jsp结果。
parse user 对象,B的filter 解析user对象等
建议直接使用它的 SDK,而不是通过它的那个 url converter 什么的。那个东东做的功能很烂,而且只能在 IE 使用。尤其如果是 composite report.
另外一个做法就是在 web server 上做手脚。如果是 report server request, 就在 cookie 里做一下标记,转到 application server 进行安全验证,如果成功,升级 cookie, 转到report server,否则,跳转到登陆界面。
加一个 web server 的另外一个好处,是可以 cache 一些 report,不用重复生成。
我们当时是用 perl 在 apache server 上写的。