优化
This commit is contained in:
parent
b921722c2a
commit
4d02e4c64d
@ -7,7 +7,6 @@ import com.zhgd.annotation.OperLog;
|
||||
import com.zhgd.jeecg.common.api.vo.Result;
|
||||
import com.zhgd.jeecg.common.constant.CommonConstant;
|
||||
import com.zhgd.mybatis.Aes;
|
||||
import com.zhgd.xmgl.handler.exception.CustomException;
|
||||
import com.zhgd.xmgl.modules.basicdata.dto.SystemUserAuthDto;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.Government;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
||||
@ -21,7 +20,6 @@ import com.zhgd.xmgl.security.JwtTokenProvider;
|
||||
import com.zhgd.xmgl.security.SecurityUser;
|
||||
import com.zhgd.xmgl.security.SecurityUtil;
|
||||
import com.zhgd.xmgl.util.CommonUtil;
|
||||
import com.zhgd.xmgl.util.JwtUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
@ -29,20 +27,14 @@ import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@ -243,22 +235,28 @@ public class SystemUserAuthController {
|
||||
@OperLog(operModul = "用户身份认证", operType="登录", operDesc = "用户身份认证")
|
||||
@Operation(summary = "用户身份认证", description = "用户身份认证")
|
||||
@PostMapping("/ssoLogin")
|
||||
public void ssoLogin(@RequestParam Map<String, Object> map, HttpServletResponse response) throws IOException {
|
||||
String token = MapUtils.getString(map, "id_token");
|
||||
String targetUrl = MapUtils.getString(map, "target_url");
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
throw new CustomException("id_token 参数不存在");
|
||||
public Result<SystemUserAuthDto> ssoLogin(@RequestParam Map<String, Object> map, HttpServletResponse response) throws IOException {
|
||||
Result<SystemUserAuthDto> result = new Result<SystemUserAuthDto>();
|
||||
// 检查账户是否已被锁定
|
||||
String account = MapUtils.getString(map, "account");
|
||||
String password = MapUtils.getString(map, "password");
|
||||
if (jwtTokenProvider.checkLock(account) >=5 ) {
|
||||
result.error500("账号已被锁定,还有" + DateUtil.formatBetween(jwtTokenProvider.getExpire(account) * 1000L) + "解锁");
|
||||
return result;
|
||||
}
|
||||
// 公钥
|
||||
RSAPublicKey publicKey;
|
||||
try {
|
||||
ClassPathResource res = new ClassPathResource("sign.cer");
|
||||
publicKey = (RSAPublicKey) JwtUtils.readPublicKey(new String(
|
||||
FileCopyUtils.copyToByteArray(res.getInputStream()), StandardCharsets.UTF_8));
|
||||
} catch (CertificateException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
SystemUser user = systemUserService.getOne(Wrappers.<SystemUser>lambdaQuery()
|
||||
.eq(SystemUser::getAccount, account)
|
||||
.eq(SystemUser::getShowPassword, password));
|
||||
SystemUserAuthDto userInfo = new SystemUserAuthDto();
|
||||
checkLogin(user, userInfo, result, account);
|
||||
if (result.getCode() != CommonConstant.SC_INTERNAL_SERVER_ERROR_500) {
|
||||
String token = jwtTokenProvider.createToken(userInfo.getAccount(), 3600 * 24 * 1000L);
|
||||
userInfo.setToken(token);
|
||||
userInfo.setIsEngineering(systemUserDataScopeService.count(Wrappers.<SystemUserDataScope>lambdaQuery()
|
||||
.eq(SystemUserDataScope::getUserId, userInfo.getUserId())) > 0);
|
||||
result.setResult(userInfo);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
String username = JwtUtils.getUserNameFromToken(token, publicKey);
|
||||
response.sendRedirect("http://jxjzw.zhgdyun.com:6080/#/home");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,6 +91,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.antMatchers("/xmgl/systemUser/analysis").permitAll()
|
||||
.antMatchers("/project/workerAttendance/add").permitAll()
|
||||
.antMatchers("/jwt/sso").permitAll()
|
||||
.antMatchers("/xmgl/systemUser/ssoLogin").permitAll()
|
||||
.antMatchers(HttpMethod.OPTIONS, "/**").anonymous()
|
||||
.anyRequest().authenticated() // 剩下所有的验证都需要验证
|
||||
.and()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user