gpt4 book ai didi

java - zk + Spring 4 + 使用 webseal 进行预身份验证

转载 作者:太空宇宙 更新时间:2023-11-04 11:14:43 28 4
gpt4 key购买 nike

首先对我的英语感到抱歉,我的问题是,当尝试使用 webseal 配置 Spring Filter 时,我可以从标题中获取“iv-user”和我的用户信息(我只需要这个),但是当重定向到内部 url 时,我的导航器显示“ERR_TOO_MANY_REDIRECTS”,也许我的配置不好

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<description>My Project Application</description>
<display-name>my-project-web</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>

<listener>
<display-name>Spring Context Loader</display-name>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>

<filter>
<filter-name>appFormacionFilterSesion</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>appFormacionFilterSesion</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<listener>
<description>ZK listener for session cleanup</description>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<servlet>
<description>ZK loader for ZUML pages</description>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<servlet>
<description>The asynchronous update engine for ZK</description>
<servlet-name>auEngine</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
</servlet>

<servlet>
<servlet-name>dspLoader</servlet-name>
<servlet-class>org.zkoss.web.servlet.dsp.InterpreterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dspLoader</servlet-name>
<url-pattern>*.dsp</url-pattern>
</servlet-mapping>


<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>appformacionwb/zkau/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<mime-mapping>
<extension>doc</extension>
<mime-type>application/vnd.ms-word</mime-type>
</mime-mapping>
<mime-mapping>
<extension>gif</extension>
<mime-type>image/gif</mime-type>
</mime-mapping>
<mime-mapping>
<extension>htm</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpeg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>text/javascript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>pdf</extension>
<mime-type>application/pdf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>png</extension>
<mime-type>image/png</mime-type>
</mime-mapping>
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xls</extension>
<mime-type>application/vnd.ms-excel</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xml</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>zhtml</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>zul</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
</web-app>

我的过滤器

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

public class AppFormacionFilter implements Filter {

private final static Logger log = Logger.getLogger(AppFormacionFilter.class.getName());

@Override
public void destroy() {

}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {


request.setCharacterEncoding("UTF-8");

if (request instanceof HttpServletRequest) {

HttpServletRequest req = (HttpServletRequest) request;

if(req.getHeader("iv-user")==null){
log.info("El usuario ingresado es vacio ");
}else{
log.info("El usuario que ingreso "+req.getHeader("iv-user"));

req.getSession().setAttribute("username", req.getHeader("iv-user"));
req.getSession().setAttribute("urlRedirect", req.getHeader("referer"));

String uriReqURI = req.getHeader("Cookie");

String[] uriArray = StringUtils.split(uriReqURI, ";");

if(uriArray.length>0){
req.getSession().setAttribute("url", uriArray[0]);
log.info(uriArray[0]);
}

}

HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.sendRedirect("/someUrl.zul");

} else {
chain.doFilter(request, response);
}

}

@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

}

拜托,也许有一些例子?谢谢大家......!!!

最佳答案

过滤器 appFormacionFilterSesion 配置为在任何路径 /* 上运行,这意味着当执行路径 httpResponse.sendRedirect("/someUrl.zul") 时,您的过滤器代码将再次被调用。也许您需要将 req.getSession().getAttribute("username") != null 添加到您的主要条件中。

关于java - zk + Spring 4 + 使用 webseal 进行预身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45602599/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com