Revision: 818
http://stripes.svn.sourceforge.net/stripes/?rev=818&view=rev
Author: bengunter
Date: 2008-01-30 20:41:17 -0800 (Wed, 30 Jan 2008)
Log Message:
-----------
More for STS-452. ActionBean property encryption was initially implemented
using new EncryptedValue and EncryptedValueFormatter classes, but they turned
out to be not very useful so I have removed them and am calling
CryptoUtil.encrypt(...) directly instead.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
trunk/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
trunk/stripes/src/net/sourceforge/stripes/util/UrlBuilder.java
Removed Paths:
-------------
trunk/stripes/src/net/sourceforge/stripes/format/EncryptedValueFormatter.java
trunk/stripes/src/net/sourceforge/stripes/tag/EncryptedValue.java
Modified:
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
2008-01-30 16:30:58 UTC (rev 817)
+++
trunk/stripes/src/net/sourceforge/stripes/format/DefaultFormatterFactory.java
2008-01-31 04:41:17 UTC (rev 818)
@@ -21,7 +21,6 @@
import java.util.concurrent.ConcurrentHashMap;
import net.sourceforge.stripes.config.Configuration;
-import net.sourceforge.stripes.tag.EncryptedValue;
import net.sourceforge.stripes.util.Log;
/**
@@ -52,7 +51,6 @@
add(Date.class, DateFormatter.class);
add(Number.class, NumberFormatter.class);
add(Enum.class, EnumFormatter.class);
- add(EncryptedValue.class, EncryptedValueFormatter.class);
}
/** Allows subclasses to access the stored configuration if needed. */
Deleted:
trunk/stripes/src/net/sourceforge/stripes/format/EncryptedValueFormatter.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/format/EncryptedValueFormatter.java
2008-01-30 16:30:58 UTC (rev 817)
+++
trunk/stripes/src/net/sourceforge/stripes/format/EncryptedValueFormatter.java
2008-01-31 04:41:17 UTC (rev 818)
@@ -1,75 +0,0 @@
-/* Copyright 2007 Ben Gunter
- *
- * 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 net.sourceforge.stripes.format;
-
-import java.util.Locale;
-
-import net.sourceforge.stripes.controller.StripesFilter;
-import net.sourceforge.stripes.tag.EncryptedValue;
-import net.sourceforge.stripes.util.CryptoUtil;
-
-/**
- * Finds the appropriate formatter for the value of an [EMAIL PROTECTED]
EncryptedValue}, formats it, and
- * encrypts the result.
- *
- * @author Ben Gunter
- */
-public class EncryptedValueFormatter implements Formatter<EncryptedValue> {
- private String formatPattern, formatType;
- private Locale locale;
-
- public void init() {
- }
-
- public void setFormatPattern(String formatPattern) {
- this.formatPattern = formatPattern;
- }
-
- public void setFormatType(String formatType) {
- this.formatType = formatType;
- }
-
- public void setLocale(Locale locale) {
- this.locale = locale;
- }
-
- @SuppressWarnings("unchecked")
- public String format(EncryptedValue input) {
- // null check
- Object object;
- if (input == null || (object = input.getValue()) == null) {
- return "";
- }
-
- // look up the type converter
- FormatterFactory factory =
StripesFilter.getConfiguration().getFormatterFactory();
- Formatter formatter = factory.getFormatter(object.getClass(), locale,
formatType, formatPattern);
-
- // format the value to plain text
- String value;
- if (formatter != null)
- value = formatter.format(object);
- else
- value = object.toString();
-
- // encrypt the value
- if (value == null)
- value = "";
- else
- value = CryptoUtil.encrypt(value);
-
- return value;
- }
-}
Deleted: trunk/stripes/src/net/sourceforge/stripes/tag/EncryptedValue.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/EncryptedValue.java
2008-01-30 16:30:58 UTC (rev 817)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/EncryptedValue.java
2008-01-31 04:41:17 UTC (rev 818)
@@ -1,43 +0,0 @@
-/* Copyright 2007 Ben Gunter
- *
- * 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 net.sourceforge.stripes.tag;
-
-import net.sourceforge.stripes.action.ActionBean;
-import net.sourceforge.stripes.format.EncryptedValueFormatter;
-import net.sourceforge.stripes.format.Formatter;
-
-/**
- * A simple class that wraps an object that is intended to be encrypted before
it is written into a
- * JSP page. This class, coupled with [EMAIL PROTECTED]
EncryptedValueFormatter}, allows for
- * [EMAIL PROTECTED] ActionBean} properties marked as encrypted to be
encrypted transparently to the normal
- * [EMAIL PROTECTED] Formatter} for the value.
- *
- * @author Ben Gunter
- */
-public class EncryptedValue {
- private Object value;
-
- /**
- * Create a new instance that wraps the given [EMAIL PROTECTED] value}.
- */
- public EncryptedValue(Object value) {
- this.value = value;
- }
-
- /** Get the actual value that is to be encrypted. */
- public Object getValue() {
- return value;
- }
-}
Modified: trunk/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
2008-01-30 16:30:58 UTC (rev 817)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
2008-01-31 04:41:17 UTC (rev 818)
@@ -21,6 +21,7 @@
import net.sourceforge.stripes.format.Formatter;
import net.sourceforge.stripes.format.FormatterFactory;
import net.sourceforge.stripes.localization.LocalizationUtility;
+import net.sourceforge.stripes.util.CryptoUtil;
import net.sourceforge.stripes.validation.ValidationError;
import net.sourceforge.stripes.validation.ValidationErrors;
import net.sourceforge.stripes.validation.BooleanTypeConverter;
@@ -304,30 +305,27 @@
return "";
}
- if (forOutput) {
+ // format the value
+ FormatterFactory factory =
StripesFilter.getConfiguration().getFormatterFactory();
+ Formatter formatter = factory.getFormatter(input.getClass(),
+
getPageContext().getRequest().getLocale(),
+ this.formatType,
+ this.formatPattern);
+ String formatted = (formatter == null) ? String.valueOf(input) :
formatter.format(input);
+
+ // encrypt the formatted value if required
+ if (forOutput && formatted != null) {
try {
- // check validation for encryption flag
ValidationMetadata validate = getValidationMetadata();
- if (validate != null && validate.encrypted()) {
- input = new EncryptedValue(input);
- }
+ if (validate != null && validate.encrypted())
+ formatted = CryptoUtil.encrypt(formatted);
}
catch (JspException e) {
throw new StripesRuntimeException(e);
}
}
- FormatterFactory factory =
StripesFilter.getConfiguration().getFormatterFactory();
- Formatter formatter = factory.getFormatter(input.getClass(),
-
getPageContext().getRequest().getLocale(),
- this.formatType,
- this.formatPattern);
- if (formatter != null) {
- return formatter.format(input);
- }
- else {
- return String.valueOf(input);
- }
+ return formatted;
}
/**
Modified: trunk/stripes/src/net/sourceforge/stripes/util/UrlBuilder.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/util/UrlBuilder.java
2008-01-30 16:30:58 UTC (rev 817)
+++ trunk/stripes/src/net/sourceforge/stripes/util/UrlBuilder.java
2008-01-31 04:41:17 UTC (rev 818)
@@ -33,7 +33,6 @@
import net.sourceforge.stripes.exception.StripesRuntimeException;
import net.sourceforge.stripes.format.Formatter;
import net.sourceforge.stripes.format.FormatterFactory;
-import net.sourceforge.stripes.tag.EncryptedValue;
import net.sourceforge.stripes.validation.ValidationMetadata;
import net.sourceforge.stripes.validation.ValidationMetadataProvider;
@@ -407,12 +406,10 @@
buffer.append(URLEncoder.encode(param.name,
"UTF-8")).append('=');
if (param.value != null) {
ValidationMetadata validation =
validations.get(param.name);
- String value;
+ String formatted = format(param.value);
if (validation != null && validation.encrypted())
- value = format(new EncryptedValue(param.value));
- else
- value = format(param.value);
- buffer.append(URLEncoder.encode(value, "UTF-8"));
+ formatted = CryptoUtil.encrypt(formatted);
+ buffer.append(URLEncoder.encode(formatted, "UTF-8"));
}
}
return buffer.toString();
@@ -481,12 +478,10 @@
if (value != null) {
// format (and maybe encrypt) the value as a string
+ String formatted = format(value);
ValidationMetadata validation =
validations.get(parameter.getName());
- String formatted;
if (validation != null && validation.encrypted())
- formatted = format(new EncryptedValue(value));
- else
- formatted = format(value);
+ formatted = CryptoUtil.encrypt(formatted);
// if after formatting we still have a value then embed it
in the URI
if (formatted != null && formatted.length() > 0) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development