mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-08 01:48:33 +08:00
resolve
This commit is contained in:
parent
0f7189c51d
commit
a02822d0b3
@ -18,8 +18,6 @@
|
|||||||
package org.maxkey.web.contorller;
|
package org.maxkey.web.contorller;
|
||||||
|
|
||||||
import com.google.code.kaptcha.Producer;
|
import com.google.code.kaptcha.Producer;
|
||||||
import com.nimbusds.jwt.JWTClaimsSet;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@ -30,7 +28,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.maxkey.authn.jwt.AuthJwtService;
|
import org.maxkey.authn.jwt.AuthJwtService;
|
||||||
import org.maxkey.entity.Message;
|
import org.maxkey.entity.Message;
|
||||||
import org.maxkey.persistence.MomentaryService;
|
import org.maxkey.persistence.MomentaryService;
|
||||||
import org.maxkey.web.WebContext;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -87,11 +84,11 @@ public class ImageCaptchaEndpoint {
|
|||||||
if(StringUtils.isNotBlank(state)
|
if(StringUtils.isNotBlank(state)
|
||||||
&& !state.equalsIgnoreCase("state")
|
&& !state.equalsIgnoreCase("state")
|
||||||
&& authJwtService.validateJwtToken(state)) {
|
&& authJwtService.validateJwtToken(state)) {
|
||||||
JWTClaimsSet claim = authJwtService.resolve(state);
|
//do nothing
|
||||||
kaptchaKey = claim.getJWTID();
|
|
||||||
}else {
|
}else {
|
||||||
kaptchaKey = WebContext.genId();
|
state = authJwtService.genJwt();
|
||||||
}
|
}
|
||||||
|
kaptchaKey = authJwtService.resolveTicket(state);
|
||||||
_logger.trace("kaptchaKey {} , Captcha Text is {}" ,kaptchaKey, kaptchaValue);
|
_logger.trace("kaptchaKey {} , Captcha Text is {}" ,kaptchaKey, kaptchaValue);
|
||||||
|
|
||||||
momentaryService.put("", kaptchaKey, kaptchaValue);
|
momentaryService.put("", kaptchaKey, kaptchaValue);
|
||||||
@ -108,7 +105,7 @@ public class ImageCaptchaEndpoint {
|
|||||||
|
|
||||||
stream.close();
|
stream.close();
|
||||||
return new Message<ImageCaptcha>(
|
return new Message<ImageCaptcha>(
|
||||||
new ImageCaptcha(kaptchaKey,b64Image)
|
new ImageCaptcha(state,b64Image)
|
||||||
).buildResponse();
|
).buildResponse();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
_logger.error("captcha Producer Error " + e.getMessage());
|
_logger.error("captcha Producer Error " + e.getMessage());
|
||||||
|
|||||||
@ -37,8 +37,6 @@ 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;
|
||||||
import com.nimbusds.jwt.JWTClaimsSet;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* database Authentication provider.
|
* database Authentication provider.
|
||||||
@ -136,16 +134,17 @@ public class NormalAuthenticationProvider extends AbstractAuthenticationProvider
|
|||||||
*/
|
*/
|
||||||
protected void captchaValid(String state ,String captcha) throws ParseException {
|
protected void captchaValid(String state ,String captcha) throws ParseException {
|
||||||
// for basic
|
// for basic
|
||||||
JWTClaimsSet claim = authJwtService.resolve(state);
|
String ticket = authJwtService.resolveTicket(state);
|
||||||
if(claim == null) {
|
if(ticket == null) {
|
||||||
throw new BadCredentialsException(WebContext.getI18nValue("login.error.captcha"));
|
throw new BadCredentialsException(WebContext.getI18nValue("login.error.captcha"));
|
||||||
}
|
}
|
||||||
Object momentaryCaptcha = momentaryService.get("", claim.getJWTID());
|
Object momentaryCaptcha = momentaryService.get("", ticket);
|
||||||
_logger.info("captcha : {} , momentary Captcha : {} " ,captcha, momentaryCaptcha);
|
_logger.info("captcha : {} , momentary Captcha : {} " ,captcha, momentaryCaptcha);
|
||||||
if (StringUtils.isBlank(captcha) || !captcha.equals(momentaryCaptcha.toString())) {
|
if (StringUtils.isBlank(captcha) || !captcha.equals(momentaryCaptcha.toString())) {
|
||||||
_logger.debug("login captcha valid error.");
|
_logger.debug("login captcha valid error.");
|
||||||
throw new BadCredentialsException(WebContext.getI18nValue("login.error.captcha"));
|
throw new BadCredentialsException(WebContext.getI18nValue("login.error.captcha"));
|
||||||
}
|
}
|
||||||
|
momentaryService.remove("", ticket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user