diff --git a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/LightNoise.java b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/LightNoise.java index 2a0570771..e4b32f22f 100644 --- a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/LightNoise.java +++ b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/LightNoise.java @@ -78,11 +78,10 @@ public class LightNoise extends Configurable implements NoiseProducer while (!pi.isDone()) { float[] coords = new float[6]; - switch (pi.currentSegment(coords)) - { - case PathIterator.SEG_MOVETO: - case PathIterator.SEG_LINETO: + switch (pi.currentSegment(coords)){ + case PathIterator.SEG_MOVETO,PathIterator.SEG_LINETO:{ tmp[i] = new Point2D.Float(coords[0], coords[1]); + } } i++; pi.next(); diff --git a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/UniqueTextCreator.java b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/UniqueTextCreator.java index 9629ec148..4bbf6007e 100644 --- a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/UniqueTextCreator.java +++ b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/impl/UniqueTextCreator.java @@ -23,12 +23,12 @@ import com.google.code.kaptcha.text.TextProducer; import com.google.code.kaptcha.util.Configurable; public class UniqueTextCreator extends Configurable implements TextProducer{ - + Random rand = new Random(); + @Override public String getText() { int length = getConfig().getTextProducerCharLength(); char[] chars = getConfig().getTextProducerCharString(); - Random rand = new Random(); StringBuffer text = new StringBuffer(); int i = 0; while ( i < length){ diff --git a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/text/impl/RandomColorWordRenderer.java b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/text/impl/RandomColorWordRenderer.java index 28277e061..74a2d3dfe 100644 --- a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/text/impl/RandomColorWordRenderer.java +++ b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/com/google/code/kaptcha/text/impl/RandomColorWordRenderer.java @@ -77,10 +77,7 @@ public class RandomColorWordRenderer extends Configurable implements WordRendere Font[] chosenFonts = new Font[wordChars.length]; int [] charWidths = new int[wordChars.length]; int widthNeeded = 0; - for (int i = 0; i < wordChars.length; i++) - { - - //chosenFonts[i] = new Font("Arial", Font.BOLD, fontSize); + for (int i = 0; i < wordChars.length; i++){ //random chosenFonts[i] = fonts[random.nextInt(fonts.length)]; @@ -96,14 +93,14 @@ public class RandomColorWordRenderer extends Configurable implements WordRendere widthNeeded = widthNeeded + charWidths[i]; } - HashMap selectedColor =new HashMap(); + HashMap selectedColor =new HashMap<>(); int startPosX = (width - widthNeeded) / 2; for (int i = 0; i < wordChars.length; i++) { String randomcolor=""; do { - randomcolor=COLOR_LIST[random.nextInt(COLOR_LIST.length)].replaceAll(" ", ""); + randomcolor=COLOR_LIST[random.nextInt(COLOR_LIST.length)].replace(" ", ""); }while(selectedColor.containsKey(randomcolor)); selectedColor.put(randomcolor, randomcolor); @@ -117,7 +114,6 @@ public class RandomColorWordRenderer extends Configurable implements WordRendere wordChars[i] }; - //System.out.println(charToDraw[0] +" - "+chosenFonts[i]); g2D.drawChars(charToDraw, 0, charToDraw.length, startPosX, startPosY); startPosX = startPosX + (int) charWidths[i] + charSpace; } @@ -125,7 +121,7 @@ public class RandomColorWordRenderer extends Configurable implements WordRendere return image; } - static String [] COLOR_LIST = { + static final String [] COLOR_LIST = { //"255, 255, 255", //white //"192, 192, 192", //silver //"128, 128, 128", //gray diff --git a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/org/dromara/maxkey/autoconfigure/KaptchaAutoConfiguration.java b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/org/dromara/maxkey/autoconfigure/KaptchaAutoConfiguration.java index cde019443..b5b359332 100644 --- a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/org/dromara/maxkey/autoconfigure/KaptchaAutoConfiguration.java +++ b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/org/dromara/maxkey/autoconfigure/KaptchaAutoConfiguration.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.core.io.ClassPathResource; @@ -32,19 +31,20 @@ import org.springframework.core.io.Resource; @AutoConfiguration -public class KaptchaAutoConfiguration implements InitializingBean { +public class KaptchaAutoConfiguration { private static final Logger _logger = LoggerFactory.getLogger(KaptchaAutoConfiguration.class); - public static final String kaptchaPropertySource = "/kaptcha.properties"; + public static final String KAPTCHA_PROPERTY = "/kaptcha.properties"; + /** * Captcha Producer Config . * @return Producer * @throws IOException kaptcha.properties is null */ @Bean - public Producer captchaProducer() throws IOException { - Resource resource = new ClassPathResource(kaptchaPropertySource); - _logger.debug("Kaptcha config file " + resource.getURL()); + Producer captchaProducer() throws IOException { + Resource resource = new ClassPathResource(KAPTCHA_PROPERTY); + _logger.debug("Kaptcha config file {}" , resource.getURL()); DefaultKaptcha kaptcha = new DefaultKaptcha(); Properties properties = new Properties(); properties.load(resource.getInputStream()); @@ -53,8 +53,4 @@ public class KaptchaAutoConfiguration implements InitializingBean { return kaptcha; } - @Override - public void afterPropertiesSet() throws Exception { - - } } diff --git a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/org/dromara/maxkey/web/contorller/ImageCaptchaEndpoint.java b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/org/dromara/maxkey/web/contorller/ImageCaptchaEndpoint.java index 1c8155d0f..0b28788b7 100644 --- a/maxkey-authentications/maxkey-authentication-captcha/src/main/java/org/dromara/maxkey/web/contorller/ImageCaptchaEndpoint.java +++ b/maxkey-authentications/maxkey-authentication-captcha/src/main/java/org/dromara/maxkey/web/contorller/ImageCaptchaEndpoint.java @@ -30,7 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -58,7 +58,7 @@ public class ImageCaptchaEndpoint { * @param request HttpServletRequest * @param response HttpServletResponse */ - @RequestMapping(value={"/captcha"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + @GetMapping(value={"/captcha"}, produces = {MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity captchaHandleRequest( @RequestParam(value="captcha",required=false,defaultValue="text") String captchaType, @RequestParam(value="state",required=false,defaultValue="state") String state) { @@ -98,7 +98,7 @@ public class ImageCaptchaEndpoint { new ImageCaptcha(state,b64Image) ).buildResponse(); } catch (Exception e) { - _logger.error("captcha Producer Error " + e.getMessage()); + _logger.error("captcha Producer Error" , e); } return new Message< Object>(Message.FAIL).buildResponse(); } diff --git a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/AuthTokenService.java b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/AuthTokenService.java index 0112fca02..a46cdaf94 100644 --- a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/AuthTokenService.java +++ b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/AuthTokenService.java @@ -68,12 +68,11 @@ public class AuthTokenService extends AuthJwtService{ String refreshToken = refreshTokenService.genRefreshToken(authentication); _logger.trace("generate JWT Token"); String accessToken = genJwt(authentication); - AuthJwt authJwt = new AuthJwt( + return new AuthJwt( accessToken, authentication, authJwkConfig.getExpires(), refreshToken); - return authJwt; } return null; } @@ -118,8 +117,7 @@ public class AuthTokenService extends AuthJwtService{ } public AuthJwt consumeCongress(String congress) { - AuthJwt authJwt = congressService.consume(congress); - return authJwt; + return congressService.consume(congress); } public boolean validateCaptcha(String state,String captcha) { diff --git a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/InMemoryCongressService.java b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/InMemoryCongressService.java index b4028d3c9..7b202da73 100644 --- a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/InMemoryCongressService.java +++ b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/InMemoryCongressService.java @@ -26,7 +26,7 @@ import com.github.benmanes.caffeine.cache.Caffeine; public class InMemoryCongressService implements CongressService{ - private static final Logger _logger = LoggerFactory.getLogger(InMemoryCongressService.class); + private static final Logger logger = LoggerFactory.getLogger(InMemoryCongressService.class); protected static Cache congressStore = Caffeine.newBuilder() @@ -52,8 +52,7 @@ public class InMemoryCongressService implements CongressService{ @Override public AuthJwt get(String congress) { - AuthJwt authJwt = congressStore.getIfPresent(congress); - return authJwt; + return congressStore.getIfPresent(congress); } @Override diff --git a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/RedisCongressService.java b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/RedisCongressService.java index ee60de3cc..ca95a67dc 100644 --- a/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/RedisCongressService.java +++ b/maxkey-authentications/maxkey-authentication-core/src/main/java/org/dromara/maxkey/authn/jwt/RedisCongressService.java @@ -24,13 +24,13 @@ import org.slf4j.LoggerFactory; public class RedisCongressService implements CongressService { - private static final Logger _logger = LoggerFactory.getLogger(RedisCongressService.class); + private static final Logger logger = LoggerFactory.getLogger(RedisCongressService.class); protected int validitySeconds = 60 * 3; //default 3 minutes. RedisConnectionFactory connectionFactory; - public static String PREFIX="REDIS_CONGRESS_"; + public static final String PREFIX = "REDIS:CONGRESS:"; /** * @param connectionFactory */