configure filter
This commit is contained in:
parent
3a91ccd23e
commit
b26eb7d873
|
@ -113,7 +113,7 @@ public class TestPlanActionController extends BaseControllerService {
|
|||
runTestPlanResultModel.getTestPlanId().toString(),
|
||||
runTestPlanResultModel.getCurrentStatus().toString());
|
||||
if (model.get("testPlanTaskList") == null) {
|
||||
List<TestPlanTaskModel> testPlanTaskModels = new ArrayList<>();
|
||||
List<TestPlanTaskModel> testPlanTaskModels = new ArrayList<TestPlanTaskModel>();
|
||||
testPlanTaskModels.add(testPlanTaskModel);
|
||||
model.put("testPlanTaskList", testPlanTaskModels);
|
||||
System.out.println("add the test task!");
|
||||
|
@ -243,10 +243,11 @@ public class TestPlanActionController extends BaseControllerService {
|
|||
Iterator<RunningScriptModel> itr = runningScriptModelList.iterator();
|
||||
while (itr.hasNext()) {
|
||||
RunningScriptModel runningScriptModel = itr.next();
|
||||
|
||||
|
||||
ScriptIndexModel scriptIndexModel = new ScriptIndexModel();
|
||||
scriptIndexModel.setScriptId(runningScriptModel.getScriptId());
|
||||
System.out.println("buildRunningIndexModel"+runningScriptModel.getScriptId());
|
||||
System.out.println("buildRunningIndexModel"
|
||||
+ runningScriptModel.getScriptId());
|
||||
String scriptName = this.getScriptService()
|
||||
.queryScript(runningScriptModel.getScriptId(), accessToken)
|
||||
.getName();
|
||||
|
@ -263,9 +264,9 @@ public class TestPlanActionController extends BaseControllerService {
|
|||
@RequestMapping("getScriptBriefStatus")
|
||||
@ResponseBody
|
||||
public ScriptBriefResultModel getAgentBriefStatus(
|
||||
|
||||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam String testPlanId,@RequestParam String scriptID) {
|
||||
|
||||
@ModelAttribute("accessToken") String accessToken,
|
||||
@RequestParam String testPlanId, @RequestParam String scriptID) {
|
||||
System.out.println("getscriptbriefstatus");
|
||||
if (scriptID == null) {
|
||||
System.out.println("the scriptID is null");
|
||||
|
@ -353,7 +354,8 @@ public class TestPlanActionController extends BaseControllerService {
|
|||
+ testPlanId.toString() + ".pdf\"");
|
||||
response.addHeader("Content-Length", "" + pdfBuffer.length);
|
||||
response.setContentType("application/pdf");
|
||||
System.out.println("set response contentType:"+ response.getContentType());
|
||||
System.out.println("set response contentType:"
|
||||
+ response.getContentType());
|
||||
outputStream.write(pdfBuffer);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
|
|
@ -7,13 +7,13 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
|
||||
import org.bench4q.web.entity.master.Script;
|
||||
|
||||
|
||||
@XmlRootElement(name = "OperateScriptServerResponse")
|
||||
public class OperateScriptServerResponseModel {
|
||||
private boolean success;
|
||||
private String failCauseString;
|
||||
private String hostNameString;
|
||||
private int port;
|
||||
private String fileName;
|
||||
private List<Script> scripts;
|
||||
|
||||
@XmlElement
|
||||
|
@ -52,6 +52,15 @@ public class OperateScriptServerResponseModel {
|
|||
this.port = port;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<Script> getScripts() {
|
||||
return scripts;
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package org.bench4q.web.security;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
public class SessionFilter extends OncePerRequestFilter {
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request,
|
||||
HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
String[] notFilter = new String[] { "login.html", "index.html" };
|
||||
|
||||
// 请求的uri
|
||||
String uri = request.getRequestURI();
|
||||
System.out.println(uri);
|
||||
// uri中包含background时才进行过滤
|
||||
if (uri.indexOf("background") != -1) {
|
||||
// 是否过滤
|
||||
boolean doFilter = true;
|
||||
for (String s : notFilter) {
|
||||
if (uri.indexOf(s) != -1) {
|
||||
// 如果uri中包含不过滤的uri,则不进行过滤
|
||||
doFilter = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (doFilter) {
|
||||
// 执行过滤
|
||||
// 从session中获取登录者实体
|
||||
Object obj = request.getSession().getAttribute("loginedUser");
|
||||
if (null == obj) {
|
||||
// 如果session中不存在登录者实体,则弹出框提示重新登录
|
||||
// 设置request和response的字符集,防止乱码
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String loginPage = "....";
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("<script type=\"text/javascript\">");
|
||||
builder.append("alert('网页过期,请重新登录!');");
|
||||
builder.append("window.top.location.href='");
|
||||
builder.append(loginPage);
|
||||
builder.append("';");
|
||||
builder.append("</script>");
|
||||
out.print(builder.toString());
|
||||
} else {
|
||||
// 如果session中存在登录者实体,则继续
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
} else {
|
||||
// 如果不执行过滤,则继续
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
} else {
|
||||
// 如果uri中不包含background,则继续
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,5 +7,4 @@
|
|||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
<context:component-scan base-package="org.bench4q" />
|
||||
<mvc:annotation-driven />
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:component-scan base-package="org.bench4q.web" />
|
||||
|
||||
<mvc:resources mapping="/images/**" location="/images/" />
|
||||
|
@ -15,12 +14,7 @@
|
|||
<mvc:resources mapping="/static/**" location="/static/" />
|
||||
<mvc:resources location="/img/" mapping="/img/**" />
|
||||
<mvc:default-servlet-handler />
|
||||
<mvc:interceptors>
|
||||
<mvc:interceptor>
|
||||
<mvc:mapping path="/**" />
|
||||
<bean class="org.bench4q.web.security.SecurityFilter"></bean>
|
||||
</mvc:interceptor>
|
||||
</mvc:interceptors>
|
||||
|
||||
<!-- ③:对模型视图名称的解析,即在模型视图名称添加前后缀 -->
|
||||
<bean
|
||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
|
|
|
@ -6,6 +6,14 @@
|
|||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
<filter>
|
||||
<filter-name>sessionFilter</filter-name>
|
||||
<filter-class>org.bench4q.web.security.SessionFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>sessionFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
<servlet>
|
||||
<servlet-name>dispatcherServlet</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
|
@ -21,9 +29,9 @@
|
|||
<servlet-name>dispatcherServlet</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
<context-param>
|
||||
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
|
||||
<param-value>i18n</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
|
||||
<param-value>i18n</param-value>
|
||||
</context-param>
|
||||
|
||||
</web-app>
|
Loading…
Reference in New Issue