+ * 登录控制层 + *
+ * + * @author YLL + * @since 2025/6/13 + */ +@RestController +@RequiredArgsConstructor +@Slf4j +public class LoginController { + + private final AuthenticationManager authenticationManager; + private final JwtUtil jwtUtil; + + @PostMapping("/login") + public ResponseEntity> login(@RequestBody LoginRequest loginRequest) { + try { + UsernamePasswordAuthenticationToken authToken = + new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword()); + + Authentication authentication = authenticationManager.authenticate(authToken); + + log.info("{}", authentication.getPrincipal()); + String token = jwtUtil.generateToken(authentication, false); // 可根据需要传 true/false + + return ResponseEntity.ok(token); + } catch (AuthenticationException ex) { + log.info("{}", ex.getMessage()); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("用户名或密码错误"); + } + } +} + diff --git a/src/main/java/asia/yulinling/workflow/controller/TestController.java b/src/main/java/asia/yulinling/workflow/controller/TestController.java index 6ba19e9..73e0ee0 100644 --- a/src/main/java/asia/yulinling/workflow/controller/TestController.java +++ b/src/main/java/asia/yulinling/workflow/controller/TestController.java @@ -8,10 +8,12 @@ import asia.yulinling.workflow.model.ApiResponse; import asia.yulinling.workflow.dto.response.PageResult; import asia.yulinling.workflow.model.vo.user.UserVO; import asia.yulinling.workflow.service.UserService; +import asia.yulinling.workflow.utils.JwtUtil; import cn.hutool.core.lang.Dict; import cn.hutool.json.JSONUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.security.authentication.AuthenticationManager; import org.springframework.web.bind.annotation.*; import java.util.Map; @@ -29,6 +31,8 @@ import java.util.Map; @RequiredArgsConstructor public class TestController { private final UserService userService; + private final JwtUtil jwtUtil; + private final AuthenticationManager authenticationManager; /** * 测试方法 GET @@ -72,9 +76,4 @@ public class TestController { public ApiResponse+ * 登录请求类 + *
+ * + * @author YLL + * @since 2025/6/13 + */ +@Data +public class LoginRequest { + private String username; + private String password; +} diff --git a/src/main/java/asia/yulinling/workflow/mapper/PermissionMapper.java b/src/main/java/asia/yulinling/workflow/mapper/PermissionMapper.java new file mode 100644 index 0000000..249b112 --- /dev/null +++ b/src/main/java/asia/yulinling/workflow/mapper/PermissionMapper.java @@ -0,0 +1,19 @@ +package asia.yulinling.workflow.mapper; + +import asia.yulinling.workflow.model.entity.Permission; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Component; + +/** + *+ * + *
+ * + * @author YLL + * @since 2025/6/13 + */ +@Mapper +@Component +public interface PermissionMapper extends BaseMapper+ * 角色Mapper + *
+ * + * @author YLL + * @since 2025/6/13 + */ +@Mapper +@Component +public interface RoleMapper extends BaseMapper
@@ -49,12 +54,6 @@ public class UserPrincipal implements UserDetails {
@JsonIgnore
private String password;
- /**
- * 加密使用盐
- */
- @JsonIgnore
- private String salt;
-
/**
* 邮箱
*/
@@ -98,25 +97,80 @@ public class UserPrincipal implements UserDetails {
/**
* 用户角色列表
*/
- private List
+ * 权限不足处理器
+ *
+ * Jwt登录拦截器
+ *
+ * JWT认证
+ *
+ * 自定义UserDetail查询
+ *
- * 分页工具类
+ * 分页工具类
*
+ * Jwt工具类测试
+ *