SEC-368: Tidied up captcha spelling.

This commit is contained in:
Luke Taylor 2007-09-11 11:11:05 +00:00
parent c91400b03b
commit dd2a46c7ca
14 changed files with 34 additions and 43 deletions

View File

@ -29,29 +29,28 @@ public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessor extends CaptchaCh
//~ Static fields/initializers ===================================================================================== //~ Static fields/initializers =====================================================================================
/** Keyword for this channelProcessor */ /** Keyword for this channelProcessor */
public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_ABOVE_THRESOLD_REQUESTS"; public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_ABOVE_THRESHOLD_REQUESTS";
//~ Constructors =================================================================================================== //~ Constructors ===================================================================================================
/** /**
* Constructor * Constructor
*/ */
public AlwaysTestAfterMaxRequestsCaptchaChannelProcessor() { public AlwaysTestAfterMaxRequestsCaptchaChannelProcessor() {
super();
this.setKeyword(DEFAULT_KEYWORD); this.setKeyword(DEFAULT_KEYWORD);
} }
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
/** /**
* Verify wheter the context is valid concerning humanity * Verify whether the context is valid concerning humanity
* *
* @param context * @param context
* *
* @return true if valid, false otherwise * @return true if valid, false otherwise
*/ */
boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) { boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
if (context.getHumanRestrictedResourcesRequestsCount() < getThresold()) { if (context.getHumanRestrictedResourcesRequestsCount() < getThreshold()) {
logger.debug("context is valid : request count < thresold"); logger.debug("context is valid : request count < thresold");
return true; return true;

View File

@ -26,15 +26,15 @@ public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor extends CaptchaC
//~ Static fields/initializers ===================================================================================== //~ Static fields/initializers =====================================================================================
/** Keyword for this channelProcessor */ /** Keyword for this channelProcessor */
public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_AFTER_THRESOLD_IN_MILLIS"; public static final String DEFAULT_KEYWORD = "REQUIRES_CAPTCHA_AFTER_THRESHOLD_IN_MILLIS";
//~ Constructors =================================================================================================== //~ Constructors ===================================================================================================
/** /**
* Constructor * Constructor
*/ */
public AlwaysTestAfterTimeInMillisCaptchaChannelProcessor() { public AlwaysTestAfterTimeInMillisCaptchaChannelProcessor() {
super();
this.setKeyword(DEFAULT_KEYWORD); this.setKeyword(DEFAULT_KEYWORD);
} }
@ -48,7 +48,7 @@ public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor extends CaptchaC
* @return true if valid, false otherwise * @return true if valid, false otherwise
*/ */
boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) { boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
if ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < getThresold()) { if ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < getThreshold()) {
logger.debug("context is valid : last passed captcha date - current time < thresold"); logger.debug("context is valid : last passed captcha date - current time < thresold");
return true; return true;

View File

@ -35,11 +35,10 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor e
//~ Constructors =================================================================================================== //~ Constructors ===================================================================================================
/** /**
* Constructor * Constructor
*/ */
public AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor() { public AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor() {
super();
this.setKeyword(DEFAULT_KEYWORD); this.setKeyword(DEFAULT_KEYWORD);
} }
@ -52,7 +51,7 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor e
*/ */
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet(); super.afterPropertiesSet();
Assert.isTrue(getThresold() > 0, "thresold must be > 0"); Assert.isTrue(getThreshold() > 0, "thresold must be > 0");
} }
/** /**
@ -64,7 +63,7 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor e
*/ */
boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) { boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
int req = context.getHumanRestrictedResourcesRequestsCount(); int req = context.getHumanRestrictedResourcesRequestsCount();
float thresold = getThresold(); float thresold = getThreshold();
float duration = System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis(); float duration = System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis();
float average; float average;

View File

@ -99,7 +99,7 @@ public abstract class CaptchaChannelProcessorTemplate implements ChannelProcesso
redirectToEntryPoint(invocation); redirectToEntryPoint(invocation);
} else { } else {
logger.debug("has been successfully checked this keyword, increment request count"); logger.debug("has been successfully checked this keyword, increment request count");
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedResourcesRequestsCount();
} }
} else { } else {
logger.debug("do not support this attribute"); logger.debug("do not support this attribute");
@ -115,7 +115,7 @@ public abstract class CaptchaChannelProcessorTemplate implements ChannelProcesso
return keyword; return keyword;
} }
public int getThresold() { public int getThreshold() {
return thresold; return thresold;
} }

View File

@ -92,8 +92,6 @@ public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
//~ Instance fields ================================================================================================ //~ Instance fields ================================================================================================
// ~ Instance fields
// ========================================================
private PortMapper portMapper = new PortMapperImpl(); private PortMapper portMapper = new PortMapperImpl();
private PortResolver portResolver = new PortResolverImpl(); private PortResolver portResolver = new PortResolverImpl();
private String captchaFormUrl; private String captchaFormUrl;
@ -208,7 +206,6 @@ public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
} }
/** /**
* DOCUMENT ME!
* *
* @return the captcha test page to redirect to. * @return the captcha test page to redirect to.
*/ */

View File

@ -43,7 +43,7 @@ public interface CaptchaSecurityContext extends SecurityContext {
/** /**
* Method to increment the human Restricted Resrouces Requests Count; * Method to increment the human Restricted Resrouces Requests Count;
*/ */
void incrementHumanRestrictedRessoucesRequestsCount(); void incrementHumanRestrictedResourcesRequestsCount();
/** /**
* DOCUMENT ME! * DOCUMENT ME!

View File

@ -86,7 +86,7 @@ public class CaptchaSecurityContextImpl extends SecurityContextImpl implements C
/** /**
* Method to increment the human Restricted Resrouces Requests Count; * Method to increment the human Restricted Resrouces Requests Count;
*/ */
public void incrementHumanRestrictedRessoucesRequestsCount() { public void incrementHumanRestrictedResourcesRequestsCount() {
humanRestrictedResourcesRequestsCount++; humanRestrictedResourcesRequestsCount++;
} }

View File

@ -31,14 +31,13 @@ public class TestOnceAfterMaxRequestsCaptchaChannelProcessor extends CaptchaChan
//~ Constructors =================================================================================================== //~ Constructors ===================================================================================================
public TestOnceAfterMaxRequestsCaptchaChannelProcessor() { public TestOnceAfterMaxRequestsCaptchaChannelProcessor() {
super();
this.setKeyword(DEFAULT_KEYWORD); this.setKeyword(DEFAULT_KEYWORD);
} }
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) { boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
if (context.isHuman() || (context.getHumanRestrictedResourcesRequestsCount() < getThresold())) { if (context.isHuman() || (context.getHumanRestrictedResourcesRequestsCount() < getThreshold())) {
logger.debug("context is valid concerning humanity or request count < thresold"); logger.debug("context is valid concerning humanity or request count < thresold");
return true; return true;

View File

@ -15,13 +15,10 @@
package org.acegisecurity.captcha; package org.acegisecurity.captcha;
import junit.framework.*; import junit.framework.TestCase;
import org.acegisecurity.captcha.AlwaysTestAfterMaxRequestsCaptchaChannelProcessor;
/** /**
* DOCUMENT ME!
* *
* @author $author$ * @author $author$
* @version $Revision$ * @version $Revision$
@ -45,16 +42,16 @@ public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessorTests extends Test
CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl(); CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedResourcesRequestsCount();
alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(-1); alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(-1);
assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(3); alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(3);
assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedResourcesRequestsCount();
assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedResourcesRequestsCount();
assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
} }

View File

@ -61,7 +61,7 @@ public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessorTests extends Tes
context.setHuman(); context.setHuman();
while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < alwaysTestAfterTimeInMillisCaptchaChannelProcessor while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < alwaysTestAfterTimeInMillisCaptchaChannelProcessor
.getThresold()) { .getThreshold()) {
assertTrue(alwaysTestAfterTimeInMillisCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertTrue(alwaysTestAfterTimeInMillisCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedRessoucesRequestsCount();

View File

@ -74,7 +74,7 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessorTe
context.setHuman(); context.setHuman();
while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < (10 * alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < (10 * alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
.getThresold())) { .getThreshold())) {
assertTrue(alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor assertTrue(alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
.isContextValidConcerningHumanity(context)); .isContextValidConcerningHumanity(context));
} }
@ -98,14 +98,14 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessorTe
int i = 0; int i = 0;
while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < (100 * alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < (100 * alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
.getThresold())) { .getThreshold())) {
System.out.println((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis())); System.out.println((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()));
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedRessoucesRequestsCount();
i++; i++;
while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < (alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < (alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
.getThresold() * i)) {} .getThreshold() * i)) {}
System.out.println((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis())); System.out.println((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()));

View File

@ -122,9 +122,9 @@ public class CaptchaChannelProcessorTemplateTests extends TestCase {
processor.setKeyword("X"); processor.setKeyword("X");
assertEquals("X", processor.getKeyword()); assertEquals("X", processor.getKeyword());
assertEquals(0, processor.getThresold()); assertEquals(0, processor.getThreshold());
processor.setThresold(1); processor.setThresold(1);
assertEquals(1, processor.getThresold()); assertEquals(1, processor.getThreshold());
assertTrue(processor.getEntryPoint() == null); assertTrue(processor.getEntryPoint() == null);
processor.setEntryPoint(new CaptchaEntryPoint()); processor.setEntryPoint(new CaptchaEntryPoint());

View File

@ -48,7 +48,7 @@ public class CaptchaSecurityContextImplTests extends SecurityContextImplTests {
context1 = new CaptchaSecurityContextImpl(); context1 = new CaptchaSecurityContextImpl();
assertEquals(context1, context2); assertEquals(context1, context2);
context1.incrementHumanRestrictedRessoucesRequestsCount(); context1.incrementHumanRestrictedResourcesRequestsCount();
assertNotSame(context1, context2); assertNotSame(context1, context2);
} }
@ -66,7 +66,7 @@ public class CaptchaSecurityContextImplTests extends SecurityContextImplTests {
context1 = new CaptchaSecurityContextImpl(); context1 = new CaptchaSecurityContextImpl();
assertEquals(context1.hashCode(), context2.hashCode()); assertEquals(context1.hashCode(), context2.hashCode());
context1.incrementHumanRestrictedRessoucesRequestsCount(); context1.incrementHumanRestrictedResourcesRequestsCount();
assertTrue(context1 != context2); assertTrue(context1 != context2);
} }
@ -75,7 +75,7 @@ public class CaptchaSecurityContextImplTests extends SecurityContextImplTests {
context.setHuman(); context.setHuman();
assertEquals("should be human", true, context.isHuman()); assertEquals("should be human", true, context.isHuman());
assertEquals("should be 0", 0, context.getHumanRestrictedResourcesRequestsCount()); assertEquals("should be 0", 0, context.getHumanRestrictedResourcesRequestsCount());
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedResourcesRequestsCount();
assertEquals("should be 1", 1, context.getHumanRestrictedResourcesRequestsCount()); assertEquals("should be 1", 1, context.getHumanRestrictedResourcesRequestsCount());
} }
@ -84,7 +84,7 @@ public class CaptchaSecurityContextImplTests extends SecurityContextImplTests {
context.setHuman(); context.setHuman();
assertEquals("should be human", true, context.isHuman()); assertEquals("should be human", true, context.isHuman());
assertEquals("should be 0", 0, context.getHumanRestrictedResourcesRequestsCount()); assertEquals("should be 0", 0, context.getHumanRestrictedResourcesRequestsCount());
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedResourcesRequestsCount();
assertEquals("should be 1", 1, context.getHumanRestrictedResourcesRequestsCount()); assertEquals("should be 1", 1, context.getHumanRestrictedResourcesRequestsCount());
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();

View File

@ -45,20 +45,20 @@ public class TestOnceAfterMaxRequestsCaptchaChannelProcessorTests extends TestCa
CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl(); CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedResourcesRequestsCount();
testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(-1); testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(-1);
assertFalse(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertFalse(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(3); testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(3);
assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedResourcesRequestsCount();
assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
context.incrementHumanRestrictedRessoucesRequestsCount(); context.incrementHumanRestrictedResourcesRequestsCount();
assertFalse(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertFalse(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
context.setHuman(); context.setHuman();
for (int i = 0; i < (2 * testOnceAfterMaxRequestsCaptchaChannelProcessor.getThresold()); i++) { for (int i = 0; i < (2 * testOnceAfterMaxRequestsCaptchaChannelProcessor.getThreshold()); i++) {
assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context)); assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
} }
} }