import mir.session.Request;
import mir.session.Session;
import mir.session.SessionHandler;
-import mircoders.abuse.FilterType;
-import mircoders.abuse.ThrottleFilter;
-import mircoders.abuse.IPFilterType;
-import mircoders.abuse.RegularExpressionFilterType;
+import mircoders.abuse.*;
import mircoders.entity.EntityComment;
import mircoders.entity.EntityContent;
import mircoders.global.MirGlobal;
import mircoders.localizer.MirOpenPostingLocalizer;
import java.util.*;
+import java.awt.image.BufferedImage;
+
+import com.octo.captcha.service.image.DefaultManageableImageCaptchaService;
+import com.octo.captcha.service.image.ImageCaptchaService;
public class MirBasicOpenPostingLocalizer implements MirOpenPostingLocalizer {
private List afterContentProducerTasks;
private Map filterTypesMap;
protected LoggerWrapper logger;
protected MirPropertiesConfiguration configuration;
+ private static ImageCaptchaService captchaService = new DefaultManageableImageCaptchaService();
- public MirBasicOpenPostingLocalizer() throws MirLocalizerExc, MirLocalizerFailure {
+ public MirBasicOpenPostingLocalizer() throws MirLocalizerFailure {
logger = new LoggerWrapper("Localizer.Basic.OpenPosting");
try {
filterTypesMap = new HashMap();
addSimpleAntiAbuseFilterType(new RegularExpressionFilterType("regexp"));
- addSimpleAntiAbuseFilterType(new RegularExpressionFilterType("useragent", false, false,
- RegularExpressionFilterType.REQUEST_HEADERS, new String[] {"User-Agent"}));
+ addSimpleAntiAbuseFilterType(new SubStringFilterType("useragent", false, false,
+ SubStringFilterType.REQUEST_HEADERS, new String[] {"User-Agent"}));
addSimpleAntiAbuseFilterType(new IPFilterType("ip"));
addSimpleAntiAbuseFilterType(new RegularExpressionFilterType("hostname", false, false,
RegularExpressionFilterType.REQUEST_HEADERS, new String[] {"hostname"}));
- addSimpleAntiAbuseFilterType(new ThrottleFilter("throttle", 60*60*1000));
+ addSimpleAntiAbuseFilterType(new ThrottleFilter("throttle"));
+ addSimpleAntiAbuseFilterType(new PostingSizeFilterType("size"));
+ addSimpleAntiAbuseFilterType(new URLBlacklistFilterType("urlblacklist",
+ Arrays.asList(MirGlobal.config().getStringArray("Mir.URLBlacklistFilter.WhiteList"))));
}
public SessionHandler getOpenSessionHandler(String aSessionType) throws MirLocalizerExc, MirLocalizerFailure {
}
}
- public void afterContentPosting(EntityContent aContent) {
+ public void afterArticlePosting() {
afterContentPosting();
}
+ public void afterArticlePosting(EntityContent anArticle) {
+ afterContentPosting(anArticle);
+ }
+
+ public void afterContentPosting(EntityContent anArticle) {
+ afterArticlePosting();
+ }
+
public void afterCommentPosting(EntityComment aComment) {
afterCommentPosting();
}
}
}
- public String generateOnetimePassword() {
- Random r = new Random();
- int random = r.nextInt();
-
- long l = System.currentTimeMillis();
-
- l = (l*l*l*l)/random;
- if (l<0)
- l = l * -1;
-
- String returnString = ""+l;
-
- return returnString.substring(5);
+ public List getAntiAbuseFilterTypes() {
+ return Collections.unmodifiableList(filterTypes);
}
- public List getAntiAbuseFilterTypes() {
- return filterTypes;
+ public boolean allowArticlePublication(EntityContent anArticle){
+ return anArticle != null && "1".equals(anArticle.getFieldValue("is_published"));
}
public void removeSimpleAntiAbuseFilterType(String aName) {
filterTypesMap.put(aFilterType.getName(), aFilterType);
filterTypes.add(aFilterType);
}
-}
+
+ public Captcha generateCaptcha(final String aSessionId) {
+ final BufferedImage challenge = captchaService.getImageChallengeForID(aSessionId);
+
+ return new Captcha() {
+
+ public BufferedImage getChallenge() {
+ return challenge;
+ }
+
+ public boolean validateAnswer(String anAnswer) {
+ return captchaService.validateResponseForID(aSessionId, anAnswer).booleanValue();
+ }
+ };
+ }
+
+}
\ No newline at end of file