Author: woonsan
Date: Fri Nov 13 14:55:13 2009
New Revision: 835867
URL: http://svn.apache.org/viewvc?rev=835867&view=rev
Log:
JS2-979: Code clean ups to avoid compilation error in ecliipse IDE by using
reflection
Added:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/JPEGImgDecoder.java
(with props)
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/DefaultJPEGImgDecoder.java
(with props)
portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/
portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/mfa/
portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/mfa/TestCaptchaImageResource.java
(with props)
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/Jetspeed_white_sm-1.jpg
(with props)
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/mfa.properties
(with props)
Modified:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaBeanImpl.java
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaImageResource.java
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/TTSConfiguration.java
Added:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/JPEGImgDecoder.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/JPEGImgDecoder.java?rev=835867&view=auto
==============================================================================
---
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/JPEGImgDecoder.java
(added)
+++
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/JPEGImgDecoder.java
Fri Nov 13 14:55:13 2009
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.security.mfa;
+
+import java.awt.image.BufferedImage;
+import java.io.InputStream;
+
+/**
+ * JPEG Image Decoder interface
+ *
+ * @version $Id$
+ */
+public interface JPEGImgDecoder
+{
+
+ public BufferedImage decodeAsBufferedImage(InputStream input) throws
Exception;
+
+}
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/JPEGImgDecoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/JPEGImgDecoder.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/JPEGImgDecoder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaBeanImpl.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaBeanImpl.java?rev=835867&r1=835866&r2=835867&view=diff
==============================================================================
---
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaBeanImpl.java
(original)
+++
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaBeanImpl.java
Fri Nov 13 14:55:13 2009
@@ -20,7 +20,7 @@
/**
* @author <a href="mailto:[email protected]">David Sean Taylor</a>
- * @version $Id: $
+ * @version $Id$
*/
public class CaptchaBeanImpl implements CaptchaBean
{
Modified:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaImageResource.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaImageResource.java?rev=835867&r1=835866&r2=835867&view=diff
==============================================================================
---
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaImageResource.java
(original)
+++
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/CaptchaImageResource.java
Fri Nov 13 14:55:13 2009
@@ -49,18 +49,16 @@
import javax.imageio.ImageWriter;
import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.jetspeed.security.mfa.JPEGImgDecoder;
import org.apache.jetspeed.security.mfa.MFA;
import org.apache.jetspeed.security.mfa.MultiFacetedAuthentication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.sun.image.codec.jpeg.JPEGCodec;
-import com.sun.image.codec.jpeg.JPEGImageDecoder;
-
/**
* TODO: try to find a javax.imageio equivalent and not use Sun classes
* @author <a href="mailto:[email protected]">David Sean Taylor</a>
- * @version $Id: $
+ * @version $Id$
*/
public final class CaptchaImageResource
{
@@ -181,10 +179,10 @@
if (config.isUseImageBackground() && background != null)
{
ByteArrayInputStream is = new ByteArrayInputStream(background);
- JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(is);
+ JPEGImgDecoder decoder = new DefaultJPEGImgDecoder();
try
{
- this.image = decoder.decodeAsBufferedImage();
+ this.image = decoder.decodeAsBufferedImage(is);
this.width = image.getWidth();
this.height = image.getHeight();
emptyBackground = false;
Added:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/DefaultJPEGImgDecoder.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/DefaultJPEGImgDecoder.java?rev=835867&view=auto
==============================================================================
---
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/DefaultJPEGImgDecoder.java
(added)
+++
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/DefaultJPEGImgDecoder.java
Fri Nov 13 14:55:13 2009
@@ -0,0 +1,19 @@
+package org.apache.jetspeed.security.mfa.impl;
+
+import java.awt.image.BufferedImage;
+import java.io.InputStream;
+
+import org.apache.commons.beanutils.MethodUtils;
+import org.apache.jetspeed.security.mfa.JPEGImgDecoder;
+
+public class DefaultJPEGImgDecoder implements JPEGImgDecoder
+{
+
+ public BufferedImage decodeAsBufferedImage(InputStream input) throws
Exception
+ {
+ Class codecClazz = Class.forName("com.sun.image.codec.jpeg.JPEGCodec");
+ Object decoder = MethodUtils.invokeStaticMethod(codecClazz,
"createJPEGDecoder", input);
+ return (BufferedImage) MethodUtils.invokeMethod(decoder,
"decodeAsBufferedImage", null);
+ }
+
+}
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/DefaultJPEGImgDecoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/DefaultJPEGImgDecoder.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/DefaultJPEGImgDecoder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/TTSConfiguration.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/TTSConfiguration.java?rev=835867&r1=835866&r2=835867&view=diff
==============================================================================
---
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/TTSConfiguration.java
(original)
+++
portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/security/mfa/impl/TTSConfiguration.java
Fri Nov 13 14:55:13 2009
@@ -20,7 +20,7 @@
/**
* @author <a href="mailto:[email protected]">David Sean Taylor</a>
- * @version $Id: $
+ * @version $Id$
*/
public final class TTSConfiguration
{
Added:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/mfa/TestCaptchaImageResource.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/mfa/TestCaptchaImageResource.java?rev=835867&view=auto
==============================================================================
---
portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/mfa/TestCaptchaImageResource.java
(added)
+++
portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/mfa/TestCaptchaImageResource.java
Fri Nov 13 14:55:13 2009
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jetspeed.security.mfa;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.jetspeed.security.mfa.impl.CaptchaConfiguration;
+import org.apache.jetspeed.security.mfa.impl.CaptchaImageResource;
+import org.apache.wicket.util.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestCaptchaImageResource extends TestCase
+{
+
+ private static Logger log =
LoggerFactory.getLogger(TestCaptchaImageResource.class);
+
+ private CaptchaConfiguration captchaConfig;
+ private byte [] background;
+ private File tempCaptchaFile;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ PropertiesConfiguration config = new PropertiesConfiguration();
+
+ InputStream input = null;
+
+ try
+ {
+ input =
Thread.currentThread().getContextClassLoader().getResourceAsStream("mfa.properties");
+ config.load(input);
+ }
+ finally
+ {
+ IOUtils.closeQuietly(input);
+ }
+
+ captchaConfig = new CaptchaConfiguration(config);
+ captchaConfig.setUseImageBackground(true);
+
+ ByteArrayOutputStream output = null;
+
+ try
+ {
+ input =
Thread.currentThread().getContextClassLoader().getResourceAsStream("Jetspeed_white_sm-1.jpg");
+ output = new ByteArrayOutputStream();
+ IOUtils.copy(input, output);
+ background = output.toByteArray();
+ }
+ finally
+ {
+ IOUtils.closeQuietly(output);
+ IOUtils.closeQuietly(input);
+ }
+
+ tempCaptchaFile = File.createTempFile("captcha-", ".jpg");
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ if (tempCaptchaFile != null)
+ {
+ tempCaptchaFile.delete();
+ }
+ }
+
+ public void testCaptchaImageData() throws Exception
+ {
+ CaptchaImageResource cir = new CaptchaImageResource(captchaConfig);
+ cir.setBackgroundImage(background);
+ cir.init();
+
+ OutputStream output = null;
+
+
+ try
+ {
+ output = new FileOutputStream(tempCaptchaFile);
+ IOUtils.write(cir.getImageBytes(), output);
+ }
+ finally
+ {
+ IOUtils.closeQuietly(output);
+ }
+
+ assertTrue(tempCaptchaFile.length() > 0);
+ }
+
+}
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/mfa/TestCaptchaImageResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/mfa/TestCaptchaImageResource.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/java/org/apache/jetspeed/security/mfa/TestCaptchaImageResource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/Jetspeed_white_sm-1.jpg
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/Jetspeed_white_sm-1.jpg?rev=835867&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/Jetspeed_white_sm-1.jpg
------------------------------------------------------------------------------
svn:mime-type = image/jpeg
Added:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/mfa.properties
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/mfa.properties?rev=835867&view=auto
==============================================================================
---
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/mfa.properties
(added)
+++
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/mfa.properties
Fri Nov 13 14:55:13 2009
@@ -0,0 +1,43 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+# captcha properties
+captcha.directory = /captchas
+captcha.effects.noise = false
+captcha.image.background = images/jetspeedlogo98.jpg
+captcha.image.background.use = true
+catcha.image.format = .jpg
+captcha.font.antialiasing = true
+captcha.font.size = 36
+captcha.font.size.random = false
+captcha.font.style = 0
+captcha.font.names = Times
+captcha.scanrate.seconds = 300
+captcha.timetolive.seconds = 120
+captcha.text.maxlength = 8
+captcha.text.margin.left = 2
+captcha.text.margin.bottom = 10
+captcha.text.minlength = 6
+captcha.text.rise.range = 30
+# vertical alignment variance (35)
+captcha.text.rotation = 10
+# shearing 0.2 - 0.9
+captcha.text.shear = 0
+captcha.text.spacing = 2
+captcha.timestamp = true
+captcha.timestamp.24hr = true
+captcha.timestamp.tz = America/New_York
+captcha.timestamp.font.size = 8
+
+
\ No newline at end of file
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/mfa.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/mfa.properties
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/applications/j2-admin/trunk/src/test/resources/mfa.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]