|
@@ -11,6 +11,7 @@ import cn.com.qmth.scancentral.service.AuthService;
|
|
import cn.com.qmth.scancentral.service.ScannerService;
|
|
import cn.com.qmth.scancentral.service.ScannerService;
|
|
import cn.com.qmth.scancentral.service.SessionService;
|
|
import cn.com.qmth.scancentral.service.SessionService;
|
|
import cn.com.qmth.scancentral.service.UserService;
|
|
import cn.com.qmth.scancentral.service.UserService;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.qmth.boot.core.exception.ParameterException;
|
|
import com.qmth.boot.core.exception.ParameterException;
|
|
import com.qmth.boot.core.security.annotation.AuthorizationComponent;
|
|
import com.qmth.boot.core.security.annotation.AuthorizationComponent;
|
|
import com.qmth.boot.core.security.service.AuthorizationService;
|
|
import com.qmth.boot.core.security.service.AuthorizationService;
|
|
@@ -27,7 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
@AuthorizationComponent
|
|
@AuthorizationComponent
|
|
public class AuthServiceImpl implements AuthorizationService<User>, AuthService {
|
|
public class AuthServiceImpl implements AuthorizationService<User>, AuthService {
|
|
|
|
|
|
- protected static final Logger log = LoggerFactory.getLogger(AuthServiceImpl.class);
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(AuthServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private UserService userService;
|
|
private UserService userService;
|
|
@@ -52,12 +53,46 @@ public class AuthServiceImpl implements AuthorizationService<User>, AuthService
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public User login(String loginName, String password, String deviceIp) {
|
|
|
|
+ UserEntity userEntity = userService.getByLoginName(loginName);
|
|
|
|
+ if (userEntity == null) {
|
|
|
|
+ throw new ParameterException("用户不存在");
|
|
|
|
+ }
|
|
|
|
+ if (!userEntity.getEnable()) {
|
|
|
|
+ throw new ParameterException("用户已禁用");
|
|
|
|
+ }
|
|
|
|
+ if (!password.equals(userEntity.getPassword())) {
|
|
|
|
+ throw new ParameterException("密码错误");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ LambdaUpdateWrapper<UserEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
+ updateWrapper.set(UserEntity::getDevice, deviceIp);
|
|
|
|
+ updateWrapper.eq(UserEntity::getId, userEntity.getId());
|
|
|
|
+ userService.update(updateWrapper);
|
|
|
|
+
|
|
|
|
+ User user = new User();
|
|
|
|
+ user.setRole(userEntity.getRole());
|
|
|
|
+ user.setAccount(loginName);
|
|
|
|
+ user.setAccessToken(RandomStringUtils.randomAlphanumeric(32));
|
|
|
|
+ user.buildKey();
|
|
|
|
+ user.setName(userEntity.getName());
|
|
|
|
+ user.setId(userEntity.getId());
|
|
|
|
+ sessionService.userLogin(user);
|
|
|
|
+ log.warn("登录成功! role:{} loginName:{}", userEntity.getRole(), loginName);
|
|
|
|
+ return user;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
- public User login(String ip, ScannerLoginInfo loginInfo) {
|
|
|
|
- if (StringUtils.isBlank(ip)) {
|
|
|
|
- throw new ParameterException("IP获取失败");
|
|
|
|
|
|
+ public User scannerLogin(ScannerLoginInfo loginInfo) {
|
|
|
|
+ if (StringUtils.isBlank(loginInfo.getDevice())) {
|
|
|
|
+ throw new ParameterException("device不能为空");
|
|
}
|
|
}
|
|
|
|
+ if (StringUtils.isBlank(loginInfo.getDeviceName())) {
|
|
|
|
+ throw new ParameterException("deviceName不能为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
SystemConfigEntity config = systemConfigService.find();
|
|
SystemConfigEntity config = systemConfigService.find();
|
|
if (config != null) {
|
|
if (config != null) {
|
|
if (config.getScannerEnableLogin() != null && !config.getScannerEnableLogin()) {
|
|
if (config.getScannerEnableLogin() != null && !config.getScannerEnableLogin()) {
|
|
@@ -72,38 +107,17 @@ public class AuthServiceImpl implements AuthorizationService<User>, AuthService
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
User user = new User();
|
|
User user = new User();
|
|
user.setRole(Role.SCANNER);
|
|
user.setRole(Role.SCANNER);
|
|
- user.setAccount(ip);
|
|
|
|
|
|
+ user.setAccount(loginInfo.getDevice());
|
|
user.setAccessToken(RandomStringUtils.randomAlphanumeric(32));
|
|
user.setAccessToken(RandomStringUtils.randomAlphanumeric(32));
|
|
user.buildKey();
|
|
user.buildKey();
|
|
- scannerService.onLogin(ip);
|
|
|
|
|
|
+ user.setName(loginInfo.getDeviceName());
|
|
|
|
+ scannerService.onLogin(loginInfo);
|
|
sessionService.userLogin(user);
|
|
sessionService.userLogin(user);
|
|
- return user;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
- public User adminLogin(String loginName, String password, String device) {
|
|
|
|
- UserEntity userEntity = userService.getByLoginName(loginName);
|
|
|
|
- if (userEntity == null) {
|
|
|
|
- throw new ParameterException("用户不存在");
|
|
|
|
- }
|
|
|
|
- if (!userEntity.getEnable()) {
|
|
|
|
- throw new ParameterException("用户已禁用");
|
|
|
|
- }
|
|
|
|
- if (!password.equals(userEntity.getPassword())) {
|
|
|
|
- throw new ParameterException("密码错误");
|
|
|
|
- }
|
|
|
|
- userEntity.setDevice(device);
|
|
|
|
- userService.saveOrUpdate(userEntity);
|
|
|
|
- User user = new User();
|
|
|
|
- user.setRole(userEntity.getRole());
|
|
|
|
- user.setAccount(loginName);
|
|
|
|
- user.setAccessToken(RandomStringUtils.randomAlphanumeric(32));
|
|
|
|
- user.buildKey();
|
|
|
|
- user.setId(userEntity.getId());
|
|
|
|
- user.setName(userEntity.getName());
|
|
|
|
- sessionService.userLogin(user);
|
|
|
|
|
|
+ log.warn("登录成功! role:{} device:{}_{} {}", Role.SCANNER, loginInfo.getDevice(), loginInfo.getDeviceName(), loginInfo.getDeviceIp());
|
|
return user;
|
|
return user;
|
|
}
|
|
}
|
|
|
|
|