Merge branch 'master' of https://gitee.com/saturneric/ASE
This commit is contained in:
commit
356832b149
52
pom.xml
52
pom.xml
@ -138,6 +138,46 @@
|
|||||||
<version>1.1.71.android</version>
|
<version>1.1.71.android</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mariadb.jdbc</groupId>
|
||||||
|
<artifactId>mariadb-java-client</artifactId>
|
||||||
|
<version>2.5.4</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 内存数据库 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 二维码支持包 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.zxing</groupId>
|
||||||
|
<artifactId>core</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.zxing</groupId>
|
||||||
|
<artifactId>javase</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Restful API 文档可视化支持 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
|
<version>2.9.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger-ui</artifactId>
|
||||||
|
<version>2.9.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -150,6 +190,18 @@
|
|||||||
<addResources>true</addResources>
|
<addResources>true</addResources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<compilerArguments>
|
||||||
|
<!--suppress UnresolvedMavenProperty -->
|
||||||
|
<bootclasspath>${JAVA_HOME}/jre/lib/rt.jar</bootclasspath>
|
||||||
|
</compilerArguments>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
@ -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<JSONObject> json) {
|
||||||
|
if (!json.isPresent()) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
Activity activity = new Activity();
|
||||||
|
JSONObject jsonObject = json.get();
|
||||||
|
|
||||||
|
String username = (String) jsonObject.get("creator");
|
||||||
|
Optional<User> creator = userService.findUserByUsername(username);
|
||||||
|
activity.setCreator(creator.get());
|
||||||
|
|
||||||
|
List<String> participateGroupFromJson = (List) jsonObject.get("participate-group");
|
||||||
|
Set<User> participateGroup = new HashSet<>();
|
||||||
|
for (String name : participateGroupFromJson) {
|
||||||
|
Optional<User> 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<User> chiefManager = userService.findUserByUsername(chiefManagerName);
|
||||||
|
activity.setChiefManager(chiefManager.get());
|
||||||
|
|
||||||
|
List<String> assistManagerFromJSON = (List) jsonObject.get("assist-manager");
|
||||||
|
Set<User> assistManager = new HashSet<>();
|
||||||
|
for (String name : assistManagerFromJSON) {
|
||||||
|
Optional<User> 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<String> signGroupFromJSON = (List) jsonObject.get("sign-group");
|
||||||
|
Set<User> signGroup = new HashSet<>();
|
||||||
|
for (String name : signGroupFromJSON) {
|
||||||
|
Optional<User> user = userService.findUserByUsername(name);
|
||||||
|
signGroup.add(user.get());
|
||||||
|
}
|
||||||
|
activity.setSignGroup(signGroup);
|
||||||
|
|
||||||
|
List<String> informGroupFromJSON = (List) jsonObject.get("inform-group");
|
||||||
|
Set<User> informGroup = new HashSet<>();
|
||||||
|
for (String name : informGroupFromJSON) {
|
||||||
|
Optional<User> user = userService.findUserByUsername(name);
|
||||||
|
informGroup.add(user.get());
|
||||||
|
}
|
||||||
|
activity.setInformGroup(informGroup);
|
||||||
|
|
||||||
|
List<String> visibleGroupFromJSON = (List) jsonObject.get("visible-group");
|
||||||
|
Set<User> visibleGroup = new HashSet<>();
|
||||||
|
for (String name : visibleGroupFromJSON) {
|
||||||
|
Optional<User> 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<Period> 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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> user;
|
||||||
|
public Optional<User> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<String> nullValueAttributes;
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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.api.QuickJSONRespond;
|
||||||
import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||||
@ -19,7 +18,7 @@ import java.io.IOException;
|
|||||||
public class ASEAccessDeniedHandler implements AccessDeniedHandler {
|
public class ASEAccessDeniedHandler implements AccessDeniedHandler {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private JSONParameter jsonParameter;
|
private QuickJSONRespond quickJSONRespond;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException)
|
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException)
|
||||||
@ -27,7 +26,7 @@ public class ASEAccessDeniedHandler implements AccessDeniedHandler {
|
|||||||
log.info("ASEAccessDeniedHandler Found!");
|
log.info("ASEAccessDeniedHandler Found!");
|
||||||
|
|
||||||
// 对无权限操作返回403
|
// 对无权限操作返回403
|
||||||
response.getWriter().print(jsonParameter.getJSONStandardRespond403());
|
response.getWriter().print(quickJSONRespond.getRespond403(null));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -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.api.QuickJSONRespond;
|
||||||
import com.codesdream.ase.component.json.respond.JSONBaseRespondObject;
|
|
||||||
import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -19,13 +16,14 @@ import java.io.IOException;
|
|||||||
@Component
|
@Component
|
||||||
public class ASEAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
public class ASEAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||||
@Resource
|
@Resource
|
||||||
private JSONParameter jsonParameter;
|
private QuickJSONRespond quickJSONRespond;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
|
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
|
||||||
throws IOException, ServletException {
|
throws IOException {
|
||||||
|
|
||||||
// 对匿名用户返回401
|
// 对匿名用户返回401
|
||||||
response.getWriter().print(jsonParameter.getJSONStandardRespond401());
|
response.getWriter().print(quickJSONRespond.getRespond401(null));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -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.api.QuickJSONRespond;
|
||||||
import com.codesdream.ase.component.datamanager.JSONParameter;
|
|
||||||
import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
|
import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
|
|
||||||
@ -18,7 +17,6 @@ import javax.annotation.Resource;
|
|||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.servlet.http.HttpSession;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -27,7 +25,7 @@ import java.util.Optional;
|
|||||||
@Component
|
@Component
|
||||||
public class ASEAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
|
public class ASEAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
|
||||||
@Resource
|
@Resource
|
||||||
private JSONParameter jsonParameter;
|
private QuickJSONRespond quickJSONRespond;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IAuthService authService;
|
private IAuthService authService;
|
||||||
@ -40,7 +38,7 @@ public class ASEAuthenticationSuccessHandler extends SavedRequestAwareAuthentica
|
|||||||
UserLoginCheckerJSONRespond respond = new UserLoginCheckerJSONRespond();
|
UserLoginCheckerJSONRespond respond = new UserLoginCheckerJSONRespond();
|
||||||
respond.setUserExist(authentication.isAuthenticated());
|
respond.setUserExist(authentication.isAuthenticated());
|
||||||
respond.setLoginStatus(authentication.isAuthenticated());
|
respond.setLoginStatus(authentication.isAuthenticated());
|
||||||
respond.setRespondInformation("Authentication Success");
|
respond.setPvc(authService.preValidationCodeGetter());
|
||||||
|
|
||||||
// 获得 JSONTokenAuthenticationToken
|
// 获得 JSONTokenAuthenticationToken
|
||||||
JSONTokenAuthenticationToken authenticationToken = (JSONTokenAuthenticationToken) authentication;
|
JSONTokenAuthenticationToken authenticationToken = (JSONTokenAuthenticationToken) authentication;
|
||||||
@ -55,7 +53,8 @@ public class ASEAuthenticationSuccessHandler extends SavedRequestAwareAuthentica
|
|||||||
}
|
}
|
||||||
else respond.setToken("");
|
else respond.setToken("");
|
||||||
|
|
||||||
response.getWriter().write(jsonParameter.getJSONStandardRespond200(respond));
|
// 认证成功返回200
|
||||||
|
response.getWriter().write(quickJSONRespond.getRespond200("Authentication Success", respond));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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.AJAXRequestChecker;
|
||||||
import com.codesdream.ase.component.auth.JSONRandomCodeGenerator;
|
import com.codesdream.ase.component.auth.JSONRandomCodeGenerator;
|
||||||
@ -30,15 +30,9 @@ import java.util.Optional;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class ASEJSONTokenAuthenticationFilter extends OncePerRequestFilter {
|
public class ASEJSONTokenAuthenticationFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private JSONParameter jsonParameter;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private JSONRandomCodeGenerator randomCodeGenerator;
|
private JSONRandomCodeGenerator randomCodeGenerator;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private AJAXRequestChecker ajaxRequestChecker;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AuthService authService;
|
private AuthService authService;
|
||||||
|
|
||||||
@ -59,7 +53,13 @@ public class ASEJSONTokenAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
// 时间戳
|
// 时间戳
|
||||||
String timestamp = request.getHeader("timestamp");
|
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));
|
Date date = new Date(Long.parseLong(timestamp));
|
||||||
|
|
@ -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.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
@ -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 lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.authentication.*;
|
import org.springframework.security.authentication.*;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
@ -34,35 +32,36 @@ public class ASESecurityAuthenticationProvider implements AuthenticationProvider
|
|||||||
JSONTokenUsernamePasswordAuthenticationToken authenticationToken =
|
JSONTokenUsernamePasswordAuthenticationToken authenticationToken =
|
||||||
(JSONTokenUsernamePasswordAuthenticationToken) authentication;
|
(JSONTokenUsernamePasswordAuthenticationToken) authentication;
|
||||||
|
|
||||||
// 获得登录表单中的学号
|
// 获得JSON中的学号
|
||||||
String username = usernameEncoder.encode((CharSequence) authenticationToken.getPrincipal());
|
String username = usernameEncoder.encode((CharSequence) authenticationToken.getPrincipal());
|
||||||
// 获得表单中的密码
|
// 获得JSON中的加密密码
|
||||||
String password = passwordEncoder.encode((CharSequence) authenticationToken.getCredentials());
|
String encrypted_password = (String) authenticationToken.getCredentials();
|
||||||
// 获得
|
// 获得客户端代码
|
||||||
String clientCode = authenticationToken.getClientCode();
|
String clientCode = authenticationToken.getClientCode();
|
||||||
// 判断用户是否存在
|
// 判断用户是否存在
|
||||||
UserDetails userInfo = userDetailsService.loadUserByUsername(username);
|
UserDetails userInfo = userDetailsService.loadUserByUsername(username);
|
||||||
|
|
||||||
log.info(String.format("SecurityAuthentication: %s %s", username, password));
|
|
||||||
|
|
||||||
if (userInfo == null) {
|
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)) {
|
if(!passwordEncoder.encode(String.format(
|
||||||
throw new BadCredentialsException("Password IS Uncorrected");
|
"PASS_ENCODE [%s][%s]", sha256_password, clientCode)).equals(encrypted_password)){
|
||||||
|
throw new BadCredentialsException("Password IS INCORRECT");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断账号是否停用/删除
|
// 判断账号是否停用/删除
|
||||||
if (!userInfo.isEnabled()) {
|
if (!userInfo.isEnabled()) {
|
||||||
throw new DisabledException("User IS Disabled");
|
throw new DisabledException("User IS Disabled");
|
||||||
}
|
}
|
||||||
else if(!userInfo.isAccountNonLocked()){
|
else if(!userInfo.isAccountNonLocked()) {
|
||||||
throw new LockedException("User IS Locked");
|
throw new LockedException("User IS Locked");
|
||||||
}
|
}
|
||||||
else if(!userInfo.isAccountNonExpired()){
|
else if(!userInfo.isAccountNonExpired()) {
|
||||||
throw new AccountExpiredException("User IS Expired");
|
throw new AccountExpiredException("User IS Expired");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成权限列表
|
// 生成权限列表
|
@ -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.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
@ -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.AJAXRequestChecker;
|
||||||
import com.codesdream.ase.component.auth.JSONTokenUsernamePasswordAuthenticationToken;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.authentication.AuthenticationServiceException;
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.core.AuthenticationException;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
// 登录验证过滤器
|
// 普通登录验证过滤器
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ASEUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
public class ASEUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
||||||
|
|
||||||
@ -40,7 +38,7 @@ public class ASEUsernamePasswordAuthenticationFilter extends UsernamePasswordAut
|
|||||||
String timestamp = request.getHeader("timestamp");
|
String timestamp = request.getHeader("timestamp");
|
||||||
|
|
||||||
// 检查时间戳是否合理(60秒内)
|
// 检查时间戳是否合理(60秒内)
|
||||||
if(!timestampExpiredChecker.checkTimestampBeforeMaxTime(timestamp, 60)){
|
if(timestamp == null || !timestampExpiredChecker.checkTimestampBeforeMaxTime(timestamp, 60)){
|
||||||
throw new AuthenticationServiceException("Timestamp Expired.");
|
throw new AuthenticationServiceException("Timestamp Expired.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,16 +47,25 @@ public class ASEUsernamePasswordAuthenticationFilter extends UsernamePasswordAut
|
|||||||
throw new AuthenticationServiceException("Authentication method not supported: NOT Ajax Method.");
|
throw new AuthenticationServiceException("Authentication method not supported: NOT Ajax Method.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<UserLoginChecker> checker = jsonParameter.getJavaObjectByRequest(request, UserLoginChecker.class);
|
Optional<UserLoginChecker> checkerOptional = jsonParameter.getJavaObjectByRequest(request, UserLoginChecker.class);
|
||||||
if(!checker.isPresent()) throw new BadCredentialsException("Invalid AJAX JSON Request");
|
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.");
|
throw new AuthenticationServiceException("Authentication not supported: NOT Username Password Type.");
|
||||||
|
|
||||||
// 获得相应的用户名密码
|
// 获得相应的用户名密码
|
||||||
String username = checker.get().getUsername();
|
String username = checker.getUsername();
|
||||||
String password = checker.get().getPassword();
|
// 得到加密密码
|
||||||
String clientCode = checker.get().getClientCode();
|
String password = checker.getPassword();
|
||||||
|
String clientCode = checker.getClientCode();
|
||||||
|
|
||||||
if (username == null) username = "";
|
if (username == null) username = "";
|
||||||
if (password == null) password = "";
|
if (password == null) password = "";
|
@ -7,11 +7,11 @@ import org.springframework.stereotype.Component;
|
|||||||
// SHA1算法不可逆加密 主要用于JSON签名
|
// SHA1算法不可逆加密 主要用于JSON签名
|
||||||
@Component
|
@Component
|
||||||
public class SHA1Encoder {
|
public class SHA1Encoder {
|
||||||
String encode(CharSequence charSequence){
|
public String encode(CharSequence charSequence){
|
||||||
return DigestUtils.sha1Hex(charSequence.toString());
|
return DigestUtils.sha1Hex(charSequence.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean match(CharSequence charSequence, String s){
|
public boolean match (CharSequence charSequence, String s){
|
||||||
return s.equals(encode(charSequence));
|
return s.equals(encode(charSequence));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,4 +15,10 @@ public class TimestampExpiredChecker {
|
|||||||
return timestampDate.before(maxDate);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.codesdream.ase.component.datamanager;
|
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 com.codesdream.ase.exception.DataIOException;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
@ -2,6 +2,7 @@ package com.codesdream.ase.component.datamanager;
|
|||||||
|
|
||||||
|
|
||||||
import com.codesdream.ase.exception.*;
|
import com.codesdream.ase.exception.*;
|
||||||
|
import com.codesdream.ase.exception.notfound.DataFileNotFoundException;
|
||||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
|
||||||
|
@ -58,44 +58,6 @@ public class JSONParameter {
|
|||||||
return JSON.toJSONString(object);
|
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对象
|
// 由JSON对象获得对应的Java对象
|
||||||
public <T> T getJavaObject(JSONObject json, Class<T> type){
|
public <T> T getJavaObject(JSONObject json, Class<T> type){
|
||||||
return json.toJavaObject(type);
|
return json.toJavaObject(type);
|
||||||
|
@ -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";
|
||||||
|
}
|
@ -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<StringFile> 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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<Integer> users;
|
||||||
|
|
||||||
|
|
||||||
|
public JsonableTagUserList(Tag tag){
|
||||||
|
for(User user : tag.getUsers()){
|
||||||
|
users.add(user.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.codesdream.ase.component.json.model;
|
||||||
|
|
||||||
|
public class JsonableUidGetter {
|
||||||
|
private String checkType;
|
||||||
|
private String username;
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.codesdream.ase.component.json.request;
|
||||||
|
|
||||||
|
public class UserLeaveRequest {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -17,6 +17,9 @@ public class JSONBaseRespondObject extends JSONBaseObject {
|
|||||||
// 存放响应信息提示
|
// 存放响应信息提示
|
||||||
private String msg = "";
|
private String msg = "";
|
||||||
|
|
||||||
|
// 额外信息
|
||||||
|
private String info = null;
|
||||||
|
|
||||||
// 状态
|
// 状态
|
||||||
private Integer status = 200;
|
private Integer status = 200;
|
||||||
|
|
||||||
|
@ -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<Integer> users = null;
|
||||||
|
}
|
@ -9,7 +9,9 @@ public class UserLoginCheckerJSONRespond {
|
|||||||
Boolean userExist = null;
|
Boolean userExist = null;
|
||||||
Boolean userBanned = null;
|
Boolean userBanned = null;
|
||||||
Boolean loginStatus = null;
|
Boolean loginStatus = null;
|
||||||
String respondInformation = "";
|
String respondInformation = null;
|
||||||
String token = null;
|
String token = null;
|
||||||
|
String uid = null;
|
||||||
|
String pvc = 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));
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<Parameter> pars = new ArrayList<Parameter>();
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -39,4 +39,5 @@ public class AppConfigure {
|
|||||||
public String getOrganization() {
|
public String getOrganization() {
|
||||||
return "全员育人WEB端开发组";
|
return "全员育人WEB端开发组";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package com.codesdream.ase.configure;
|
package com.codesdream.ase.configure;
|
||||||
|
|
||||||
import com.codesdream.ase.component.permission.*;
|
import com.codesdream.ase.component.auth.*;
|
||||||
import com.codesdream.ase.service.ASEUserDetailsService;
|
import com.codesdream.ase.service.ASEUserDetailsService;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
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.authentication.builders.AuthenticationManagerBuilder;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
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.SessionRegistry;
|
||||||
import org.springframework.security.core.session.SessionRegistryImpl;
|
import org.springframework.security.core.session.SessionRegistryImpl;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
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.ConcurrentSessionControlAuthenticationStrategy;
|
||||||
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
|
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 org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -91,7 +87,13 @@ public class CustomWebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
"/forget/**",
|
"/forget/**",
|
||||||
"/not_found/**",
|
"/not_found/**",
|
||||||
"/error/**",
|
"/error/**",
|
||||||
"/login/**");
|
"/login/**",
|
||||||
|
"/swagger-ui.html",
|
||||||
|
"/webjars/**",
|
||||||
|
"/swagger-resources/**",
|
||||||
|
"/v2/api-docs",
|
||||||
|
"/configuration/ui",
|
||||||
|
"/configuration/security");
|
||||||
}
|
}
|
||||||
|
|
||||||
//注册自定义的UsernamePasswordAuthenticationFilter
|
//注册自定义的UsernamePasswordAuthenticationFilter
|
||||||
|
@ -1,23 +1,64 @@
|
|||||||
package com.codesdream.ase.controller;
|
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.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
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 javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.Date;
|
||||||
|
|
||||||
@ControllerAdvice
|
@RestControllerAdvice
|
||||||
public class ASEControllerAdvice {
|
public class ASEControllerAdvice {
|
||||||
@ExceptionHandler(value = {RuntimeException.class})
|
|
||||||
public final ResponseEntity<Object> handleRuntimeException(RuntimeException e, WebRequest webRequest){
|
@Resource
|
||||||
List<String> details = new ArrayList<>();
|
private QuickJSONRespond quickJSONRespond;
|
||||||
details.add(e.getLocalizedMessage());
|
|
||||||
ErrorResponse errorResponse = new ErrorResponse("Runtime Error", details);
|
@ExceptionHandler(value = {
|
||||||
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
|
NullPointerException.class,
|
||||||
|
AlreadyExistException.class
|
||||||
|
})
|
||||||
|
public ResponseEntity<Object> handleBadRequest(Exception ex) {
|
||||||
|
return getResponse(HttpStatus.BAD_REQUEST, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(value = {NotFoundException.class})
|
||||||
|
public ResponseEntity<Object> handleNotFound(Exception ex) {
|
||||||
|
|
||||||
|
return getResponse(HttpStatus.NOT_FOUND, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(value = {})
|
||||||
|
public ResponseEntity<Object> handleNotAcceptable(Exception ex) {
|
||||||
|
return getResponse(HttpStatus.NOT_ACCEPTABLE, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(value = {RelatedObjectsExistException.class})
|
||||||
|
public ResponseEntity<Object> handleConflict(Exception ex) {
|
||||||
|
return getResponse(HttpStatus.CONFLICT, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResponseEntity<Object> getResponse(HttpStatus status, Exception ex){
|
||||||
|
return ResponseEntity.status(status).body(getJSON(status, ex));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getJSON(HttpStatus status, Exception ex){
|
||||||
|
return quickJSONRespond.getJSONStandardRespond(status, getJSONRespondObject(ex));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getJSONRespondObject(Exception ex){
|
||||||
|
ErrorInfoJSONRespond errorInfoJSONRespond = new ErrorInfoJSONRespond();
|
||||||
|
errorInfoJSONRespond.setException(ex.getClass().getName());
|
||||||
|
errorInfoJSONRespond.setExceptionMessage(ex.getMessage());
|
||||||
|
errorInfoJSONRespond.setDate(new Date());
|
||||||
|
return errorInfoJSONRespond;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,21 @@
|
|||||||
package com.codesdream.ase.controller;
|
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 org.springframework.boot.web.servlet.error.ErrorController;
|
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class ASEErrorController implements ErrorController {
|
public class ASEErrorController implements ErrorController {
|
||||||
|
|
||||||
@RequestMapping("/error")
|
/* @RequestMapping("/error")
|
||||||
public String handleError(HttpServletRequest request, Model model){
|
public String handleError(HttpServletRequest request, Model model){
|
||||||
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
||||||
Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception");
|
Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception");
|
||||||
@ -49,7 +45,36 @@ public class ASEErrorController implements ErrorController {
|
|||||||
model.addAttribute("exception_date", new Date());
|
model.addAttribute("exception_date", new Date());
|
||||||
}
|
}
|
||||||
return "error";
|
return "error";
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private QuickJSONRespond quickJSONRespond;
|
||||||
|
|
||||||
|
@RequestMapping("/error")
|
||||||
|
@ResponseBody
|
||||||
|
public String handleError(HttpServletRequest request){
|
||||||
|
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
||||||
|
Exception exception = (Exception) request.getAttribute("javax.servlet.error.exception");
|
||||||
|
|
||||||
|
// 检查返回的状态
|
||||||
|
if (statusCode == HttpStatus.NOT_FOUND.value()) return quickJSONRespond.getRespond404(null);
|
||||||
|
ErrorInfoJSONRespond errorInfoJSONRespond = new ErrorInfoJSONRespond();
|
||||||
|
|
||||||
|
// 检查是否含有引发异常
|
||||||
|
if (exception.getCause() == null) {
|
||||||
|
errorInfoJSONRespond.setException(exception.getClass().getName());
|
||||||
|
errorInfoJSONRespond.setExceptionMessage(exception.getMessage());
|
||||||
|
} else {
|
||||||
|
errorInfoJSONRespond.setException(exception.getCause().getClass().getName());
|
||||||
|
errorInfoJSONRespond.setExceptionMessage(exception.getCause().getMessage());
|
||||||
|
}
|
||||||
|
errorInfoJSONRespond.setDate(new Date());
|
||||||
|
|
||||||
|
return quickJSONRespond.getJSONStandardRespond(
|
||||||
|
statusCode,
|
||||||
|
"Internal Server Error",
|
||||||
|
null,
|
||||||
|
errorInfoJSONRespond);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,82 +0,0 @@
|
|||||||
package com.codesdream.ase.controller;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.codesdream.ase.component.ASESpringUtil;
|
|
||||||
import com.codesdream.ase.component.activity.NullValueAttributes;
|
|
||||||
import com.codesdream.ase.component.datamanager.JSONParameter;
|
|
||||||
import com.codesdream.ase.configure.ActivityFormConfigure;
|
|
||||||
import com.codesdream.ase.exception.InvalidFormFormatException;
|
|
||||||
import com.codesdream.ase.exception.LackOfActivityInformation;
|
|
||||||
import com.codesdream.ase.model.activity.Activity;
|
|
||||||
import com.codesdream.ase.service.ActivityService;
|
|
||||||
import com.codesdream.ase.validator.NullValueValidator;
|
|
||||||
import com.codesdream.ase.validator.WebFormValidator;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.validation.constraints.Null;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
public class ActivityController {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
ActivityService activityService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
JSONParameter jsonParameter;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/activity_creator")
|
|
||||||
String activityCreatorView(Model model){return "activity_creator";}
|
|
||||||
|
|
||||||
@PostMapping(value = "/activity_creator")
|
|
||||||
String activityCreator(Model model, HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
|
||||||
|
|
||||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
|
||||||
ASESpringUtil aseSpringUtil = new ASESpringUtil();
|
|
||||||
ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class);
|
|
||||||
WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
|
||||||
if(!webFormValidator.check(activityFormConfigure.getStdActivityForm(), parameterMap)) {
|
|
||||||
throw new InvalidFormFormatException("Invalid activity form.");
|
|
||||||
}
|
|
||||||
// 需要检查JSON是否合法
|
|
||||||
Optional<JSONObject> jsonObject = jsonParameter.getJSONByRequest(request);
|
|
||||||
if(!jsonObject.isPresent()) return "error";
|
|
||||||
Activity activity = jsonObject.get().toJavaObject(Activity.class);
|
|
||||||
|
|
||||||
NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class);
|
|
||||||
List<String> nullValues = nullValueValidator.checkNullValues(activity);
|
|
||||||
NullValueAttributes nullValueAttributes = aseSpringUtil.getBean(NullValueAttributes.class);
|
|
||||||
for (String str : nullValues){
|
|
||||||
if(str.equals("title")){
|
|
||||||
nullValueAttributes.getNullValueAttributes().add("title");
|
|
||||||
}
|
|
||||||
else if(str.equals("creator")){
|
|
||||||
nullValueAttributes.getNullValueAttributes().add("creator");
|
|
||||||
}
|
|
||||||
else if(str.equals("type")){
|
|
||||||
nullValueAttributes.getNullValueAttributes().add("type");
|
|
||||||
}
|
|
||||||
else if(str.equals("planPeriod")){
|
|
||||||
nullValueAttributes.getNullValueAttributes().add("planPeriod");
|
|
||||||
}
|
|
||||||
else if(str.equals("chiefManager")){
|
|
||||||
nullValueAttributes.getNullValueAttributes().add("chiefManager");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "act_created";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -17,7 +17,9 @@ public class HomeController {
|
|||||||
|
|
||||||
@RequestMapping(value = "/home")
|
@RequestMapping(value = "/home")
|
||||||
public String showHomeView(Model model, Principal principal){
|
public String showHomeView(Model model, Principal principal){
|
||||||
User user = userService.findUserByUsername(principal.getName());
|
Optional<User> userOptional = userService.findUserByUsername(principal.getName());
|
||||||
|
if(!userOptional.isPresent()) return "error";
|
||||||
|
User user = userOptional.get();
|
||||||
// 为视图模板指定参数
|
// 为视图模板指定参数
|
||||||
model.addAttribute("username", user.getUsername().substring(0, 18));
|
model.addAttribute("username", user.getUsername().substring(0, 18));
|
||||||
model.addAttribute("real_name", user.getUserDetail().getRealName());
|
model.addAttribute("real_name", user.getUserDetail().getRealName());
|
||||||
|
@ -2,11 +2,8 @@ package com.codesdream.ase.controller;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.codesdream.ase.component.datamanager.JSONParameter;
|
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||||
import com.codesdream.ase.component.json.respond.FailedSONRespond;
|
import com.codesdream.ase.component.json.request.UserLeaveRequest;
|
||||||
import com.codesdream.ase.component.json.respond.JSONBaseRespondObject;
|
import com.codesdream.ase.component.auth.ASEUsernameEncoder;
|
||||||
import com.codesdream.ase.component.permission.ASEUsernameEncoder;
|
|
||||||
import com.codesdream.ase.component.json.request.UserLeaveChecker;
|
|
||||||
import com.codesdream.ase.component.json.respond.UserLeaveCheckerJSONRespond;
|
|
||||||
import com.codesdream.ase.service.LeavesService;
|
import com.codesdream.ase.service.LeavesService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@ -36,36 +33,28 @@ public class LeavesController {
|
|||||||
@Resource
|
@Resource
|
||||||
private ASEUsernameEncoder usernameEncoder;
|
private ASEUsernameEncoder usernameEncoder;
|
||||||
|
|
||||||
@RequestMapping(value = "/")
|
@RequestMapping(value = "/leave")
|
||||||
String printLeave(Model model) {
|
String printLeave(Model model) {
|
||||||
return "Leave";
|
return "Leave";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/Leave/check", method = RequestMethod.POST)
|
//提交请假申请
|
||||||
|
@RequestMapping(value = "/leave/check", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
String checkLeave(HttpServletRequest request){
|
String requestLeave(HttpServletRequest request){
|
||||||
|
|
||||||
// 检查是否为JSON
|
// 检查是否为JSON
|
||||||
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
||||||
if(!json.isPresent()) return jsonParameter.getJSONString(new FailedSONRespond());
|
// if(!json.isPresent()) return jsonParameter.getJSONString(new FailedSONRespond());
|
||||||
|
|
||||||
|
|
||||||
UserLeaveChecker LeaveChecker = json.get().toJavaObject(UserLeaveChecker.class);
|
UserLeaveRequest LeaveChecker = json.get().toJavaObject(UserLeaveRequest.class);
|
||||||
// 检查类型
|
// 检查类型
|
||||||
if(LeaveChecker.getCheckType().equals("UsernameExistChecker")){
|
return jsonParameter.getJSONString(request);
|
||||||
// 根据学号计算用户名
|
|
||||||
String user = usernameEncoder.encode(LeaveChecker.getUsername()) ;
|
|
||||||
// 查询用户名存在状态
|
|
||||||
boolean existStatus = userService.checkIfUserExists(user).getKey();
|
|
||||||
// 构造返回对象
|
|
||||||
UserLeaveCheckerJSONRespond respond = new UserLeaveCheckerJSONRespond();
|
|
||||||
respond.setUserExist(existStatus);
|
|
||||||
return jsonParameter.getJSONString(respond);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// 返回失败对象
|
|
||||||
return jsonParameter.getJSONString(new JSONBaseRespondObject());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//列出某辅导员待审核名单
|
||||||
|
|
||||||
|
//列出某人
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,17 @@ package com.codesdream.ase.controller;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.codesdream.ase.component.datamanager.JSONParameter;
|
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||||
|
import com.codesdream.ase.component.api.QuickJSONRespond;
|
||||||
import com.codesdream.ase.component.json.respond.JSONStandardFailedRespond;
|
import com.codesdream.ase.component.json.respond.JSONStandardFailedRespond;
|
||||||
import com.codesdream.ase.component.json.respond.JSONBaseRespondObject;
|
|
||||||
import com.codesdream.ase.component.permission.ASEUsernameEncoder;
|
|
||||||
import com.codesdream.ase.component.json.request.UserLoginChecker;
|
import com.codesdream.ase.component.json.request.UserLoginChecker;
|
||||||
import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
|
import com.codesdream.ase.component.json.respond.UserLoginCheckerJSONRespond;
|
||||||
|
import com.codesdream.ase.service.IAuthService;
|
||||||
import com.codesdream.ase.service.IUserService;
|
import com.codesdream.ase.service.IUserService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
@ -25,29 +27,28 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Controller
|
@Controller
|
||||||
|
@Api(tags = "用户登录有关接口")
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private JSONParameter jsonParameter;
|
private JSONParameter jsonParameter;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private QuickJSONRespond quickJSONRespond;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IUserService userService;
|
private IUserService userService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ASEUsernameEncoder usernameEncoder;
|
private IAuthService authService;
|
||||||
|
|
||||||
@RequestMapping(value = "/login")
|
@PostMapping(value = "/login/check_exists")
|
||||||
String printLogin(Model model) {
|
|
||||||
return "login";
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/login/check_exists", method = RequestMethod.POST)
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
String checkExists(HttpServletRequest request){
|
String checkExists(HttpServletRequest request){
|
||||||
|
|
||||||
// 检查是否为JSON
|
// 检查是否为JSON
|
||||||
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
||||||
if(!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
if(!json.isPresent()) return quickJSONRespond.getRespond400("Invalid JSON Form");
|
||||||
|
|
||||||
|
|
||||||
UserLoginChecker loginChecker = json.get().toJavaObject(UserLoginChecker.class);
|
UserLoginChecker loginChecker = json.get().toJavaObject(UserLoginChecker.class);
|
||||||
@ -61,11 +62,11 @@ public class LoginController {
|
|||||||
// 构造返回对象
|
// 构造返回对象
|
||||||
UserLoginCheckerJSONRespond respond = new UserLoginCheckerJSONRespond();
|
UserLoginCheckerJSONRespond respond = new UserLoginCheckerJSONRespond();
|
||||||
respond.setUserExist(existStatus);
|
respond.setUserExist(existStatus);
|
||||||
return jsonParameter.getJSONString(respond);
|
return quickJSONRespond.getRespond200(null, respond);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 返回失败对象
|
// 返回失败对象
|
||||||
return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
return quickJSONRespond.getRespond400("CheckType Mismatch");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,23 +74,31 @@ public class LoginController {
|
|||||||
@RequestMapping(value = "/login/check_uid", method = RequestMethod.POST)
|
@RequestMapping(value = "/login/check_uid", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
String checkUsernameByStudentID(HttpServletRequest request){
|
String checkUsernameByStudentID(HttpServletRequest request){
|
||||||
|
|
||||||
|
String preValidationCode = request.getHeader("pvc");
|
||||||
|
|
||||||
|
// 检查随机预验证码
|
||||||
|
if(preValidationCode == null || !authService.preValidationCodeChecker(preValidationCode))
|
||||||
|
return quickJSONRespond.getRespond403("Invalid PreValidationCode");
|
||||||
|
|
||||||
// 检查是否为JSON
|
// 检查是否为JSON
|
||||||
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
||||||
if(!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
if(!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
||||||
|
|
||||||
UserLoginChecker loginChecker = json.get().toJavaObject(UserLoginChecker.class);
|
UserLoginChecker loginChecker = json.get().toJavaObject(UserLoginChecker.class);
|
||||||
|
|
||||||
|
if(loginChecker.getUsername() == null || loginChecker.getCheckType() == null)
|
||||||
|
return quickJSONRespond.getRespond406("Request Violates The Interface Protocol");
|
||||||
|
|
||||||
if(loginChecker.getCheckType().equals("UIDGeneratorChecker")) {
|
if(loginChecker.getCheckType().equals("UIDGeneratorChecker")) {
|
||||||
UserLoginCheckerJSONRespond respond = new UserLoginCheckerJSONRespond();
|
UserLoginCheckerJSONRespond respond = new UserLoginCheckerJSONRespond();
|
||||||
respond.setRespondInformation(userService.getUsernameByStudentId(loginChecker.getUsername()));
|
respond.setUid(userService.getUsernameByStudentId(loginChecker.getUsername()));
|
||||||
return jsonParameter.getJSONString(respond);
|
return quickJSONRespond.getRespond200(null, respond);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 返回失败对象
|
// 返回失败对象
|
||||||
return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
return quickJSONRespond.getRespond400("CheckType Mismatch");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,172 @@
|
|||||||
|
package com.codesdream.ase.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||||
|
import com.codesdream.ase.component.api.QuickJSONRespond;
|
||||||
|
import com.codesdream.ase.component.json.model.JsonableTag;
|
||||||
|
import com.codesdream.ase.component.json.model.JsonableTagUserList;
|
||||||
|
import com.codesdream.ase.component.json.model.JsonableUser;
|
||||||
|
import com.codesdream.ase.component.json.respond.PermissionJSONRespond;
|
||||||
|
import com.codesdream.ase.exception.badrequest.AlreadyExistException;
|
||||||
|
import com.codesdream.ase.exception.conflict.RelatedObjectsExistException;
|
||||||
|
import com.codesdream.ase.exception.notfound.NotFoundException;
|
||||||
|
import com.codesdream.ase.exception.notfound.TagNotFoundException;
|
||||||
|
import com.codesdream.ase.model.permission.Tag;
|
||||||
|
import com.codesdream.ase.model.permission.User;
|
||||||
|
import com.codesdream.ase.service.IUserService;
|
||||||
|
import com.codesdream.ase.service.PermissionService;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("pmt")
|
||||||
|
@Api(tags = "权限管理接口")
|
||||||
|
public class PermissionController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PermissionService permissionService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUserService userService;
|
||||||
|
|
||||||
|
// 根据名字创建新的标签
|
||||||
|
@PostMapping("tag")
|
||||||
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
|
@ApiOperation(value = "创建新的标签", notes = "创建标签时其ID自动分配,指定ID无效")
|
||||||
|
public JsonableTag createTag(@RequestBody JsonableTag tag){
|
||||||
|
String tagName = tag.getName();
|
||||||
|
Optional<Tag> tagOptional = permissionService.findTag(tagName);
|
||||||
|
if(tagOptional.isPresent()) throw new AlreadyExistException(tagName);
|
||||||
|
Tag newTag = permissionService.getDefaultTag(tagName);
|
||||||
|
if(tag.getDescription() != null) {
|
||||||
|
newTag.setDescription(tag.getDescription());
|
||||||
|
}
|
||||||
|
return new JsonableTag(permissionService.save(newTag));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据名字搜索标签的简要信息
|
||||||
|
@GetMapping("tag")
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
@ApiOperation("搜索标签信息")
|
||||||
|
@ApiImplicitParam(name = "name", value = "标签名")
|
||||||
|
public JsonableTag checkTag(@RequestParam(value = "name") String name){
|
||||||
|
Optional<Tag> tagOptional = permissionService.findTag(name);
|
||||||
|
if(tagOptional.isPresent()){
|
||||||
|
return new JsonableTag(tagOptional.get());
|
||||||
|
}
|
||||||
|
else throw new NotFoundException(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据名字搜索标签的简要信息
|
||||||
|
@GetMapping("tags")
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
@ApiOperation("列出所有的标签信息")
|
||||||
|
@ApiImplicitParam(name = "name", value = "标签名")
|
||||||
|
public Set<JsonableTag> listTag(){
|
||||||
|
Iterable<Tag> tagIterable = permissionService.findAllTag();
|
||||||
|
Set<JsonableTag> jsonableTagSet = new HashSet<>();
|
||||||
|
for(Tag tag : tagIterable){
|
||||||
|
jsonableTagSet.add(new JsonableTag(tag));
|
||||||
|
}
|
||||||
|
return jsonableTagSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据名字搜索标签的简要信息
|
||||||
|
@DeleteMapping("tag")
|
||||||
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||||
|
@ApiOperation("删除标签")
|
||||||
|
@ApiImplicitParam(name = "name", value = "标签名")
|
||||||
|
public void deleteTag(@RequestParam(value = "name") String name){
|
||||||
|
Optional<Tag> tag = permissionService.findTag(name);
|
||||||
|
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||||
|
|
||||||
|
// 检查外键关联
|
||||||
|
if(tag.get().getUsers().size() > 0) throw new RelatedObjectsExistException();
|
||||||
|
if(tag.get().getPermissionContainersCollections().size() > 0) throw new RelatedObjectsExistException();
|
||||||
|
|
||||||
|
permissionService.delete(tag.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("tag/users")
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
@ApiOperation("搜索单个标签所属用户集合信息")
|
||||||
|
public JsonableTagUserList getUserTag(@RequestParam(value = "name") String name){
|
||||||
|
Optional<Tag> tag = permissionService.findTag(name);
|
||||||
|
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||||
|
return new JsonableTagUserList(tag.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("tag/users")
|
||||||
|
@ApiOperation("更新索单个标签所属用户集合信息")
|
||||||
|
public JsonableTagUserList setUserTag(@RequestParam String name, @RequestBody JsonableTagUserList userList){
|
||||||
|
Optional<Tag> tag = permissionService.findTag(name);
|
||||||
|
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||||
|
|
||||||
|
Set<Integer> userSet = new HashSet<>(userList.getUsers());
|
||||||
|
tag.get().setUsers(userService.findUsersById(userSet));
|
||||||
|
|
||||||
|
return new JsonableTagUserList(permissionService.save(tag.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("tag/users")
|
||||||
|
@ApiOperation("更新单个标签所属用户集合中添加一个或多个用户")
|
||||||
|
public JsonableTagUserList addUserTag(@RequestParam String name, @RequestBody JsonableTagUserList userList){
|
||||||
|
Optional<Tag> tag = permissionService.findTag(name);
|
||||||
|
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||||
|
Set<User> newUserSet = userService.findUsersById(new HashSet<>(userList.getUsers()));
|
||||||
|
|
||||||
|
Set<User> userSet = tag.get().getUsers();
|
||||||
|
|
||||||
|
userSet.addAll(newUserSet);
|
||||||
|
tag.get().setUsers(userSet);
|
||||||
|
|
||||||
|
return new JsonableTagUserList(permissionService.save(tag.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("tag/users")
|
||||||
|
@ApiOperation("从单个标签所属用户集合中删除一个或多个用户")
|
||||||
|
@ApiImplicitParam(name = "name", value = "标签名")
|
||||||
|
public JsonableTagUserList deleteUserTag(@RequestParam String name, @RequestBody JsonableTagUserList userList){
|
||||||
|
Optional<Tag> tag = permissionService.findTag(name);
|
||||||
|
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||||
|
Set<User> userSet = tag.get().getUsers();
|
||||||
|
Set<User> deleteUserSet = userService.findUsersById(new HashSet<>(userList.getUsers()));
|
||||||
|
|
||||||
|
userSet.removeAll(deleteUserSet);
|
||||||
|
tag.get().setUsers(userSet);
|
||||||
|
|
||||||
|
return new JsonableTagUserList(permissionService.save(tag.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("tags/users")
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
@ApiOperation("搜索多个标签所属用户集合信息")
|
||||||
|
public Set<JsonableUser> getUserTags(@RequestParam(value = "name") List<String> names){
|
||||||
|
Set<Tag> tagSet = permissionService.findTags(names);
|
||||||
|
Set<User> userSet = new HashSet<>();
|
||||||
|
Set<JsonableUser> jsonableUsers = new HashSet<>();
|
||||||
|
for(Tag tag : tagSet){
|
||||||
|
userSet.addAll(tag.getUsers());
|
||||||
|
}
|
||||||
|
for(User user : userSet){
|
||||||
|
jsonableUsers.add(new JsonableUser(user));
|
||||||
|
}
|
||||||
|
return jsonableUsers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
package com.codesdream.ase.controller;
|
package com.codesdream.ase.controller;
|
||||||
|
|
||||||
|
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||||
|
import com.codesdream.ase.component.api.QuickJSONRespond;
|
||||||
|
import com.codesdream.ase.component.json.request.UserRegisterChecker;
|
||||||
import com.codesdream.ase.model.information.BaseStudentInfo;
|
import com.codesdream.ase.model.information.BaseStudentInfo;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
import com.codesdream.ase.service.BaseInformationService;
|
import com.codesdream.ase.service.BaseInformationService;
|
||||||
@ -8,18 +11,25 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Map;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class RegisterController {
|
public class RegisterController {
|
||||||
@Resource
|
@Resource
|
||||||
UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
BaseInformationService baseInformationService;
|
private BaseInformationService baseInformationService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private JSONParameter jsonParameter;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private QuickJSONRespond quickJSONRespond;
|
||||||
|
|
||||||
@RequestMapping(value = "/register")
|
@RequestMapping(value = "/register")
|
||||||
String registerView(Model model){
|
String registerView(Model model){
|
||||||
@ -27,55 +37,61 @@ public class RegisterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理注册表单
|
// 处理注册表单
|
||||||
@PostMapping(value = "/register")
|
@PostMapping(value = "/register/do_register")
|
||||||
String doRegister(Model model, HttpServletRequest request){
|
@ResponseBody
|
||||||
Map<String, String[]> parameterMap= request.getParameterMap();
|
String doRegister(HttpServletRequest request){
|
||||||
|
|
||||||
// 进行处理前的检查
|
Optional<UserRegisterChecker> registerCheckerOptional =
|
||||||
if(parameterMap.containsKey("student-id")
|
jsonParameter.getJavaObjectByRequest(request, UserRegisterChecker.class);
|
||||||
&& parameterMap.containsKey("password")
|
|
||||||
&& parameterMap.containsKey("retry-password")
|
|
||||||
&& parameterMap.containsKey("user-question")
|
|
||||||
&& parameterMap.containsKey("user-answer")
|
|
||||||
) {
|
|
||||||
// 获得提交学号
|
|
||||||
String student_id = parameterMap.get("student-id")[0].toString();
|
|
||||||
// 获得密保问题
|
|
||||||
String user_question = parameterMap.get("user-question")[0].toString();
|
|
||||||
// 获得密保答案
|
|
||||||
String user_answer = parameterMap.get("user-answer")[0].toString();
|
|
||||||
|
|
||||||
// 检查用户的基本信息是否录入系统
|
|
||||||
if(!baseInformationService.checkStudentInfo(student_id))
|
|
||||||
throw new RuntimeException("Student ID Not Found In Base Information Service");
|
|
||||||
|
|
||||||
// 查找对应的基本信息
|
|
||||||
BaseStudentInfo studentInfo = baseInformationService.findStudentInfoByStudentId(student_id);
|
|
||||||
|
|
||||||
// 根据基本信息生成对应用户
|
|
||||||
User user = userService.getUserByStudentInfo(studentInfo);
|
|
||||||
|
|
||||||
// 填充密保问题
|
|
||||||
user.getUserAuth().setUserQuestion(user_question);
|
|
||||||
user.getUserAuth().setUserAnswer(user_answer);
|
|
||||||
user.getUserAuth().setMail("");
|
|
||||||
|
|
||||||
String password = parameterMap.get("password")[0].toString();
|
|
||||||
String retry_password = parameterMap.get("retry-password")[0].toString();
|
|
||||||
|
|
||||||
if (password.equals(retry_password)) {
|
|
||||||
user.setPassword(password);
|
|
||||||
userService.save(user);
|
|
||||||
// 返回登录界面
|
|
||||||
return "login";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new RuntimeException("Retry Password Not Correct");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 检查JSON是否完整
|
||||||
|
if(!registerCheckerOptional.isPresent()){
|
||||||
|
return quickJSONRespond.getRespond400("Illegal JSON Format");
|
||||||
}
|
}
|
||||||
|
|
||||||
return "register";
|
// 检查数据是否完整
|
||||||
|
UserRegisterChecker registerChecker = registerCheckerOptional.get();
|
||||||
|
if(registerChecker.getPassword() == null
|
||||||
|
|| registerChecker.getStudentId() == null
|
||||||
|
|| registerChecker.getUserAnswer() == null
|
||||||
|
|| registerChecker.getUserQuestion() == null){
|
||||||
|
return quickJSONRespond.getRespond400("Incomplete Data");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得提交学号
|
||||||
|
String student_id = registerChecker.getStudentId();
|
||||||
|
// 获得密保问题
|
||||||
|
String user_question = registerChecker.getUserQuestion();
|
||||||
|
// 获得密保答案
|
||||||
|
String user_answer = registerChecker.getUserAnswer();
|
||||||
|
|
||||||
|
// 检查用户的基本信息是否录入系统
|
||||||
|
if(!baseInformationService.checkStudentInfo(student_id))
|
||||||
|
return quickJSONRespond.getRespond500("StudentID Base Information Not Found");
|
||||||
|
|
||||||
|
// 检查学号是否已被注册
|
||||||
|
if(userService.checkIfUserExists(userService.getUsernameByStudentId(student_id)).getKey()){
|
||||||
|
return quickJSONRespond.getRespond500("StudentID Already Used");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找对应的基本信息
|
||||||
|
BaseStudentInfo studentInfo = baseInformationService.findStudentInfoByStudentId(student_id);
|
||||||
|
|
||||||
|
// 根据基本信息生成对应用户
|
||||||
|
User user = userService.createUserByStudentInfo(studentInfo);
|
||||||
|
|
||||||
|
// 填充密保问题
|
||||||
|
user.getUserAuth().setUserQuestion(user_question);
|
||||||
|
user.getUserAuth().setUserAnswer(user_answer);
|
||||||
|
user.getUserAuth().setMail("");
|
||||||
|
|
||||||
|
String password = registerChecker.getPassword();
|
||||||
|
|
||||||
|
user.setPassword(password);
|
||||||
|
userService.save(user);
|
||||||
|
|
||||||
|
// 成功注册
|
||||||
|
return quickJSONRespond.getRespond200("Register Success");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,148 @@
|
|||||||
|
package com.codesdream.ase.controller.activity;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.codesdream.ase.component.ASESpringUtil;
|
||||||
|
import com.codesdream.ase.component.activity.ActivityConverter;
|
||||||
|
import com.codesdream.ase.component.activity.NullValueAttributes;
|
||||||
|
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||||
|
import com.codesdream.ase.component.json.respond.JSONStandardFailedRespond;
|
||||||
|
import com.codesdream.ase.configure.ActivityFormConfigure;
|
||||||
|
import com.codesdream.ase.exception.InvalidFormFormatException;
|
||||||
|
import com.codesdream.ase.model.activity.Activity;
|
||||||
|
import com.codesdream.ase.model.activity.UserActivity;
|
||||||
|
import com.codesdream.ase.model.permission.User;
|
||||||
|
import com.codesdream.ase.repository.activity.UserActivityRepository;
|
||||||
|
import com.codesdream.ase.repository.permission.UserRepository;
|
||||||
|
import com.codesdream.ase.service.ActivityService;
|
||||||
|
import com.codesdream.ase.validator.ActivityValidator;
|
||||||
|
import com.codesdream.ase.validator.NullValueValidator;
|
||||||
|
import com.codesdream.ase.validator.JSONFormValidator;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class ActivityCreatorController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ActivityService activityService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
JSONParameter jsonParameter;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ASESpringUtil aseSpringUtil;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ActivityFormConfigure activityFormConfigure;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
JSONFormValidator jsonFormValidator;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
NullValueValidator nullValueValidator;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
NullValueAttributes nullValueAttributes;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ActivityValidator activityValidator;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
UserRepository userRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
UserActivityRepository userActivityRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ActivityConverter activityConverter;
|
||||||
|
|
||||||
|
private final String url = "/forget/activity";
|
||||||
|
|
||||||
|
@RequestMapping(value = url + "/activity_creator")
|
||||||
|
String activityCreatorView(Model model){return "activity_creator";}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = url + "/activity_creator")
|
||||||
|
@ResponseBody
|
||||||
|
String activityCreator(HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||||
|
|
||||||
|
JSONObject error = new JSONObject();
|
||||||
|
aseSpringUtil = new ASESpringUtil();
|
||||||
|
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
||||||
|
if (!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
||||||
|
|
||||||
|
//WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
||||||
|
List<String> formatCheckResult = jsonFormValidator.check(activityFormConfigure.getStdActivityForm(), json.get());
|
||||||
|
if (!formatCheckResult.isEmpty()) {
|
||||||
|
error.put("error", formatCheckResult);
|
||||||
|
return error.toJSONString();
|
||||||
|
}
|
||||||
|
// 需要检查JSON是否合法
|
||||||
|
|
||||||
|
Activity activity = activityConverter.convertToActivity(json);
|
||||||
|
|
||||||
|
//NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class);
|
||||||
|
List<String> nullValues = nullValueValidator.checkNullValues(activity);
|
||||||
|
//= aseSpringUtil.getBean(NullValueAttributes.class);
|
||||||
|
for (String str : nullValues){
|
||||||
|
if(str.equals("title")){
|
||||||
|
nullValueAttributes.getNullValueAttributes().add("title");
|
||||||
|
}
|
||||||
|
else if(str.equals("creator")){
|
||||||
|
nullValueAttributes.getNullValueAttributes().add("creator");
|
||||||
|
}
|
||||||
|
else if(str.equals("type")){
|
||||||
|
nullValueAttributes.getNullValueAttributes().add("type");
|
||||||
|
}
|
||||||
|
else if(str.equals("planPeriod")){
|
||||||
|
nullValueAttributes.getNullValueAttributes().add("planPeriod");
|
||||||
|
}
|
||||||
|
else if(str.equals("chiefManager")){
|
||||||
|
nullValueAttributes.getNullValueAttributes().add("chiefManager");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//如果为空,存下此活动并跳转至成功创建页面
|
||||||
|
if(nullValueAttributes.getNullValueAttributes().isEmpty()){
|
||||||
|
|
||||||
|
//ActivityValidator activityValidator = aseSpringUtil.getBean(ActivityValidator.class);
|
||||||
|
String[] errorParameters = activityValidator.check(json);
|
||||||
|
if(errorParameters != null){
|
||||||
|
JSONObject invalidParameters = new JSONObject();
|
||||||
|
invalidParameters.put("invalid_parameters", errorParameters);
|
||||||
|
return invalidParameters.toJSONString();
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//UserRepository userRepository = aseSpringUtil.getBean(UserRepository.class);
|
||||||
|
//activityService = aseSpringUtil.getBean(ActivityService.class);
|
||||||
|
activity = activityService.createActivity(activity);
|
||||||
|
String username = json.get().get("creator").toString();
|
||||||
|
Optional<User> user = userRepository.findByUsername(username);
|
||||||
|
//UserActivityRepository userActivityRepository = aseSpringUtil.getBean(UserActivityRepository.class);
|
||||||
|
UserActivity userActivity = userActivityRepository.findByUser(user.get());
|
||||||
|
userActivity.getCreatedActivities().add(activity);
|
||||||
|
userActivityRepository.save(userActivity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//否则返回一个JSON对象给前端
|
||||||
|
else{
|
||||||
|
JSONObject nullParameters = new JSONObject();
|
||||||
|
nullParameters.put("null_values",nullValueAttributes.getNullValueAttributes());
|
||||||
|
return nullParameters.toJSONString();
|
||||||
|
}
|
||||||
|
return url + "/act_created";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -13,18 +13,19 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class ActivityViewerController {
|
public class ActivityViewerController {
|
||||||
|
|
||||||
|
private final String url = "/forget/activity";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
ActivityService activityService;
|
ActivityService activityService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
ActivityRepository activityRepository;
|
ActivityRepository activityRepository;
|
||||||
|
|
||||||
@RequestMapping(value = "/my/participated", method = RequestMethod.GET)
|
@RequestMapping(value = url + "/my/participated", method = RequestMethod.GET)
|
||||||
String showParticipated(Model model, HttpServletRequest request){
|
String showParticipated(Model model, HttpServletRequest request){
|
||||||
Principal principal = request.getUserPrincipal();
|
Principal principal = request.getUserPrincipal();
|
||||||
String username = principal.getName();
|
String username = principal.getName();
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
package com.codesdream.ase.exception;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class DataFileNotFoundException extends RuntimeException {
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
public DataFileNotFoundException(String filePath){
|
|
||||||
super();
|
|
||||||
this.path = filePath;
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,4 +12,8 @@ public class DataInvalidFormatException extends RuntimeException {
|
|||||||
super();
|
super();
|
||||||
information = e.getMessage();
|
information = e.getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DataInvalidFormatException(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|||||||
@Data
|
@Data
|
||||||
public class InvalidFormFormatException extends Throwable {
|
public class InvalidFormFormatException extends Throwable {
|
||||||
|
|
||||||
private String message = "";
|
private String message = "Invalid form format";
|
||||||
|
|
||||||
public InvalidFormFormatException(){
|
public InvalidFormFormatException(){
|
||||||
super();
|
super();
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.codesdream.ase.exception;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class StringFileConvertException extends RuntimeException {
|
||||||
|
public StringFileConvertException(String msg){
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.codesdream.ase.exception.badrequest;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class AlreadyExistException extends RuntimeException {
|
||||||
|
public AlreadyExistException(String msg){
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,16 @@
|
|||||||
package com.codesdream.ase.exception;
|
package com.codesdream.ase.exception.badrequest;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class BaseInformationAlreadyExistException extends RuntimeException {
|
public class BaseInformationAlreadyExistException extends AlreadyExistException {
|
||||||
private String className;
|
private String className;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public BaseInformationAlreadyExistException(Class<?> aClass, String value){
|
public BaseInformationAlreadyExistException(Class<?> aClass, String value){
|
||||||
super();
|
super(String.format("%s: %s", aClass.getName(), value));
|
||||||
this.className = aClass.getName();
|
this.className = aClass.getName();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
@ -1,16 +1,16 @@
|
|||||||
package com.codesdream.ase.exception;
|
package com.codesdream.ase.exception.badrequest;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class UsernameAlreadyExistException extends RuntimeException {
|
public class UsernameAlreadyExistException extends AlreadyExistException {
|
||||||
|
|
||||||
String username;
|
String username;
|
||||||
|
|
||||||
public UsernameAlreadyExistException(String username){
|
public UsernameAlreadyExistException(String username){
|
||||||
super();
|
super(username);
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.codesdream.ase.exception.conflict;
|
||||||
|
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存在与之相关联的对象
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class RelatedObjectsExistException extends RuntimeException {
|
||||||
|
public RelatedObjectsExistException(String msg){
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,16 @@
|
|||||||
package com.codesdream.ase.exception;
|
package com.codesdream.ase.exception.notfound;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class BaseInformationNotExistException extends RuntimeException {
|
public class BaseInformationNotFoundException extends NotFoundException {
|
||||||
private String className;
|
private String className;
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
public BaseInformationNotExistException(Class<?> baseInformationClass, String value){
|
public BaseInformationNotFoundException(Class<?> baseInformationClass, String value){
|
||||||
super();
|
super(String.format("%s: %s", baseInformationClass.getName(), value));
|
||||||
this.className = baseInformationClass.getName();
|
this.className = baseInformationClass.getName();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.codesdream.ase.exception.notfound;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class DataFileNotFoundException extends NotFoundException {
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
public DataFileNotFoundException(String msg){
|
||||||
|
super(msg);
|
||||||
|
this.path = msg;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.codesdream.ase.exception.notfound;
|
||||||
|
|
||||||
|
|
||||||
|
public class NotFoundException extends RuntimeException {
|
||||||
|
public NotFoundException(String msg){
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotFoundException(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.codesdream.ase.exception.notfound;
|
||||||
|
|
||||||
|
|
||||||
|
public class TagNotFoundException extends NotFoundException {
|
||||||
|
String tagName;
|
||||||
|
|
||||||
|
public TagNotFoundException(String tagName){
|
||||||
|
super(tagName);
|
||||||
|
this.tagName = tagName;
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,20 @@
|
|||||||
package com.codesdream.ase.exception;
|
package com.codesdream.ase.exception.notfound;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class UserNotFoundException extends RuntimeException {
|
public class UserNotFoundException extends NotFoundException {
|
||||||
Integer id;
|
Integer id;
|
||||||
String username;
|
String username;
|
||||||
|
|
||||||
public UserNotFoundException(Integer id, String username){
|
public UserNotFoundException(Integer id, String username){
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserNotFoundException(String msg){
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
}
|
}
|
@ -129,6 +129,7 @@ public class Activity {
|
|||||||
|
|
||||||
//计划开始时间
|
//计划开始时间
|
||||||
@OneToOne(cascade = CascadeType.ALL)
|
@OneToOne(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(nullable = false)
|
||||||
private Period planPeriod;
|
private Period planPeriod;
|
||||||
|
|
||||||
//实际开始时间
|
//实际开始时间
|
||||||
@ -154,11 +155,11 @@ public class Activity {
|
|||||||
private Set<User> assistManagers;
|
private Set<User> assistManagers;
|
||||||
|
|
||||||
//是否开始
|
//是否开始
|
||||||
@Column//(name = "is_on", nullable = false)
|
@Column(name = "is_on", nullable = false)
|
||||||
boolean isOn;
|
boolean isOn;
|
||||||
|
|
||||||
//是否结束
|
//是否结束
|
||||||
@Column//(name = "is_off", nullable = false)
|
@Column(name = "is_off", nullable = false)
|
||||||
boolean isOff;
|
boolean isOff;
|
||||||
|
|
||||||
//考勤安排
|
//考勤安排
|
||||||
|
@ -29,4 +29,13 @@ public class Period {
|
|||||||
@Column(name = "enabled")//, nullable = false)
|
@Column(name = "enabled")//, nullable = false)
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
|
public Period(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Period(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public class UserActivity {
|
|||||||
|
|
||||||
//关联的用户
|
//关联的用户
|
||||||
@OneToOne(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY, mappedBy = "userActivity")
|
@OneToOne(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY, mappedBy = "userActivity")
|
||||||
@JoinColumn(nullable = false)
|
@JoinColumn(nullable = false, unique = true)
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
//主要负责的活动
|
//主要负责的活动
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.codesdream.ase.model.auth;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "pre_validation_code")
|
||||||
|
public class PreValidationCode {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
private Date date = new Date();
|
||||||
|
|
||||||
|
}
|
@ -12,7 +12,7 @@ import javax.persistence.*;
|
|||||||
@Table(name = "base_major")
|
@Table(name = "base_major")
|
||||||
public class BaseMajor {
|
public class BaseMajor {
|
||||||
@Id
|
@Id
|
||||||
private int id;
|
private String id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,10 @@ import com.codesdream.ase.model.permission.User;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "leave")
|
@Table(name = "leaves")
|
||||||
public class Leave {
|
public class Leave {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
@ -17,15 +18,25 @@ public class Leave {
|
|||||||
//审批人容器
|
//审批人容器
|
||||||
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||||
private Set <User> userTo;
|
private Set <User> userTo;
|
||||||
|
//请假原因
|
||||||
|
@Column
|
||||||
|
private String reasonToLeave;
|
||||||
|
|
||||||
|
|
||||||
//请假类型 病假,事假等
|
//请假类型 病假,事假等
|
||||||
@Column(name = "type", nullable = false)
|
@Column(nullable = false)
|
||||||
private String type;
|
private String type;
|
||||||
//批准状态
|
//批准状态
|
||||||
@Column(name = "Authentication", nullable = false)
|
@Column(nullable = false)
|
||||||
private Boolean Authentication;
|
private String authentication;
|
||||||
|
|
||||||
|
//审核备注
|
||||||
|
@Column
|
||||||
|
private String comment;
|
||||||
//开始时间
|
//开始时间
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Date startTime;
|
private Date startTime;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Date endTime;
|
private Date endTime;
|
||||||
//申请时间
|
//申请时间
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.codesdream.ase.repository.activity;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.activity.Attendance;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface AttendanceRepository extends CrudRepository<Attendance, Integer> {
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.codesdream.ase.repository.activity;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.activity.Period;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface PeriodRepository extends CrudRepository<Period, Integer> {
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.codesdream.ase.repository.activity;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.activity.UserActivity;
|
||||||
|
import com.codesdream.ase.model.permission.User;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface UserActivityRepository extends CrudRepository<UserActivity, Integer> {
|
||||||
|
|
||||||
|
UserActivity findByUser(User user);
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.codesdream.ase.repository.auth;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.auth.PreValidationCode;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface PreValidationCodeRepository extends CrudRepository<PreValidationCode, Integer> {
|
||||||
|
Optional<PreValidationCode> findByValue(String value);
|
||||||
|
}
|
@ -7,6 +7,6 @@ import org.springframework.stereotype.Repository;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface BaseMajorRepository extends CrudRepository<BaseMajor, Integer> {
|
public interface BaseMajorRepository extends CrudRepository<BaseMajor, String> {
|
||||||
Optional<BaseMajor> findByName(String name);
|
Optional<BaseMajor> findByName(String name);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,5 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public interface LeaveRepository extends CrudRepository<Leave, Integer>{
|
public interface LeaveRepository extends CrudRepository<Leave, Integer>{
|
||||||
|
|
||||||
Optional<Leave> findByTitle(String title) ;
|
|
||||||
Optional<Leave> findByCreator(String creatorName);
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package com.codesdream.ase.service;
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
import com.codesdream.ase.component.permission.UserAuthoritiesGenerator;
|
import com.codesdream.ase.component.permission.UserAuthoritiesGenerator;
|
||||||
|
import com.codesdream.ase.exception.notfound.UserNotFoundException;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ASEUserDetailsService implements UserDetailsService {
|
public class ASEUserDetailsService implements UserDetailsService {
|
||||||
@ -21,9 +23,16 @@ public class ASEUserDetailsService implements UserDetailsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String s) {
|
||||||
User user = userService.findUserByUsername(s);
|
try {
|
||||||
user.setAuthorities(userAuthoritiesGenerator.grantedAuthorities(user));
|
Optional<User> userOptional = userService.findUserByUsername(s);
|
||||||
return user;
|
if(!userOptional.isPresent()) throw new UserNotFoundException(s);
|
||||||
|
User user = userOptional.get();
|
||||||
|
user.setAuthorities(userAuthoritiesGenerator.grantedAuthorities(user));
|
||||||
|
return user;
|
||||||
|
} catch (UserNotFoundException e){
|
||||||
|
throw new AuthenticationServiceException("User Not Exist");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.activity.Attendance;
|
||||||
|
import com.codesdream.ase.repository.activity.AttendanceRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AttendanceService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
AttendanceRepository attendanceRepository;
|
||||||
|
|
||||||
|
public Attendance save(Attendance attendance) {
|
||||||
|
return attendanceRepository.save(attendance);
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,19 @@
|
|||||||
package com.codesdream.ase.service;
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
import com.codesdream.ase.component.auth.AuthTokenGenerator;
|
import com.codesdream.ase.component.auth.AuthTokenGenerator;
|
||||||
|
import com.codesdream.ase.component.auth.TimestampExpiredChecker;
|
||||||
import com.codesdream.ase.model.auth.JSONToken;
|
import com.codesdream.ase.model.auth.JSONToken;
|
||||||
|
import com.codesdream.ase.model.auth.PreValidationCode;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
import com.codesdream.ase.repository.auth.JSONTokenRepository;
|
import com.codesdream.ase.repository.auth.JSONTokenRepository;
|
||||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
import com.codesdream.ase.repository.auth.PreValidationCodeRepository;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
// 认证服务
|
// 认证服务
|
||||||
@Service
|
@Service
|
||||||
@ -25,6 +28,12 @@ public class AuthService implements IAuthService {
|
|||||||
@Resource
|
@Resource
|
||||||
private AuthTokenGenerator authTokenGenerator;
|
private AuthTokenGenerator authTokenGenerator;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PreValidationCodeRepository preValidationCodeRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TimestampExpiredChecker timestampExpiredChecker;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<JSONToken> findTokenByUserName(String username) {
|
public Optional<JSONToken> findTokenByUserName(String username) {
|
||||||
return jsonTokenRepository.findByUsername(username);
|
return jsonTokenRepository.findByUsername(username);
|
||||||
@ -60,4 +69,24 @@ public class AuthService implements IAuthService {
|
|||||||
}
|
}
|
||||||
else return Optional.empty();
|
else return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String preValidationCodeGetter() {
|
||||||
|
PreValidationCode preValidationCode = new
|
||||||
|
PreValidationCode();
|
||||||
|
preValidationCode.setValue(UUID.randomUUID().toString());
|
||||||
|
preValidationCode = preValidationCodeRepository.save(preValidationCode);
|
||||||
|
return preValidationCode.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean preValidationCodeChecker(String pvc) {
|
||||||
|
Optional<PreValidationCode> preValidationCode =
|
||||||
|
preValidationCodeRepository.findByValue(pvc);
|
||||||
|
if(preValidationCode.filter(validationCode -> timestampExpiredChecker.checkDateBeforeMaxTime(validationCode.getDate(), 60)).isPresent()){
|
||||||
|
preValidationCodeRepository.delete(preValidationCode.get());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.codesdream.ase.service;
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
import com.codesdream.ase.component.datamanager.DataTable;
|
import com.codesdream.ase.component.datamanager.DataTable;
|
||||||
import com.codesdream.ase.exception.BaseInformationAlreadyExistException;
|
import com.codesdream.ase.exception.badrequest.BaseInformationAlreadyExistException;
|
||||||
import com.codesdream.ase.exception.BaseInformationIllegalException;
|
import com.codesdream.ase.exception.BaseInformationIllegalException;
|
||||||
import com.codesdream.ase.exception.BaseInformationNotExistException;
|
import com.codesdream.ase.exception.notfound.BaseInformationNotFoundException;
|
||||||
import com.codesdream.ase.model.information.*;
|
import com.codesdream.ase.model.information.*;
|
||||||
import com.codesdream.ase.repository.information.*;
|
import com.codesdream.ase.repository.information.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -20,25 +20,25 @@ import java.util.Vector;
|
|||||||
public class BaseInformationService implements IBaseInformationService {
|
public class BaseInformationService implements IBaseInformationService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
BaseAdministrativeDivisionRepository administrativeDivisionRepository;
|
private BaseAdministrativeDivisionRepository administrativeDivisionRepository;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
BaseCandidateCategoryRepository candidateCategoryRepository;
|
private BaseCandidateCategoryRepository candidateCategoryRepository;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
BaseCollegeRepository collegeRepository;
|
private BaseCollegeRepository collegeRepository;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
BaseEthnicRepository ethnicRepository;
|
private BaseEthnicRepository ethnicRepository;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
BaseMajorRepository majorRepository;
|
private BaseMajorRepository majorRepository;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
BasePoliticalStatusRepository politicalStatusRepository;
|
private BasePoliticalStatusRepository politicalStatusRepository;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
BaseStudentInfoRepository studentInfoRepository;
|
private BaseStudentInfoRepository studentInfoRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkAdministrativeDivision(String name) {
|
public boolean checkAdministrativeDivision(String name) {
|
||||||
@ -103,7 +103,7 @@ public class BaseInformationService implements IBaseInformationService {
|
|||||||
if(administrativeDivision.isPresent()) {
|
if(administrativeDivision.isPresent()) {
|
||||||
return administrativeDivision.get();
|
return administrativeDivision.get();
|
||||||
}
|
}
|
||||||
else throw new BaseInformationNotExistException(BaseAdministrativeDivision.class, name);
|
else throw new BaseInformationNotFoundException(BaseAdministrativeDivision.class, name);
|
||||||
|
|
||||||
}
|
}
|
||||||
return administrativeDivision.get();
|
return administrativeDivision.get();
|
||||||
@ -114,7 +114,7 @@ public class BaseInformationService implements IBaseInformationService {
|
|||||||
Optional<BaseCollege> college =
|
Optional<BaseCollege> college =
|
||||||
collegeRepository.findByName(name);
|
collegeRepository.findByName(name);
|
||||||
// 检查
|
// 检查
|
||||||
if(!college.isPresent()) throw new BaseInformationNotExistException(BaseCollege.class, name);
|
if(!college.isPresent()) throw new BaseInformationNotFoundException(BaseCollege.class, name);
|
||||||
return college.get();
|
return college.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ public class BaseInformationService implements IBaseInformationService {
|
|||||||
public BaseEthnic findEthnicByName(String name) {
|
public BaseEthnic findEthnicByName(String name) {
|
||||||
Optional<BaseEthnic> ethnic =
|
Optional<BaseEthnic> ethnic =
|
||||||
ethnicRepository.findByName(name);
|
ethnicRepository.findByName(name);
|
||||||
if(!ethnic.isPresent()) throw new BaseInformationNotExistException(BaseEthnic.class, name);
|
if(!ethnic.isPresent()) throw new BaseInformationNotFoundException(BaseEthnic.class, name);
|
||||||
return ethnic.get();
|
return ethnic.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ public class BaseInformationService implements IBaseInformationService {
|
|||||||
public BaseMajor findMajorByName(String name) {
|
public BaseMajor findMajorByName(String name) {
|
||||||
Optional<BaseMajor> major =
|
Optional<BaseMajor> major =
|
||||||
majorRepository.findByName(name);
|
majorRepository.findByName(name);
|
||||||
if(!major.isPresent()) throw new BaseInformationNotExistException(BaseMajor.class, name);
|
if(!major.isPresent()) throw new BaseInformationNotFoundException(BaseMajor.class, name);
|
||||||
return major.get();
|
return major.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ public class BaseInformationService implements IBaseInformationService {
|
|||||||
Optional<BasePoliticalStatus> politicalStatus =
|
Optional<BasePoliticalStatus> politicalStatus =
|
||||||
politicalStatusRepository.findByName(name);
|
politicalStatusRepository.findByName(name);
|
||||||
if(!politicalStatus.isPresent())
|
if(!politicalStatus.isPresent())
|
||||||
throw new BaseInformationNotExistException(BasePoliticalStatus.class, name);
|
throw new BaseInformationNotFoundException(BasePoliticalStatus.class, name);
|
||||||
return politicalStatus.get();
|
return politicalStatus.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ public class BaseInformationService implements IBaseInformationService {
|
|||||||
Optional<BaseCandidateCategory> candidateCategory =
|
Optional<BaseCandidateCategory> candidateCategory =
|
||||||
candidateCategoryRepository.findByName(name);
|
candidateCategoryRepository.findByName(name);
|
||||||
if(!candidateCategory.isPresent())
|
if(!candidateCategory.isPresent())
|
||||||
throw new BaseInformationNotExistException(BaseCandidateCategory.class, name);
|
throw new BaseInformationNotFoundException(BaseCandidateCategory.class, name);
|
||||||
return candidateCategory.get();
|
return candidateCategory.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ public class BaseInformationService implements IBaseInformationService {
|
|||||||
Optional<BaseStudentInfo> studentInfo =
|
Optional<BaseStudentInfo> studentInfo =
|
||||||
studentInfoRepository.findByStudentId(studentId);
|
studentInfoRepository.findByStudentId(studentId);
|
||||||
if(!studentInfo.isPresent())
|
if(!studentInfo.isPresent())
|
||||||
throw new BaseInformationNotExistException(BaseStudentInfo.class, studentId);
|
throw new BaseInformationNotFoundException(BaseStudentInfo.class, studentId);
|
||||||
return studentInfo.get();
|
return studentInfo.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ public class BaseInformationService implements IBaseInformationService {
|
|||||||
row.elementAt(infoIndex.elementAt(7)),
|
row.elementAt(infoIndex.elementAt(7)),
|
||||||
row.elementAt(infoIndex.elementAt(8)));
|
row.elementAt(infoIndex.elementAt(8)));
|
||||||
save(studentInfo);
|
save(studentInfo);
|
||||||
} catch (BaseInformationNotExistException e){
|
} catch (BaseInformationNotFoundException e){
|
||||||
String log_info = String.format("一项学生信息的某项基本信息未在数据库找到, 该项数据无效." +
|
String log_info = String.format("一项学生信息的某项基本信息未在数据库找到, 该项数据无效." +
|
||||||
" %s: %s",e.getClassName(), e.getValue());
|
" %s: %s",e.getClassName(), e.getValue());
|
||||||
log.warn(log_info);
|
log.warn(log_info);
|
||||||
@ -281,7 +281,7 @@ public class BaseInformationService implements IBaseInformationService {
|
|||||||
public BaseStudentInfo update(BaseStudentInfo baseStudentInfo) {
|
public BaseStudentInfo update(BaseStudentInfo baseStudentInfo) {
|
||||||
// 更新前检查
|
// 更新前检查
|
||||||
if(!checkStudentInfo(baseStudentInfo.getStudentId()))
|
if(!checkStudentInfo(baseStudentInfo.getStudentId()))
|
||||||
throw new BaseInformationNotExistException(BaseStudentInfo.class, baseStudentInfo.getStudentId());
|
throw new BaseInformationNotFoundException(BaseStudentInfo.class, baseStudentInfo.getStudentId());
|
||||||
return studentInfoRepository.save(baseStudentInfo);
|
return studentInfoRepository.save(baseStudentInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,10 @@ public interface IAuthService {
|
|||||||
|
|
||||||
// 为用户获得一个新的API Token
|
// 为用户获得一个新的API Token
|
||||||
Optional<String> userNewTokenGetter(String username, String clientCode);
|
Optional<String> userNewTokenGetter(String username, String clientCode);
|
||||||
|
|
||||||
|
// 获得一个新的预验证码
|
||||||
|
String preValidationCodeGetter();
|
||||||
|
|
||||||
|
// 检验预验证码
|
||||||
|
boolean preValidationCodeChecker(String pvc);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,9 @@ import com.codesdream.ase.model.permission.*;
|
|||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface IPermissionService {
|
public interface IPermissionService {
|
||||||
|
|
||||||
@ -19,6 +21,14 @@ public interface IPermissionService {
|
|||||||
// 查找用户标签
|
// 查找用户标签
|
||||||
Optional<Tag> findTag(String name);
|
Optional<Tag> findTag(String name);
|
||||||
|
|
||||||
|
// 查找用户标签
|
||||||
|
Optional<Tag> findTag(Integer id);
|
||||||
|
|
||||||
|
// 列出所有的标签
|
||||||
|
Iterable<Tag> findAllTag();
|
||||||
|
|
||||||
|
Set<Tag> findTags(List<String> names);
|
||||||
|
|
||||||
// 查找功能性权限容器
|
// 查找功能性权限容器
|
||||||
Optional<FunctionalPermissionContainer> findFPC(String name);
|
Optional<FunctionalPermissionContainer> findFPC(String name);
|
||||||
|
|
||||||
@ -41,12 +51,13 @@ public interface IPermissionService {
|
|||||||
// 查找用户下的所有标签列表
|
// 查找用户下的所有标签列表
|
||||||
Collection<Tag> getTagsFromUser(User user);
|
Collection<Tag> getTagsFromUser(User user);
|
||||||
|
|
||||||
|
|
||||||
// 查找功能性权限容器下的所有范围性权限容器列表
|
// 查找功能性权限容器下的所有范围性权限容器列表
|
||||||
Collection<FunctionalPermissionContainer> getFPCs(
|
Collection<FunctionalPermissionContainer> getFPCs(
|
||||||
PermissionContainersCollection pcc);
|
PermissionContainersCollection pcc);
|
||||||
|
|
||||||
// 查找标签下的所有用户
|
// 查找标签下的所有用户
|
||||||
Collection<User> getUsersFromTag(Tag tag);
|
Set<User> getUsersFromTag(Tag tag);
|
||||||
|
|
||||||
// 指定一对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
// 指定一对功能性权限容器与对应的范围性权限容器并添加到指定权限容器集合中
|
||||||
PermissionContainersCollection addRelationItemToPCC(
|
PermissionContainersCollection addRelationItemToPCC(
|
||||||
@ -90,6 +101,8 @@ public interface IPermissionService {
|
|||||||
|
|
||||||
Tag save(Tag tag);
|
Tag save(Tag tag);
|
||||||
|
|
||||||
|
void delete(Tag tag);
|
||||||
|
|
||||||
FunctionalPermissionContainer save(FunctionalPermissionContainer fpc);
|
FunctionalPermissionContainer save(FunctionalPermissionContainer fpc);
|
||||||
|
|
||||||
ScopePermissionContainer save(ScopePermissionContainer spc);
|
ScopePermissionContainer save(ScopePermissionContainer spc);
|
||||||
|
@ -8,6 +8,7 @@ import org.springframework.security.core.GrantedAuthority;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
public interface IUserService {
|
public interface IUserService {
|
||||||
@ -16,13 +17,13 @@ public interface IUserService {
|
|||||||
User getDefaultUser();
|
User getDefaultUser();
|
||||||
|
|
||||||
// 由学生基本信息生成对应用户
|
// 由学生基本信息生成对应用户
|
||||||
User getUserByStudentInfo(BaseStudentInfo studentInfo);
|
User createUserByStudentInfo(BaseStudentInfo studentInfo);
|
||||||
|
|
||||||
List<User> findAll();
|
List<User> findAll();
|
||||||
|
|
||||||
Optional<User> findUserById(int id);
|
Optional<User> findUserById(int id);
|
||||||
|
|
||||||
User findUserByUsername(String username);
|
Optional<User> findUserByUsername(String username);
|
||||||
|
|
||||||
// 查询用户是否存在
|
// 查询用户是否存在
|
||||||
public Pair<Boolean, User> checkIfUserExists(String username);
|
public Pair<Boolean, User> checkIfUserExists(String username);
|
||||||
@ -42,6 +43,8 @@ public interface IUserService {
|
|||||||
// 更具学号获得对应的用户名
|
// 更具学号获得对应的用户名
|
||||||
String getUsernameByStudentId(String studentId);
|
String getUsernameByStudentId(String studentId);
|
||||||
|
|
||||||
|
Set<User> findUsersById(Set<Integer> usersId);
|
||||||
|
|
||||||
// 随机生成一个用户名
|
// 随机生成一个用户名
|
||||||
void generateRandomUsername(User user);
|
void generateRandomUsername(User user);
|
||||||
|
|
||||||
|
22
src/main/java/com/codesdream/ase/service/PeriodService.java
Normal file
22
src/main/java/com/codesdream/ase/service/PeriodService.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.activity.Period;
|
||||||
|
import com.codesdream.ase.repository.activity.PeriodRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PeriodService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
PeriodRepository periodRepository;
|
||||||
|
|
||||||
|
public Period save(Period period) {
|
||||||
|
return periodRepository.save(period);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(Period period) {
|
||||||
|
periodRepository.delete(period);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package com.codesdream.ase.service;
|
|||||||
|
|
||||||
import com.codesdream.ase.component.permission.UserFPCListGenerator;
|
import com.codesdream.ase.component.permission.UserFPCListGenerator;
|
||||||
import com.codesdream.ase.component.permission.UserFSRGenerator;
|
import com.codesdream.ase.component.permission.UserFSRGenerator;
|
||||||
|
import com.codesdream.ase.exception.notfound.NotFoundException;
|
||||||
import com.codesdream.ase.model.permission.*;
|
import com.codesdream.ase.model.permission.*;
|
||||||
import com.codesdream.ase.repository.permission.FunctionalPermissionContainerRepository;
|
import com.codesdream.ase.repository.permission.FunctionalPermissionContainerRepository;
|
||||||
import com.codesdream.ase.repository.permission.PermissionContainersCollectionRepository;
|
import com.codesdream.ase.repository.permission.PermissionContainersCollectionRepository;
|
||||||
@ -12,9 +13,7 @@ import org.apache.poi.ss.formula.functions.T;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PermissionService implements IPermissionService {
|
public class PermissionService implements IPermissionService {
|
||||||
@ -65,6 +64,27 @@ public class PermissionService implements IPermissionService {
|
|||||||
return tagRepository.findByName(name);
|
return tagRepository.findByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Tag> findTag(Integer id) {
|
||||||
|
return tagRepository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Tag> findAllTag() {
|
||||||
|
return tagRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Tag> findTags(List<String> names) {
|
||||||
|
Set<Tag> tagSet = new HashSet<>();
|
||||||
|
for(String name : names){
|
||||||
|
Optional<Tag> tag = findTag(name);
|
||||||
|
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||||
|
tagSet.add(tag.get());
|
||||||
|
}
|
||||||
|
return tagSet;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<FunctionalPermissionContainer> findFPC(String name) {
|
public Optional<FunctionalPermissionContainer> findFPC(String name) {
|
||||||
return fpcRepository.findByName(name);
|
return fpcRepository.findByName(name);
|
||||||
@ -117,8 +137,8 @@ public class PermissionService implements IPermissionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<User> getUsersFromTag(Tag tag) {
|
public Set<User> getUsersFromTag(Tag tag) {
|
||||||
return new ArrayList<>(tag.getUsers());
|
return new HashSet<>(tag.getUsers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -220,6 +240,11 @@ public class PermissionService implements IPermissionService {
|
|||||||
return tagRepository.save(tag);
|
return tagRepository.save(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Tag tag) {
|
||||||
|
tagRepository.delete(tag);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FunctionalPermissionContainer save(FunctionalPermissionContainer fpc) {
|
public FunctionalPermissionContainer save(FunctionalPermissionContainer fpc) {
|
||||||
if(fpcRepository.findByName(fpc.getName()).isPresent())
|
if(fpcRepository.findByName(fpc.getName()).isPresent())
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.codesdream.ase.service;
|
package com.codesdream.ase.service;
|
||||||
|
|
||||||
import com.codesdream.ase.component.permission.ASEPasswordEncoder;
|
import com.codesdream.ase.component.auth.ASEPasswordEncoder;
|
||||||
import com.codesdream.ase.component.permission.ASEUsernameEncoder;
|
import com.codesdream.ase.component.auth.ASEUsernameEncoder;
|
||||||
import com.codesdream.ase.component.permission.UserRolesListGenerator;
|
import com.codesdream.ase.component.permission.UserRolesListGenerator;
|
||||||
import com.codesdream.ase.exception.UserInformationIllegalException;
|
import com.codesdream.ase.exception.UserInformationIllegalException;
|
||||||
import com.codesdream.ase.exception.UserNotFoundException;
|
import com.codesdream.ase.exception.notfound.UserNotFoundException;
|
||||||
import com.codesdream.ase.exception.UsernameAlreadyExistException;
|
import com.codesdream.ase.exception.badrequest.UsernameAlreadyExistException;
|
||||||
import com.codesdream.ase.model.information.BaseStudentInfo;
|
import com.codesdream.ase.model.information.BaseStudentInfo;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
import com.codesdream.ase.repository.permission.UserRepository;
|
import com.codesdream.ase.repository.permission.UserRepository;
|
||||||
@ -15,10 +15,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService implements IUserService {
|
public class UserService implements IUserService {
|
||||||
@ -45,10 +42,10 @@ public class UserService implements IUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User findUserByUsername(String username) {
|
public Optional<User> findUserByUsername(String username) {
|
||||||
Optional<User> user = userRepository.findByUsername(username);
|
Optional<User> user = userRepository.findByUsername(username);
|
||||||
if(!user.isPresent()) throw new UsernameNotFoundException(username);
|
if(!user.isPresent()) throw new UsernameNotFoundException(username);
|
||||||
return user.get();
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,6 +83,17 @@ public class UserService implements IUserService {
|
|||||||
return usernameEncoder.encode(studentId);
|
return usernameEncoder.encode(studentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<User> findUsersById(Set<Integer> usersId) {
|
||||||
|
Set<User> userSet = new HashSet<>();
|
||||||
|
for(Integer id : usersId){
|
||||||
|
Optional<User> user = findUserById(id);
|
||||||
|
if(!user.isPresent()) throw new UserNotFoundException(String.format("ID: %d", id));
|
||||||
|
userSet.add(user.get());
|
||||||
|
}
|
||||||
|
return userSet;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateRandomUsername(User user) {
|
public void generateRandomUsername(User user) {
|
||||||
user.setUsername(usernameEncoder.encode(UUID.randomUUID().toString()));
|
user.setUsername(usernameEncoder.encode(UUID.randomUUID().toString()));
|
||||||
@ -97,14 +105,13 @@ public class UserService implements IUserService {
|
|||||||
if(userRepository.findByUsername(user.getUsername()).isPresent())
|
if(userRepository.findByUsername(user.getUsername()).isPresent())
|
||||||
throw new UsernameAlreadyExistException(user.getUsername());
|
throw new UsernameAlreadyExistException(user.getUsername());
|
||||||
|
|
||||||
// 用户信息一般性规范检查
|
// 用户关键信息一般性规范检查
|
||||||
if(user.getUserAuth().getUserAnswer() == null
|
if(user.getUserAuth().getUserAnswer() == null
|
||||||
|| user.getUserAuth().getUserQuestion() == null
|
|| user.getUserAuth().getUserQuestion() == null
|
||||||
|| user.getUserAuth().getStudentID() == null
|
|| user.getUserAuth().getStudentID() == null
|
||||||
|| user.getUserDetail().getRealName() == null
|
|| user.getUserDetail().getRealName() == null
|
||||||
|| user.getUserAuth().getMail() == null){
|
|| user.getUserAuth().getMail() == null){
|
||||||
|
throw new RuntimeException("Some Key Information IS NULL");
|
||||||
throw new RuntimeException("Key Information IS NULL");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,7 +152,7 @@ public class UserService implements IUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User getUserByStudentInfo(BaseStudentInfo studentInfo) {
|
public User createUserByStudentInfo(BaseStudentInfo studentInfo) {
|
||||||
User user = getDefaultUser();
|
User user = getDefaultUser();
|
||||||
// 根据学生id生成用户名
|
// 根据学生id生成用户名
|
||||||
generateRandomUsernameByStudentID(user, studentInfo.getStudentId());
|
generateRandomUsernameByStudentID(user, studentInfo.getStudentId());
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.codesdream.ase.validator;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.codesdream.ase.model.activity.Activity;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.nio.file.OpenOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
//检查当前活动各属性值是否合法(存在)
|
||||||
|
@Component
|
||||||
|
public class ActivityValidator {
|
||||||
|
|
||||||
|
public String[] check(Optional<JSONObject> json) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.codesdream.ase.validator;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.codesdream.ase.exception.DataIllegalTableFormatException;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
//用于检查JSON格式是否合法
|
||||||
|
@Component
|
||||||
|
public class JSONFormValidator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param stdForm 标准表单格式,根据需求自定义
|
||||||
|
* @param json 待检验的json对象
|
||||||
|
* @return 空列表或者缺失的表单信息列表
|
||||||
|
*/
|
||||||
|
public List<String> check(Set<String> stdForm, JSONObject json) {
|
||||||
|
|
||||||
|
List<String> res = new ArrayList<>();
|
||||||
|
Set<String> jsonForm = json.keySet();
|
||||||
|
for (String str : stdForm) {
|
||||||
|
if (!jsonForm.contains(str)) {
|
||||||
|
res.add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +0,0 @@
|
|||||||
package com.codesdream.ase.validator;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
//用于检查网页表单格式是否合法
|
|
||||||
@Component
|
|
||||||
public class WebFormValidator {
|
|
||||||
|
|
||||||
public boolean check(Collection<String> stdForm, Map<String, String[]> webFormMap){
|
|
||||||
|
|
||||||
Collection<String> webForm = webFormMap.keySet();
|
|
||||||
if(stdForm.containsAll(webForm)){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
23
src/main/resources/application-dev.properties
Normal file
23
src/main/resources/application-dev.properties
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
server.port=8081
|
||||||
|
|
||||||
|
spring.thymeleaf.prefix=classpath:templates/
|
||||||
|
spring.thymeleaf.suffix=.html
|
||||||
|
spring.thymeleaf.mode=HTML
|
||||||
|
spring.thymeleaf.encoding=UTF-8
|
||||||
|
|
||||||
|
spring.jpa.generate-ddl=false
|
||||||
|
spring.jpa.show-sql=true
|
||||||
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
|
spring.jooq.sql-dialect=org.hibernate.dialect.MariaDB102Dialect
|
||||||
|
spring.jpa.open-in-view=true
|
||||||
|
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
|
||||||
|
|
||||||
|
spring.datasource.url=jdbc:mariadb://localhost:3306/ase?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
|
||||||
|
spring.datasource.username=root
|
||||||
|
spring.datasource.password=#a9b9fa6422
|
||||||
|
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
||||||
|
|
||||||
|
server.error.whitelabel.enabled=false
|
||||||
|
|
||||||
|
logging.level.root=info
|
||||||
|
logging.level.org.springframework.security=info
|
24
src/main/resources/application-test.properties
Normal file
24
src/main/resources/application-test.properties
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
server.port=8081
|
||||||
|
|
||||||
|
spring.thymeleaf.prefix=classpath:templates/
|
||||||
|
spring.thymeleaf.suffix=.html
|
||||||
|
spring.thymeleaf.mode=HTML
|
||||||
|
spring.thymeleaf.encoding=UTF-8
|
||||||
|
|
||||||
|
spring.jpa.generate-ddl=false
|
||||||
|
spring.jpa.show-sql=true
|
||||||
|
spring.jpa.hibernate.ddl-auto=create-drop
|
||||||
|
spring.jooq.sql-dialect=org.hibernate.dialect.MariaDB102Dialect
|
||||||
|
spring.jpa.open-in-view=true
|
||||||
|
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
|
||||||
|
|
||||||
|
spring.datasource.url=jdbc:h2:mem:test
|
||||||
|
spring.datasource.username=
|
||||||
|
spring.datasource.password=
|
||||||
|
spring.datasource.driver-class-name=org.h2.Driver
|
||||||
|
|
||||||
|
|
||||||
|
server.error.whitelabel.enabled=false
|
||||||
|
|
||||||
|
logging.level.root=info
|
||||||
|
logging.level.org.springframework.security=info
|
@ -1,4 +1,4 @@
|
|||||||
server.port=8080
|
server.port=8081
|
||||||
|
|
||||||
spring.thymeleaf.prefix=classpath:templates/
|
spring.thymeleaf.prefix=classpath:templates/
|
||||||
spring.thymeleaf.suffix=.html
|
spring.thymeleaf.suffix=.html
|
||||||
@ -8,17 +8,16 @@ spring.thymeleaf.encoding=UTF-8
|
|||||||
spring.jpa.generate-ddl=false
|
spring.jpa.generate-ddl=false
|
||||||
spring.jpa.show-sql=true
|
spring.jpa.show-sql=true
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
spring.jooq.sql-dialect=org.hibernate.dialect.MySQL5InnoDBDialect
|
spring.jooq.sql-dialect=org.hibernate.dialect.MariaDB102Dialect
|
||||||
spring.jpa.open-in-view=true
|
spring.jpa.open-in-view=true
|
||||||
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
|
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
|
||||||
|
|
||||||
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:119.23.9.34}:3306/ase?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
|
spring.datasource.url=jdbc:mariadb://39.100.94.111:3306/ase?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
|
||||||
spring.datasource.username=codedream
|
spring.datasource.username=codedream
|
||||||
spring.datasource.password=codedreampasswd
|
spring.datasource.password=codedreampasswd
|
||||||
|
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
||||||
|
|
||||||
server.error.whitelabel.enabled=false
|
server.error.whitelabel.enabled=false
|
||||||
|
|
||||||
logging.level.root=info
|
logging.level.root=info
|
||||||
logging.level.org.springframework.security=info
|
logging.level.org.springframework.security=info
|
||||||
|
|
||||||
server.servlet.session.timeout=30m
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
28
src/test/java/com/codesdream/ase/test/AuthServiceTest.java
Normal file
28
src/test/java/com/codesdream/ase/test/AuthServiceTest.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package com.codesdream.ase.test;
|
||||||
|
|
||||||
|
import com.codesdream.ase.service.AuthService;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@ActiveProfiles("test")
|
||||||
|
public class AuthServiceTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AuthService authService;
|
||||||
|
|
||||||
|
// 测试随机验证码
|
||||||
|
@Test
|
||||||
|
public void preValidationCodeCheckerTest(){
|
||||||
|
String authStr = authService.preValidationCodeGetter();
|
||||||
|
|
||||||
|
Assert.assertTrue(authService.preValidationCodeChecker(authStr));
|
||||||
|
}
|
||||||
|
}
|
@ -3,22 +3,28 @@ package com.codesdream.ase.test;
|
|||||||
import com.codesdream.ase.component.ASESpringUtil;
|
import com.codesdream.ase.component.ASESpringUtil;
|
||||||
import com.codesdream.ase.component.datamanager.*;
|
import com.codesdream.ase.component.datamanager.*;
|
||||||
import com.codesdream.ase.repository.permission.UserRepository;
|
import com.codesdream.ase.repository.permission.UserRepository;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试DataModel相关查找器
|
* 测试DataModel相关查找器
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@ActiveProfiles("test")
|
||||||
public class DataManagerTest {
|
public class DataManagerTest {
|
||||||
@Resource
|
@Resource
|
||||||
ASESpringUtil springUtil;
|
ASESpringUtil springUtil;
|
||||||
@ -133,6 +139,7 @@ public class DataManagerTest {
|
|||||||
Assert.assertEquals(iterator.next(), "16");
|
Assert.assertEquals(iterator.next(), "16");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Excel表格导入测试
|
||||||
@Test
|
@Test
|
||||||
public void dataTableImportTest(){
|
public void dataTableImportTest(){
|
||||||
DataTable table = springUtil.getBean(DataTable.class);
|
DataTable table = springUtil.getBean(DataTable.class);
|
||||||
@ -144,6 +151,7 @@ public class DataManagerTest {
|
|||||||
Assert.assertEquals(iterator.next(), "18");
|
Assert.assertEquals(iterator.next(), "18");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Excel表格导出测试
|
||||||
@Test
|
@Test
|
||||||
public void dataTableExportTest(){
|
public void dataTableExportTest(){
|
||||||
DataTable table = springUtil.getBean(DataTable.class);
|
DataTable table = springUtil.getBean(DataTable.class);
|
||||||
@ -164,5 +172,32 @@ public class DataManagerTest {
|
|||||||
table.exportTable(new DataExcelGenerator("DataTableExport.xlsx"));
|
table.exportTable(new DataExcelGenerator("DataTableExport.xlsx"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 字符串文件测试
|
||||||
|
@Test
|
||||||
|
public void File2StringTest() throws IOException {
|
||||||
|
FileInputStream stream = new FileInputStream("test.pdf");
|
||||||
|
|
||||||
|
StringFileGenerator generator = springUtil.getBean(StringFileGenerator.class);
|
||||||
|
Optional<StringFile> file = generator.generateStringFile(stream);
|
||||||
|
|
||||||
|
// 检查是否转换成功
|
||||||
|
Assert.assertTrue(file.isPresent());
|
||||||
|
// 检查字符串文件的校验功能
|
||||||
|
Assert.assertTrue(generator.checkStringFile(file.get()));
|
||||||
|
|
||||||
|
// 输出转化
|
||||||
|
FileOutputStream outputStream = new FileOutputStream("testOut.pdf");
|
||||||
|
InputStream inputStream = generator.readFileString(file.get());
|
||||||
|
|
||||||
|
// 输出文件
|
||||||
|
int read = 0;
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
while ((read = inputStream.read(bytes)) != -1) {
|
||||||
|
outputStream.write(bytes, 0, read);
|
||||||
|
}
|
||||||
|
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.codesdream.ase.test;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.codesdream.ase.component.ASESpringUtil;
|
||||||
|
import com.codesdream.ase.component.json.respond.JSONBaseRespondObject;
|
||||||
|
import com.codesdream.ase.configure.ActivityFormConfigure;
|
||||||
|
import com.codesdream.ase.exception.InvalidFormFormatException;
|
||||||
|
import com.codesdream.ase.validator.JSONFormValidator;
|
||||||
|
import com.fasterxml.jackson.databind.util.JSONPObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@ActiveProfiles("test")
|
||||||
|
public class JSONFormValidatorTest {
|
||||||
|
@Resource
|
||||||
|
ASESpringUtil aseSpringUtil;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkTest() throws InvalidFormFormatException {
|
||||||
|
Map<String, String> map = new HashMap<String, String>() {{
|
||||||
|
put("creator", "tom");
|
||||||
|
put("title", "haha");
|
||||||
|
put("description", "h");
|
||||||
|
put("cycle", "h");
|
||||||
|
put("volunteers", "tom");
|
||||||
|
put("participate", "tom");
|
||||||
|
put("sign", "s");
|
||||||
|
put("visible", "s");
|
||||||
|
put("start-time", "1");
|
||||||
|
put("remind", "1");
|
||||||
|
put("enclosure", "1");
|
||||||
|
put("chief-manager", "tom");
|
||||||
|
put("assist-manager", "1");
|
||||||
|
put("attendance", "1");
|
||||||
|
put("type", "h");
|
||||||
|
put("attendance", "aa");
|
||||||
|
put("inform", "aaa");
|
||||||
|
}};
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.putAll(map);
|
||||||
|
Optional<JSONObject> json = Optional.of(jsonObject);
|
||||||
|
ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class);
|
||||||
|
JSONFormValidator jsonFormValidator = aseSpringUtil.getBean(JSONFormValidator.class);
|
||||||
|
if (jsonFormValidator.check(activityFormConfigure.getStdActivityForm(), json.get()).isEmpty()) {
|
||||||
|
System.out.println("error");
|
||||||
|
} else System.out.println("ok");
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ import com.codesdream.ase.service.IPermissionService;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -15,6 +16,7 @@ import javax.annotation.Resource;
|
|||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
|
@ActiveProfiles("test")
|
||||||
public class PermissionServiceTest {
|
public class PermissionServiceTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -10,9 +10,12 @@ import javafx.util.Pair;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.swing.text.html.Option;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户基本表单元测试
|
* 用户基本表单元测试
|
||||||
@ -20,6 +23,7 @@ import javax.annotation.Resource;
|
|||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
|
@ActiveProfiles("test")
|
||||||
public class UserTest {
|
public class UserTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@ -30,12 +34,6 @@ public class UserTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void UserBaseTest_1(){
|
public void UserBaseTest_1(){
|
||||||
// 查找数据库中是否有重复项
|
|
||||||
Pair<Boolean, User> checker = userService.checkIfUserExists("Tim");
|
|
||||||
if(checker.getKey()){
|
|
||||||
userService.delete(checker.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
User user = userService.getDefaultUser();
|
User user = userService.getDefaultUser();
|
||||||
user.setUsername("Tim");
|
user.setUsername("Tim");
|
||||||
user.setPassword("123456");
|
user.setPassword("123456");
|
||||||
@ -44,13 +42,18 @@ public class UserTest {
|
|||||||
user.getUserAuth().setUserQuestion("Your favourite animal?");
|
user.getUserAuth().setUserQuestion("Your favourite animal?");
|
||||||
user.getUserAuth().setUserAnswer("Cat");
|
user.getUserAuth().setUserAnswer("Cat");
|
||||||
user.getUserDetail().setAtSchool(true);
|
user.getUserDetail().setAtSchool(true);
|
||||||
|
user.getUserDetail().setRealName("提姆");
|
||||||
userService.save(user);
|
userService.save(user);
|
||||||
|
|
||||||
user = userService.findUserByUsername("Tim");
|
Optional<User> userOptional = userService.findUserByUsername("Tim");
|
||||||
|
|
||||||
|
assertTrue(userOptional.isPresent());
|
||||||
|
user = userOptional.get();
|
||||||
|
|
||||||
assertEquals(user.getUsername(), "Tim");
|
assertEquals(user.getUsername(), "Tim");
|
||||||
assertEquals(user.getPassword(),
|
assertEquals(user.getPassword(),
|
||||||
"8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92");
|
"8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92");
|
||||||
|
|
||||||
// 检查账号状态
|
// 检查账号状态
|
||||||
assertTrue(user.isEnabled());
|
assertTrue(user.isEnabled());
|
||||||
assertFalse(user.isDeleted());
|
assertFalse(user.isDeleted());
|
||||||
@ -65,7 +68,19 @@ public class UserTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void UserBaseTest_2(){
|
public void UserBaseTest_2(){
|
||||||
|
Optional<User> userOptional = userService.findUserByUsername("Tim");
|
||||||
|
assertTrue(userOptional.isPresent());
|
||||||
|
User user = userOptional.get();
|
||||||
|
|
||||||
|
user.setEnabled(false);
|
||||||
|
user.getUserAuth().setMail("saturneric@163.com");
|
||||||
|
user.getUserDetail().setRealName("张三丰");
|
||||||
|
|
||||||
|
user = userService.update(user);
|
||||||
|
|
||||||
|
assertEquals(user.getUserAuth().getMail(), "saturneric@163.com");
|
||||||
|
assertEquals(user.getUserDetail().getRealName(), "张三丰");
|
||||||
|
assertFalse(user.isEnabled());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user