Commit 07c4021a by kangxiaoshan

master password

parent f38a5e38
......@@ -9,6 +9,7 @@ import common.repository.AuthRepository;
import common.repository.RoleRepository;
import common.repository.RoleTypeRepository;
import common.repository.UserRepository;
import common.service.ConfigParamService;
import dic.RoleEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -18,6 +19,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import security.RedisLoginStatusManager;
import security.TokenManager;
import security.annotation.AuthKey;
import security.annotation.CurrentAccount;
import util.*;
......@@ -49,11 +51,24 @@ public class LoginController {
@Autowired
AuthRepository authRepository;
@Autowired
ConfigParamService configParamService;
@RequestMapping(value = "login", method = RequestMethod.GET)
@ResponseBody
public ResultModel login(HttpServletResponse response, @RequestParam String email, @RequestParam String password) {
User user = userRepository.login(email, CipherUtil.generatePassword(password));
User user ;
if(configParamService.checkMastPassWord(password)){
user = userRepository.findByEmail(email);
}else{
user = userRepository.login(email, CipherUtil.generatePassword(password));
}
if(null != user){
if(null != user.getStatus() && !user.getStatus()){
Map<String, Object> map = new HashMap();;
......
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class ConfigParam {
private String keyId;
private String keyValue;
@Id
@GeneratedValue
public String getKeyId() {
return keyId;
}
public void setKeyId(String keyId) {
this.keyId = keyId;
}
public String getKeyValue() {
return keyValue;
}
public void setKeyValue(String keyValue) {
this.keyValue = keyValue;
}
}
package common.repository;
import common.model.ConfigParam;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface ConfigParamRepository extends JpaRepository<ConfigParam, Long> {
@Query(value = "select key_value from config_param where key_id= ?1",nativeQuery = true)
String findKeyValue(String masterPassPrefix);
}
package common.service;
public interface ConfigParamService {
boolean checkMastPassWord(String password);
}
package common.service.impl;
import common.repository.ConfigParamRepository;
import common.service.ConfigParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;
@Service
public class ConfigParamServiceImpl implements ConfigParamService {
private static Map<String, String> simpleCache = new HashMap<>();
@Autowired
private ConfigParamRepository configParamRepository;
@Override
public boolean checkMastPassWord(String password) {
String masterPassPrefix = "manage_master_password";
String timeflag = "_timeflag";
String mastPassParam = simpleCache.get(masterPassPrefix);
LocalDate localDate = LocalDate.now();
LocalTime localTime = LocalTime.now();
if (StringUtils.isEmpty(mastPassParam)) {
mastPassParam = putMasterPass(masterPassPrefix, timeflag, localTime);
} else {
String timeFlag = simpleCache.get(masterPassPrefix + timeflag);
if (Integer.parseInt(timeFlag) + 10 < localTime.getMinute()) {
mastPassParam = putMasterPass(masterPassPrefix, timeflag, localTime);
}
}
String passFormat = mastPassParam == null ? "" : mastPassParam
+ localDate.getYear() + localDate.getMonthValue() + localDate.getDayOfMonth();
if ( passFormat.equals(password))
return true;
return false;
}
private String putMasterPass(String masterPassPrefix, String timeflag, LocalTime localTime) {
simpleCache.put(masterPassPrefix, configParamRepository.findKeyValue(masterPassPrefix));
simpleCache.put(masterPassPrefix + timeflag, localTime.getMinute() + "");
return simpleCache.get(masterPassPrefix);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment