Merge pull request #233 from orangebabu/main

app登录+二维码登录
This commit is contained in:
orangebabu 2024-08-20 10:58:52 +08:00 committed by GitHub
commit 1d25032e2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 6 deletions

View File

@ -1,15 +1,18 @@
package org.dromara.maxkey.authn.provider.impl; package org.dromara.maxkey.authn.provider.impl;
import org.dromara.maxkey.authn.LoginCredential; import org.dromara.maxkey.authn.LoginCredential;
import org.dromara.maxkey.authn.jwt.AuthTokenService;
import org.dromara.maxkey.authn.provider.AbstractAuthenticationProvider; import org.dromara.maxkey.authn.provider.AbstractAuthenticationProvider;
import org.dromara.maxkey.authn.realm.AbstractAuthenticationRealm; import org.dromara.maxkey.authn.realm.AbstractAuthenticationRealm;
import org.dromara.maxkey.authn.session.SessionManager; import org.dromara.maxkey.authn.session.SessionManager;
import org.dromara.maxkey.configuration.ApplicationConfig;
import org.dromara.maxkey.constants.ConstsLoginType; import org.dromara.maxkey.constants.ConstsLoginType;
import org.dromara.maxkey.entity.idm.UserInfo; import org.dromara.maxkey.entity.idm.UserInfo;
import org.dromara.maxkey.web.WebConstants; import org.dromara.maxkey.web.WebConstants;
import org.dromara.maxkey.web.WebContext; import org.dromara.maxkey.web.WebContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
@ -28,9 +31,13 @@ public class AppAuthenticationProvider extends AbstractAuthenticationProvider {
public AppAuthenticationProvider( public AppAuthenticationProvider(
AbstractAuthenticationRealm authenticationRealm, AbstractAuthenticationRealm authenticationRealm,
SessionManager sessionManager) { ApplicationConfig applicationConfig,
SessionManager sessionManager,
AuthTokenService authTokenService) {
this.authenticationRealm = authenticationRealm; this.authenticationRealm = authenticationRealm;
this.applicationConfig = applicationConfig;
this.sessionManager = sessionManager; this.sessionManager = sessionManager;
this.authTokenService = authTokenService;
} }
@ -48,6 +55,9 @@ public class AppAuthenticationProvider extends AbstractAuthenticationProvider {
_logger.debug("authentication {}", loginCredential); _logger.debug("authentication {}", loginCredential);
if(this.applicationConfig.getLoginConfig().isCaptcha()) {
captchaValid(loginCredential.getState(),loginCredential.getCaptcha());
}
emptyPasswordValid(loginCredential.getPassword()); emptyPasswordValid(loginCredential.getPassword());
@ -93,4 +103,11 @@ public class AppAuthenticationProvider extends AbstractAuthenticationProvider {
return authenticationToken; return authenticationToken;
} }
protected void captchaValid(String state ,String captcha) {
// for basic
if(!authTokenService.validateCaptcha(state,captcha)) {
throw new BadCredentialsException(WebContext.getI18nValue("login.error.captcha"));
}
}
} }

View File

@ -91,11 +91,15 @@ public class AuthnProviderAutoConfiguration {
@Bean @Bean
public AppAuthenticationProvider appAuthenticationProvider( public AppAuthenticationProvider appAuthenticationProvider(
AbstractAuthenticationRealm authenticationRealm, AbstractAuthenticationRealm authenticationRealm,
SessionManager sessionManager ApplicationConfig applicationConfig,
SessionManager sessionManager,
AuthTokenService authTokenService
) { ) {
return new AppAuthenticationProvider( return new AppAuthenticationProvider(
authenticationRealm, authenticationRealm,
sessionManager applicationConfig,
sessionManager,
authTokenService
); );
} }

View File

@ -102,6 +102,13 @@ export class UserLoginComponent implements OnInit, OnDestroy {
//init socials,state //init socials,state
this.authnService.clear(); this.authnService.clear();
this.get();
this.cdr.detectChanges();
}
get() {
this.authnService this.authnService
.get({ remember_me: localStorage.getItem(CONSTS.REMEMBER) }) .get({ remember_me: localStorage.getItem(CONSTS.REMEMBER) })
.pipe( .pipe(
@ -141,7 +148,6 @@ export class UserLoginComponent implements OnInit, OnDestroy {
} }
} }
}); });
this.cdr.detectChanges();
} }
congressLogin(congress: string) { congressLogin(congress: string) {
@ -343,6 +349,8 @@ export class UserLoginComponent implements OnInit, OnDestroy {
this.authnService.navigate({}); this.authnService.navigate({});
} else if (res.code === 20004) { } else if (res.code === 20004) {
this.qrexpire = true; this.qrexpire = true;
} else if (res.code === 20005) {
this.get()
} }
// Handle response here // Handle response here

View File

@ -314,9 +314,9 @@ public class LoginEntryPoint {
} catch (BusinessException businessException) { } catch (BusinessException businessException) {
return new Message<>(businessException.getCode(), businessException.getMessage()); return new Message<>(businessException.getCode(), businessException.getMessage());
} }
} else {
return new Message<>(20005, "state失效重新获取");
} }
return new Message<>(Message.FAIL);
} }
@Operation(summary = "app扫描二维码", description = "扫描二维码登录", method = "POST") @Operation(summary = "app扫描二维码", description = "扫描二维码登录", method = "POST")