feat: auth模块初始化
This commit is contained in:
@ -16,6 +16,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool.v7</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
package day.gitlab.dolphin.common.core.exception;
|
package day.gitlab.dolphin.common.core.exception;
|
||||||
|
|
||||||
import day.gitlab.dolphin.common.core.entity.Result;
|
import day.gitlab.dolphin.common.core.entity.Result;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
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;
|
||||||
|
|
||||||
@Component
|
@RestControllerAdvice
|
||||||
@ControllerAdvice
|
public class GlobalExceptionHandler {
|
||||||
public class GlobalExceptionAdvice {
|
|
||||||
|
|
||||||
@ExceptionHandler(value = BusinessException.class)
|
@ExceptionHandler(value = BusinessException.class)
|
||||||
public Result handleBusinessException(BusinessException e) {
|
public Result handleBusinessException(BusinessException e) {
|
||||||
@ -40,6 +40,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
|
|||||||
// 在未启用或是忽略校验的地址时直接放行
|
// 在未启用或是忽略校验的地址时直接放行
|
||||||
if (!securityConfig.isEnabled() || authorityIgnoreInitializer.isIgnoreUrl(request)) {
|
if (!securityConfig.isEnabled() || authorityIgnoreInitializer.isIgnoreUrl(request)) {
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -51,6 +52,11 @@ public class AuthenticationFilter extends OncePerRequestFilter {
|
|||||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
response.getWriter().write(new ObjectMapper().writeValueAsString(Result.failure(e)));
|
response.getWriter().write(new ObjectMapper().writeValueAsString(Result.failure(e)));
|
||||||
|
} catch (Exception e) {
|
||||||
|
response.setStatus(500);
|
||||||
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.getWriter().write(new ObjectMapper().writeValueAsString(Result.failure(e.getMessage())));
|
||||||
} finally {
|
} finally {
|
||||||
SecurityContextHolder.clearAuthentication();
|
SecurityContextHolder.clearAuthentication();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package day.gitlab.dolphin.common.security.annotation;
|
|||||||
|
|
||||||
import day.gitlab.dolphin.common.security.config.SecurityConfig;
|
import day.gitlab.dolphin.common.security.config.SecurityConfig;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
@ -21,6 +22,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class AuthorityIgnoreInitializer implements ApplicationContextAware {
|
public class AuthorityIgnoreInitializer implements ApplicationContextAware {
|
||||||
|
|
||||||
@ -34,6 +36,8 @@ public class AuthorityIgnoreInitializer implements ApplicationContextAware {
|
|||||||
RequestMappingHandlerMapping requestMappingHandlerMapping = ctx.getBean(RequestMappingHandlerMapping.class);
|
RequestMappingHandlerMapping requestMappingHandlerMapping = ctx.getBean(RequestMappingHandlerMapping.class);
|
||||||
Map<RequestMappingInfo, HandlerMethod> handlerMethods = requestMappingHandlerMapping.getHandlerMethods();
|
Map<RequestMappingInfo, HandlerMethod> handlerMethods = requestMappingHandlerMapping.getHandlerMethods();
|
||||||
|
|
||||||
|
log.info("authorityIgnoreInitialize begin, contextPath: {}", contextPath);
|
||||||
|
|
||||||
if (StringUtils.hasText(securityConfig.getIgnoreUrls())) {
|
if (StringUtils.hasText(securityConfig.getIgnoreUrls())) {
|
||||||
Arrays.stream(securityConfig.getIgnoreUrls().split(","))
|
Arrays.stream(securityConfig.getIgnoreUrls().split(","))
|
||||||
.filter(StringUtils::hasText)
|
.filter(StringUtils::hasText)
|
||||||
@ -45,6 +49,7 @@ public class AuthorityIgnoreInitializer implements ApplicationContextAware {
|
|||||||
.map(IgnoreUrl::new)
|
.map(IgnoreUrl::new)
|
||||||
.forEach(this.ignoreUrls::add);
|
.forEach(this.ignoreUrls::add);
|
||||||
}
|
}
|
||||||
|
log.info("authorityIgnoreInitialize default urls: {}", this.ignoreUrls);
|
||||||
|
|
||||||
for (RequestMappingInfo mappingInfo : handlerMethods.keySet()) {
|
for (RequestMappingInfo mappingInfo : handlerMethods.keySet()) {
|
||||||
HandlerMethod handlerMethod = handlerMethods.get(mappingInfo);
|
HandlerMethod handlerMethod = handlerMethods.get(mappingInfo);
|
||||||
@ -75,13 +80,21 @@ public class AuthorityIgnoreInitializer implements ApplicationContextAware {
|
|||||||
urlPrefix.add(prefixUrl);
|
urlPrefix.add(prefixUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
urlPrefix.stream()
|
List<IgnoreUrl> methodIgnoreUrls = urlPrefix.stream()
|
||||||
.flatMap(sub -> mappingInfo.getPatternValues().stream().filter(StringUtils::hasText).map(s -> sub + s))
|
.flatMap(sub -> mappingInfo.getPatternValues().stream().filter(StringUtils::hasText).map(s -> sub + s))
|
||||||
.map(IgnoreUrl::new)
|
.map(IgnoreUrl::new)
|
||||||
.forEach(this.ignoreUrls::add);
|
.toList();
|
||||||
|
log.info("authorityIgnoreInitialize class [{}] method [{}] urls: {}", beanClass.getCanonicalName(), handlerMethod.getMethod().getName(), methodIgnoreUrls);
|
||||||
|
if (!methodIgnoreUrls.isEmpty()) {
|
||||||
|
ignoreUrls.addAll(methodIgnoreUrls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("authorityIgnoreInitialize current urls: {}", this.ignoreUrls);
|
||||||
|
|
||||||
|
log.info("authorityIgnoreInitialize end");
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isIgnoreUrl(HttpServletRequest request) {
|
public boolean isIgnoreUrl(HttpServletRequest request) {
|
||||||
String method = request.getMethod();
|
String method = request.getMethod();
|
||||||
String url = request.getRequestURI();
|
String url = request.getRequestURI();
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package day.gitlab.dolphin.common.security.jwt;
|
package day.gitlab.dolphin.common.security.jwt;
|
||||||
|
|
||||||
|
import cn.hutool.v7.crypto.digest.DigestUtil;
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.security.Keys;
|
import io.jsonwebtoken.security.Keys;
|
||||||
@ -64,7 +65,7 @@ public class Jwt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SecretKey getSigningKey() {
|
private SecretKey getSigningKey() {
|
||||||
byte[] keyBytes = secret.getBytes(StandardCharsets.UTF_8);
|
byte[] keyBytes = DigestUtil.sha256(secret);
|
||||||
return Keys.hmacShaKeyFor(keyBytes);
|
return Keys.hmacShaKeyFor(keyBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
<!-- Project -->
|
<!-- Project -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>day.gitlab</groupId>
|
<groupId>day.gitlab</groupId>
|
||||||
<artifactId>dolphin-common-security</artifactId>
|
<artifactId>dolphin-module-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -23,6 +23,11 @@
|
|||||||
<artifactId>dolphin-module-rbac</artifactId>
|
<artifactId>dolphin-module-rbac</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>day.gitlab</groupId>
|
||||||
|
<artifactId>dolphin-module-auth</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<!-- Spring Boot -->
|
<!-- Spring Boot -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -52,6 +57,19 @@
|
|||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- JWT -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-impl</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.jsonwebtoken</groupId>
|
||||||
|
<artifactId>jjwt-jackson</artifactId>
|
||||||
|
</dependency>
|
||||||
<!-- Lombok -->
|
<!-- Lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
package day.gitlab.dolphin.authorize.entity.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class LoginDTO {
|
|
||||||
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
private String password;
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
package day.gitlab.dolphin.authorize.entity.vo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class LoginVO {
|
|
||||||
|
|
||||||
private String accessToken;
|
|
||||||
|
|
||||||
private String refreshToken;
|
|
||||||
}
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
package day.gitlab.dolphin.authorize.service;
|
|
||||||
|
|
||||||
import day.gitlab.dolphin.authorize.entity.dto.LoginDTO;
|
|
||||||
import day.gitlab.dolphin.authorize.entity.vo.LoginVO;
|
|
||||||
import day.gitlab.dolphin.common.security.AuthenticationProvider;
|
|
||||||
|
|
||||||
public interface AuthorizeService extends AuthenticationProvider {
|
|
||||||
|
|
||||||
LoginVO login(LoginDTO loginDTO);
|
|
||||||
}
|
|
||||||
65
dolphin-modules/dolphin-module-auth/pom.xml
Normal file
65
dolphin-modules/dolphin-module-auth/pom.xml
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>day.gitlab</groupId>
|
||||||
|
<artifactId>dolphin-modules</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>dolphin-module-auth</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 项目依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>day.gitlab</groupId>
|
||||||
|
<artifactId>dolphin-common-security</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>day.gitlab</groupId>
|
||||||
|
<artifactId>dolphin-common-mybatis</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>day.gitlab</groupId>
|
||||||
|
<artifactId>dolphin-module-rbac</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Spring Boot -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- MyBatis Flex -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package day.gitlab.dolphin.authorize.controller;
|
package day.gitlab.dolphin.auth.controller;
|
||||||
|
|
||||||
import day.gitlab.dolphin.authorize.entity.dto.LoginDTO;
|
import day.gitlab.dolphin.auth.entity.dto.LoginDTO;
|
||||||
import day.gitlab.dolphin.authorize.service.AuthorizeService;
|
import day.gitlab.dolphin.auth.service.AuthService;
|
||||||
import day.gitlab.dolphin.common.core.entity.Result;
|
import day.gitlab.dolphin.common.core.entity.Result;
|
||||||
import day.gitlab.dolphin.common.security.annotation.AuthorityIgnore;
|
import day.gitlab.dolphin.common.security.annotation.AuthorityIgnore;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@ -11,15 +11,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/authorize")
|
@RequestMapping("/auth")
|
||||||
public class AuthorizeController {
|
public class AuthController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private AuthorizeService authorizeService;
|
private AuthService authService;
|
||||||
|
|
||||||
@AuthorityIgnore
|
@AuthorityIgnore
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public Result login(@RequestBody LoginDTO loginDTO) {
|
public Result login(@RequestBody LoginDTO loginDTO) {
|
||||||
return Result.success(authorizeService.login(loginDTO));
|
return Result.success(authService.login(loginDTO));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package day.gitlab.dolphin.auth.entity.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LoginDTO {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package day.gitlab.dolphin.auth.entity.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class LoginVO {
|
||||||
|
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
private String refreshToken;
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package day.gitlab.dolphin.auth.service;
|
||||||
|
|
||||||
|
import day.gitlab.dolphin.auth.entity.dto.LoginDTO;
|
||||||
|
import day.gitlab.dolphin.auth.entity.vo.LoginVO;
|
||||||
|
|
||||||
|
public interface AuthService {
|
||||||
|
|
||||||
|
LoginVO login(LoginDTO loginDTO);
|
||||||
|
}
|
||||||
@ -1,16 +1,16 @@
|
|||||||
package day.gitlab.dolphin.authorize.service.impl;
|
package day.gitlab.dolphin.auth.service.impl;
|
||||||
|
|
||||||
import cn.hutool.v7.crypto.digest.BCrypt;
|
import cn.hutool.v7.crypto.digest.BCrypt;
|
||||||
import com.mybatisflex.core.query.QueryCondition;
|
import day.gitlab.dolphin.auth.entity.dto.LoginDTO;
|
||||||
import day.gitlab.dolphin.authorize.entity.dto.LoginDTO;
|
import day.gitlab.dolphin.auth.entity.vo.LoginVO;
|
||||||
import day.gitlab.dolphin.authorize.entity.vo.LoginVO;
|
import day.gitlab.dolphin.auth.service.AuthService;
|
||||||
import day.gitlab.dolphin.authorize.service.AuthorizeService;
|
|
||||||
import day.gitlab.dolphin.common.core.exception.BusinessException;
|
import day.gitlab.dolphin.common.core.exception.BusinessException;
|
||||||
|
import day.gitlab.dolphin.common.security.AuthenticationProvider;
|
||||||
import day.gitlab.dolphin.common.security.UserPrincipal;
|
import day.gitlab.dolphin.common.security.UserPrincipal;
|
||||||
import day.gitlab.dolphin.common.security.jwt.JwtInfo;
|
import day.gitlab.dolphin.common.security.jwt.JwtInfo;
|
||||||
|
import day.gitlab.dolphin.rbac.constants.UserEnabled;
|
||||||
import day.gitlab.dolphin.rbac.entity.Role;
|
import day.gitlab.dolphin.rbac.entity.Role;
|
||||||
import day.gitlab.dolphin.rbac.entity.User;
|
import day.gitlab.dolphin.rbac.entity.User;
|
||||||
import day.gitlab.dolphin.rbac.entity.table.UserTableDef;
|
|
||||||
import day.gitlab.dolphin.rbac.mapper.UserMapper;
|
import day.gitlab.dolphin.rbac.mapper.UserMapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -20,7 +20,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class AuthorizeServiceImpl implements AuthorizeService {
|
public class AuthServiceImpl implements AuthService, AuthenticationProvider {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
@ -28,6 +28,22 @@ public class AuthorizeServiceImpl implements AuthorizeService {
|
|||||||
@Resource
|
@Resource
|
||||||
private JwtInfo jwtInfo;
|
private JwtInfo jwtInfo;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoginVO login(LoginDTO loginDTO) {
|
||||||
|
User dbUser = userMapper.findByUsername(loginDTO.getUsername());
|
||||||
|
if (dbUser == null || !BCrypt.checkpw(loginDTO.getPassword(), dbUser.getPassword())) {
|
||||||
|
throw new BusinessException("Username or password is incorrect");
|
||||||
|
}
|
||||||
|
if (!UserEnabled.ENABLED.equals(dbUser.getEnabled())) {
|
||||||
|
throw new BusinessException("User is not enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
return LoginVO.builder()
|
||||||
|
.accessToken(jwtInfo.generateAccessToken(dbUser.getId()))
|
||||||
|
.refreshToken(jwtInfo.generateRefreshToken(dbUser.getId()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserPrincipal getUserPrincipal(String userId) {
|
public UserPrincipal getUserPrincipal(String userId) {
|
||||||
User user = userMapper.selectOneById(userId);
|
User user = userMapper.selectOneById(userId);
|
||||||
@ -50,22 +66,4 @@ public class AuthorizeServiceImpl implements AuthorizeService {
|
|||||||
|
|
||||||
return roles.stream().map(Role::getCode).collect(Collectors.toList());
|
return roles.stream().map(Role::getCode).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public LoginVO login(LoginDTO loginDTO) {
|
|
||||||
QueryCondition queryCondition = UserTableDef.USER.USERNAME.eq(loginDTO.getUsername());
|
|
||||||
User user = userMapper.selectOneByCondition(queryCondition);
|
|
||||||
|
|
||||||
if (user == null || !BCrypt.checkpw(loginDTO.getPassword(), user.getPassword())) {
|
|
||||||
throw new BusinessException("User name or password is incorrect");
|
|
||||||
}
|
|
||||||
if (!"1".equalsIgnoreCase(user.getEnabled())) {
|
|
||||||
throw new BusinessException("User has been disabled");
|
|
||||||
}
|
|
||||||
|
|
||||||
LoginVO loginVO = new LoginVO();
|
|
||||||
loginVO.setAccessToken(jwtInfo.generateAccessToken(user.getId()));
|
|
||||||
loginVO.setRefreshToken(jwtInfo.generateRefreshToken(user.getId()));
|
|
||||||
return loginVO;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -12,6 +12,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- 项目依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>day.gitlab</groupId>
|
<groupId>day.gitlab</groupId>
|
||||||
<artifactId>dolphin-common-security</artifactId>
|
<artifactId>dolphin-common-security</artifactId>
|
||||||
@ -22,20 +23,25 @@
|
|||||||
<artifactId>dolphin-common-mybatis</artifactId>
|
<artifactId>dolphin-common-mybatis</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Spring Boot -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- MyBatis Flex -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mybatis-flex</groupId>
|
<groupId>com.mybatis-flex</groupId>
|
||||||
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
|||||||
@ -7,8 +7,10 @@ import java.sql.Timestamp;
|
|||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典 实体类。
|
* 字典 实体类。
|
||||||
@ -18,6 +20,8 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Table("sys_core_dictionary")
|
@Table("sys_core_dictionary")
|
||||||
public class Dictionary implements Serializable {
|
public class Dictionary implements Serializable {
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,10 @@ import java.sql.Timestamp;
|
|||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典项 实体类。
|
* 字典项 实体类。
|
||||||
@ -18,6 +20,8 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Table("sys_core_dictionary_item")
|
@Table("sys_core_dictionary_item")
|
||||||
public class DictionaryItem implements Serializable {
|
public class DictionaryItem implements Serializable {
|
||||||
|
|
||||||
|
|||||||
@ -12,12 +12,36 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- 项目依赖 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>day.gitlab</groupId>
|
<groupId>day.gitlab</groupId>
|
||||||
<artifactId>dolphin-module-core</artifactId>
|
<artifactId>dolphin-common-security</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>day.gitlab</groupId>
|
||||||
|
<artifactId>dolphin-common-mybatis</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Spring Boot -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- MyBatis Flex -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mybatis-flex</groupId>
|
||||||
|
<artifactId>mybatis-flex-spring-boot3-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
package day.gitlab.dolphin.rbac.constants;
|
||||||
|
|
||||||
|
public class UserEnabled {
|
||||||
|
|
||||||
|
public static final String ENABLED = "1";
|
||||||
|
|
||||||
|
public static final String DISABLED = "0";
|
||||||
|
}
|
||||||
@ -7,8 +7,10 @@ import java.sql.Timestamp;
|
|||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门表 实体类。
|
* 部门表 实体类。
|
||||||
@ -18,6 +20,8 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Table("sys_rbac_department")
|
@Table("sys_rbac_department")
|
||||||
public class Department implements Serializable {
|
public class Department implements Serializable {
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,10 @@ import java.sql.Timestamp;
|
|||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 区划项 实体类。
|
* 区划项 实体类。
|
||||||
@ -18,6 +20,8 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Table("sys_rbac_region")
|
@Table("sys_rbac_region")
|
||||||
public class Region implements Serializable {
|
public class Region implements Serializable {
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,10 @@ import java.sql.Timestamp;
|
|||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色表 实体类。
|
* 角色表 实体类。
|
||||||
@ -18,6 +20,8 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Table("sys_rbac_role")
|
@Table("sys_rbac_role")
|
||||||
public class Role implements Serializable {
|
public class Role implements Serializable {
|
||||||
|
|
||||||
|
|||||||
@ -9,8 +9,10 @@ import java.sql.Timestamp;
|
|||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户表 实体类。
|
* 用户表 实体类。
|
||||||
@ -20,6 +22,8 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
@Table("sys_rbac_user")
|
@Table("sys_rbac_user")
|
||||||
public class User implements Serializable {
|
public class User implements Serializable {
|
||||||
|
|
||||||
|
|||||||
@ -14,5 +14,6 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>dolphin-module-core</module>
|
<module>dolphin-module-core</module>
|
||||||
<module>dolphin-module-rbac</module>
|
<module>dolphin-module-rbac</module>
|
||||||
|
<module>dolphin-module-auth</module>
|
||||||
</modules>
|
</modules>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
Reference in New Issue
Block a user