Init Commit

This commit is contained in:
松岳 陈
2024-01-02 10:16:15 +08:00
commit 66c710c034
31 changed files with 956 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package com.realtime.protection.server.user.login;
import com.realtime.protection.configuration.entity.user.User;
import com.realtime.protection.configuration.response.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.security.auth.login.LoginException;
// Just for example, not in production environment
@RestController
@RequestMapping("/user")
public class LoginController {
private final LoginService loginService;
public LoginController(LoginService loginService) {
this.loginService = loginService;
}
@PostMapping("/doLogin")
public ResponseResult doLogin(@RequestBody User user) {
Integer userId;
try {
userId = loginService.login(user);
} catch (LoginException e) {
return ResponseResult.error().setMessage("User not valid")
.setData("userId", null)
.setData("success", false);
}
return ResponseResult.ok().setMessage("success")
.setData("userId", userId)
.setData("success", true);
}
}

View File

@@ -0,0 +1,10 @@
package com.realtime.protection.server.user.login;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
// just for example, not for production environment
public interface LoginMapper {
Integer login(@Param("username") String username, @Param("password") String password);
}

View File

@@ -0,0 +1,31 @@
package com.realtime.protection.server.user.login;
import cn.dev33.satoken.stp.StpUtil;
import com.realtime.protection.configuration.entity.user.User;
import org.springframework.stereotype.Service;
import javax.security.auth.login.LoginException;
@Service
// just for example, not for production environment
public class LoginService {
private final LoginMapper loginMapper;
public LoginService(LoginMapper loginMapper) {
this.loginMapper = loginMapper;
}
public Integer login(User user) throws LoginException {
String username = user.getUsername();
String password = user.getPassword();
Integer userId = loginMapper.login(username, password);
if (userId == null) {
throw new LoginException();
}
StpUtil.login(userId);
return userId;
}
}

View File

@@ -0,0 +1,28 @@
package com.realtime.protection.server.whitelist;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import com.realtime.protection.configuration.response.ResponseResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/whiteobj")
public class WhiteListController {
private final WhiteListService whiteListService;
public WhiteListController(WhiteListService whiteListService) {
this.whiteListService = whiteListService;
}
@RequestMapping("/new")
public ResponseResult newWhitelistObject(@RequestBody WhiteListObject object) {
Integer whiteListObjectId = whiteListService.newWhiteListObject(object);
return ResponseResult.ok()
.setData("whiteobj_name", object.getWhiteListName())
.setData("whiteobj_id", whiteListObjectId)
.setData("success", true);
}
}

View File

@@ -0,0 +1,11 @@
package com.realtime.protection.server.whitelist;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface WhiteListMapper {
void newWhiteListObject(@Param("object") WhiteListObject object);
}

View File

@@ -0,0 +1,21 @@
package com.realtime.protection.server.whitelist;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import org.springframework.stereotype.Service;
@Service
public class WhiteListService {
private final WhiteListMapper whiteListMapper;
public WhiteListService(WhiteListMapper whiteListMapper) {
this.whiteListMapper = whiteListMapper;
}
public Integer newWhiteListObject(WhiteListObject object) {
whiteListMapper.newWhiteListObject(object);
return object.getWhiteListId();
}
}