同时支持打包为Jar和War
This commit is contained in:
@@ -10,6 +10,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
@@ -23,6 +24,7 @@ import java.io.IOException;
|
||||
* @author lin
|
||||
*/
|
||||
@WebFilter(filterName = "ApiAccessFilter", urlPatterns = "/api/*", asyncSupported=true)
|
||||
@Component
|
||||
public class ApiAccessFilter extends OncePerRequestFilter {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ApiAccessFilter.class);
|
||||
@@ -48,7 +50,7 @@ public class ApiAccessFilter extends OncePerRequestFilter {
|
||||
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
|
||||
if (uriName != null && userSetting.getLogInDatebase()) {
|
||||
if (uriName != null && userSetting != null && userSetting.getLogInDatebase() != null && userSetting.getLogInDatebase()) {
|
||||
|
||||
LogDto logDto = new LogDto();
|
||||
logDto.setName(uriName);
|
||||
|
||||
30
src/main/java/com/genersoft/iot/vmp/conf/ServiceInfo.java
Normal file
30
src/main/java/com/genersoft/iot/vmp/conf/ServiceInfo.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.genersoft.iot.vmp.conf;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ServiceInfo implements ApplicationListener<WebServerInitializedEvent> {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(ServiceInfo.class);
|
||||
|
||||
private static int serverPort;
|
||||
|
||||
public static int getServerPort() {
|
||||
return serverPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(WebServerInitializedEvent event) {
|
||||
// 项目启动获取启动的端口号
|
||||
ServiceInfo.serverPort = event.getWebServer().getPort();
|
||||
logger.info("项目启动获取启动的端口号: " + ServiceInfo.serverPort);
|
||||
}
|
||||
|
||||
public void setServerPort(int serverPort) {
|
||||
ServiceInfo.serverPort = serverPort;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.genersoft.iot.vmp.conf.security;
|
||||
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.SessionCookieConfig;
|
||||
import javax.servlet.SessionTrackingMode;
|
||||
import java.util.Collections;
|
||||
|
||||
public class UrlTokenHandler extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
public void onStartup(ServletContext servletContext) throws ServletException {
|
||||
super.onStartup(servletContext);
|
||||
|
||||
servletContext.setSessionTrackingModes(
|
||||
Collections.singleton(SessionTrackingMode.COOKIE)
|
||||
);
|
||||
SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
|
||||
sessionCookieConfig.setHttpOnly(true);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user