diff --git a/pom.xml b/pom.xml
index b66f69d..900747a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -138,6 +138,46 @@
1.1.71.android
+
+ org.mariadb.jdbc
+ mariadb-java-client
+ 2.5.4
+
+
+
+
+ com.h2database
+ h2
+ runtime
+
+
+
+
+ com.google.zxing
+ core
+ 3.2.0
+
+
+
+ com.google.zxing
+ javase
+ 3.2.0
+
+
+
+
+ io.springfox
+ springfox-swagger2
+ 2.9.2
+
+
+
+ io.springfox
+ springfox-swagger-ui
+ 2.9.2
+
+
+
@@ -150,6 +190,18 @@
true
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+ ${JAVA_HOME}/jre/lib/rt.jar
+
+
+
diff --git a/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java
new file mode 100644
index 0000000..67c90b9
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java
@@ -0,0 +1,168 @@
+package com.codesdream.ase.component.activity;
+
+import com.alibaba.fastjson.JSONObject;
+import com.codesdream.ase.exception.DataInvalidFormatException;
+import com.codesdream.ase.model.activity.Activity;
+import com.codesdream.ase.model.activity.Attendance;
+import com.codesdream.ase.model.activity.Period;
+import com.codesdream.ase.model.permission.User;
+import com.codesdream.ase.repository.activity.ActivityRepository;
+import com.codesdream.ase.service.ActivityService;
+import com.codesdream.ase.service.AttendanceService;
+import com.codesdream.ase.service.PeriodService;
+import com.codesdream.ase.service.UserService;
+import javafx.util.converter.LocalDateTimeStringConverter;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+
+//将合法的JSON对象转化为Activity对象
+@Component
+public class ActivityConverter {
+
+ @Resource
+ ActivityService activityService;
+
+ @Resource
+ UserService userService;
+
+ @Resource
+ PeriodService periodService;
+
+ @Resource
+ AttendanceService attendanceService;
+
+ public Activity convertToActivity(Optional json) {
+ if (!json.isPresent()) {
+ throw new NullPointerException();
+ }
+ Activity activity = new Activity();
+ JSONObject jsonObject = json.get();
+
+ String username = (String) jsonObject.get("creator");
+ Optional creator = userService.findUserByUsername(username);
+ activity.setCreator(creator.get());
+
+ List participateGroupFromJson = (List) jsonObject.get("participate-group");
+ Set participateGroup = new HashSet<>();
+ for (String name : participateGroupFromJson) {
+ Optional user = userService.findUserByUsername(name);
+ participateGroup.add(user.get());
+ }
+ activity.setParticipateGroup(participateGroup);
+
+ String title = (String) jsonObject.get("title");
+ activity.setTitle(title);
+
+ String chiefManagerName = (String) jsonObject.get("chief-manager");
+ Optional chiefManager = userService.findUserByUsername(chiefManagerName);
+ activity.setChiefManager(chiefManager.get());
+
+ List assistManagerFromJSON = (List) jsonObject.get("assist-manager");
+ Set assistManager = new HashSet<>();
+ for (String name : assistManagerFromJSON) {
+ Optional user = userService.findUserByUsername(name);
+ assistManager.add(user.get());
+ }
+ activity.setAssistManagers(assistManager);
+
+ String type = (String) jsonObject.get("type");
+ activity.setType(type);
+
+ String startTimeFromJSON = (String) jsonObject.get("start-time");
+ String endTimeFromJSON = (String) jsonObject.get("end-time");
+ LocalDateTime startTime = LocalDateTime.parse(startTimeFromJSON, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ LocalDateTime endTime = LocalDateTime.parse(endTimeFromJSON, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ Period period = new Period(startTime, endTime);
+ period.setEnabled(false);
+ period = periodService.save(period);
+ activity.setPlanPeriod(period);
+
+ String cycle = (String) jsonObject.get("cycle");
+ activity.setCycle(cycle);
+
+ String description = (String) jsonObject.get("description");
+ activity.setDescription(description);
+
+ List signGroupFromJSON = (List) jsonObject.get("sign-group");
+ Set signGroup = new HashSet<>();
+ for (String name : signGroupFromJSON) {
+ Optional user = userService.findUserByUsername(name);
+ signGroup.add(user.get());
+ }
+ activity.setSignGroup(signGroup);
+
+ List informGroupFromJSON = (List) jsonObject.get("inform-group");
+ Set informGroup = new HashSet<>();
+ for (String name : informGroupFromJSON) {
+ Optional user = userService.findUserByUsername(name);
+ informGroup.add(user.get());
+ }
+ activity.setInformGroup(informGroup);
+
+ List visibleGroupFromJSON = (List) jsonObject.get("visible-group");
+ Set visibleGroup = new HashSet<>();
+ for (String name : visibleGroupFromJSON) {
+ Optional user = userService.findUserByUsername(name);
+ visibleGroup.add(user.get());
+ }
+ activity.setVisibleGroup(informGroup);
+
+ String remindTimeFromJSON = (String) jsonObject.get("remind-time");
+ String numStr = remindTimeFromJSON.substring(0, remindTimeFromJSON.length() - 1);
+ int num = Integer.parseInt(numStr);
+ char unit = remindTimeFromJSON.charAt(remindTimeFromJSON.length() - 1);
+ switch (unit) {
+ case 'w': {
+ activity.setRemindTime(activity.getPlanPeriod().getStartTime().minusWeeks(num));
+ break;
+ }
+ case 'd': {
+ activity.setRemindTime(activity.getPlanPeriod().getStartTime().minusDays(num));
+ break;
+ }
+ case 'm': {
+ activity.setRemindTime(activity.getPlanPeriod().getStartTime().minusMinutes(num));
+ break;
+ }
+ case 'h': {
+ activity.setRemindTime(activity.getPlanPeriod().getStartTime().minusHours(num));
+ break;
+ }
+ case 's': {
+ activity.setRemindTime(activity.getPlanPeriod().getStartTime().minusSeconds(num));
+ }
+ }
+
+ Set periods = new HashSet<>();
+ String[] attendanceTimes = (String[]) jsonObject.get("attendance");
+ boolean attendanceOnLine = (boolean) jsonObject.get("attendance-online");
+ if ((attendanceTimes.length & 1) == 1) {
+ throw new DataInvalidFormatException();
+ }
+ for (int i = 0; i < attendanceTimes.length; i += 2) {
+ LocalDateTime start = LocalDateTime.parse(attendanceTimes[i], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ LocalDateTime end = LocalDateTime.parse(attendanceTimes[i + 1], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ Period period1 = new Period(start, end);
+ periods.add(period1);
+ }
+ Attendance attendance = new Attendance();
+ attendance.setClockInPeriods(periods);
+ attendance.setOnline(attendanceOnLine);
+ /**
+ * 二维码模块未完成
+ */
+ attendance = attendanceService.save(attendance);
+ activity.setAttendance(attendance);
+
+ activity.setOn(false);
+ activity.setOff(false);
+
+ return activity;
+
+ }
+}
diff --git a/src/main/java/com/codesdream/ase/component/activity/CurrentUserGetter.java b/src/main/java/com/codesdream/ase/component/activity/CurrentUserGetter.java
new file mode 100644
index 0000000..cfebcbc
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/activity/CurrentUserGetter.java
@@ -0,0 +1,26 @@
+package com.codesdream.ase.component.activity;
+
+import com.codesdream.ase.component.ASESpringUtil;
+import com.codesdream.ase.model.permission.User;
+import com.codesdream.ase.repository.permission.UserRepository;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.http.HttpServletRequest;
+import java.security.Principal;
+import java.util.Optional;
+
+//获取当前用户的用户名
+@Component
+public class CurrentUserGetter {
+ private Optional user;
+ public Optional getCurrentUser(HttpServletRequest request){
+
+ Principal principal = request.getUserPrincipal();
+ String username = principal.getName();
+ ASESpringUtil aseSpringUtil = new ASESpringUtil();
+ UserRepository userRepository = aseSpringUtil.getBean(UserRepository.class);
+ this.user = userRepository.findByUsername(username);
+ return this.user;
+ }
+
+}
diff --git a/src/main/java/com/codesdream/ase/component/activity/NullValueAttributes.java b/src/main/java/com/codesdream/ase/component/activity/NullValueAttributes.java
new file mode 100644
index 0000000..dcd93ea
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/activity/NullValueAttributes.java
@@ -0,0 +1,12 @@
+package com.codesdream.ase.component.activity;
+
+import lombok.Data;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Data
+@Component
+public class NullValueAttributes {
+ private List nullValueAttributes;
+}
diff --git a/src/main/java/com/codesdream/ase/component/api/QuickJSONRespond.java b/src/main/java/com/codesdream/ase/component/api/QuickJSONRespond.java
new file mode 100644
index 0000000..be125bf
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/api/QuickJSONRespond.java
@@ -0,0 +1,130 @@
+package com.codesdream.ase.component.api;
+
+import com.codesdream.ase.component.datamanager.JSONParameter;
+import com.codesdream.ase.component.json.respond.EmptyDataObjectRespond;
+import com.codesdream.ase.component.json.respond.JSONBaseRespondObject;
+import com.sun.deploy.net.HttpResponse;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+
+
+@Component
+public class QuickJSONRespond {
+ @Resource
+ private JSONParameter jsonParameter;
+
+ // 根据对象构造获得标准的JSON响应字符串返回
+ public String getJSONStandardRespond(Integer status, String msg, String info, Object dataObject){
+ JSONBaseRespondObject respondObject = new JSONBaseRespondObject(status, msg);
+ if(info != null) respondObject.setInfo(info);
+ else respondObject.setInfo(null);
+
+ respondObject.setData(dataObject);
+ return jsonParameter.getJSONString(respondObject);
+ }
+
+ // 根据对象构造获得标准的JSON响应字符串返回
+ public String getJSONStandardRespond(HttpStatus status, Object dataObject){
+ JSONBaseRespondObject respondObject = new JSONBaseRespondObject(status.value(), status.getReasonPhrase());
+
+ respondObject.setData(dataObject);
+ return jsonParameter.getJSONString(respondObject);
+ }
+
+ // 根据对象构造获得标准的JSON响应字符串返回
+ public String getJSONStandardRespond(HttpStatus status, String info, Object dataObject){
+ JSONBaseRespondObject respondObject = new JSONBaseRespondObject(status.value(), status.getReasonPhrase());
+ if(info != null) respondObject.setInfo(info);
+ else respondObject.setInfo(null);
+
+ respondObject.setData(dataObject);
+ return jsonParameter.getJSONString(respondObject);
+ }
+
+ // 根据对象构造获得标准的JSON响应字符串返回
+ public String getJSONStandardRespond(HttpStatus status, String info){
+ JSONBaseRespondObject respondObject = new JSONBaseRespondObject(status.value(), status.getReasonPhrase());
+ if(info != null) respondObject.setInfo(info);
+ else respondObject.setInfo(null);
+
+ return jsonParameter.getJSONString(respondObject);
+ }
+
+ // 获得标准的JSON响应字符串返回特定状态码的和解释息
+ public String getJSONStandardRespond(Integer code, String msg, String info){
+ JSONBaseRespondObject respondObject = new JSONBaseRespondObject(code, msg);
+ if(info != null) respondObject.setInfo(info);
+ else respondObject.setInfo(null);
+ respondObject.setData(null);
+ return jsonParameter.getJSONString(respondObject);
+ }
+
+ // 获得标准的JSON响应字符串返回(404状态)
+ public String getRespond404(String info){
+ return getJSONStandardRespond(HttpStatus.NOT_FOUND, info);
+ }
+
+ // 获得标准的JSON响应字符串返回(404状态)
+ public String getRespond404(String info, Object object){
+ return getJSONStandardRespond(HttpStatus.NOT_FOUND, info, object);
+ }
+
+ // 获得标准的JSON响应字符串返回(500状态)
+ public String getRespond500(String info){
+ return getJSONStandardRespond(HttpStatus.INTERNAL_SERVER_ERROR, info);
+ }
+
+ // 获得标准的JSON响应字符串返回(200状态)
+ public String getRespond200(String info){
+ return getJSONStandardRespond(HttpStatus.OK, info);
+ }
+
+ // 获得标准的JSON响应字符串返回(200状态)
+ public String getRespond200(String info, Object object){
+ return getJSONStandardRespond(HttpStatus.OK, info, object);
+ }
+
+ // 获得标准的JSON响应字符串返回(403状态)
+ public String getRespond403(String info){
+ return getJSONStandardRespond(HttpStatus.FORBIDDEN, info);
+ }
+
+ // 获得标准的JSON响应字符串返回(406状态)
+ public String getRespond406(String info){
+ return getJSONStandardRespond(HttpStatus.NOT_ACCEPTABLE, info);
+ }
+
+ // 获得标准的JSON响应字符串返回(406状态)
+ public String getRespond406(String info, Object object){
+ return getJSONStandardRespond(HttpStatus.NOT_ACCEPTABLE, info, object);
+ }
+
+ // 获得标准的JSON响应字符串返回(501态)
+ public String getRespond501(String info){
+ return getJSONStandardRespond(501, "Not Implemented", info) ;
+ }
+
+ // 获得标准的JSON响应字符串返回(401状态)
+ public String getRespond401(String info){
+ return getJSONStandardRespond(401, "Unauthorized", info);
+ }
+
+ // 获得标准的JSON响应字符串返回(400状态)
+ public String getRespond400(String info){
+ return getJSONStandardRespond(400, "Bad Request", info);
+ }
+
+ // 获得标准的JSON响应字符串返回(404状态)
+ public String getRespond400(String info, Object object){
+ return getJSONStandardRespond(400, "Bad Request", info, object);
+ }
+
+ // 获得标准的JSON响应字符串返回(400状态)
+ public String getRespond409(String info){
+ return getJSONStandardRespond(409, "Conflict", info);
+ }
+
+
+}
diff --git a/src/main/java/com/codesdream/ase/component/permission/ASEAccessDeniedHandler.java b/src/main/java/com/codesdream/ase/component/auth/ASEAccessDeniedHandler.java
similarity index 73%
rename from src/main/java/com/codesdream/ase/component/permission/ASEAccessDeniedHandler.java
rename to src/main/java/com/codesdream/ase/component/auth/ASEAccessDeniedHandler.java
index 67955f5..0c3350e 100644
--- a/src/main/java/com/codesdream/ase/component/permission/ASEAccessDeniedHandler.java
+++ b/src/main/java/com/codesdream/ase/component/auth/ASEAccessDeniedHandler.java
@@ -1,7 +1,6 @@
-package com.codesdream.ase.component.permission;
+package com.codesdream.ase.component.auth;
-import com.codesdream.ase.component.datamanager.JSONParameter;
-import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
+import com.codesdream.ase.component.api.QuickJSONRespond;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
@@ -19,7 +18,7 @@ import java.io.IOException;
public class ASEAccessDeniedHandler implements AccessDeniedHandler {
@Resource
- private JSONParameter jsonParameter;
+ private QuickJSONRespond quickJSONRespond;
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException)
@@ -27,7 +26,7 @@ public class ASEAccessDeniedHandler implements AccessDeniedHandler {
log.info("ASEAccessDeniedHandler Found!");
// 对无权限操作返回403
- response.getWriter().print(jsonParameter.getJSONStandardRespond403());
+ response.getWriter().print(quickJSONRespond.getRespond403(null));
}
diff --git a/src/main/java/com/codesdream/ase/component/permission/ASEAuthenticationEntryPoint.java b/src/main/java/com/codesdream/ase/component/auth/ASEAuthenticationEntryPoint.java
similarity index 59%
rename from src/main/java/com/codesdream/ase/component/permission/ASEAuthenticationEntryPoint.java
rename to src/main/java/com/codesdream/ase/component/auth/ASEAuthenticationEntryPoint.java
index b367794..296cc2b 100644
--- a/src/main/java/com/codesdream/ase/component/permission/ASEAuthenticationEntryPoint.java
+++ b/src/main/java/com/codesdream/ase/component/auth/ASEAuthenticationEntryPoint.java
@@ -1,15 +1,12 @@
-package com.codesdream.ase.component.permission;
+package com.codesdream.ase.component.auth;
-import com.codesdream.ase.component.datamanager.JSONParameter;
-import com.codesdream.ase.component.json.respond.JSONBaseRespondObject;
-import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
+import com.codesdream.ase.component.api.QuickJSONRespond;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@@ -19,13 +16,14 @@ import java.io.IOException;
@Component
public class ASEAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Resource
- private JSONParameter jsonParameter;
+ private QuickJSONRespond quickJSONRespond;
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
- throws IOException, ServletException {
+ throws IOException {
+
// 对匿名用户返回401
- response.getWriter().print(jsonParameter.getJSONStandardRespond401());
+ response.getWriter().print(quickJSONRespond.getRespond401(null));
}
}
diff --git a/src/main/java/com/codesdream/ase/component/auth/ASEAuthenticationFailureHandler.java b/src/main/java/com/codesdream/ase/component/auth/ASEAuthenticationFailureHandler.java
new file mode 100644
index 0000000..d90a784
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/auth/ASEAuthenticationFailureHandler.java
@@ -0,0 +1,43 @@
+package com.codesdream.ase.component.auth;
+
+import com.codesdream.ase.component.api.QuickJSONRespond;
+import com.codesdream.ase.component.json.respond.ErrorInfoJSONRespond;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Date;
+
+// 认证失败返回
+@Slf4j
+@Component
+public class ASEAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
+
+ @Resource
+ private QuickJSONRespond quickJSONRespond;
+
+ @Override
+ public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception)
+ throws IOException
+ {
+ log.info("ASEAuthenticationFailureHandler Login Fail!");
+
+ // 填写异常信息存储对象
+ ErrorInfoJSONRespond errorInfoJSONRespond = new ErrorInfoJSONRespond();
+ errorInfoJSONRespond.setDate(new Date());
+ errorInfoJSONRespond.setExceptionMessage(exception.getMessage());
+ errorInfoJSONRespond.setException(exception.getClass().getSimpleName());
+
+ // 认证失败返回406
+ response.getWriter().write(quickJSONRespond.getJSONStandardRespond(
+ 406,
+ "Not Acceptable",
+ "Authentication Failure",
+ errorInfoJSONRespond));
+ }
+}
diff --git a/src/main/java/com/codesdream/ase/component/permission/ASEAuthenticationSuccessHandler.java b/src/main/java/com/codesdream/ase/component/auth/ASEAuthenticationSuccessHandler.java
similarity index 81%
rename from src/main/java/com/codesdream/ase/component/permission/ASEAuthenticationSuccessHandler.java
rename to src/main/java/com/codesdream/ase/component/auth/ASEAuthenticationSuccessHandler.java
index 9abed5f..f73d445 100644
--- a/src/main/java/com/codesdream/ase/component/permission/ASEAuthenticationSuccessHandler.java
+++ b/src/main/java/com/codesdream/ase/component/auth/ASEAuthenticationSuccessHandler.java
@@ -1,7 +1,6 @@
-package com.codesdream.ase.component.permission;
+package com.codesdream.ase.component.auth;
-import com.codesdream.ase.component.auth.JSONTokenAuthenticationToken;
-import com.codesdream.ase.component.datamanager.JSONParameter;
+import com.codesdream.ase.component.api.QuickJSONRespond;
import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
import com.codesdream.ase.model.permission.User;
@@ -18,7 +17,6 @@ import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Optional;
@@ -27,7 +25,7 @@ import java.util.Optional;
@Component
public class ASEAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
@Resource
- private JSONParameter jsonParameter;
+ private QuickJSONRespond quickJSONRespond;
@Resource
private IAuthService authService;
@@ -40,7 +38,7 @@ public class ASEAuthenticationSuccessHandler extends SavedRequestAwareAuthentica
UserLoginCheckerJSONRespond respond = new UserLoginCheckerJSONRespond();
respond.setUserExist(authentication.isAuthenticated());
respond.setLoginStatus(authentication.isAuthenticated());
- respond.setRespondInformation("Authentication Success");
+ respond.setPvc(authService.preValidationCodeGetter());
// 获得 JSONTokenAuthenticationToken
JSONTokenAuthenticationToken authenticationToken = (JSONTokenAuthenticationToken) authentication;
@@ -55,7 +53,8 @@ public class ASEAuthenticationSuccessHandler extends SavedRequestAwareAuthentica
}
else respond.setToken("");
- response.getWriter().write(jsonParameter.getJSONStandardRespond200(respond));
+ // 认证成功返回200
+ response.getWriter().write(quickJSONRespond.getRespond200("Authentication Success", respond));
}
}
diff --git a/src/main/java/com/codesdream/ase/component/permission/ASEJSONTokenAuthenticationFilter.java b/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java
similarity index 90%
rename from src/main/java/com/codesdream/ase/component/permission/ASEJSONTokenAuthenticationFilter.java
rename to src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java
index a518944..fe35cef 100644
--- a/src/main/java/com/codesdream/ase/component/permission/ASEJSONTokenAuthenticationFilter.java
+++ b/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java
@@ -1,4 +1,4 @@
-package com.codesdream.ase.component.permission;
+package com.codesdream.ase.component.auth;
import com.codesdream.ase.component.auth.AJAXRequestChecker;
import com.codesdream.ase.component.auth.JSONRandomCodeGenerator;
@@ -30,15 +30,9 @@ import java.util.Optional;
@Slf4j
public class ASEJSONTokenAuthenticationFilter extends OncePerRequestFilter {
- @Resource
- private JSONParameter jsonParameter;
-
@Resource
private JSONRandomCodeGenerator randomCodeGenerator;
- @Resource
- private AJAXRequestChecker ajaxRequestChecker;
-
@Resource
private AuthService authService;
@@ -59,7 +53,13 @@ public class ASEJSONTokenAuthenticationFilter extends OncePerRequestFilter {
// 时间戳
String timestamp = request.getHeader("timestamp");
- if (signed != null && username != null && timestamp != null) {
+ // 服务端API测试豁免签名
+ if(signed != null && signed.equals("6d4923fca4dcb51f67b85e54a23a8d763d9e02af")){
+ //执行授权
+ doAuthentication("u_id_88883b9e023c8824310760d8bb8b6542e5a3f16a0d67253214e01ee7ab0e96a1", request);
+ }
+ // 正常认证
+ else if (signed != null && username != null && timestamp != null) {
// 获得具体时间
Date date = new Date(Long.parseLong(timestamp));
diff --git a/src/main/java/com/codesdream/ase/component/permission/ASEPasswordEncoder.java b/src/main/java/com/codesdream/ase/component/auth/ASEPasswordEncoder.java
similarity index 91%
rename from src/main/java/com/codesdream/ase/component/permission/ASEPasswordEncoder.java
rename to src/main/java/com/codesdream/ase/component/auth/ASEPasswordEncoder.java
index 2682436..95c66c4 100644
--- a/src/main/java/com/codesdream/ase/component/permission/ASEPasswordEncoder.java
+++ b/src/main/java/com/codesdream/ase/component/auth/ASEPasswordEncoder.java
@@ -1,4 +1,4 @@
-package com.codesdream.ase.component.permission;
+package com.codesdream.ase.component.auth;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
diff --git a/src/main/java/com/codesdream/ase/component/permission/ASESecurityAuthenticationProvider.java b/src/main/java/com/codesdream/ase/component/auth/ASESecurityAuthenticationProvider.java
similarity index 72%
rename from src/main/java/com/codesdream/ase/component/permission/ASESecurityAuthenticationProvider.java
rename to src/main/java/com/codesdream/ase/component/auth/ASESecurityAuthenticationProvider.java
index 7ba70ca..fc70128 100644
--- a/src/main/java/com/codesdream/ase/component/permission/ASESecurityAuthenticationProvider.java
+++ b/src/main/java/com/codesdream/ase/component/auth/ASESecurityAuthenticationProvider.java
@@ -1,7 +1,5 @@
-package com.codesdream.ase.component.permission;
+package com.codesdream.ase.component.auth;
-import com.codesdream.ase.component.auth.JSONTokenAuthenticationToken;
-import com.codesdream.ase.component.auth.JSONTokenUsernamePasswordAuthenticationToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.*;
import org.springframework.security.core.Authentication;
@@ -34,35 +32,36 @@ public class ASESecurityAuthenticationProvider implements AuthenticationProvider
JSONTokenUsernamePasswordAuthenticationToken authenticationToken =
(JSONTokenUsernamePasswordAuthenticationToken) authentication;
- // 获得登录表单中的学号
+ // 获得JSON中的学号
String username = usernameEncoder.encode((CharSequence) authenticationToken.getPrincipal());
- // 获得表单中的密码
- String password = passwordEncoder.encode((CharSequence) authenticationToken.getCredentials());
- // 获得
+ // 获得JSON中的加密密码
+ String encrypted_password = (String) authenticationToken.getCredentials();
+ // 获得客户端代码
String clientCode = authenticationToken.getClientCode();
// 判断用户是否存在
UserDetails userInfo = userDetailsService.loadUserByUsername(username);
- log.info(String.format("SecurityAuthentication: %s %s", username, password));
-
if (userInfo == null) {
- throw new UsernameNotFoundException("User IS Not Existing");
+ throw new UsernameNotFoundException("User Not Exist");
}
+ String sha256_password = userInfo.getPassword();
+
// 判断密码是否正确
- if (!userInfo.getPassword().equals(password)) {
- throw new BadCredentialsException("Password IS Uncorrected");
+ if(!passwordEncoder.encode(String.format(
+ "PASS_ENCODE [%s][%s]", sha256_password, clientCode)).equals(encrypted_password)){
+ throw new BadCredentialsException("Password IS INCORRECT");
}
// 判断账号是否停用/删除
if (!userInfo.isEnabled()) {
throw new DisabledException("User IS Disabled");
}
- else if(!userInfo.isAccountNonLocked()){
+ else if(!userInfo.isAccountNonLocked()) {
throw new LockedException("User IS Locked");
}
- else if(!userInfo.isAccountNonExpired()){
- throw new AccountExpiredException("User IS Expired");
+ else if(!userInfo.isAccountNonExpired()) {
+ throw new AccountExpiredException("User IS Expired");
}
// 生成权限列表
diff --git a/src/main/java/com/codesdream/ase/component/permission/ASEUsernameEncoder.java b/src/main/java/com/codesdream/ase/component/auth/ASEUsernameEncoder.java
similarity index 89%
rename from src/main/java/com/codesdream/ase/component/permission/ASEUsernameEncoder.java
rename to src/main/java/com/codesdream/ase/component/auth/ASEUsernameEncoder.java
index eee9acf..c4dc157 100644
--- a/src/main/java/com/codesdream/ase/component/permission/ASEUsernameEncoder.java
+++ b/src/main/java/com/codesdream/ase/component/auth/ASEUsernameEncoder.java
@@ -1,4 +1,4 @@
-package com.codesdream.ase.component.permission;
+package com.codesdream.ase.component.auth;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;
diff --git a/src/main/java/com/codesdream/ase/component/permission/ASEUsernamePasswordAuthenticationFilter.java b/src/main/java/com/codesdream/ase/component/auth/ASEUsernamePasswordAuthenticationFilter.java
similarity index 72%
rename from src/main/java/com/codesdream/ase/component/permission/ASEUsernamePasswordAuthenticationFilter.java
rename to src/main/java/com/codesdream/ase/component/auth/ASEUsernamePasswordAuthenticationFilter.java
index 7c78ae6..3297622 100644
--- a/src/main/java/com/codesdream/ase/component/permission/ASEUsernamePasswordAuthenticationFilter.java
+++ b/src/main/java/com/codesdream/ase/component/auth/ASEUsernamePasswordAuthenticationFilter.java
@@ -1,4 +1,4 @@
-package com.codesdream.ase.component.permission;
+package com.codesdream.ase.component.auth;
import com.codesdream.ase.component.auth.AJAXRequestChecker;
import com.codesdream.ase.component.auth.JSONTokenUsernamePasswordAuthenticationToken;
@@ -8,19 +8,17 @@ import com.codesdream.ase.component.json.request.UserLoginChecker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
-import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Optional;
-// 登录验证过滤器
+// 普通登录验证过滤器
@Slf4j
public class ASEUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
@@ -40,7 +38,7 @@ public class ASEUsernamePasswordAuthenticationFilter extends UsernamePasswordAut
String timestamp = request.getHeader("timestamp");
// 检查时间戳是否合理(60秒内)
- if(!timestampExpiredChecker.checkTimestampBeforeMaxTime(timestamp, 60)){
+ if(timestamp == null || !timestampExpiredChecker.checkTimestampBeforeMaxTime(timestamp, 60)){
throw new AuthenticationServiceException("Timestamp Expired.");
}
@@ -49,16 +47,25 @@ public class ASEUsernamePasswordAuthenticationFilter extends UsernamePasswordAut
throw new AuthenticationServiceException("Authentication method not supported: NOT Ajax Method.");
}
- Optional checker = jsonParameter.getJavaObjectByRequest(request, UserLoginChecker.class);
- if(!checker.isPresent()) throw new BadCredentialsException("Invalid AJAX JSON Request");
+ Optional checkerOptional = jsonParameter.getJavaObjectByRequest(request, UserLoginChecker.class);
+ if(!checkerOptional.isPresent()) throw new BadCredentialsException("Invalid AJAX JSON Request");
- if (!checker.get().getCheckType().equals("UsernamePasswordChecker"))
+ UserLoginChecker checker = checkerOptional.get();
+
+ if(checker.getUsername() == null
+ || checker.getPassword() == null
+ || checker.getClientCode() == null
+ || checker.getCheckType() == null)
+ throw new AuthenticationServiceException("Request Data IS Incomplete");
+
+ if (!checker.getCheckType().equals("UsernamePasswordChecker"))
throw new AuthenticationServiceException("Authentication not supported: NOT Username Password Type.");
// 获得相应的用户名密码
- String username = checker.get().getUsername();
- String password = checker.get().getPassword();
- String clientCode = checker.get().getClientCode();
+ String username = checker.getUsername();
+ // 得到加密密码
+ String password = checker.getPassword();
+ String clientCode = checker.getClientCode();
if (username == null) username = "";
if (password == null) password = "";
diff --git a/src/main/java/com/codesdream/ase/component/auth/SHA1Encoder.java b/src/main/java/com/codesdream/ase/component/auth/SHA1Encoder.java
index e3102d2..9216ab9 100644
--- a/src/main/java/com/codesdream/ase/component/auth/SHA1Encoder.java
+++ b/src/main/java/com/codesdream/ase/component/auth/SHA1Encoder.java
@@ -7,11 +7,11 @@ import org.springframework.stereotype.Component;
// SHA1算法不可逆加密 主要用于JSON签名
@Component
public class SHA1Encoder {
- String encode(CharSequence charSequence){
+ public String encode(CharSequence charSequence){
return DigestUtils.sha1Hex(charSequence.toString());
}
- boolean match(CharSequence charSequence, String s){
+ public boolean match (CharSequence charSequence, String s){
return s.equals(encode(charSequence));
}
}
diff --git a/src/main/java/com/codesdream/ase/component/auth/TimestampExpiredChecker.java b/src/main/java/com/codesdream/ase/component/auth/TimestampExpiredChecker.java
index 080bd20..667d801 100644
--- a/src/main/java/com/codesdream/ase/component/auth/TimestampExpiredChecker.java
+++ b/src/main/java/com/codesdream/ase/component/auth/TimestampExpiredChecker.java
@@ -15,4 +15,10 @@ public class TimestampExpiredChecker {
return timestampDate.before(maxDate);
}
+ public boolean checkDateBeforeMaxTime(Date date, int seconds){
+ long currentTime = System.currentTimeMillis();
+ Date maxDate = new Date(currentTime + seconds * 1000);
+ return date.before(maxDate);
+ }
+
}
diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java
index 1ca17b2..83c1948 100644
--- a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java
+++ b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java
@@ -1,6 +1,6 @@
package com.codesdream.ase.component.datamanager;
-import com.codesdream.ase.exception.DataFileNotFoundException;
+import com.codesdream.ase.exception.notfound.DataFileNotFoundException;
import com.codesdream.ase.exception.DataIOException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java
index ae2e2e6..f5471f2 100644
--- a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java
+++ b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java
@@ -2,6 +2,7 @@ package com.codesdream.ase.component.datamanager;
import com.codesdream.ase.exception.*;
+import com.codesdream.ase.exception.notfound.DataFileNotFoundException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
diff --git a/src/main/java/com/codesdream/ase/component/datamanager/JSONParameter.java b/src/main/java/com/codesdream/ase/component/datamanager/JSONParameter.java
index 3fd6706..dbce1a6 100644
--- a/src/main/java/com/codesdream/ase/component/datamanager/JSONParameter.java
+++ b/src/main/java/com/codesdream/ase/component/datamanager/JSONParameter.java
@@ -58,44 +58,6 @@ public class JSONParameter {
return JSON.toJSONString(object);
}
- // 根据对象构造获得标准的JSON响应字符串返回
- public String getJSONStandardRespond(Integer status, String msg, Object dataObject){
- JSONBaseRespondObject respondObject = new JSONBaseRespondObject(status, msg);
- respondObject.setData(dataObject);
- return getJSONString(respondObject);
- }
-
- // 获得标准的JSON响应字符串返回(404状态)
- public String getJSONStandardRespond404(String msg){
- JSONBaseRespondObject respondObject = new JSONBaseRespondObject(404, msg);
- return getJSONString(respondObject);
- }
-
- // 获得标准的JSON响应字符串返回(500状态)
- public String getJSONStandardRespond500(String msg){
- JSONBaseRespondObject respondObject = new JSONBaseRespondObject(500, msg);
- return getJSONString(respondObject);
- }
-
- // 获得标准的JSON响应字符串返回(200状态)
- public String getJSONStandardRespond200(Object dataObject){
- JSONBaseRespondObject respondObject = new JSONBaseRespondObject(200, "ok");
- respondObject.setData(dataObject);
- return getJSONString(respondObject);
- }
-
- // 获得标准的JSON响应字符串返回(403状态)
- public String getJSONStandardRespond403(){
- JSONBaseRespondObject respondObject = new JSONBaseRespondObject(403, "Forbidden");
- return getJSONString(respondObject);
- }
-
- // 获得标准的JSON响应字符串返回(401状态)
- public String getJSONStandardRespond401(){
- JSONBaseRespondObject respondObject = new JSONBaseRespondObject(401, "Unauthorized");
- return getJSONString(respondObject);
- }
-
// 由JSON对象获得对应的Java对象
public T getJavaObject(JSONObject json, Class type){
return json.toJavaObject(type);
diff --git a/src/main/java/com/codesdream/ase/component/datamanager/StringFile.java b/src/main/java/com/codesdream/ase/component/datamanager/StringFile.java
new file mode 100644
index 0000000..7ef0f5e
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/datamanager/StringFile.java
@@ -0,0 +1,12 @@
+package com.codesdream.ase.component.datamanager;
+
+import lombok.Data;
+
+// 储存字符串标识的文件,并可以转换为json进行传输
+@Data
+public class StringFile {
+ private String strData = null;
+ private String sha1Checker = null;
+ private Integer size = null;
+ private String type = "none";
+}
diff --git a/src/main/java/com/codesdream/ase/component/datamanager/StringFileGenerator.java b/src/main/java/com/codesdream/ase/component/datamanager/StringFileGenerator.java
new file mode 100644
index 0000000..a64fd32
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/datamanager/StringFileGenerator.java
@@ -0,0 +1,92 @@
+package com.codesdream.ase.component.datamanager;
+
+import com.codesdream.ase.component.auth.SHA1Encoder;
+import com.codesdream.ase.exception.StringFileConvertException;
+import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.*;
+import java.util.Base64;
+import java.util.Optional;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+// 将文件处理成可发送的字符串文件对象
+@Component
+public class StringFileGenerator {
+
+ @Resource
+ private SHA1Encoder encoder;
+
+ // 用过读入流创建一个字符串文件
+ public Optional generateStringFile(InputStream stream){
+ StringFile file = new StringFile();
+ // 字符串内容计算
+ file.setStrData(generateFile2String(stream));
+ if(file.getStrData() == null) return Optional.empty();
+ // 相关校验值计算
+ file.setSha1Checker(generateSHA1Checker(file.getStrData()));
+ file.setSize(file.getStrData().length());
+ return Optional.of(file);
+ }
+
+ private byte[] readSteamAll(InputStream stream) {
+ try {
+ byte[] bytes = new byte[stream.available()];
+
+ //检查文件书否完全读取
+ if (stream.read(bytes) != bytes.length) return null;
+ else return bytes;
+ } catch (IOException e){
+ return null;
+ }
+ }
+
+ private String generateFile2String(InputStream stream){
+ ByteArrayOutputStream zipDataStream = new ByteArrayOutputStream();
+ try {
+ GZIPOutputStream gzipOutputStream = new GZIPOutputStream(zipDataStream);
+ byte[] bytes = readSteamAll(stream);
+ if(bytes == null) return null;
+ gzipOutputStream.write(bytes);
+ gzipOutputStream.close();
+ return Base64.getEncoder().encodeToString(zipDataStream.toByteArray());
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ // 生成字符串文件的校验码
+ private String generateSHA1Checker(String str){
+ return encoder.encode(str);
+ }
+
+ // 检查文件内容是否正确,包括大小与校验码
+ public boolean checkStringFile(StringFile file){
+ return file.getStrData().length() == file.getSize()
+ && encoder.match(file.getStrData(), file.getSha1Checker());
+ }
+
+ // 从字符串文件中读取真实的文件数据
+ public InputStream readFileString(StringFile file){
+ try {
+ // 字符串转换为二进制数据
+ byte[] bytes = Base64.getDecoder().decode(file.getStrData());
+ GZIPInputStream stream = new GZIPInputStream(new ByteArrayInputStream(bytes), bytes.length);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ // 数据解压缩
+ int readBits = 0;
+ byte[] rawBytes = new byte[1024];
+ while ((readBits = stream.read(rawBytes)) != -1) {
+ outputStream.write(rawBytes, 0, readBits);
+ }
+
+ stream.close();
+ return new ByteArrayInputStream(outputStream.toByteArray());
+ } catch (IOException e) {
+ throw new StringFileConvertException("Read FileString Failed");
+ }
+ }
+}
diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableTag.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableTag.java
new file mode 100644
index 0000000..8db125b
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableTag.java
@@ -0,0 +1,34 @@
+package com.codesdream.ase.component.json.model;
+
+import com.codesdream.ase.model.permission.Tag;
+import com.codesdream.ase.model.permission.User;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import net.bytebuddy.implementation.bind.annotation.DefaultMethod;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+@Data
+@NoArgsConstructor
+@ApiModel("标签")
+public class JsonableTag {
+ @ApiModelProperty(value = "标签id")
+ private Integer id = null;
+ @ApiModelProperty(value = "标签名", example = "系统管理员")
+ private String name;
+ @ApiModelProperty(value = "标签说明", example = "该系统的管理员")
+ private String description;
+
+
+ public JsonableTag(Tag tag){
+ this.id = tag.getId();
+ this.name = tag.getName();
+ this.description = tag.getDescription();
+ }
+
+}
diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableTagUserList.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableTagUserList.java
new file mode 100644
index 0000000..523c61e
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableTagUserList.java
@@ -0,0 +1,26 @@
+package com.codesdream.ase.component.json.model;
+
+import com.codesdream.ase.model.permission.Tag;
+import com.codesdream.ase.model.permission.User;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@Data
+@NoArgsConstructor
+@ApiModel("标签所属用户集合")
+public class JsonableTagUserList {
+
+ @ApiModelProperty(name = "用户列表")
+ private List users;
+
+
+ public JsonableTagUserList(Tag tag){
+ for(User user : tag.getUsers()){
+ users.add(user.getId());
+ }
+ }
+}
diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableUidGetter.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableUidGetter.java
new file mode 100644
index 0000000..9eee677
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableUidGetter.java
@@ -0,0 +1,6 @@
+package com.codesdream.ase.component.json.model;
+
+public class JsonableUidGetter {
+ private String checkType;
+ private String username;
+}
diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableUser.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableUser.java
new file mode 100644
index 0000000..74f6467
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableUser.java
@@ -0,0 +1,19 @@
+package com.codesdream.ase.component.json.model;
+
+import com.codesdream.ase.model.permission.User;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@ApiModel("用户")
+@NoArgsConstructor
+public class JsonableUser {
+ private Integer id;
+ private String username;
+
+ public JsonableUser(User user){
+ this.id = user.getId();
+ this.username = user.getUsername();
+ }
+}
diff --git a/src/main/java/com/codesdream/ase/component/json/request/UserLeaveRequest.java b/src/main/java/com/codesdream/ase/component/json/request/UserLeaveRequest.java
new file mode 100644
index 0000000..485c0ce
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/json/request/UserLeaveRequest.java
@@ -0,0 +1,7 @@
+package com.codesdream.ase.component.json.request;
+
+public class UserLeaveRequest {
+
+
+
+}
diff --git a/src/main/java/com/codesdream/ase/component/json/request/UserRegisterChecker.java b/src/main/java/com/codesdream/ase/component/json/request/UserRegisterChecker.java
new file mode 100644
index 0000000..491cda6
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/json/request/UserRegisterChecker.java
@@ -0,0 +1,19 @@
+package com.codesdream.ase.component.json.request;
+
+import lombok.Data;
+
+@Data
+public class UserRegisterChecker {
+
+ // 学号
+ private String studentId;
+
+ // 密码
+ private String password;
+
+ // 密保问题
+ private String userQuestion;
+
+ // 密保答案
+ private String userAnswer;
+}
diff --git a/src/main/java/com/codesdream/ase/component/json/respond/ErrorInfoJSONRespond.java b/src/main/java/com/codesdream/ase/component/json/respond/ErrorInfoJSONRespond.java
new file mode 100644
index 0000000..4495e20
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/json/respond/ErrorInfoJSONRespond.java
@@ -0,0 +1,12 @@
+package com.codesdream.ase.component.json.respond;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class ErrorInfoJSONRespond {
+ String exception = null;
+ String exceptionMessage = null;
+ Date date = null;
+}
diff --git a/src/main/java/com/codesdream/ase/component/json/respond/JSONBaseRespondObject.java b/src/main/java/com/codesdream/ase/component/json/respond/JSONBaseRespondObject.java
index f180023..d1a2d2f 100644
--- a/src/main/java/com/codesdream/ase/component/json/respond/JSONBaseRespondObject.java
+++ b/src/main/java/com/codesdream/ase/component/json/respond/JSONBaseRespondObject.java
@@ -17,6 +17,9 @@ public class JSONBaseRespondObject extends JSONBaseObject {
// 存放响应信息提示
private String msg = "";
+ // 额外信息
+ private String info = null;
+
// 状态
private Integer status = 200;
diff --git a/src/main/java/com/codesdream/ase/component/json/respond/PermissionJSONRespond.java b/src/main/java/com/codesdream/ase/component/json/respond/PermissionJSONRespond.java
new file mode 100644
index 0000000..915804a
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/component/json/respond/PermissionJSONRespond.java
@@ -0,0 +1,16 @@
+package com.codesdream.ase.component.json.respond;
+
+import com.sun.org.apache.xpath.internal.operations.Bool;
+import lombok.Data;
+
+import java.util.List;
+import java.util.Set;
+
+@Data
+public class PermissionJSONRespond {
+ private Boolean tagExist = null;
+ private Boolean actionSuccess = null;
+ private Integer tagId = null;
+ private String tagName = null;
+ private Set users = null;
+}
diff --git a/src/main/java/com/codesdream/ase/component/json/respond/UserLoginCheckerJSONRespond.java b/src/main/java/com/codesdream/ase/component/json/respond/UserLoginCheckerJSONRespond.java
index 208851a..e12c077 100644
--- a/src/main/java/com/codesdream/ase/component/json/respond/UserLoginCheckerJSONRespond.java
+++ b/src/main/java/com/codesdream/ase/component/json/respond/UserLoginCheckerJSONRespond.java
@@ -9,7 +9,9 @@ public class UserLoginCheckerJSONRespond {
Boolean userExist = null;
Boolean userBanned = null;
Boolean loginStatus = null;
- String respondInformation = "";
+ String respondInformation = null;
String token = null;
+ String uid = null;
+ String pvc = null;
}
diff --git a/src/main/java/com/codesdream/ase/component/permission/ASEAuthenticationFailureHandler.java b/src/main/java/com/codesdream/ase/component/permission/ASEAuthenticationFailureHandler.java
deleted file mode 100644
index 393d591..0000000
--- a/src/main/java/com/codesdream/ase/component/permission/ASEAuthenticationFailureHandler.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.codesdream.ase.component.permission;
-
-import com.codesdream.ase.component.datamanager.JSONParameter;
-import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-// 认证失败返回
-@Slf4j
-@Component
-public class ASEAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
-
- @Resource
- private JSONParameter jsonParameter;
-
- @Override
- public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception)
- throws IOException
- {
- log.info("ASEAuthenticationFailureHandler Login Fail!");
- UserLoginCheckerJSONRespond respond = new UserLoginCheckerJSONRespond();
-
- respond.setUserExist(null);
- respond.setUserBanned(null);
- respond.setLoginStatus(false);
- respond.setRespondInformation("Authentication Failed");
-
- // 填充response对象
- response.getWriter().write(jsonParameter.getJSONStandardRespond200(respond));
- }
-}
diff --git a/src/main/java/com/codesdream/ase/configure/ASESwaggerConfigure.java b/src/main/java/com/codesdream/ase/configure/ASESwaggerConfigure.java
new file mode 100644
index 0000000..1e2061e
--- /dev/null
+++ b/src/main/java/com/codesdream/ase/configure/ASESwaggerConfigure.java
@@ -0,0 +1,57 @@
+package com.codesdream.ase.configure;
+
+import com.google.common.collect.Sets;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.core.parameters.P;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.ParameterBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.schema.ModelRef;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Parameter;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Configuration
+@EnableSwagger2
+public class ASESwaggerConfigure {
+ @Bean
+ public Docket createRestApi() {
+
+ List pars = new ArrayList();
+
+ pars.add(new ParameterBuilder().name("username").description("真实用户名").hidden(true).order(1)
+ .modelRef(new ModelRef("string")).parameterType("header")
+ .required(false).defaultValue("u_id_88883b9e023c8824310760d8bb8b6542e5a3f16a0d67253214e01ee7ab0e96a1").build());
+ pars.add(new ParameterBuilder().name("signed").description("客户端签名").hidden(true).order(2)
+ .modelRef(new ModelRef("string")).parameterType("header")
+ .required(false).defaultValue("6d4923fca4dcb51f67b85e54a23a8d763d9e02af").build());
+ pars.add(new ParameterBuilder().name("timestamp").description("时间戳").hidden(true).order(3)
+ .modelRef(new ModelRef("string")).parameterType("header")
+ .required(false).defaultValue(Long.toString(new Date().getTime())).build());
+
+ return new Docket(DocumentationType.SWAGGER_2)
+ .protocols(Sets.newHashSet("http"))
+ .apiInfo(apiInfo())
+ .select()
+ .apis(RequestHandlerSelectors.basePackage("com.codesdream.ase.controller"))
+ .paths(PathSelectors.any())
+ .build()
+ .globalOperationParameters(pars);
+ }
+
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder()
+ .title("全员育人管理系统后端接口定义")
+ .version("0.0.1")
+ .description("用于对后端接口进行说明")
+ .build();
+ }
+}
diff --git a/src/main/java/com/codesdream/ase/configure/AppConfigure.java b/src/main/java/com/codesdream/ase/configure/AppConfigure.java
index c59dd88..2d606c6 100644
--- a/src/main/java/com/codesdream/ase/configure/AppConfigure.java
+++ b/src/main/java/com/codesdream/ase/configure/AppConfigure.java
@@ -39,4 +39,5 @@ public class AppConfigure {
public String getOrganization() {
return "全员育人WEB端开发组";
}
+
}
diff --git a/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java b/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java
index 1bb0f98..b2d3413 100644
--- a/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java
+++ b/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java
@@ -1,10 +1,9 @@
package com.codesdream.ase.configure;
-import com.codesdream.ase.component.permission.*;
+import com.codesdream.ase.component.auth.*;
import com.codesdream.ase.service.ASEUserDetailsService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
@@ -14,11 +13,8 @@ import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.core.session.SessionRegistryImpl;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
-import org.springframework.security.web.authentication.session.CompositeSessionAuthenticationStrategy;
import org.springframework.security.web.authentication.session.ConcurrentSessionControlAuthenticationStrategy;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
-import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
-import org.springframework.security.web.context.SecurityContextPersistenceFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import javax.annotation.Resource;
@@ -91,7 +87,13 @@ public class CustomWebSecurityConfig extends WebSecurityConfigurerAdapter {
"/forget/**",
"/not_found/**",
"/error/**",
- "/login/**");
+ "/login/**",
+ "/swagger-ui.html",
+ "/webjars/**",
+ "/swagger-resources/**",
+ "/v2/api-docs",
+ "/configuration/ui",
+ "/configuration/security");
}
//注册自定义的UsernamePasswordAuthenticationFilter
diff --git a/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java b/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java
index d5166ff..bdddf30 100644
--- a/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java
+++ b/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java
@@ -1,23 +1,64 @@
package com.codesdream.ase.controller;
-import com.codesdream.ase.component.error.ErrorResponse;
+import com.codesdream.ase.component.api.QuickJSONRespond;
+import com.codesdream.ase.component.json.respond.ErrorInfoJSONRespond;
+import com.codesdream.ase.exception.badrequest.AlreadyExistException;
+import com.codesdream.ase.exception.conflict.RelatedObjectsExistException;
+import com.codesdream.ase.exception.notfound.NotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.context.request.WebRequest;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
-import java.util.ArrayList;
-import java.util.List;
+import javax.annotation.Resource;
+import java.util.Date;
-@ControllerAdvice
+@RestControllerAdvice
public class ASEControllerAdvice {
- @ExceptionHandler(value = {RuntimeException.class})
- public final ResponseEntity