瀏覽代碼

otpCaptcha

MaxKey 3 年之前
父節點
當前提交
e31a83b679

+ 1 - 1
maxkey-authentications/maxkey-authentication-captcha/src/main/java/org/maxkey/web/contorller/ImageCaptchaEndpoint.java

@@ -84,7 +84,7 @@ public class ImageCaptchaEndpoint {
             if(StringUtils.isNotBlank(state) 
             		&& !state.equalsIgnoreCase("state")
             		&& authJwtService.validateJwtToken(state)) {
-            	//do nothing
+            	//just validate state Token
             }else {
             	state = authJwtService.genJwt();
             }

+ 5 - 1
maxkey-authentications/maxkey-authentication-core/src/main/java/org/maxkey/authn/provider/NormalAuthenticationProvider.java

@@ -79,7 +79,11 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
 	        _logger.debug("authentication " + loginCredential);
 	        
 	        Institutions inst = (Institutions)WebContext.getAttribute(WebConstants.CURRENT_INST);
-	        if(inst.getCaptchaSupport().equalsIgnoreCase("YES")) {
+	        
+	        if(this.applicationConfig.getLoginConfig().isCaptcha()) {
+	        	captchaValid(loginCredential.getState(),loginCredential.getCaptcha());
+	        }
+	        else if(inst.getCaptchaSupport().equalsIgnoreCase("YES")) {
 	        	captchaValid(loginCredential.getState(),loginCredential.getCaptcha());
 	        }
 	

+ 10 - 1
maxkey-core/src/main/java/org/maxkey/configuration/LoginConfig.java

@@ -23,6 +23,9 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 public class LoginConfig {
     
+	@Value("${maxkey.login.captcha}")
+    boolean captcha;
+	
     @Value("${maxkey.login.mfa}")
     boolean mfa;
     
@@ -41,9 +44,15 @@ public class LoginConfig {
     public LoginConfig() {
     }
 
+    public boolean isCaptcha() {
+		return captcha;
+	}
 
+	public void setCaptcha(boolean captcha) {
+		this.captcha = captcha;
+	}
 
-    public boolean isKerberos() {
+	public boolean isKerberos() {
         return kerberos;
     }
 

+ 6 - 2
maxkey-webs/maxkey-web-maxkey/src/main/java/org/maxkey/web/endpoint/LoginEntryPoint.java

@@ -118,8 +118,12 @@ public class LoginEntryPoint {
 		
 		Institutions inst = (Institutions)WebContext.getAttribute(WebConstants.CURRENT_INST);
 		model.put("inst", inst);
-		model.put("captcha", inst.getCaptchaSupport());
-		model.put("captchaType", inst.getCaptchaType());
+		if(applicationConfig.getLoginConfig().isCaptcha()) {
+			model.put("captcha", "true");
+		}else {
+			model.put("captcha", inst.getCaptchaSupport());
+			model.put("captchaType", inst.getCaptchaType());
+		}
 		model.put("state", authJwtService.genJwt());
 		//load Social Sign On Providers
 		model.put("socials", socialSignOnProviderService.loadSocials(inst.getId()));

+ 2 - 0
maxkey-webs/maxkey-web-maxkey/src/main/resources/application-http.properties

@@ -56,6 +56,8 @@ maxkey.auth.jwt.secret                          =7heM-14BtxjyKPuH3ITIm7q2-ps5MuB
 ############################################################################
 #Login configuration                                                       #
 ############################################################################
+#enable captcha
+maxkey.login.captcha                            =${LOGIN_CAPTCHA:false}
 #enable two factor,use one time password
 maxkey.login.mfa                                =${LOGIN_MFA_ENABLED:true}
 #TimeBasedOtpAuthn MailOtpAuthn SmsOtpAuthnYunxin SmsOtpAuthnAliyun SmsOtpAuthnTencentCloud

+ 2 - 0
maxkey-webs/maxkey-web-maxkey/src/main/resources/application-https.properties

@@ -52,6 +52,8 @@ maxkey.auth.jwt.secret                          =7heM-14BtxjyKPuH3ITIm7q2-ps5MuB
 ############################################################################
 #Login configuration                                                       #
 ############################################################################
+#enable captcha
+maxkey.login.captcha                            =${LOGIN_CAPTCHA:false}
 #enable two factor,use one time password
 maxkey.login.mfa                                =${LOGIN_MFA_ENABLED:true}
 #TimeBasedOtpAuthn MailOtpAuthn SmsOtpAuthnYunxin SmsOtpAuthnAliyun SmsOtpAuthnTencentCloud

+ 6 - 2
maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/LoginEntryPoint.java

@@ -70,8 +70,12 @@ public class LoginEntryPoint {
 		model.put("isRemeberMe", applicationConfig.getLoginConfig().isRemeberMe());
 		Institutions inst = (Institutions)WebContext.getAttribute(WebConstants.CURRENT_INST);
 		model.put("inst", inst);
-		model.put("captcha", inst.getCaptchaSupport());
-		model.put("captchaType", inst.getCaptchaType());
+		if(applicationConfig.getLoginConfig().isCaptcha()) {
+			model.put("captcha", "true");
+		}else {
+			model.put("captcha", inst.getCaptchaSupport());
+			model.put("captchaType", inst.getCaptchaType());
+		}
 		model.put("state", authJwtService.genJwt());
 		return new Message<HashMap<String , Object>>(model).buildResponse();
 	}

+ 2 - 0
maxkey-webs/maxkey-web-mgt/src/main/resources/application-http.properties

@@ -46,6 +46,8 @@ maxkey.auth.jwt.secret                          =7heM-14BtxjyKPuH3ITIm7q2-ps5MuB
 ############################################################################
 #Login configuration                                                       #
 ############################################################################
+#enable captcha
+maxkey.login.captcha                            =${LOGIN_CAPTCHA:true}
 #enable two factor,use one time password
 maxkey.login.mfa                                =false
 #Enable kerberos/SPNEGO