mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-27 14:22:47 +00:00
SEC-368: Tidied up captcha spelling.
This commit is contained in:
parent
c91400b03b
commit
dd2a46c7ca
@ -29,29 +29,28 @@ public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessor extends CaptchaCh
|
||||
//~ Static fields/initializers =====================================================================================
|
||||
|
||||
/** 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 ===================================================================================================
|
||||
|
||||
/**
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public AlwaysTestAfterMaxRequestsCaptchaChannelProcessor() {
|
||||
super();
|
||||
this.setKeyword(DEFAULT_KEYWORD);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
/**
|
||||
* Verify wheter the context is valid concerning humanity
|
||||
* Verify whether the context is valid concerning humanity
|
||||
*
|
||||
* @param context
|
||||
*
|
||||
* @return true if valid, false otherwise
|
||||
*/
|
||||
boolean isContextValidConcerningHumanity(CaptchaSecurityContext context) {
|
||||
if (context.getHumanRestrictedResourcesRequestsCount() < getThresold()) {
|
||||
if (context.getHumanRestrictedResourcesRequestsCount() < getThreshold()) {
|
||||
logger.debug("context is valid : request count < thresold");
|
||||
|
||||
return true;
|
||||
|
@ -26,15 +26,15 @@ public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor extends CaptchaC
|
||||
//~ Static fields/initializers =====================================================================================
|
||||
|
||||
/** 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 ===================================================================================================
|
||||
|
||||
/**
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public AlwaysTestAfterTimeInMillisCaptchaChannelProcessor() {
|
||||
super();
|
||||
|
||||
this.setKeyword(DEFAULT_KEYWORD);
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessor extends CaptchaC
|
||||
* @return true if valid, false otherwise
|
||||
*/
|
||||
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");
|
||||
|
||||
return true;
|
||||
|
@ -35,11 +35,10 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor e
|
||||
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
/**
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor() {
|
||||
super();
|
||||
this.setKeyword(DEFAULT_KEYWORD);
|
||||
}
|
||||
|
||||
@ -52,7 +51,7 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor e
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
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) {
|
||||
int req = context.getHumanRestrictedResourcesRequestsCount();
|
||||
float thresold = getThresold();
|
||||
float thresold = getThreshold();
|
||||
float duration = System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis();
|
||||
float average;
|
||||
|
||||
|
@ -99,7 +99,7 @@ public abstract class CaptchaChannelProcessorTemplate implements ChannelProcesso
|
||||
redirectToEntryPoint(invocation);
|
||||
} else {
|
||||
logger.debug("has been successfully checked this keyword, increment request count");
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context.incrementHumanRestrictedResourcesRequestsCount();
|
||||
}
|
||||
} else {
|
||||
logger.debug("do not support this attribute");
|
||||
@ -115,7 +115,7 @@ public abstract class CaptchaChannelProcessorTemplate implements ChannelProcesso
|
||||
return keyword;
|
||||
}
|
||||
|
||||
public int getThresold() {
|
||||
public int getThreshold() {
|
||||
return thresold;
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,6 @@ public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
|
||||
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
// ~ Instance fields
|
||||
// ========================================================
|
||||
private PortMapper portMapper = new PortMapperImpl();
|
||||
private PortResolver portResolver = new PortResolverImpl();
|
||||
private String captchaFormUrl;
|
||||
@ -208,7 +206,6 @@ public class CaptchaEntryPoint implements ChannelEntryPoint, InitializingBean {
|
||||
}
|
||||
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
*
|
||||
* @return the captcha test page to redirect to.
|
||||
*/
|
||||
|
@ -43,7 +43,7 @@ public interface CaptchaSecurityContext extends SecurityContext {
|
||||
/**
|
||||
* Method to increment the human Restricted Resrouces Requests Count;
|
||||
*/
|
||||
void incrementHumanRestrictedRessoucesRequestsCount();
|
||||
void incrementHumanRestrictedResourcesRequestsCount();
|
||||
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
|
@ -86,7 +86,7 @@ public class CaptchaSecurityContextImpl extends SecurityContextImpl implements C
|
||||
/**
|
||||
* Method to increment the human Restricted Resrouces Requests Count;
|
||||
*/
|
||||
public void incrementHumanRestrictedRessoucesRequestsCount() {
|
||||
public void incrementHumanRestrictedResourcesRequestsCount() {
|
||||
humanRestrictedResourcesRequestsCount++;
|
||||
}
|
||||
|
||||
|
@ -31,14 +31,13 @@ public class TestOnceAfterMaxRequestsCaptchaChannelProcessor extends CaptchaChan
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public TestOnceAfterMaxRequestsCaptchaChannelProcessor() {
|
||||
super();
|
||||
this.setKeyword(DEFAULT_KEYWORD);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
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");
|
||||
|
||||
return true;
|
||||
|
@ -15,13 +15,10 @@
|
||||
|
||||
package org.acegisecurity.captcha;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import org.acegisecurity.captcha.AlwaysTestAfterMaxRequestsCaptchaChannelProcessor;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
*
|
||||
* @author $author$
|
||||
* @version $Revision$
|
||||
@ -45,16 +42,16 @@ public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessorTests extends Test
|
||||
CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
|
||||
assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context.incrementHumanRestrictedResourcesRequestsCount();
|
||||
|
||||
alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(-1);
|
||||
assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
|
||||
alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(3);
|
||||
assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context.incrementHumanRestrictedResourcesRequestsCount();
|
||||
assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context.incrementHumanRestrictedResourcesRequestsCount();
|
||||
assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class AlwaysTestAfterTimeInMillisCaptchaChannelProcessorTests extends Tes
|
||||
context.setHuman();
|
||||
|
||||
while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < alwaysTestAfterTimeInMillisCaptchaChannelProcessor
|
||||
.getThresold()) {
|
||||
.getThreshold()) {
|
||||
assertTrue(alwaysTestAfterTimeInMillisCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
|
||||
|
@ -74,7 +74,7 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessorTe
|
||||
context.setHuman();
|
||||
|
||||
while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < (10 * alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
|
||||
.getThresold())) {
|
||||
.getThreshold())) {
|
||||
assertTrue(alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
|
||||
.isContextValidConcerningHumanity(context));
|
||||
}
|
||||
@ -98,14 +98,14 @@ public class AlwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessorTe
|
||||
int i = 0;
|
||||
|
||||
while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < (100 * alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
|
||||
.getThresold())) {
|
||||
.getThreshold())) {
|
||||
System.out.println((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()));
|
||||
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
i++;
|
||||
|
||||
while ((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()) < (alwaysTestBelowAverageTimeInMillisBetweenRequestsChannelProcessor
|
||||
.getThresold() * i)) {}
|
||||
.getThreshold() * i)) {}
|
||||
|
||||
System.out.println((System.currentTimeMillis() - context.getLastPassedCaptchaDateInMillis()));
|
||||
|
||||
|
@ -122,9 +122,9 @@ public class CaptchaChannelProcessorTemplateTests extends TestCase {
|
||||
processor.setKeyword("X");
|
||||
assertEquals("X", processor.getKeyword());
|
||||
|
||||
assertEquals(0, processor.getThresold());
|
||||
assertEquals(0, processor.getThreshold());
|
||||
processor.setThresold(1);
|
||||
assertEquals(1, processor.getThresold());
|
||||
assertEquals(1, processor.getThreshold());
|
||||
|
||||
assertTrue(processor.getEntryPoint() == null);
|
||||
processor.setEntryPoint(new CaptchaEntryPoint());
|
||||
|
@ -48,7 +48,7 @@ public class CaptchaSecurityContextImplTests extends SecurityContextImplTests {
|
||||
context1 = new CaptchaSecurityContextImpl();
|
||||
assertEquals(context1, context2);
|
||||
|
||||
context1.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context1.incrementHumanRestrictedResourcesRequestsCount();
|
||||
assertNotSame(context1, context2);
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class CaptchaSecurityContextImplTests extends SecurityContextImplTests {
|
||||
context1 = new CaptchaSecurityContextImpl();
|
||||
assertEquals(context1.hashCode(), context2.hashCode());
|
||||
|
||||
context1.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context1.incrementHumanRestrictedResourcesRequestsCount();
|
||||
assertTrue(context1 != context2);
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ public class CaptchaSecurityContextImplTests extends SecurityContextImplTests {
|
||||
context.setHuman();
|
||||
assertEquals("should be human", true, context.isHuman());
|
||||
assertEquals("should be 0", 0, context.getHumanRestrictedResourcesRequestsCount());
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context.incrementHumanRestrictedResourcesRequestsCount();
|
||||
assertEquals("should be 1", 1, context.getHumanRestrictedResourcesRequestsCount());
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ public class CaptchaSecurityContextImplTests extends SecurityContextImplTests {
|
||||
context.setHuman();
|
||||
assertEquals("should be human", true, context.isHuman());
|
||||
assertEquals("should be 0", 0, context.getHumanRestrictedResourcesRequestsCount());
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context.incrementHumanRestrictedResourcesRequestsCount();
|
||||
assertEquals("should be 1", 1, context.getHumanRestrictedResourcesRequestsCount());
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
@ -45,20 +45,20 @@ public class TestOnceAfterMaxRequestsCaptchaChannelProcessorTests extends TestCa
|
||||
CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
|
||||
assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context.incrementHumanRestrictedResourcesRequestsCount();
|
||||
|
||||
testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(-1);
|
||||
assertFalse(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
|
||||
testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(3);
|
||||
assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context.incrementHumanRestrictedResourcesRequestsCount();
|
||||
assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
context.incrementHumanRestrictedRessoucesRequestsCount();
|
||||
context.incrementHumanRestrictedResourcesRequestsCount();
|
||||
assertFalse(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
context.setHuman();
|
||||
|
||||
for (int i = 0; i < (2 * testOnceAfterMaxRequestsCaptchaChannelProcessor.getThresold()); i++) {
|
||||
for (int i = 0; i < (2 * testOnceAfterMaxRequestsCaptchaChannelProcessor.getThreshold()); i++) {
|
||||
assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor.isContextValidConcerningHumanity(context));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user