You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jd...@apache.org on 2009/09/14 21:59:42 UTC

svn commit: r814819 [2/3] - in /wicket/trunk: wicket-auth-roles/src/main/java/org/apache/wicket/authentication/ wicket-auth-roles/src/main/java/org/apache/wicket/authentication/panel/ wicket-auth-roles/src/test/java/org/apache/wicket/authorization/stra...

Modified: wicket/trunk/wicket-examples/src/test/java/org/apache/wicket/examples/signin2/Signin2Test.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-examples/src/test/java/org/apache/wicket/examples/signin2/Signin2Test.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket-examples/src/test/java/org/apache/wicket/examples/signin2/Signin2Test.java (original)
+++ wicket/trunk/wicket-examples/src/test/java/org/apache/wicket/examples/signin2/Signin2Test.java Mon Sep 14 19:59:38 2009
@@ -22,6 +22,10 @@
 
 import junit.framework.TestCase;
 
+import org.apache.wicket.examples.authentication2.Home;
+import org.apache.wicket.examples.authentication2.SignIn2;
+import org.apache.wicket.examples.authentication2.SignIn2Application;
+import org.apache.wicket.examples.authentication2.SignOut;
 import org.apache.wicket.util.tester.FormTester;
 import org.apache.wicket.util.tester.WicketTester;
 

Modified: wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/Initializer.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/Initializer.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/Initializer.java (original)
+++ wicket/trunk/wicket-jmx/src/main/java/org/apache/wicket/jmx/Initializer.java Mon Sep 14 19:59:38 2009
@@ -41,11 +41,11 @@
  * <p>
  * Users can specify the MBeanServer implementation in which to register the MBeans by setting the
  * <code>org.apache.wicket.mbean.server.agentid</code> property to the agent id of the MBeanServer
- * implementation they want, or by setting <code>org.apache.wicket.mbean.server.class</code> to
- * the mbean server class they want (if both are provided, and the agent id returns a server, that
- * one is used). This initializer will log an error when no mbean server with the provided agent id
- * can be found, and will then fall back to use the platform mbean server. When no agent id is
- * provided, the platform mbean server will be used.
+ * implementation they want, or by setting <code>org.apache.wicket.mbean.server.class</code> to the
+ * mbean server class they want (if both are provided, and the agent id returns a server, that one
+ * is used). This initializer will log an error when no mbean server with the provided agent id can
+ * be found, and will then fall back to use the platform mbean server. When no agent id is provided,
+ * the platform mbean server will be used.
  * 
  * @author eelcohillenius
  * @author David Hosier
@@ -88,7 +88,6 @@
 	/**
 	 * @see org.apache.wicket.IInitializer#init(org.apache.wicket.Application)
 	 */
-	@SuppressWarnings("unchecked")
 	public void init(org.apache.wicket.Application application)
 	{
 		try
@@ -128,7 +127,8 @@
 				catch (SecurityException e)
 				{
 					// Ignore - we're not allowed to read this property.
-					log.warn("not allowed to read property wicket.mbean.server.class due to security settings; ignoring");
+					log
+							.warn("not allowed to read property wicket.mbean.server.class due to security settings; ignoring");
 				}
 				if (impl != null)
 				{
@@ -191,8 +191,6 @@
 					":type=Application,name=SecuritySettings"));
 			register(new SessionSettings(application), new ObjectName(domain +
 					":type=Application,name=SessionSettings"));
-			register(new CookieValuePersisterSettings(application), new ObjectName(domain +
-					":type=Application,name=CookieValuePersisterSettings"));
 
 			RequestLogger sessionsBean = new RequestLogger(application);
 			ObjectName sessionsBeanName = new ObjectName(domain + ":type=RequestLogger");

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/Page.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/Page.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/Page.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/Page.java Mon Sep 14 19:59:38 2009
@@ -34,7 +34,6 @@
 import org.apache.wicket.markup.MarkupStream;
 import org.apache.wicket.markup.html.WebPage;
 import org.apache.wicket.markup.html.border.Border;
-import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.resolver.IComponentResolver;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.request.RequestParameters;
@@ -687,12 +686,10 @@
 		{
 			try
 			{
-
-				if (getClass().getConstructor(new Class[] {}) != null)
+				if (getClass().getConstructor(new Class[] { }) != null)
 				{
 					bookmarkable = Boolean.TRUE;
 				}
-
 			}
 			catch (Exception ignore)
 			{
@@ -707,14 +704,15 @@
 				{
 				}
 			}
+
 			if (bookmarkable == null)
 			{
 				bookmarkable = Boolean.FALSE;
 			}
 			pageClassToBookmarkableCache.put(getClass().getName(), bookmarkable);
 		}
-		return bookmarkable.booleanValue();
 
+		return bookmarkable.booleanValue();
 	}
 
 	/**
@@ -821,47 +819,6 @@
 	}
 
 	/**
-	 * Convenience method. Search for children of type fromClass and invoke their respective
-	 * removePersistedFormData() methods.
-	 * 
-	 * @param <C>
-	 * 
-	 * @see Form#removePersistentFormComponentValues(boolean)
-	 * 
-	 * @param formClass
-	 *            Form to be selected. Pages may have more than one Form.
-	 * @param disablePersistence
-	 *            if true, disable persistence for all FormComponents on that page. If false, it
-	 *            will remain unchanged.
-	 */
-	public final <C extends Form<?>> void removePersistedFormData(final Class<C> formClass,
-		final boolean disablePersistence)
-	{
-		// Check that formClass is an instanceof Form
-		if (!Form.class.isAssignableFrom(formClass))
-		{
-			throw new WicketRuntimeException("Form class " + formClass.getName() +
-				" is not a subclass of Form");
-		}
-
-		// Visit all children which are an instance of formClass
-		visitChildren(formClass, new IVisitor<Component>()
-		{
-			public Object component(final Component component)
-			{
-				// They must be of type Form as well
-				if (component instanceof Form)
-				{
-					// Delete persistent FormComponent data and disable
-					// persistence
-					((Form<?>)component).removePersistentFormComponentValues(disablePersistence);
-				}
-				return CONTINUE_TRAVERSAL;
-			}
-		});
-	}
-
-	/**
 	 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
 	 */
 	public final void renderPage()
@@ -885,9 +842,6 @@
 			stateless = null;
 		}
 
-		// Set form component values from cookies
-		setFormComponentValuesFromCookies();
-
 		try
 		{
 			prepareForRender();
@@ -1610,24 +1564,6 @@
 	}
 
 	/**
-	 * Sets values for form components based on cookie values in the request.
-	 * 
-	 */
-	final void setFormComponentValuesFromCookies()
-	{
-		// Visit all Forms contained in the page
-		visitChildren(Form.class, new Component.IVisitor<Component>()
-		{
-			// For each FormComponent found on the Page (not Form)
-			public Object component(final Component component)
-			{
-				((Form<?>)component).loadPersistentFormComponentValues();
-				return CONTINUE_TRAVERSAL;
-			}
-		});
-	}
-
-	/**
 	 * @param pageMap
 	 *            Sets this page into the page map with the given name. If the page map does not yet
 	 *            exist, it is automatically created.

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/Session.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/Session.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/Session.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/Session.java Mon Sep 14 19:59:38 2009
@@ -147,8 +147,10 @@
 		}
 	}
 
-	/** a sequence used for whenever something session-specific needs a unique value */
-	private int sequence = 1;
+	private static final long serialVersionUID = 1L;
+
+	/** Logging object */
+	private static final Logger log = LoggerFactory.getLogger(Session.class);
 
 	/** meta data key for missing body tags logging. */
 	public static final MetaDataKey<PageMapAccessMetaData> PAGEMAP_ACCESS_MDK = new MetaDataKey<PageMapAccessMetaData>()
@@ -165,20 +167,18 @@
 	/** A store for dirty objects for one request */
 	private static final ThreadLocal<List<IClusterable>> dirtyObjects = new ThreadLocal<List<IClusterable>>();
 
-	/** Logging object */
-	private static final Logger log = LoggerFactory.getLogger(Session.class);
-
 	/** Attribute prefix for page maps stored in the session */
 	private static final String pageMapAttributePrefix = "m:";
 
-	private static final long serialVersionUID = 1L;
-
 	/** A store for touched pages for one request */
 	private static final ThreadLocal<List<Page>> touchedPages = new ThreadLocal<List<Page>>();
 
 	/** Prefix for attributes holding page map entries */
 	static final String pageMapEntryAttributePrefix = "p:";
 
+	/** a sequence used for whenever something session-specific needs a unique value */
+	private int sequence = 1;
+
 	/** */
 	private int pageIdCounter = 0;
 
@@ -869,11 +869,10 @@
 	 */
 	public void invalidateNow()
 	{
-		sessionInvalidated = true; // set this for isSessionInvalidated
+		invalidate();
 		getSessionStore().invalidate(RequestCycle.get().getRequest());
 	}
 
-
 	/**
 	 * Replaces the underlying (Web)Session, invalidating the current one and creating a new one. By
 	 * calling {@link ISessionStore#invalidate(Request)} and {@link #bind()}

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/ajax/form/AjaxFormComponentUpdatingBehavior.java Mon Sep 14 19:59:38 2009
@@ -20,7 +20,6 @@
 import org.apache.wicket.ajax.AjaxEventBehavior;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.markup.html.form.FormComponent;
-import org.apache.wicket.markup.html.form.persistence.IValuePersister;
 import org.apache.wicket.markup.html.form.validation.IFormValidator;
 import org.apache.wicket.util.string.AppendingStringBuffer;
 

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/IAuthenticationStrategy.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/IAuthenticationStrategy.java?rev=814819&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/IAuthenticationStrategy.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/IAuthenticationStrategy.java Mon Sep 14 19:59:38 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.wicket.authentication;
+
+import org.apache.wicket.Application;
+
+/**
+ * The interface of an authorization strategy which is accessible via
+ * {@link Application#getSecuritySettings()}. Implementations determine how logon data (username and
+ * password) are persisted (e.g. Cookie), retrieved and removed.
+ * 
+ * @author Juergen Donnerstag
+ */
+public interface IAuthenticationStrategy
+{
+	/**
+	 * If "rememberMe" is enabled, than load login name and password from the persistence storage
+	 * (e.g. Cookie) for automatic sign in. This is useful for applications which users typically
+	 * have open the whole day but where the server invalidates the session after a timeout and you
+	 * want to force the user to sign in again and again during the day.
+	 * 
+	 * @return [0] = username, [1] = password, null if not found
+	 */
+	String[] load();
+
+	/**
+	 * If "rememberMe" is enabled and login was successful, than store username and password in the
+	 * persistence store (e.g. Cookie).
+	 * 
+	 * @param username
+	 * @param password
+	 */
+	void save(final String username, final String password);
+
+	/**
+	 * When the user logs out (session invalidation), than remove username and password from the
+	 * persistence store
+	 */
+	void remove();
+}

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/strategy/DefaultAuthenticationStrategy.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/strategy/DefaultAuthenticationStrategy.java?rev=814819&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/strategy/DefaultAuthenticationStrategy.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/strategy/DefaultAuthenticationStrategy.java Mon Sep 14 19:59:38 2009
@@ -0,0 +1,139 @@
+/*
+ * 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.wicket.authentication.strategy;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.authentication.IAuthenticationStrategy;
+import org.apache.wicket.util.cookies.CookieUtils;
+import org.apache.wicket.util.crypt.ICrypt;
+import org.apache.wicket.util.string.Strings;
+
+/**
+ * Wicket's default implementation of an authentication strategy. It'll concatenate username and
+ * password, encrypt it and put it into one Cookie.
+ * 
+ * @author Juergen Donnerstag
+ */
+public class DefaultAuthenticationStrategy implements IAuthenticationStrategy
+{
+	private static final long serialVersionUID = 1L;
+
+	/** The cookie name to store the username and password */
+	private final String cookieKey;
+
+	/** The separator used to concatenate the username and password */
+	private final String VALUE_SEPARATOR = "-sep-";
+
+	/** Cookie utils with default settings */
+	private CookieUtils cookieUtils;
+
+	/** Use to encrypt cookie values for username and password. */
+	private ICrypt crypt;
+
+	/**
+	 * Constructor
+	 * 
+	 * @param cookieKey
+	 *            The name of the cookie
+	 */
+	public DefaultAuthenticationStrategy(final String cookieKey)
+	{
+		if (Strings.isEmpty(cookieKey))
+		{
+			throw new IllegalArgumentException("Parameter 'cookieKey' must not be null or empty.");
+		}
+		this.cookieKey = cookieKey;
+	}
+
+	/**
+	 * Make sure you always return a valid CookieUtils
+	 * 
+	 * @return CookieUtils
+	 */
+	protected CookieUtils getCookieUtils()
+	{
+		if (cookieUtils == null)
+		{
+			cookieUtils = new CookieUtils();
+		}
+		return cookieUtils;
+	}
+
+	/**
+	 * @return The crypt engine to be used
+	 */
+	protected ICrypt getCrypt()
+	{
+		if (crypt == null)
+		{
+			crypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();
+		}
+		return crypt;
+	}
+
+	/**
+	 * @see org.apache.wicket.authentication.IAuthenticationStrategy#load()
+	 */
+	public String[] load()
+	{
+		String value = getCookieUtils().load(cookieKey);
+		if (Strings.isEmpty(value) == false)
+		{
+			value = getCrypt().decryptUrlSafe(value);
+			if (Strings.isEmpty(value) == false)
+			{
+				String username = null;
+				String password = null;
+
+				String[] values = value.split(VALUE_SEPARATOR);
+				if ((values.length > 0) && (Strings.isEmpty(values[0]) == false))
+				{
+					username = values[0];
+				}
+				if ((values.length > 1) && (Strings.isEmpty(values[1]) == false))
+				{
+					password = values[1];
+				}
+
+				return new String[] { username, password };
+			}
+		}
+
+		return null;
+	}
+
+	/**
+	 * @see org.apache.wicket.authentication.IAuthenticationStrategy#save(java.lang.String,
+	 *      java.lang.String)
+	 */
+	public void save(final String username, final String password)
+	{
+		String value = "" + username + VALUE_SEPARATOR + password;
+
+		String encryptedValue = getCrypt().encryptUrlSafe(value);
+
+		getCookieUtils().save(cookieKey, encryptedValue);
+	}
+
+	/**
+	 * @see org.apache.wicket.authentication.IAuthenticationStrategy#remove()
+	 */
+	public void remove()
+	{
+		getCookieUtils().remove(cookieKey);
+	}
+}

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/strategy/NoOpAuthenticationStrategy.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/strategy/NoOpAuthenticationStrategy.java?rev=814819&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/strategy/NoOpAuthenticationStrategy.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/authentication/strategy/NoOpAuthenticationStrategy.java Mon Sep 14 19:59:38 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.wicket.authentication.strategy;
+
+import org.apache.wicket.authentication.IAuthenticationStrategy;
+
+/**
+ * A no-op implementation. No username or password will be persisted or retrieved.
+ * 
+ * @author Juergen Donnerstag
+ */
+public class NoOpAuthenticationStrategy implements IAuthenticationStrategy
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Constructor
+	 */
+	public NoOpAuthenticationStrategy()
+	{
+	}
+
+	/**
+	 * @see org.apache.wicket.authentication.IAuthenticationStrategy#load()
+	 */
+	public String[] load()
+	{
+		return null;
+	}
+
+	/**
+	 * @see org.apache.wicket.authentication.IAuthenticationStrategy#save(java.lang.String,
+	 *      java.lang.String)
+	 */
+	public void save(final String username, final String password)
+	{
+	}
+
+	/**
+	 * @see org.apache.wicket.authentication.IAuthenticationStrategy#remove()
+	 */
+	public void remove()
+	{
+	}
+}

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java Mon Sep 14 19:59:38 2009
@@ -433,15 +433,6 @@
 	}
 
 	/**
-	 * @see org.apache.wicket.markup.html.form.FormComponent#supportsPersistence()
-	 */
-	@Override
-	protected boolean supportsPersistence()
-	{
-		return true;
-	}
-
-	/**
 	 * Override this method if you want to localize the display values of the generated options. By
 	 * default false is returned so that the display values of options are not tested if they have a
 	 * i18n key.

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractTextComponent.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractTextComponent.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractTextComponent.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractTextComponent.java Mon Sep 14 19:59:38 2009
@@ -200,13 +200,4 @@
 		}
 		return super.convertValue(value);
 	}
-
-	/**
-	 * @see FormComponent#supportsPersistence()
-	 */
-	@Override
-	protected boolean supportsPersistence()
-	{
-		return true;
-	}
 }

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBox.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBox.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBox.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBox.java Mon Sep 14 19:59:38 2009
@@ -189,16 +189,6 @@
 	}
 
 	/**
-	 * @see FormComponent#supportsPersistence()
-	 */
-	@Override
-	protected final boolean supportsPersistence()
-	{
-		return true;
-	}
-
-
-	/**
 	 * Final because we made {@link #convertInput()} final and it no longer delegates to
 	 * {@link #getConverter(Class)}
 	 * 

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java Mon Sep 14 19:59:38 2009
@@ -174,17 +174,6 @@
 	}
 
 	/**
-	 * Check group does not support persistence through cookies
-	 * 
-	 * @see FormComponent#supportsPersistence()
-	 */
-	@Override
-	protected final boolean supportsPersistence()
-	{
-		return false;
-	}
-
-	/**
 	 * @see FormComponent#onComponentTag(ComponentTag)
 	 */
 	@Override

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/Form.java Mon Sep 14 19:59:38 2009
@@ -38,15 +38,12 @@
 import org.apache.wicket.markup.MarkupStream;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.border.Border;
-import org.apache.wicket.markup.html.form.persistence.CookieValuePersister;
-import org.apache.wicket.markup.html.form.persistence.IValuePersister;
 import org.apache.wicket.markup.html.form.upload.FileUploadField;
 import org.apache.wicket.markup.html.form.validation.IFormValidator;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
 import org.apache.wicket.protocol.http.RequestUtils;
 import org.apache.wicket.protocol.http.WebRequest;
-import org.apache.wicket.protocol.http.WebRequestCycle;
 import org.apache.wicket.protocol.http.WicketURLDecoder;
 import org.apache.wicket.request.IRequestCycleProcessor;
 import org.apache.wicket.request.RequestParameters;
@@ -798,37 +795,6 @@
 	}
 
 	/**
-	 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
-	 * <p>
-	 * Retrieves FormComponent values related to the page using the persister and assign the values
-	 * to the FormComponent. Thus initializing them.
-	 */
-	public final void loadPersistentFormComponentValues()
-	{
-		visitFormComponentsPostOrder(new FormComponent.AbstractVisitor()
-		{
-			@Override
-			public void onFormComponent(final FormComponent<?> formComponent)
-			{
-				// Component must implement persister interface and
-				// persistence for that component must be enabled.
-				// Else ignore the persisted value. It'll be deleted
-				// once the user submits the Form containing that FormComponent.
-				// Note: if that is true, values may remain persisted longer
-				// than really necessary
-				if (formComponent.isPersistent() && formComponent.isVisibleInHierarchy())
-				{
-					// The persister
-					final IValuePersister persister = getValuePersister();
-
-					// Retrieve persisted value
-					persister.load(formComponent);
-				}
-			}
-		});
-	}
-
-	/**
 	 * THIS METHOD IS NOT PART OF THE WICKET API. DO NOT ATTEMPT TO OVERRIDE OR CALL IT.
 	 * 
 	 * Handles form submissions.
@@ -983,9 +949,6 @@
 			// Update model using form data
 			updateFormComponentModels();
 
-			// Persist FormComponents if requested
-			persistFormComponentData();
-
 			// Form has no error
 			return true;
 		}
@@ -1041,44 +1004,6 @@
 	}
 
 	/**
-	 * Removes already persisted data for all FormComponent children and disable persistence for the
-	 * same components.
-	 * 
-	 * @see Page#removePersistedFormData(Class, boolean)
-	 * 
-	 * @param disablePersistence
-	 *            if true, disable persistence for all FormComponents on that page. If false, it
-	 *            will remain unchanged.
-	 */
-	public void removePersistentFormComponentValues(final boolean disablePersistence)
-	{
-		// The persistence manager responsible to persist and retrieve
-		// FormComponent data
-		final IValuePersister persister = getValuePersister();
-
-		// Search for FormComponents like TextField etc.
-		visitFormComponentsPostOrder(new FormComponent.AbstractVisitor()
-		{
-			@Override
-			public void onFormComponent(final FormComponent<?> formComponent)
-			{
-				if (formComponent.isVisibleInHierarchy())
-				{
-					// remove the FormComponent's persisted data
-					persister.clear(formComponent);
-
-					// Disable persistence if requested. Leave unchanged
-					// otherwise.
-					if (formComponent.isPersistent() && disablePersistence)
-					{
-						formComponent.setPersistent(false);
-					}
-				}
-			}
-		});
-	}
-
-	/**
 	 * Sets the default IFormSubmittingComponent. If set (not null), a hidden submit component will
 	 * be rendered right after the form tag, so that when users press enter in a textfield, this
 	 * submit component's action will be selected. If no default component is set (so unset by
@@ -1394,48 +1319,6 @@
 	}
 
 	/**
-	 * Persist (e.g. Cookie) FormComponent data to be reloaded and re-assigned to the FormComponent
-	 * automatically when the page is visited by the user next time.
-	 * 
-	 * @see org.apache.wicket.markup.html.form.FormComponent#updateModel()
-	 */
-	private void persistFormComponentData()
-	{
-		// Cannot add cookies to request cycle unless it accepts them
-		// We could conceivably be HTML over some other protocol!
-		if (getRequestCycle() instanceof WebRequestCycle)
-		{
-			// The persistence manager responsible to persist and retrieve
-			// FormComponent data
-			final IValuePersister persister = getValuePersister();
-
-			// Search for FormComponent children. Ignore all other
-			visitFormComponentsPostOrder(new FormComponent.AbstractVisitor()
-			{
-				@Override
-				public void onFormComponent(final FormComponent<?> formComponent)
-				{
-					if (formComponent.isVisibleInHierarchy())
-					{
-						// If persistence is switched on for that FormComponent
-						// ...
-						if (formComponent.isPersistent())
-						{
-							// Save component's data (e.g. in a cookie)
-							persister.save(formComponent);
-						}
-						else
-						{
-							// Remove component's data (e.g. cookie)
-							persister.clear(formComponent);
-						}
-					}
-				}
-			});
-		}
-	}
-
-	/**
 	 * If a default IFormSubmittingComponent was set on this form, this method will be called to
 	 * render an extra field with an invisible style so that pressing enter in one of the textfields
 	 * will do a form submit using this component. This method is overridable as what we do is best
@@ -1583,16 +1466,6 @@
 		return false;
 	}
 
-	/**
-	 * Gets the form component persistence manager; it is lazy loaded.
-	 * 
-	 * @return The form component value persister
-	 */
-	protected IValuePersister getValuePersister()
-	{
-		return new CookieValuePersister();
-	}
-
 	private boolean isMultiPart()
 	{
 		if (multiPart)

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java Mon Sep 14 19:59:38 2009
@@ -361,12 +361,6 @@
 
 	private static final String[] EMPTY_STRING_ARRAY = new String[] { "" };
 
-	/**
-	 * Whether this form component should save and restore state between sessions. This is false by
-	 * default.
-	 */
-	private static final short FLAG_PERSISTENT = FLAG_RESERVED2;
-
 	/** Whether or not this component's value is required (non-empty) */
 	private static final short FLAG_REQUIRED = FLAG_RESERVED3;
 
@@ -974,15 +968,6 @@
 	}
 
 	/**
-	 * @return True if this component supports persistence AND it has been asked to persist itself
-	 *         with setPersistent().
-	 */
-	public final boolean isPersistent()
-	{
-		return supportsPersistence() && getFlag(FLAG_PERSISTENT);
-	}
-
-	/**
 	 * @return whether or not this component's value is required
 	 */
 	public boolean isRequired()
@@ -1091,27 +1076,6 @@
 	}
 
 	/**
-	 * Sets whether this component is to be persisted.
-	 * 
-	 * @param persistent
-	 *            True if this component is to be persisted.
-	 * @return this for chaining
-	 */
-	public final FormComponent<T> setPersistent(final boolean persistent)
-	{
-		if (supportsPersistence())
-		{
-			setFlag(FLAG_PERSISTENT, persistent);
-		}
-		else
-		{
-			throw new UnsupportedOperationException("FormComponent " + getClass() +
-				" does not support cookies");
-		}
-		return this;
-	}
-
-	/**
 	 * Sets the required flag
 	 * 
 	 * @param required
@@ -1561,14 +1525,6 @@
 	}
 
 	/**
-	 * @return True if this type of FormComponent can be persisted.
-	 */
-	protected boolean supportsPersistence()
-	{
-		return false;
-	}
-
-	/**
 	 * Checks if the raw input value is not null if this component is required.
 	 */
 	protected final void validateRequired()

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/ListChoice.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/ListChoice.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/ListChoice.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/ListChoice.java Mon Sep 14 19:59:38 2009
@@ -253,13 +253,4 @@
 			tag.put("size", maxRows);
 		}
 	}
-
-	/**
-	 * @see org.apache.wicket.markup.html.form.FormComponent#supportsPersistence()
-	 */
-	@Override
-	protected final boolean supportsPersistence()
-	{
-		return true;
-	}
 }

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/PasswordTextField.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/PasswordTextField.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/PasswordTextField.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/PasswordTextField.java Mon Sep 14 19:59:38 2009
@@ -119,13 +119,4 @@
 	{
 		return "password";
 	}
-
-	/**
-	 * @see org.apache.wicket.markup.html.form.AbstractTextComponent#supportsPersistence()
-	 */
-	@Override
-	protected boolean supportsPersistence()
-	{
-		return false;
-	}
 }

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java Mon Sep 14 19:59:38 2009
@@ -170,15 +170,4 @@
 	protected void onSelectionChanged(final Object newSelection)
 	{
 	}
-
-	/**
-	 * Radio group does not support persistence through cookies
-	 * 
-	 * @see org.apache.wicket.markup.html.form.FormComponent#supportsPersistence()
-	 */
-	@Override
-	protected final boolean supportsPersistence()
-	{
-		return false;
-	}
 }

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/upload/FileUploadField.java Mon Sep 14 19:59:38 2009
@@ -165,17 +165,6 @@
 	}
 
 	/**
-	 * FileInputs cannot be persisted; returns false.
-	 * 
-	 * @see org.apache.wicket.markup.html.form.FormComponent#supportsPersistence()
-	 */
-	@Override
-	protected boolean supportsPersistence()
-	{
-		return false;
-	}
-
-	/**
 	 * Clean up at the end of the request. This means closing all inputstreams which might have been
 	 * opened from the fileUpload.
 	 * 

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/PageLink.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/PageLink.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/PageLink.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/link/PageLink.java Mon Sep 14 19:59:38 2009
@@ -33,7 +33,6 @@
  *            type of model object
  * 
  * @deprecated use {@link BookmarkablePageLink} or {@link Link} instead
- * 
  */
 @Deprecated
 public class PageLink<T> extends Link<T>

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WebApplication.java Mon Sep 14 19:59:38 2009
@@ -626,6 +626,11 @@
 		return Application.DEVELOPMENT;
 	}
 
+	/**
+	 * By default it return a WebApplicationPath
+	 * 
+	 * @return resource finder
+	 */
 	protected IResourceFinder getResourceFinder()
 	{
 		return new WebApplicationPath(getServletContext());

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java Mon Sep 14 19:59:38 2009
@@ -24,6 +24,7 @@
 import org.apache.wicket.Request;
 import org.apache.wicket.RequestCycle;
 import org.apache.wicket.Session;
+import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.feedback.FeedbackMessage;
 import org.apache.wicket.feedback.IFeedbackMessageFilter;
 import org.apache.wicket.settings.IRequestCycleSettings;
@@ -55,6 +56,7 @@
 			return message.getReporter() != null;
 		}
 	};
+
 	/**
 	 * Filter that returns all session scoped messages ({@link FeedbackMessage#getReporter()} ==
 	 * null).
@@ -69,6 +71,9 @@
 		}
 	};
 
+	/** True when the user is signed in */
+	private boolean signedIn;
+
 	/**
 	 * Constructor. Note that {@link RequestCycle} is not available until this constructor returns.
 	 * 
@@ -201,9 +206,73 @@
 		}
 	}
 
+	/**
+	 * Clear all feedback messages
+	 */
 	protected void cleanupComponentFeedbackMessages()
 	{
 		// clean up all component related feedback messages
 		getFeedbackMessages().clear(WebSession.MESSAGES_FOR_COMPONENTS);
 	}
-}
+
+	/**
+	 * Call signOut() and remove the logon data from whereever they have been persisted (e.g.
+	 * Cookies)
+	 * 
+	 * @see org.apache.wicket.Session#invalidate()
+	 */
+	@Override
+	public void invalidate()
+	{
+		signOut();
+
+		getApplication().getSecuritySettings().getAuthenticationStrategy().remove();
+
+		super.invalidate();
+	}
+
+	/**
+	 * Try to logon the user. It'll call {@link #authenticate(String, String)} to do the real work
+	 * and that is what you need to subclass to provide your own authentication mechanism.
+	 * 
+	 * @param username
+	 * @param password
+	 * @return true, if logon was successful
+	 */
+	public final boolean signIn(final String username, final String password)
+	{
+		return signedIn = authenticate(username, password);
+	}
+
+	/**
+	 * @return true, if user is signed in
+	 */
+	public final boolean isSignedIn()
+	{
+		return signedIn;
+	}
+
+	/**
+	 * Sign the user out.
+	 */
+	public void signOut()
+	{
+		signedIn = false;
+	}
+
+	/**
+	 * Note: You must subclass WebSession and implement your own. We didn't want to make it abstract
+	 * to force every application to implement it. Instead we throw an exception.
+	 * 
+	 * @param username
+	 *            The username
+	 * @param password
+	 *            The password
+	 * @return True if the user was authenticated successfully
+	 */
+	public boolean authenticate(final String username, final String password)
+	{
+		throw new WicketRuntimeException(
+			"You must subclass WebSession and implement your own authentication method for all Wicket applications using authentication.");
+	}
+}
\ No newline at end of file

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/ISecuritySettings.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/ISecuritySettings.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/ISecuritySettings.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/ISecuritySettings.java Mon Sep 14 19:59:38 2009
@@ -16,9 +16,9 @@
  */
 package org.apache.wicket.settings;
 
+import org.apache.wicket.authentication.IAuthenticationStrategy;
 import org.apache.wicket.authorization.IAuthorizationStrategy;
 import org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener;
-import org.apache.wicket.markup.html.form.persistence.CookieValuePersisterSettings;
 import org.apache.wicket.util.crypt.ICryptFactory;
 
 /**
@@ -41,11 +41,11 @@
 	IAuthorizationStrategy getAuthorizationStrategy();
 
 	/**
-	 * Get the defaults to be used by persistence manager
+	 * Gets the authentication strategy.
 	 * 
-	 * @return CookieValuePersisterSettings
+	 * @return Returns the authentication strategy.
 	 */
-	CookieValuePersisterSettings getCookieValuePersisterSettings();
+	IAuthenticationStrategy getAuthenticationStrategy();
 
 	/**
 	 * @return crypt factory used to generate crypt objects
@@ -72,15 +72,16 @@
 	 * 
 	 * @param strategy
 	 *            new authorization strategy
-	 * 
 	 */
 	void setAuthorizationStrategy(IAuthorizationStrategy strategy);
 
 	/**
-	 * @param cookieValuePersisterSettings
-	 *            The cookieValuePersisterSettings to set.
+	 * Sets the authentication strategy.
+	 * 
+	 * @param strategy
+	 *            new authentication strategy
 	 */
-	void setCookieValuePersisterSettings(CookieValuePersisterSettings cookieValuePersisterSettings);
+	void setAuthenticationStrategy(IAuthenticationStrategy strategy);
 
 	/**
 	 * Sets the factory that will be used to create crypt objects. The crypt object returned from

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/settings/Settings.java Mon Sep 14 19:59:38 2009
@@ -33,6 +33,8 @@
 import org.apache.wicket.Page;
 import org.apache.wicket.application.DefaultClassResolver;
 import org.apache.wicket.application.IClassResolver;
+import org.apache.wicket.authentication.IAuthenticationStrategy;
+import org.apache.wicket.authentication.strategy.DefaultAuthenticationStrategy;
 import org.apache.wicket.authorization.IAuthorizationStrategy;
 import org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener;
 import org.apache.wicket.authorization.UnauthorizedInstantiationException;
@@ -43,7 +45,6 @@
 import org.apache.wicket.markup.MarkupParserFactory;
 import org.apache.wicket.markup.html.IPackageResourceGuard;
 import org.apache.wicket.markup.html.PackageResourceGuard;
-import org.apache.wicket.markup.html.form.persistence.CookieValuePersisterSettings;
 import org.apache.wicket.markup.html.pages.BrowserInfoPage;
 import org.apache.wicket.markup.resolver.AutoComponentResolver;
 import org.apache.wicket.markup.resolver.IComponentResolver;
@@ -112,6 +113,9 @@
 	/** The authorization strategy. */
 	private IAuthorizationStrategy authorizationStrategy = IAuthorizationStrategy.ALLOW_ALL;
 
+	/** The authentication strategy. */
+	private IAuthenticationStrategy authenticationStrategy;
+
 	/** Application default for automatically resolving hrefs */
 	private boolean automaticLinking = false;
 
@@ -135,9 +139,6 @@
 	/** True if multiple tabs/spaces should be compressed to a single space */
 	private boolean compressWhitespace = false;
 
-	/** Default values for persistence of form data (by means of cookies) */
-	private CookieValuePersisterSettings cookieValuePersisterSettings = new CookieValuePersisterSettings();
-
 	/** factory for creating crypt objects */
 	private ICryptFactory cryptFactory;
 
@@ -492,14 +493,6 @@
 	}
 
 	/**
-	 * @see org.apache.wicket.settings.ISecuritySettings#getCookieValuePersisterSettings()
-	 */
-	public CookieValuePersisterSettings getCookieValuePersisterSettings()
-	{
-		return cookieValuePersisterSettings;
-	}
-
-	/**
 	 * @see org.apache.wicket.settings.ISecuritySettings#getCryptFactory()
 	 */
 	public synchronized ICryptFactory getCryptFactory()
@@ -922,15 +915,6 @@
 	}
 
 	/**
-	 * @see org.apache.wicket.settings.ISecuritySettings#setCookieValuePersisterSettings(org.apache.wicket.markup.html.form.persistence.CookieValuePersisterSettings)
-	 */
-	public void setCookieValuePersisterSettings(
-		CookieValuePersisterSettings cookieValuePersisterSettings)
-	{
-		this.cookieValuePersisterSettings = cookieValuePersisterSettings;
-	}
-
-	/**
 	 * @see org.apache.wicket.settings.ISecuritySettings#setCryptFactory(org.apache.wicket.util.crypt.ICryptFactory)
 	 */
 	public void setCryptFactory(ICryptFactory cryptFactory)
@@ -1548,4 +1532,24 @@
 		}
 		defaultCacheDuration = defaultDuration;
 	}
+
+	/**
+	 * @see org.apache.wicket.settings.ISecuritySettings#getAuthenticationStrategy()
+	 */
+	public IAuthenticationStrategy getAuthenticationStrategy()
+	{
+		if (authenticationStrategy == null)
+		{
+			authenticationStrategy = new DefaultAuthenticationStrategy("LoggedIn");
+		}
+		return authenticationStrategy;
+	}
+
+	/**
+	 * @see org.apache.wicket.settings.ISecuritySettings#setAuthenticationStrategy(org.apache.wicket.authentication.IAuthenticationStrategy)
+	 */
+	public void setAuthenticationStrategy(final IAuthenticationStrategy strategy)
+	{
+		authenticationStrategy = strategy;
+	}
 }

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieDefaults.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieDefaults.java?rev=814819&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieDefaults.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieDefaults.java Mon Sep 14 19:59:38 2009
@@ -0,0 +1,162 @@
+/*
+ * 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.wicket.util.cookies;
+
+import org.apache.wicket.IClusterable;
+
+/**
+ * This class provides default values that are used by the CookieValuePersister class when it
+ * creates cookies.
+ * 
+ * @author Juergen Donnerstag
+ * 
+ * @TODO rename to CookieDefaultValues in 1.5
+ */
+public class CookieDefaults implements IClusterable
+{
+	private static final long serialVersionUID = 1L;
+
+	/** Max age that the component will be persisted in seconds. */
+	private int maxAge = 3600 * 24 * 30; // 30 days
+
+	/** Cookie comment. */
+	private String comment;
+
+	/** Cookie domain. */
+	private String domain;
+
+	/** Whether the cookie is secure. */
+	private boolean secure;
+
+	/** Cookie version. */
+	private int version;
+
+	/**
+	 * Gets the max age. After
+	 * 
+	 * @return the max age
+	 */
+	public int getMaxAge()
+	{
+		return maxAge;
+	}
+
+	/**
+	 * Sets the maximum age of the cookie in seconds.
+	 * 
+	 * @param maxAge
+	 *            the max age in seconds.
+	 */
+	public void setMaxAge(int maxAge)
+	{
+		this.maxAge = maxAge;
+	}
+
+	/**
+	 * Gets the cookie comment.
+	 * 
+	 * @return the cookie comment
+	 */
+	public String getComment()
+	{
+		return comment;
+	}
+
+	/**
+	 * Sets the cookie comment.
+	 * 
+	 * @param comment
+	 *            the cookie comment
+	 */
+	public void setComment(String comment)
+	{
+		this.comment = comment;
+	}
+
+	/**
+	 * Gets the cookie domain name.
+	 * 
+	 * @return the cookie domain name
+	 */
+	public String getDomain()
+	{
+		return domain;
+	}
+
+	/**
+	 * Sets the cookie domain name.
+	 * 
+	 * @param domain
+	 *            the cookie domain name
+	 */
+	public void setDomain(String domain)
+	{
+		this.domain = domain;
+	}
+
+	/**
+	 * Returns true if the browser is sending cookies only over a secure protocol, or false if the
+	 * browser can send cookies using any protocol.
+	 * 
+	 * @return whether this cookie is secure
+	 */
+	public boolean getSecure()
+	{
+		return secure;
+	}
+
+	/**
+	 * Indicates to the browser whether the cookie should only be sent using a secure protocol, such
+	 * as HTTPS or SSL.
+	 * 
+	 * @param secure
+	 *            if true, sends the cookie from the browser to the server using only when using a
+	 *            secure protocol; if false, sent on any protocol
+	 */
+	public void setSecure(boolean secure)
+	{
+		this.secure = secure;
+	}
+
+	/**
+	 * Returns the version of the protocol this cookie complies with. Version 1 complies with RFC
+	 * 2109, and version 0 complies with the original cookie specification drafted by Netscape.
+	 * Cookies provided by a browser use and identify the browser's cookie version.
+	 * 
+	 * @return 0 if the cookie complies with the original Netscape specification; 1 if the cookie
+	 *         complies with RFC 2109
+	 */
+	public int getVersion()
+	{
+		return version;
+	}
+
+	/**
+	 * Sets the version of the cookie protocol this cookie complies with. Version 0 complies with
+	 * the original Netscape cookie specification. Version 1 complies with RFC 2109. <br/>
+	 * Since RFC 2109 is still somewhat new, consider version 1 as experimental; do not use it yet
+	 * on production sites.
+	 * 
+	 * @param version
+	 *            0 if the cookie should comply with the original Netscape specification; 1 if the
+	 *            cookie should comply with RFC 2109
+	 */
+	public void setVersion(int version)
+	{
+		this.version = version;
+	}
+}

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java?rev=814819&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/CookieUtils.java Mon Sep 14 19:59:38 2009
@@ -0,0 +1,374 @@
+/*
+ * 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.wicket.util.cookies;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.wicket.RequestCycle;
+import org.apache.wicket.markup.html.form.FormComponent;
+import org.apache.wicket.protocol.http.WebRequest;
+import org.apache.wicket.protocol.http.WebResponse;
+import org.apache.wicket.util.string.Strings;
+import org.apache.wicket.util.time.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Helper class to simplify Cookie handling.
+ * 
+ * @author Juergen Donnerstag
+ * @author Jonathan Locke
+ */
+public class CookieUtils
+{
+	private static final long serialVersionUID = 1L;
+
+	private final static Logger log = LoggerFactory.getLogger(CookieUtils.class);
+
+	private final CookieDefaults settings;
+
+	/**
+	 * Construct.
+	 */
+	public CookieUtils()
+	{
+		settings = new CookieDefaults();
+	}
+
+	/**
+	 * Construct.
+	 * 
+	 * @param settings
+	 */
+	public CookieUtils(final CookieDefaults settings)
+	{
+		this.settings = settings;
+	}
+
+	/**
+	 * @return Gets the settings for these utils
+	 */
+	public final CookieDefaults getSettings()
+	{
+		return settings;
+	}
+
+	/**
+	 * Remove the cookie identified by the key
+	 * 
+	 * @param key
+	 */
+	public final void remove(final String key)
+	{
+		final Cookie cookie = getCookie(key);
+		if (cookie != null)
+		{
+			remove(cookie);
+		}
+	}
+
+	/**
+	 * Remove the cookie identified by the form component
+	 * 
+	 * @param formComponent
+	 */
+	public final void remove(final FormComponent<?> formComponent)
+	{
+		remove(getKey(formComponent));
+	}
+
+	/**
+	 * This method gets used when a cookie key needs to be derived from a form component. By default
+	 * the component's page relative path is used.
+	 * 
+	 * @param component
+	 * @return cookie key
+	 */
+	protected String getKey(final FormComponent<?> component)
+	{
+		return component.getPageRelativePath();
+	}
+
+	/**
+	 * Retrieve the cookie value by means of its key.
+	 * 
+	 * @param key
+	 * @return The cookie value associated with the key
+	 */
+	public final String load(final String key)
+	{
+		final Cookie cookie = getCookie(key);
+		if (cookie != null)
+		{
+			return cookie.getValue();
+		}
+		return null;
+	}
+
+	/**
+	 * Retrieve the cookie value associated with the formComponent and load the model object with
+	 * the cookie value.
+	 * 
+	 * @param formComponent
+	 * @return The Cookie value which has also been used to set the component's model value
+	 */
+	public final String load(final FormComponent<?> formComponent)
+	{
+		String value = load(getKey(formComponent));
+		if (value != null)
+		{
+			// Assign the retrieved/persisted value to the component
+			formComponent.setModelValue(splitValue(value));
+		}
+		return value;
+	}
+
+	/**
+	 * Split the loaded Cookie value
+	 * 
+	 * @param value
+	 * @return The cookie's value split into fragments
+	 */
+	protected String[] splitValue(final String value)
+	{
+		return value.split(FormComponent.VALUE_SEPARATOR);
+	}
+
+	/**
+	 * Join all fragments into one Cookie value
+	 * 
+	 * @param values
+	 * @return The cookie's value splitted into its constituent parts
+	 */
+	protected String joinValues(final String... values)
+	{
+		return Strings.join(FormComponent.VALUE_SEPARATOR, values);
+	}
+
+	/**
+	 * Create a Cookie with key and value and save it in the browser with the next response
+	 * 
+	 * @param key
+	 * @param values
+	 */
+	public final void save(String key, final String... values)
+	{
+		key = getSaveKey(key);
+		String value = joinValues(values);
+		Cookie cookie = getCookie(key);
+		if (cookie == null)
+		{
+			cookie = new Cookie(key, value);
+		}
+		else
+		{
+			cookie.setValue(value);
+		}
+		cookie.setSecure(false);
+		cookie.setMaxAge(settings.getMaxAge());
+
+		save(cookie);
+	}
+
+	/**
+	 * Save the form components model value in a cookie
+	 * 
+	 * @param formComponent
+	 */
+	public final void save(final FormComponent<?> formComponent)
+	{
+		save(getKey(formComponent), formComponent.getValue());
+	}
+
+	/**
+	 * Make sure the 'key' does not contain any illegal chars. E.g. for cookies ':' is not allowed.
+	 * 
+	 * @param key
+	 *            The key to be validated
+	 * @return The save key
+	 */
+	protected String getSaveKey(String key)
+	{
+		if (Strings.isEmpty(key))
+		{
+			throw new IllegalArgumentException("A Cookie name can not be null or empty");
+		}
+
+		// cookie names cannot contain ':',
+		// we replace ':' with '.' but first we have to encode '.' as '..'
+		key = key.replace(".", "..");
+		key = key.replace(":", ".");
+		return key;
+	}
+
+	/**
+	 * Convenience method for deleting a cookie by name. Delete the cookie by setting its maximum
+	 * age to zero.
+	 * 
+	 * @param cookie
+	 *            The cookie to delete
+	 */
+	private void remove(final Cookie cookie)
+	{
+		if (cookie != null)
+		{
+			// Delete the cookie by setting its maximum age to zero
+			cookie.setMaxAge(0);
+			cookie.setValue(null);
+
+			save(cookie);
+
+			if (log.isDebugEnabled())
+			{
+				log.debug("Removed Cookie: " + cookie.getName());
+			}
+		}
+	}
+
+	/**
+	 * Gets the cookie with 'name' attached to the latest WebRequest.
+	 * 
+	 * @param name
+	 *            The name of the cookie to be looked up
+	 * 
+	 * @return Any cookies for this request
+	 */
+	private Cookie getCookie(final String name)
+	{
+		String key = getSaveKey(name);
+
+		try
+		{
+			Cookie cookie = getWebRequest().getCookie(key);
+			if (log.isDebugEnabled())
+			{
+				if (cookie != null)
+				{
+					log.debug("Found Cookie with name=" + key + " and request URI=" +
+						getWebRequest().getHttpServletRequest().getRequestURI());
+				}
+				else
+				{
+					log.debug("Unable to find Cookie with name=" + key + " and request URI=" +
+						getWebRequest().getHttpServletRequest().getRequestURI());
+				}
+			}
+
+			return cookie;
+		}
+		catch (NullPointerException ex)
+		{
+			// Ignore any app server problem here
+		}
+
+		return null;
+	}
+
+	/**
+	 * Persist/save the data using Cookies.
+	 * 
+	 * @param cookie
+	 *            The Cookie to be persisted.
+	 * @return The cookie provided
+	 */
+	private Cookie save(final Cookie cookie)
+	{
+		if (cookie == null)
+		{
+			return null;
+		}
+
+		initializeCookie(cookie);
+
+		getWebResponse().addCookie(cookie);
+
+		if (log.isDebugEnabled())
+		{
+			log.debug("Cookie saved: " + cookieToDebugString(cookie) + "; request URI=" +
+				getWebRequest().getHttpServletRequest().getRequestURI());
+		}
+
+		return cookie;
+	}
+
+	/**
+	 * Is called before the Cookie is saved. May be subclassed for different (dynamic) Cookie
+	 * parameters. Static parameters can also be changed via {@link CookieDefaults}.
+	 * 
+	 * @param cookie
+	 */
+	protected void initializeCookie(final Cookie cookie)
+	{
+		final String comment = settings.getComment();
+		if (comment != null)
+		{
+			cookie.setComment(comment);
+		}
+
+		final String domain = settings.getDomain();
+		if (domain != null)
+		{
+			cookie.setDomain(domain);
+		}
+
+		HttpServletRequest request = getWebRequest().getHttpServletRequest();
+		String path = request.getContextPath() + request.getServletPath();
+		if (Strings.isEmpty(path))
+		{
+			path = "/";
+		}
+		cookie.setPath(path);
+		cookie.setVersion(settings.getVersion());
+		cookie.setSecure(settings.getSecure());
+	}
+
+	/**
+	 * Convenience method to get the http request.
+	 * 
+	 * @return WebRequest related to the RequestCycle
+	 */
+	private WebRequest getWebRequest()
+	{
+		return (WebRequest)RequestCycle.get().getRequest();
+	}
+
+	/**
+	 * Convenience method to get the http response.
+	 * 
+	 * @return WebResponse related to the RequestCycle
+	 */
+	private WebResponse getWebResponse()
+	{
+		return (WebResponse)RequestCycle.get().getResponse();
+	}
+
+	/**
+	 * Gets debug info as a string for the given cookie.
+	 * 
+	 * @param cookie
+	 *            the cookie to debug.
+	 * @return a string that represents the internals of the cookie.
+	 */
+	private String cookieToDebugString(final Cookie cookie)
+	{
+		return "[Cookie " + " name = " + cookie.getName() + ", value = " + cookie.getValue() +
+			", domain = " + cookie.getDomain() + ", path = " + cookie.getPath() + ", maxAge = " +
+			Time.valueOf(cookie.getMaxAge()).toDateString() + "(" + cookie.getMaxAge() + ")" + "]";
+	}
+}

Added: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/package.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/package.html?rev=814819&view=auto
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/package.html (added)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/cookies/package.html Mon Sep 14 19:59:38 2009
@@ -0,0 +1,27 @@
+<!--
+   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.
+-->
+<!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 3.2 Final//NL">
+<html>
+<head>
+<title>wicket.markup.html.form.persistence package</title>
+</head>
+<body>
+<p>
+Persistence support for forms.
+</p>
+</body>
+</html>
\ No newline at end of file

Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/util/crypt/AbstractCrypt.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/crypt/AbstractCrypt.java?rev=814819&r1=814818&r2=814819&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/util/crypt/AbstractCrypt.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/util/crypt/AbstractCrypt.java Mon Sep 14 19:59:38 2009
@@ -63,13 +63,14 @@
 	{
 		try
 		{
-			byte[] encrypted = Base64UrlSafe.decodeBase64(text.getBytes());
-			return new String(decryptByteArray(encrypted), CHARACTER_ENCODING);
+			byte[] decoded = new Base64(true).decode(text);
+			return new String(decryptByteArray(decoded), CHARACTER_ENCODING);
 		}
-		catch (UnsupportedEncodingException ex)
+		catch (Exception ex)
 		{
-			throw new WicketRuntimeException("Error decoding text: " + text, ex);
+			log.error("Error decoding text: " + text, ex);
 		}
+		return null;
 	}
 
 	/**
@@ -83,14 +84,19 @@
 	{
 		try
 		{
-			byte[] cipherText = encryptStringToByteArray(plainText);
-			return new String(Base64UrlSafe.encodeBase64(cipherText));
+			byte[] encrypted = encryptStringToByteArray(plainText);
+			return new String(new Base64(-1, null, true).encode(encrypted), CHARACTER_ENCODING);
 		}
 		catch (GeneralSecurityException e)
 		{
 			log.error("Unable to encrypt text '" + plainText + "'", e);
 			return null;
 		}
+		catch (UnsupportedEncodingException e)
+		{
+			log.error("Unable to encrypt text '" + plainText + "'", e);
+			return null;
+		}
 	}
 
 	/**