|
|
@@ -16,6 +16,7 @@
|
|
|
*/
|
|
|
package org.springblade.modules.auth.endpoint;
|
|
|
|
|
|
+import cn.hutool.crypto.digest.DigestUtil;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiSort;
|
|
|
import com.wf.captcha.SpecCaptcha;
|
|
|
import io.swagger.annotations.Api;
|
|
|
@@ -34,13 +35,18 @@ import org.springblade.core.secure.BladeUser;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tenant.annotation.NonDS;
|
|
|
import org.springblade.core.tool.support.Kv;
|
|
|
+import org.springblade.core.tool.utils.DesUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.WebUtil;
|
|
|
+import org.springblade.modules.auth.ldap.service.LdapService;
|
|
|
import org.springblade.modules.auth.provider.ITokenGranter;
|
|
|
import org.springblade.modules.auth.provider.TokenGranterBuilder;
|
|
|
import org.springblade.modules.auth.provider.TokenParameter;
|
|
|
import org.springblade.modules.auth.utils.TokenUtil;
|
|
|
import org.springblade.modules.system.entity.UserInfo;
|
|
|
+import org.springblade.modules.system.service.IParamService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.Assert;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
@@ -64,6 +70,11 @@ public class BladeTokenEndPoint {
|
|
|
|
|
|
private final BladeRedis bladeRedis;
|
|
|
private final JwtProperties jwtProperties;
|
|
|
+ private final IParamService paramService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LdapService ldapService;
|
|
|
+
|
|
|
|
|
|
@ApiLog("登录用户验证")
|
|
|
@PostMapping("/oauth/token")
|
|
|
@@ -77,6 +88,21 @@ public class BladeTokenEndPoint {
|
|
|
String grantType = WebUtil.getRequest().getParameter("grant_type");
|
|
|
String refreshToken = WebUtil.getRequest().getParameter("refresh_token");
|
|
|
|
|
|
+ String ldapOpen = paramService.getValue("account.ldapOpen");
|
|
|
+ String decryptFormHex = DesUtil.decryptFormHex(password, "cyzh2020");
|
|
|
+ if (ldapOpen != null && "true".equals(ldapOpen)){
|
|
|
+ System.out.println("decryptFormHex=" + decryptFormHex);
|
|
|
+
|
|
|
+ boolean ldapAuth = ldapService.ldapAuth(username, decryptFormHex);
|
|
|
+// boolean ldapAuth = false;
|
|
|
+ Assert.isTrue(ldapAuth, "ldap驗證失敗,請確認用戶名和密碼是否正確!");
|
|
|
+ // 用了ldap用戶驗證鑒權之後,系統原鑒權保留,但需要把所有用戶的密碼統一改為123456,統一用此密碼去登錄
|
|
|
+ password = "123456";
|
|
|
+ }else{
|
|
|
+ String passwordMD5 = DigestUtil.md5Hex(decryptFormHex);
|
|
|
+ password = passwordMD5;
|
|
|
+ }
|
|
|
+
|
|
|
String userType = Func.toStr(WebUtil.getRequest().getHeader(TokenUtil.USER_TYPE_HEADER_KEY), TokenUtil.DEFAULT_USER_TYPE);
|
|
|
|
|
|
TokenParameter tokenParameter = new TokenParameter();
|