Add supportedParams method

Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
Rahul Rudragoudar 2021-03-11 21:23:24 +05:30
parent a30a977572
commit 2c0f3deb8a
No known key found for this signature in database
GPG Key ID: 0D2CE231A7287EBC
7 changed files with 76 additions and 0 deletions

View File

@ -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<String, List<String>> supportedParameters() {
HashMap<String, List<String>> supportedParams = new HashMap<String, List<String>>();
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
}

View File

@ -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<String, List<String>> supportedParameters() {
HashMap<String, List<String>> supportedParams = new HashMap<String, List<String>>();
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());

View File

@ -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<String, List<String>> supportedParameters() {
HashMap<String, List<String>> supportedParams = new HashMap<String, List<String>>();
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);
}

View File

@ -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<String, List<String>> supportedParameters();
}

View File

@ -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

View File

@ -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)

View File

@ -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()