sunyj 8 лет назад
Родитель
Сommit
384a2bb6b9

+ 4 - 0
kanban-auth/pom.xml

@@ -17,5 +17,9 @@
 			<artifactId>kanban-common</artifactId>
 			<version>${kanban.common.version}</version>
 		</dependency>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-webmvc</artifactId>
+		</dependency>
 	</dependencies>
 </project>

+ 9 - 1
kanban-auth/src/main/java/com/uas/kanban/controller/ResourcePointController.java

@@ -1,6 +1,9 @@
 package com.uas.kanban.controller;
 
+import java.io.IOException;
+
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -39,7 +42,12 @@ public class ResourcePointController extends BaseController<ResourcePoint> {
 	@ResponseBody
 	public boolean login(@NotEmpty("name") String name, @NotEmpty("password") String password,
 			HttpServletRequest request) {
-		return resourcePointService.login(name, password);
+		boolean success = resourcePointService.login(name, password);
+		if (success) {
+			request.getSession().setAttribute("name", name);
+			return true;
+		}
+		return false;
 	}
 
 	/**

+ 40 - 0
kanban-auth/src/main/java/com/uas/kanban/filter/SecurityInterceptor.java

@@ -0,0 +1,40 @@
+package com.uas.kanban.filter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+/**
+ * 安全验证
+ * 
+ * @author sunyj
+ * @since 2017年9月12日 下午2:04:36
+ */
+@Component
+public class SecurityInterceptor extends HandlerInterceptorAdapter {
+
+	private Logger logger = LoggerFactory.getLogger(getClass());
+
+	@Override
+	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
+			throws Exception {
+		String requestURI = request.getRequestURI();
+		StringBuffer requestURL = request.getRequestURL();
+		String contextPath = request.getContextPath();
+		logger.info("requestURI " + requestURI);
+		logger.info("requestURL " + requestURL.toString());
+		logger.info("contextPath " + contextPath);
+		Object resourcePointName = request.getSession().getAttribute("name");
+		logger.info("resourcePointName " + resourcePointName);
+		if (resourcePointName == null) {
+			response.sendRedirect("/login");
+			return false;
+		}
+		return true;
+	}
+
+}

+ 11 - 0
kanban-console/src/main/java/com/uas/kanban/WebAppConfiguration.java

@@ -4,6 +4,7 @@ import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.List;
 
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.web.servlet.FilterRegistrationBean;
 import org.springframework.boot.web.servlet.ServletRegistrationBean;
 import org.springframework.context.annotation.Bean;
@@ -13,6 +14,7 @@ import org.springframework.http.MediaType;
 import org.springframework.http.converter.HttpMessageConverter;
 import org.springframework.http.converter.StringHttpMessageConverter;
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
 import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
@@ -24,6 +26,7 @@ import com.alibaba.druid.support.http.WebStatFilter;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.alibaba.fastjson.support.config.FastJsonConfig;
 import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
+import com.uas.kanban.filter.SecurityInterceptor;
 
 /**
  * Web相关配置
@@ -106,4 +109,12 @@ public class WebAppConfiguration extends WebMvcConfigurerAdapter {
 		return filterRegistrationBean;
 	}
 
+	@Autowired
+	private SecurityInterceptor securityInterceptor;
+
+	@Override
+	public void addInterceptors(InterceptorRegistry registry) {
+		registry.addInterceptor(securityInterceptor).addPathPatterns("/*").excludePathPatterns("/WEB-INF/*","/login","/error");
+	}
+
 }

+ 1 - 1
kanban-console/src/main/resources/bootstrap.yml

@@ -3,7 +3,7 @@ spring:
   name: kanban
  cloud:
   config:
-   uri: http://config.ubtob.com
+   uri: http://10.10.100.145:8080
  http:
   encoding:
    force: true