我已经为所有jsp页面创建了过滤器,当远程用户不为空并且用户允许时,它允许重定向页面。代码如下
public void doFilter(final ServletRequest request,
final ServletResponse response, final FilterChain chain)
throws IOException, ServletException {
String ssoUser = null;
String fullURL = null;
boolean isUserAuthorized = false;
try {
ssoUser = ((HttpServletRequest) request).getRemoteUser();
String queryString =((HttpServletRequest)request).getQueryString();
if(queryString!=null){
fullURL = ((HttpServletRequest)request).getRequestURL().append("?").append( queryString).toString();
}
else{
fullURL = ((HttpServletRequest)request).getRequestURL().toString();
}
//want to forward if correct this condition
if(ssoUser!=null){
if(isUserAuthorized(ssoUser))
request.getRequestDispatcher(fullURL).forward(request, response);
}
chain.doFilter(request, response);
} catch (Exception e) {
}
web.xml
<filter>
<filter-name>UserFilter</filter-name>
<filter-class>com.filter.UserFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UserFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
它将检查用户并进行身份验证,但成功验证后无法转发页面。
请建议。