From 2c0f3deb8a4f0ba702618df3062568158048b2dd Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Thu, 11 Mar 2021 21:23:24 +0530 Subject: [PATCH] Add supportedParams method Signed-off-by: Rahul Rudragoudar --- src/main/java/lc/captchas/FontFunCaptcha.java | 11 +++++++++++ src/main/java/lc/captchas/GifCaptcha.java | 12 ++++++++++++ src/main/java/lc/captchas/ShadowTextCaptcha.java | 12 ++++++++++++ .../lc/captchas/interfaces/ChallengeProvider.java | 5 +++++ src/main/scala/lc/captchas/FilterChallenge.scala | 12 ++++++++++++ src/main/scala/lc/captchas/LabelCaptcha.scala | 12 ++++++++++++ src/main/scala/lc/captchas/RainDropsCaptcha.scala | 12 ++++++++++++ 7 files changed, 76 insertions(+) diff --git a/src/main/java/lc/captchas/FontFunCaptcha.java b/src/main/java/lc/captchas/FontFunCaptcha.java index e4379fc..bb1c278 100644 --- a/src/main/java/lc/captchas/FontFunCaptcha.java +++ b/src/main/java/lc/captchas/FontFunCaptcha.java @@ -6,6 +6,8 @@ import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FilenameFilter; +import java.util.HashMap; +import java.util.List; import lc.captchas.interfaces.Challenge; import lc.captchas.interfaces.ChallengeProvider; import lc.misc.HelperFunctions; @@ -16,6 +18,15 @@ public class FontFunCaptcha implements ChallengeProvider { return "FontFunCaptcha"; } + public HashMap> supportedParameters() { + HashMap> supportedParams = new HashMap>(); + supportedParams.put("supportedLevels", List.of("medium")); + supportedParams.put("supportedMedia", List.of("image/png")); + supportedParams.put("supportedInputType", List.of("text")); + + return supportedParams; + } + public void configure(String config) { // TODO: Add custom config } diff --git a/src/main/java/lc/captchas/GifCaptcha.java b/src/main/java/lc/captchas/GifCaptcha.java index 9352167..13cf0fa 100644 --- a/src/main/java/lc/captchas/GifCaptcha.java +++ b/src/main/java/lc/captchas/GifCaptcha.java @@ -6,6 +6,9 @@ import java.awt.RenderingHints; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.IOException; +import java.util.HashMap; +import java.util.List; + import javax.imageio.stream.ImageOutputStream; import javax.imageio.stream.MemoryCacheImageOutputStream; import java.io.ByteArrayOutputStream; @@ -52,6 +55,15 @@ public class GifCaptcha implements ChallengeProvider { // TODO: Add custom config } + public HashMap> supportedParameters() { + HashMap> supportedParams = new HashMap>(); + supportedParams.put("supportedLevels", List.of("hard")); + supportedParams.put("supportedMedia", List.of("image/gif")); + supportedParams.put("supportedInputType", List.of("text")); + + return supportedParams; + } + public Challenge returnChallenge() { String secret = HelperFunctions.randomString(6); return new Challenge(gifCaptcha(secret), "image/gif", secret.toLowerCase()); diff --git a/src/main/java/lc/captchas/ShadowTextCaptcha.java b/src/main/java/lc/captchas/ShadowTextCaptcha.java index 3462df2..5b3b873 100644 --- a/src/main/java/lc/captchas/ShadowTextCaptcha.java +++ b/src/main/java/lc/captchas/ShadowTextCaptcha.java @@ -10,6 +10,9 @@ import java.awt.image.BufferedImage; import java.awt.image.ConvolveOp; import java.awt.image.Kernel; import java.io.ByteArrayOutputStream; +import java.util.HashMap; +import java.util.List; + import lc.misc.HelperFunctions; import lc.captchas.interfaces.Challenge; import lc.captchas.interfaces.ChallengeProvider; @@ -24,6 +27,15 @@ public class ShadowTextCaptcha implements ChallengeProvider { // TODO: Add custom config } + public HashMap> supportedParameters() { + HashMap> supportedParams = new HashMap>(); + supportedParams.put("supportedLevels", List.of("easy")); + supportedParams.put("supportedMedia", List.of("image/png")); + supportedParams.put("supportedInputType", List.of("text")); + + return supportedParams; + } + public boolean checkAnswer(String secret, String answer) { return answer.toLowerCase().equals(secret); } diff --git a/src/main/java/lc/captchas/interfaces/ChallengeProvider.java b/src/main/java/lc/captchas/interfaces/ChallengeProvider.java index 09ad8c0..a3a70e2 100644 --- a/src/main/java/lc/captchas/interfaces/ChallengeProvider.java +++ b/src/main/java/lc/captchas/interfaces/ChallengeProvider.java @@ -1,5 +1,8 @@ package lc.captchas.interfaces; +import java.util.Map; +import java.util.List; + public interface ChallengeProvider { public String getId(); @@ -8,4 +11,6 @@ public interface ChallengeProvider { public boolean checkAnswer(String secret, String answer); public void configure(String config); + + public Map> supportedParameters(); } diff --git a/src/main/scala/lc/captchas/FilterChallenge.scala b/src/main/scala/lc/captchas/FilterChallenge.scala index 80c8d6f..a4508b6 100644 --- a/src/main/scala/lc/captchas/FilterChallenge.scala +++ b/src/main/scala/lc/captchas/FilterChallenge.scala @@ -7,6 +7,8 @@ import java.awt.Font import java.awt.Color import lc.captchas.interfaces.ChallengeProvider import lc.captchas.interfaces.Challenge +import scala.jdk.CollectionConverters.MapHasAsJava +import java.util.{List => JavaList, Map => JavaMap} class FilterChallenge extends ChallengeProvider { def getId = "FilterChallenge" @@ -15,6 +17,16 @@ class FilterChallenge extends ChallengeProvider { // TODO: add custom config } + def supportedParameters(): JavaMap[String, JavaList[String]] = { + val supportedParams = Map( + "supportedLevels" -> JavaList.of("medium", "hard"), + "supportedMedia" -> JavaList.of("image/png"), + "supportedInputType" -> JavaList.of("text") + ).asJava + + supportedParams + } + def returnChallenge(): Challenge = { val filterTypes = List(new FilterType1, new FilterType2) val r = new scala.util.Random diff --git a/src/main/scala/lc/captchas/LabelCaptcha.scala b/src/main/scala/lc/captchas/LabelCaptcha.scala index 9b86568..5233678 100644 --- a/src/main/scala/lc/captchas/LabelCaptcha.scala +++ b/src/main/scala/lc/captchas/LabelCaptcha.scala @@ -9,6 +9,8 @@ import java.awt.image.BufferedImage import java.awt.Color import lc.captchas.interfaces.ChallengeProvider import lc.captchas.interfaces.Challenge +import scala.jdk.CollectionConverters.MapHasAsJava +import java.util.{List => JavaList, Map => JavaMap} class LabelCaptcha extends ChallengeProvider { private var knownFiles = new File("known").list.toList @@ -27,6 +29,16 @@ class LabelCaptcha extends ChallengeProvider { // TODO: add custom config } + def supportedParameters(): JavaMap[String, JavaList[String]] = { + val supportedParams = Map( + "supportedLevels" -> JavaList.of("hard"), + "supportedMedia" -> JavaList.of("image/png"), + "supportedInputType" -> JavaList.of("text") + ).asJava + + supportedParams + } + def returnChallenge(): Challenge = synchronized { val r = scala.util.Random.nextInt(knownFiles.length) diff --git a/src/main/scala/lc/captchas/RainDropsCaptcha.scala b/src/main/scala/lc/captchas/RainDropsCaptcha.scala index 214a525..2788096 100644 --- a/src/main/scala/lc/captchas/RainDropsCaptcha.scala +++ b/src/main/scala/lc/captchas/RainDropsCaptcha.scala @@ -10,6 +10,8 @@ import javax.imageio.stream.MemoryCacheImageOutputStream; import lc.captchas.interfaces.ChallengeProvider import lc.captchas.interfaces.Challenge import lc.misc.GifSequenceWriter +import scala.jdk.CollectionConverters.MapHasAsJava +import java.util.{List => JavaList, Map => JavaMap} class Drop { var x = 0 @@ -35,6 +37,16 @@ class RainDropsCP extends ChallengeProvider { // TODO: add custom config } + def supportedParameters(): JavaMap[String, JavaList[String]] = { + val supportedParams = Map( + "supportedLevels" -> JavaList.of("medium", "easy"), + "supportedMedia" -> JavaList.of("image/gif"), + "supportedInputType" -> JavaList.of("text") + ).asJava + + supportedParams + } + private def extendDrops(drops: Array[Drop], steps: Int, xOffset: Int) = { drops.map(d => { val nd = new Drop()