Author: drobiazko
Date: Sun Jul 24 22:20:12 2011
New Revision: 1150503
URL: http://svn.apache.org/viewvc?rev=1150503&view=rev
Log:
TAP5-1586: Introduce the Kaptcha component
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/ (with props)
tapestry/tapestry5/trunk/tapestry-kaptcha/build.gradle
tapestry/tapestry5/trunk/tapestry-kaptcha/src/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaField.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaImage.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/internal/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/internal/services/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/internal/services/KaptchaProducerImpl.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaModule.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaProducer.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/org/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/org/apache/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/org/apache/tapestry5/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/org/apache/tapestry5/kaptcha/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/org/apache/tapestry5/kaptcha/tapestry-kaptcha.properties
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/conf/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/conf/testng.xml
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/components/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/components/Layout.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/Index.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/KaptchaDemo.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/services/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/services/AppModule.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/apache/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/apache/tapestry5/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/apache/tapestry5/kaptcha/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/apache/tapestry5/kaptcha/integration/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/apache/tapestry5/kaptcha/integration/KaptchaIntegrationTest.java
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/components/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/components/Layout.tml
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/Index.tml
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/KaptchaDemo.tml
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/log4j.properties
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/webapp/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/webapp/WEB-INF/
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/webapp/WEB-INF/web.xml
Modified:
tapestry/tapestry5/trunk/settings.gradle
tapestry/tapestry5/trunk/tapestry5-annotations/ (props changed)
Modified: tapestry/tapestry5/trunk/settings.gradle
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/settings.gradle?rev=1150503&r1=1150502&r2=1150503&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/settings.gradle (original)
+++ tapestry/tapestry5/trunk/settings.gradle Sun Jul 24 22:20:12 2011
@@ -1,6 +1,6 @@
include "plastic", "tapestry5-annotations", "tapestry-test", "tapestry-func",
"tapestry-ioc", "tapestry-json", "tapestry-core"
include "tapestry-hibernate-core", "tapestry-hibernate", "tapestry-jmx",
"tapestry-upload", "tapestry-spring"
-include "tapestry-beanvalidator", "tapestry-yuicompressor", "tapestry-jpa"
+include "tapestry-beanvalidator", "tapestry-yuicompressor", "tapestry-jpa",
"tapestry-kaptcha"
include "tapestry-javadoc"
// TODO (LATER): tapestry-component-report, quickstart
Propchange: tapestry/tapestry5/trunk/tapestry-kaptcha/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Jul 24 22:20:12 2011
@@ -0,0 +1,3 @@
+*.iml
+build
+test-output
Added: tapestry/tapestry5/trunk/tapestry-kaptcha/build.gradle
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/build.gradle?rev=1150503&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-kaptcha/build.gradle (added)
+++ tapestry/tapestry5/trunk/tapestry-kaptcha/build.gradle Sun Jul 24 22:20:12
2011
@@ -0,0 +1,18 @@
+description = "Kaptcha image support"
+
+dependencies {
+ compile project(':tapestry-core')
+ compile "com.google.code.kaptcha:kaptcha:2.3"
+
+ testCompile project(':tapestry-test')
+}
+
+repositories {
+ mavenRepo urls: "http://howardlewisship.com/repository/"
+}
+
+jar {
+ manifest {
+ attributes 'Tapestry-Module-Classes':
'org.apache.tapestry5.kaptcha.services.KaptchaModule'
+ }
+}
\ No newline at end of file
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaField.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaField.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaField.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaField.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,108 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.kaptcha.components;
+
+import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.FieldValidator;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.ValidationTracker;
+import org.apache.tapestry5.annotations.BeginRender;
+import org.apache.tapestry5.annotations.Environmental;
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.SupportsInformalParameters;
+import org.apache.tapestry5.corelib.base.AbstractField;
+import org.apache.tapestry5.internal.TapestryInternalUtils;
+import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.FieldValidatorSource;
+import org.apache.tapestry5.services.Request;
+
+/**
+ * Field paired with a {@link KaptchaImage} to ensure that the user has
provided
+ * the correct value.
+ *
+ * @since 5.3
+ */
+@SupportsInformalParameters
+public class KaptchaField extends AbstractField
+{
+
+ /**
+ * The image output for this field. The image will display a distorted text
+ * string. The user must decode the distorted text and enter the same
value.
+ */
+ @Parameter(required = true, defaultPrefix = BindingConstants.COMPONENT)
+ private KaptchaImage image;
+
+ @Inject
+ private Request request;
+
+ @Inject
+ private Messages messages;
+
+ @Inject
+ private ComponentResources resources;
+
+ @Environmental
+ private ValidationTracker validationTracker;
+
+ @Inject
+ private FieldValidatorSource fieldValidatorSource;
+
+ @Override
+ public boolean isRequired()
+ {
+ return true;
+ }
+
+ @Override
+ protected void processSubmission(String elementName)
+ {
+ String userValue = request.getParameter(elementName);
+
+ if (TapestryInternalUtils.isEqual(image.getCaptchaText(), userValue))
+ return;
+
+ validationTracker.recordError(this,
messages.get("tapestry-incorrect-captcha"));
+ }
+
+ @SuppressWarnings("rawtypes")
+ @BeginRender
+ boolean begin(MarkupWriter writer)
+ {
+
+ writer.element("input",
+
+ "type", "password",
+
+ "id", getClientId(),
+
+ "name", getControlName(),
+
+ "value", "");
+
+ resources.renderInformalParameters(writer);
+
+ FieldValidator fieldValidator = fieldValidatorSource
+ .createValidator(this, "required", null);
+
+ fieldValidator.render(writer);
+
+ writer.end();
+
+ return false;
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaImage.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaImage.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaImage.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/components/KaptchaImage.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,108 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.kaptcha.components;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.imageio.ImageIO;
+
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.Link;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.SupportsInformalParameters;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.Response;
+
+import org.apache.tapestry5.kaptcha.services.KaptchaProducer;
+
+/**
+ * Part of a Captcha based authentication scheme; a KaptchaImage generates a
new
+ * text image whenever it <em>renders</em> and can provide the previously
+ * rendred text subsequently (it is stored persistently in the session).
+ * <p>
+ * The component renders an <img> tag, including width and height
attributes. Other attributes
+ * come from informal parameters.
+ *
+ * @since 5.3
+ */
+@SupportsInformalParameters
+public class KaptchaImage
+{
+
+ @Persist
+ private String captchaText;
+
+ @Inject
+ private KaptchaProducer producer;
+
+ @Inject
+ private ComponentResources resources;
+
+ @Inject
+ private Response response;
+
+ public String getCaptchaText()
+ {
+ return captchaText;
+ }
+
+ void setupRender()
+ {
+ captchaText = producer.createText();
+ }
+
+ boolean beginRender(MarkupWriter writer)
+ {
+ Link link = resources.createEventLink("image");
+
+ writer.element("img",
+
+ "src", link.toURI(),
+
+ "width", producer.getWidth(),
+
+ "height", producer.getHeight());
+
+ resources.renderInformalParameters(writer);
+
+ writer.end();
+
+ return false;
+ }
+
+ void onImage() throws IOException
+ {
+ BufferedImage image = producer.createImage(captchaText);
+
+ response.setDateHeader("Expires", 0);
+ // Set standard HTTP/1.1 no-cache headers.
+ response.setHeader("Cache-Control", "no-store, no-cache,
must-revalidate");
+ // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
+ response.setHeader("Cache-Control", "post-check=0, pre-check=0");
+ // Set standard HTTP/1.0 no-cache header.
+ response.setHeader("Pragma", "no-cache");
+
+ OutputStream stream = response.getOutputStream("image/jpeg");
+
+ ImageIO.write(image, "jpg", stream);
+
+ stream.flush();
+
+ stream.close();
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/internal/services/KaptchaProducerImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/internal/services/KaptchaProducerImpl.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/internal/services/KaptchaProducerImpl.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/internal/services/KaptchaProducerImpl.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,77 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.kaptcha.internal.services;
+
+import com.google.code.kaptcha.impl.DefaultKaptcha;
+import com.google.code.kaptcha.util.Config;
+import org.apache.tapestry5.kaptcha.services.KaptchaProducer;
+
+import java.awt.image.BufferedImage;
+import java.util.Map;
+import java.util.Properties;
+
+public class KaptchaProducerImpl implements KaptchaProducer
+{
+ private final DefaultKaptcha producer;
+
+ private final int height;
+
+ private final int width;
+
+ public KaptchaProducerImpl(Map<String, String> configuration)
+ {
+ producer = new DefaultKaptcha();
+
+ Config config = new Config(toProperties(configuration));
+
+ producer.setConfig(config);
+
+ height = config.getHeight();
+ width = config.getWidth();
+ }
+
+ public int getHeight()
+ {
+ return height;
+ }
+
+ public int getWidth()
+ {
+ return width;
+ }
+
+ public BufferedImage createImage(String text)
+ {
+ return producer.createImage(text);
+ }
+
+ public String createText()
+ {
+ return producer.createText();
+ }
+
+ private static Properties toProperties(Map<String, String> map)
+ {
+ Properties result = new Properties();
+
+ for (String key : map.keySet())
+ {
+ result.put(key, map.get(key));
+ }
+
+ return result;
+
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaModule.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaModule.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaModule.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,54 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.kaptcha.services;
+
+import org.apache.tapestry5.ioc.Configuration;
+import org.apache.tapestry5.ioc.OrderedConfiguration;
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.ioc.ServiceBinder;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+import org.apache.tapestry5.ioc.annotations.Value;
+import org.apache.tapestry5.kaptcha.internal.services.KaptchaProducerImpl;
+import org.apache.tapestry5.services.ComponentClassResolver;
+import org.apache.tapestry5.services.LibraryMapping;
+import org.apache.tapestry5.services.messages.ComponentMessagesSource;
+
+/**
+ * Defines core services for Kaptcha support.
+ *
+ * @since 5.3
+ */
+public class KaptchaModule
+{
+ public static void bind(ServiceBinder binder)
+ {
+ binder.bind(KaptchaProducer.class, KaptchaProducerImpl.class);
+ }
+
+ @Contribute(ComponentClassResolver.class)
+ public static void provideLibraryMapping(Configuration<LibraryMapping>
configuration)
+ {
+ configuration.add(new LibraryMapping("core",
"org.apache.tapestry5.kaptcha"));
+ }
+
+ @Contribute(ComponentMessagesSource.class)
+ public static void provideLibrayMessages(
+ OrderedConfiguration<Resource> configuration,
+
@Value("classpath:org/apache/tapestry5/kaptcha/tapestry-kaptcha.properties")
+ Resource coreCatalog)
+ {
+ configuration.add("TapestryKaptcha", coreCatalog, "before:AppCatalog");
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaProducer.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaProducer.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaProducer.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/java/org/apache/tapestry5/kaptcha/services/KaptchaProducer.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,30 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.kaptcha.services;
+
+import com.google.code.kaptcha.Producer;
+
+/**
+ * Extension of the {@link Producer} interface, adding property for getting
the Kaptcha image
+ * width and height (used when rendering the <img> element).
+ *
+ * @since 5.3
+ */
+public interface KaptchaProducer extends Producer
+{
+ int getWidth();
+
+ int getHeight();
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/org/apache/tapestry5/kaptcha/tapestry-kaptcha.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/org/apache/tapestry5/kaptcha/tapestry-kaptcha.properties?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/org/apache/tapestry5/kaptcha/tapestry-kaptcha.properties
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/main/resources/org/apache/tapestry5/kaptcha/tapestry-kaptcha.properties
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,17 @@
+#
+# // Copyright 2011 The Apache Software Foundation
+# //
+# // Licensed under the Apache License, Version 2.0 (the "License");
+# // you may not use this file except in compliance with the License.
+# // You may obtain a copy of the License at
+# //
+# // http://www.apache.org/licenses/LICENSE-2.0
+# //
+# // Unless required by applicable law or agreed to in writing, software
+# // distributed under the License is distributed on an "AS IS" BASIS,
+# // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# // See the License for the specific language governing permissions and
+# // limitations under the License.
+#
+
+tapestry-incorrect-captcha=Enter the text displayed in the image.
\ No newline at end of file
Added: tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/conf/testng.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/conf/testng.xml?rev=1150503&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/conf/testng.xml (added)
+++ tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/conf/testng.xml Sun Jul
24 22:20:12 2011
@@ -0,0 +1,9 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
+<suite name="tapestry-kaptcha">
+ <test name="Integration Tests">
+ <parameter name="tapestry.web-app-folder" value="src/test/webapp"/>
+ <packages>
+ <package name="org.apache.tapestry5.kaptcha.integration"/>
+ </packages>
+ </test>
+</suite>
\ No newline at end of file
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/components/Layout.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/components/Layout.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/components/Layout.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/components/Layout.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,20 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package kaptcha.demo.components;
+
+public class Layout
+{
+
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/Index.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/Index.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/Index.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/Index.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,20 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package kaptcha.demo.pages;
+
+public class Index
+{
+
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/KaptchaDemo.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/KaptchaDemo.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/KaptchaDemo.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/pages/KaptchaDemo.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,30 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package kaptcha.demo.pages;
+
+import org.apache.tapestry5.PersistenceConstants;
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+
+public class KaptchaDemo
+{
+ @Property
+ @Persist(PersistenceConstants.FLASH)
+ private String message;
+
+ void onSuccessFromForm()
+ {
+ message = "Kaptcha passed.";
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/services/AppModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/services/AppModule.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/services/AppModule.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/kaptcha/demo/services/AppModule.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,75 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package kaptcha.demo.services;
+
+import com.google.code.kaptcha.Constants;
+import org.apache.tapestry5.SymbolConstants;
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+import org.apache.tapestry5.ioc.annotations.SubModule;
+import org.apache.tapestry5.ioc.services.ApplicationDefaults;
+import org.apache.tapestry5.ioc.services.SymbolProvider;
+import org.apache.tapestry5.kaptcha.services.KaptchaModule;
+import org.apache.tapestry5.kaptcha.services.KaptchaProducer;
+import org.slf4j.Logger;
+
+import java.awt.image.BufferedImage;
+
+@SubModule(KaptchaModule.class)
+public class AppModule
+{
+ @Contribute(SymbolProvider.class)
+ @ApplicationDefaults
+ public static void provideApplicationDefaults(
+ MappedConfiguration<String, String> configuration)
+ {
+ configuration.add(SymbolConstants.PRODUCTION_MODE, "false");
+ }
+
+ public static Object decorateKaptchaProducer(final KaptchaProducer
producer, final Logger logger)
+ {
+ return new KaptchaProducer()
+ {
+
+ public int getWidth()
+ {
+ return producer.getWidth();
+ }
+
+ public int getHeight()
+ {
+ return producer.getHeight();
+ }
+
+ public BufferedImage createImage(String text)
+ {
+ return producer.createImage(text);
+ }
+
+ public String createText()
+ {
+ logger.info(String.format("Kaptcha text: '%s'",
producer.createText()));
+
+ return "i8cookies";
+ }
+ };
+ }
+
+ @Contribute(KaptchaProducer.class)
+ public static void configureKaptchaProducer(MappedConfiguration<String,
String> configuration)
+ {
+ configuration.add(Constants.KAPTCHA_IMAGE_WIDTH, "210");
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/apache/tapestry5/kaptcha/integration/KaptchaIntegrationTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/apache/tapestry5/kaptcha/integration/KaptchaIntegrationTest.java?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/apache/tapestry5/kaptcha/integration/KaptchaIntegrationTest.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/java/org/apache/tapestry5/kaptcha/integration/KaptchaIntegrationTest.java
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,41 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.kaptcha.integration;
+
+import org.apache.tapestry5.test.SeleniumTestCase;
+import org.testng.annotations.Test;
+
+public class KaptchaIntegrationTest extends SeleniumTestCase
+{
+
+ @Test
+ public void kaptcha()
+ {
+ open("/KaptchaDemo");
+
+ type("kf", "invalid input");
+
+ clickAndWait(SUBMIT);
+
+ assertTextPresent("Enter the text displayed in the image.");
+
+ type("kf", "i8cookies");
+
+ clickAndWait(SUBMIT);
+
+ assertTextPresent("Kaptcha passed.");
+
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/components/Layout.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/components/Layout.tml?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/components/Layout.tml
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/components/Layout.tml
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,23 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter">
+ <head>
+ <title>${componentResources.pageName}</title>
+ </head>
+
+ <body>
+ <h1>${componentResources.pageName}</h1>
+
+ <t:body/>
+
+ <hr/>
+
+ <p>
+ [
+ <t:pagelink page="index">index</t:pagelink>
+ ] |
+ [
+ <t:pagelink page="${componentResources.pageName}">refresh</t:pagelink>
+ ]
+ </p>
+
+ </body>
+</html>
\ No newline at end of file
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/Index.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/Index.tml?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/Index.tml
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/Index.tml
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,12 @@
+<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
+
+
+ <h1>tapestry-kaptcha Demos</h1>
+
+ <ul>
+ <li>
+ <t:pagelink page="kaptchaDemo">Kaptcha Demo</t:pagelink>
+ </li>
+ </ul>
+
+</t:layout>
\ No newline at end of file
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/KaptchaDemo.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/KaptchaDemo.tml?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/KaptchaDemo.tml
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/kaptcha/demo/pages/KaptchaDemo.tml
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,29 @@
+<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:tx="tapestry-library:tapx">
+
+ <p id="message">${message}</p>
+
+ <t:form t:id="form">
+ <t:errors/>
+
+ <table>
+ <tr>
+ <td>
+ <t:label for="kf"/>
+ </td>
+ <td>
+ <t:kaptchaimage t:id="ki"/>
+ <br/>
+ <t:kaptchafield label="Security Check" t:id="kf" image="ki"/>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ </td>
+ <td>
+ <input type="submit" value="Go"/>
+ </td>
+ </tr>
+ </table>
+ </t:form>
+
+</t:layout>
\ No newline at end of file
Added:
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/log4j.properties
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/log4j.properties?rev=1150503&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/log4j.properties
(added)
+++
tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/resources/log4j.properties
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,22 @@
+# Copyright 2011 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+log4j.rootCategory=INFO, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=[%p] %c{1} %m%n
Added: tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/webapp/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/webapp/WEB-INF/web.xml?rev=1150503&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/webapp/WEB-INF/web.xml
(added)
+++ tapestry/tapestry5/trunk/tapestry-kaptcha/src/test/webapp/WEB-INF/web.xml
Sun Jul 24 22:20:12 2011
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+ <display-name>tapestry-kaptcha Test App</display-name>
+ <context-param>
+ <param-name>tapestry.app-package</param-name>
+ <param-value>kaptcha.demo</param-value>
+ </context-param>
+ <filter>
+ <filter-name>app</filter-name>
+ <filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>app</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+</web-app>
Propchange: tapestry/tapestry5/trunk/tapestry5-annotations/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Jul 24 22:20:12 2011
@@ -0,0 +1,2 @@
+*.iml
+build