Merge branch 'master' of https://gitee.com/saturneric/ASE
Conflicts: src/main/java/com/codesdream/ase/controller/LeavesController.java
This commit is contained in:
commit
311ace2bd0
39
pom.xml
39
pom.xml
@ -144,12 +144,39 @@
|
|||||||
<version>2.5.4</version>
|
<version>2.5.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 内存数据库 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</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>
|
||||||
|
|
||||||
@ -163,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,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,8 +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.datamanager.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;
|
@ -1,16 +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.datamanager.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;
|
@ -1,16 +1,13 @@
|
|||||||
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.datamanager.QuickJSONRespond;
|
|
||||||
import com.codesdream.ase.component.json.respond.ErrorInfoJSONRespond;
|
import com.codesdream.ase.component.json.respond.ErrorInfoJSONRespond;
|
||||||
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.authentication.SimpleUrlAuthenticationFailureHandler;
|
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
|
||||||
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;
|
@ -1,8 +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.datamanager.QuickJSONRespond;
|
|
||||||
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;
|
||||||
|
|
||||||
@ -19,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;
|
||||||
|
|
||||||
@ -41,6 +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.setPvc(authService.preValidationCodeGetter());
|
||||||
|
|
||||||
// 获得 JSONTokenAuthenticationToken
|
// 获得 JSONTokenAuthenticationToken
|
||||||
JSONTokenAuthenticationToken authenticationToken = (JSONTokenAuthenticationToken) authentication;
|
JSONTokenAuthenticationToken authenticationToken = (JSONTokenAuthenticationToken) authentication;
|
@ -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;
|
||||||
@ -53,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,11 +32,11 @@ 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);
|
||||||
@ -47,20 +45,23 @@ public class ASESecurityAuthenticationProvider implements AuthenticationProvider
|
|||||||
throw new UsernameNotFoundException("User Not Exist");
|
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 {
|
||||||
|
|
||||||
@ -65,6 +63,7 @@ public class ASEUsernamePasswordAuthenticationFilter extends UsernamePasswordAut
|
|||||||
|
|
||||||
// 获得相应的用户名密码
|
// 获得相应的用户名密码
|
||||||
String username = checker.getUsername();
|
String username = checker.getUsername();
|
||||||
|
// 得到加密密码
|
||||||
String password = checker.getPassword();
|
String password = checker.getPassword();
|
||||||
String clientCode = checker.getClientCode();
|
String clientCode = checker.getClientCode();
|
||||||
|
|
@ -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.*;
|
||||||
|
|
||||||
|
@ -1,80 +0,0 @@
|
|||||||
package com.codesdream.ase.component.datamanager;
|
|
||||||
|
|
||||||
import com.codesdream.ase.component.json.respond.EmptyDataObjectRespond;
|
|
||||||
import com.codesdream.ase.component.json.respond.JSONBaseRespondObject;
|
|
||||||
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(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(404, "Not Found", info);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获得标准的JSON响应字符串返回(500状态)
|
|
||||||
public String getRespond500(String info){
|
|
||||||
return getJSONStandardRespond(500, "Internal Server Error", info);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获得标准的JSON响应字符串返回(200状态)
|
|
||||||
public String getRespond200(String info){
|
|
||||||
return getJSONStandardRespond(200, "Ok", info);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获得标准的JSON响应字符串返回(200状态)
|
|
||||||
public String getRespond200(String info, Object object){
|
|
||||||
return getJSONStandardRespond(200, "Ok", info, object);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获得标准的JSON响应字符串返回(403状态)
|
|
||||||
public String getRespond403(String info){
|
|
||||||
return getJSONStandardRespond(403, "Forbidden", info);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获得标准的JSON响应字符串返回(403状态)
|
|
||||||
public String getRespond406(String info){
|
|
||||||
return getJSONStandardRespond(406, "Not Acceptable", info);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获得标准的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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -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,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;
|
||||||
|
}
|
@ -12,5 +12,6 @@ public class UserLoginCheckerJSONRespond {
|
|||||||
String respondInformation = null;
|
String respondInformation = null;
|
||||||
String token = null;
|
String token = null;
|
||||||
String uid = null;
|
String uid = null;
|
||||||
|
String pvc = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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,31 +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.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.security.authentication.AuthenticationServiceException;
|
|
||||||
import org.springframework.security.core.AuthenticationException;
|
|
||||||
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.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class ASEControllerAdvice {
|
public class ASEControllerAdvice {
|
||||||
@ExceptionHandler(value = {RuntimeException.class})
|
|
||||||
public final Object handleRuntimeException(RuntimeException e, WebRequest webRequest){
|
@Resource
|
||||||
|
private QuickJSONRespond quickJSONRespond;
|
||||||
|
|
||||||
|
@ExceptionHandler(value = {
|
||||||
|
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 errorInfoJSONRespond = new ErrorInfoJSONRespond();
|
||||||
|
errorInfoJSONRespond.setException(ex.getClass().getName());
|
||||||
|
errorInfoJSONRespond.setExceptionMessage(ex.getMessage());
|
||||||
errorInfoJSONRespond.setDate(new Date());
|
errorInfoJSONRespond.setDate(new Date());
|
||||||
errorInfoJSONRespond.setExceptionMessage(e.getMessage());
|
|
||||||
errorInfoJSONRespond.setException(e.getClass().getName());
|
|
||||||
return errorInfoJSONRespond;
|
return errorInfoJSONRespond;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,16 @@
|
|||||||
package com.codesdream.ase.controller;
|
package com.codesdream.ase.controller;
|
||||||
|
|
||||||
import com.codesdream.ase.component.datamanager.QuickJSONRespond;
|
import com.codesdream.ase.component.api.QuickJSONRespond;
|
||||||
import com.codesdream.ase.component.error.ErrorResponse;
|
|
||||||
import com.codesdream.ase.component.json.respond.ErrorInfoJSONRespond;
|
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.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
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 {
|
||||||
@ -80,7 +72,7 @@ public class ASEErrorController implements ErrorController {
|
|||||||
|
|
||||||
return quickJSONRespond.getJSONStandardRespond(
|
return quickJSONRespond.getJSONStandardRespond(
|
||||||
statusCode,
|
statusCode,
|
||||||
"Error Controller Handle",
|
"Internal Server Error",
|
||||||
null,
|
null,
|
||||||
errorInfoJSONRespond);
|
errorInfoJSONRespond);
|
||||||
}
|
}
|
||||||
|
@ -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,16 +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.datamanager.QuickJSONRespond;
|
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;
|
||||||
@ -26,6 +27,7 @@ import java.util.Optional;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Controller
|
@Controller
|
||||||
|
@Api(tags = "用户登录有关接口")
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@ -37,19 +39,16 @@ public class LoginController {
|
|||||||
@Resource
|
@Resource
|
||||||
private IUserService userService;
|
private IUserService userService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
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);
|
||||||
@ -75,12 +74,22 @@ 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.setUid(userService.getUsernameByStudentId(loginChecker.getUsername()));
|
respond.setUid(userService.getUsernameByStudentId(loginChecker.getUsername()));
|
||||||
|
@ -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,7 +1,7 @@
|
|||||||
package com.codesdream.ase.controller;
|
package com.codesdream.ase.controller;
|
||||||
|
|
||||||
import com.codesdream.ase.component.datamanager.JSONParameter;
|
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||||
import com.codesdream.ase.component.datamanager.QuickJSONRespond;
|
import com.codesdream.ase.component.api.QuickJSONRespond;
|
||||||
import com.codesdream.ase.component.json.request.UserRegisterChecker;
|
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;
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package com.codesdream.ase.controller.activity;
|
package com.codesdream.ase.controller.activity;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.codesdream.ase.component.ASESpringUtil;
|
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.activity.NullValueAttributes;
|
||||||
import com.codesdream.ase.component.datamanager.JSONParameter;
|
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||||
import com.codesdream.ase.component.json.respond.JSONBaseRespondObject;
|
import com.codesdream.ase.component.json.respond.JSONStandardFailedRespond;
|
||||||
import com.codesdream.ase.configure.ActivityFormConfigure;
|
import com.codesdream.ase.configure.ActivityFormConfigure;
|
||||||
import com.codesdream.ase.exception.InvalidFormFormatException;
|
import com.codesdream.ase.exception.InvalidFormFormatException;
|
||||||
import com.codesdream.ase.exception.UserNotFoundException;
|
|
||||||
import com.codesdream.ase.model.activity.Activity;
|
import com.codesdream.ase.model.activity.Activity;
|
||||||
import com.codesdream.ase.model.activity.UserActivity;
|
import com.codesdream.ase.model.activity.UserActivity;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
@ -17,7 +16,7 @@ import com.codesdream.ase.repository.permission.UserRepository;
|
|||||||
import com.codesdream.ase.service.ActivityService;
|
import com.codesdream.ase.service.ActivityService;
|
||||||
import com.codesdream.ase.validator.ActivityValidator;
|
import com.codesdream.ase.validator.ActivityValidator;
|
||||||
import com.codesdream.ase.validator.NullValueValidator;
|
import com.codesdream.ase.validator.NullValueValidator;
|
||||||
import com.codesdream.ase.validator.WebFormValidator;
|
import com.codesdream.ase.validator.JSONFormValidator;
|
||||||
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.PostMapping;
|
||||||
@ -48,7 +47,7 @@ public class ActivityCreatorController {
|
|||||||
ActivityFormConfigure activityFormConfigure;
|
ActivityFormConfigure activityFormConfigure;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
WebFormValidator webFormValidator;
|
JSONFormValidator jsonFormValidator;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
NullValueValidator nullValueValidator;
|
NullValueValidator nullValueValidator;
|
||||||
@ -65,6 +64,9 @@ public class ActivityCreatorController {
|
|||||||
@Resource
|
@Resource
|
||||||
UserActivityRepository userActivityRepository;
|
UserActivityRepository userActivityRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ActivityConverter activityConverter;
|
||||||
|
|
||||||
private final String url = "/forget/activity";
|
private final String url = "/forget/activity";
|
||||||
|
|
||||||
@RequestMapping(value = url + "/activity_creator")
|
@RequestMapping(value = url + "/activity_creator")
|
||||||
@ -73,24 +75,22 @@ public class ActivityCreatorController {
|
|||||||
|
|
||||||
@PostMapping(value = url + "/activity_creator")
|
@PostMapping(value = url + "/activity_creator")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
String activityCreator(@RequestBody JSONObject jsonParam, Model model, HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
String activityCreator(HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||||
|
|
||||||
JSONObject error = new JSONObject();
|
JSONObject error = new JSONObject();
|
||||||
|
|
||||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
|
||||||
aseSpringUtil = new ASESpringUtil();
|
aseSpringUtil = new ASESpringUtil();
|
||||||
|
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
||||||
|
if (!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
||||||
|
|
||||||
//WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
//WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
||||||
if(!webFormValidator.check(activityFormConfigure.getStdActivityForm(), parameterMap)) {
|
List<String> formatCheckResult = jsonFormValidator.check(activityFormConfigure.getStdActivityForm(), json.get());
|
||||||
error.put("error", "Invalid form format");
|
if (!formatCheckResult.isEmpty()) {
|
||||||
|
error.put("error", formatCheckResult);
|
||||||
return error.toJSONString();
|
return error.toJSONString();
|
||||||
}
|
}
|
||||||
// 需要检查JSON是否合法
|
// 需要检查JSON是否合法
|
||||||
Optional<JSONObject> jsonObject = jsonParameter.getJSONByRequest(request);
|
|
||||||
if(!jsonObject.isPresent()){
|
Activity activity = activityConverter.convertToActivity(json);
|
||||||
error.put("error", "Invalid type.");
|
|
||||||
return error.toJSONString();
|
|
||||||
}
|
|
||||||
Activity activity = jsonObject.get().toJavaObject(Activity.class);
|
|
||||||
|
|
||||||
//NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class);
|
//NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class);
|
||||||
List<String> nullValues = nullValueValidator.checkNullValues(activity);
|
List<String> nullValues = nullValueValidator.checkNullValues(activity);
|
||||||
@ -116,7 +116,7 @@ public class ActivityCreatorController {
|
|||||||
if(nullValueAttributes.getNullValueAttributes().isEmpty()){
|
if(nullValueAttributes.getNullValueAttributes().isEmpty()){
|
||||||
|
|
||||||
//ActivityValidator activityValidator = aseSpringUtil.getBean(ActivityValidator.class);
|
//ActivityValidator activityValidator = aseSpringUtil.getBean(ActivityValidator.class);
|
||||||
String[] errorParameters = activityValidator.check(parameterMap);
|
String[] errorParameters = activityValidator.check(json);
|
||||||
if(errorParameters != null){
|
if(errorParameters != null){
|
||||||
JSONObject invalidParameters = new JSONObject();
|
JSONObject invalidParameters = new JSONObject();
|
||||||
invalidParameters.put("invalid_parameters", errorParameters);
|
invalidParameters.put("invalid_parameters", errorParameters);
|
||||||
@ -127,7 +127,7 @@ public class ActivityCreatorController {
|
|||||||
//UserRepository userRepository = aseSpringUtil.getBean(UserRepository.class);
|
//UserRepository userRepository = aseSpringUtil.getBean(UserRepository.class);
|
||||||
//activityService = aseSpringUtil.getBean(ActivityService.class);
|
//activityService = aseSpringUtil.getBean(ActivityService.class);
|
||||||
activity = activityService.createActivity(activity);
|
activity = activityService.createActivity(activity);
|
||||||
String username = parameterMap.get("creator")[0];
|
String username = json.get().get("creator").toString();
|
||||||
Optional<User> user = userRepository.findByUsername(username);
|
Optional<User> user = userRepository.findByUsername(username);
|
||||||
//UserActivityRepository userActivityRepository = aseSpringUtil.getBean(UserActivityRepository.class);
|
//UserActivityRepository userActivityRepository = aseSpringUtil.getBean(UserActivityRepository.class);
|
||||||
UserActivity userActivity = userActivityRepository.findByUser(user.get());
|
UserActivity userActivity = userActivityRepository.findByUser(user.get());
|
||||||
@ -135,7 +135,7 @@ public class ActivityCreatorController {
|
|||||||
userActivityRepository.save(userActivity);
|
userActivityRepository.save(userActivity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//否则返回一个JSON对象给前端,此处应该是JSP页面,动态标红
|
//否则返回一个JSON对象给前端
|
||||||
else{
|
else{
|
||||||
JSONObject nullParameters = new JSONObject();
|
JSONObject nullParameters = new JSONObject();
|
||||||
nullParameters.put("null_values",nullValueAttributes.getNullValueAttributes());
|
nullParameters.put("null_values",nullValueAttributes.getNullValueAttributes());
|
||||||
|
@ -17,13 +17,15 @@ import java.security.Principal;
|
|||||||
@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,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,22 +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;
|
||||||
String message;
|
|
||||||
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 message){
|
public UserNotFoundException(String msg){
|
||||||
super();
|
super(msg);
|
||||||
this.message = message;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
}
|
@ -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,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);
|
||||||
|
}
|
@ -1,16 +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.UserNotFoundException;
|
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.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 {
|
||||||
@ -25,7 +25,9 @@ public class ASEUserDetailsService implements UserDetailsService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public UserDetails loadUserByUsername(String s) {
|
public UserDetails loadUserByUsername(String s) {
|
||||||
try {
|
try {
|
||||||
User user = userService.findUserByUsername(s);
|
Optional<User> userOptional = userService.findUserByUsername(s);
|
||||||
|
if(!userOptional.isPresent()) throw new UserNotFoundException(s);
|
||||||
|
User user = userOptional.get();
|
||||||
user.setAuthorities(userAuthoritiesGenerator.grantedAuthorities(user));
|
user.setAuthorities(userAuthoritiesGenerator.grantedAuthorities(user));
|
||||||
return user;
|
return user;
|
||||||
} catch (UserNotFoundException e){
|
} catch (UserNotFoundException e){
|
||||||
|
@ -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;
|
||||||
@ -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 {
|
||||||
@ -22,7 +23,7 @@ public interface IUserService {
|
|||||||
|
|
||||||
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()));
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
package com.codesdream.ase.validator;
|
package com.codesdream.ase.validator;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.codesdream.ase.model.activity.Activity;
|
import com.codesdream.ase.model.activity.Activity;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.nio.file.OpenOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
//检查当前活动各属性值是否合法(存在)
|
//检查当前活动各属性值是否合法(存在)
|
||||||
@Component
|
@Component
|
||||||
public class ActivityValidator {
|
public class ActivityValidator {
|
||||||
|
|
||||||
public String[] check(Map<String, String[]> parameterMap){
|
public String[] check(Optional<JSONObject> json) {
|
||||||
return null;
|
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(webForm.containsAll(stdForm)){
|
|
||||||
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
|
@ -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
|
||||||
|
@ -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
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
||||||
|
@ -45,7 +45,10 @@ public class UserTest {
|
|||||||
user.getUserDetail().setRealName("提姆");
|
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(),
|
||||||
@ -65,9 +68,9 @@ public class UserTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void UserBaseTest_2(){
|
public void UserBaseTest_2(){
|
||||||
User user = userService.findUserByUsername("Tim");
|
Optional<User> userOptional = userService.findUserByUsername("Tim");
|
||||||
|
assertTrue(userOptional.isPresent());
|
||||||
assertNotNull(user);
|
User user = userOptional.get();
|
||||||
|
|
||||||
user.setEnabled(false);
|
user.setEnabled(false);
|
||||||
user.getUserAuth().setMail("saturneric@163.com");
|
user.getUserAuth().setMail("saturneric@163.com");
|
||||||
|
Loading…
Reference in New Issue
Block a user