Init Commit
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.realtime.protection.configuration.entity.user;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class User {
|
||||
private int userID;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
private String userDepart;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.realtime.protection.configuration.entity.whitelist;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WhiteListObject {
|
||||
@JsonProperty("whiteobj_id")
|
||||
private int whiteListId;
|
||||
|
||||
@NotNull
|
||||
@JsonProperty("whiteobj_name")
|
||||
private String whiteListName;
|
||||
|
||||
@JsonProperty("whiteobj_system_name")
|
||||
private String whiteListSystemName;
|
||||
|
||||
@JsonProperty("whiteobj_ip_address")
|
||||
private String whiteListIP;
|
||||
|
||||
@JsonProperty("whiteobj_port")
|
||||
private int whiteListPort;
|
||||
|
||||
@JsonProperty("whiteobj_url")
|
||||
private String whiteListUrl;
|
||||
|
||||
@JsonProperty("whiteobj_protocol")
|
||||
private String whiteListProtocol;
|
||||
|
||||
@JsonProperty("audit_status")
|
||||
private String whiteListAuditStatus;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.realtime.protection.configuration.exception;
|
||||
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler
|
||||
public ResponseResult handleGlobalException(Exception e) {
|
||||
|
||||
|
||||
|
||||
|
||||
return ResponseResult.error().setMessage(e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.realtime.protection.configuration.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
@Data
|
||||
public class ResponseResult implements Serializable {
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
private LinkedHashMap<String, Object> data;
|
||||
|
||||
public ResponseResult(int code, String message, LinkedHashMap<String, Object> data) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ResponseResult(int code) {
|
||||
this.code = code;
|
||||
this.data = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public ResponseResult(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public static ResponseResult ok() {
|
||||
return new ResponseResult(200, "request succeeded");
|
||||
}
|
||||
|
||||
public static ResponseResult ok(String message) {
|
||||
return new ResponseResult(200, message);
|
||||
}
|
||||
|
||||
public static ResponseResult error() {
|
||||
return new ResponseResult(500, "request failed");
|
||||
}
|
||||
|
||||
public static ResponseResult error(String message) {
|
||||
return new ResponseResult(500, message);
|
||||
}
|
||||
|
||||
public ResponseResult setCode(int code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResponseResult setMessage(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResponseResult setData(String key, Object value) {
|
||||
this.data.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResponseResult setDataMap(LinkedHashMap<String, Object> data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.realtime.protection.configuration.satoken;
|
||||
|
||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.realtime.protection.configuration.satoken.permission.Permission;
|
||||
import com.realtime.protection.configuration.satoken.permission.SystemConfiguration;
|
||||
import com.realtime.protection.configuration.satoken.permission.WhiteList;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new SaInterceptor(handler -> {
|
||||
SaRouter.match("/whiteobj/new", r ->
|
||||
this.checkPermissions(SystemConfiguration.NEW, WhiteList.NEW));
|
||||
SaRouter.match("/whiteobj/update", r ->
|
||||
this.checkPermissions(SystemConfiguration.UPDATE, WhiteList.UPDATE));
|
||||
}))
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/user/doLogin");
|
||||
}
|
||||
|
||||
void checkPermissions(Permission... permissions) {
|
||||
for (Permission permission : permissions) {
|
||||
StpUtil.checkPermission(permission.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.realtime.protection.configuration.satoken;
|
||||
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
import com.realtime.protection.configuration.satoken.permission.SystemConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class StpInterfaceImpl implements StpInterface {
|
||||
|
||||
/**
|
||||
* 返回一个账号所拥有的权限码集合
|
||||
*/
|
||||
@Override
|
||||
public List<String> getPermissionList(Object loginId, String loginType) {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
|
||||
if (loginId.equals("endera")) {
|
||||
list.add(SystemConfiguration.NEW.getName());
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
|
||||
*/
|
||||
@Override
|
||||
public List<String> getRoleList(Object loginId, String loginType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.realtime.protection.configuration.satoken.permission;
|
||||
|
||||
public interface Nameable {
|
||||
String name();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.realtime.protection.configuration.satoken.permission;
|
||||
|
||||
public interface Permission extends Nameable {
|
||||
default String getName() {
|
||||
return this.getClass().getSimpleName() + ":" + this.name();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.realtime.protection.configuration.satoken.permission;
|
||||
|
||||
public enum SystemConfiguration implements Permission {
|
||||
NEW,
|
||||
QUERY,
|
||||
UPDATE,
|
||||
DELETE
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.realtime.protection.configuration.satoken.permission;
|
||||
|
||||
public enum WhiteList implements Permission {
|
||||
NEW,
|
||||
QUERY,
|
||||
UPDATE,
|
||||
DELETE
|
||||
}
|
||||
Reference in New Issue
Block a user