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

svn commit: r1173530 - in /wicket/trunk/wicket-core/src/test/java/org/apache/wicket: intercept/ wicket4066/

Author: mgrigorov
Date: Wed Sep 21 08:51:58 2011
New Revision: 1173530

URL: http://svn.apache.org/viewvc?rev=1173530&view=rev
Log:
WICKET-4066 RestartResponseAtInterceptPageException.InterceptData is never cleared

rename the package name and test class name


Added:
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.html
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/InterceptDataCleanedAfterReadTest.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.html
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/MySession.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.html
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.html
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.java
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/Wicket4066Application.java
Removed:
    wicket/trunk/wicket-core/src/test/java/org/apache/wicket/wicket4066/

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.html?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.html Wed Sep 21 08:51:58 2011
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Apache Wicket Quickstart</title>
+  </head>
+  <body>
+    
+    <wicket:link>
+      <h1>Quickstart</h1>
+      <p>This quickstart illustrates a bug where the InterceptData is never cleared.</p>
+    
+      <h2>Step 1 - Intercepted Login</h2>
+      <p>
+        This link goes to Secure Page, which requires login. You should see the login page, followed
+        by Secure Page upon successful login. This is accomplished with
+        RestartResponseAtInterceptPageException, which places InterceptData in the Session.
+        The Login page then calls continueToOriginalDestination().
+      </p>
+      <p>Click:</p>
+      <blockquote><a href="SecurePage.html">Secure Page via Login</a></blockquote>
+    
+      <h2>Step 2 - Explicit Login</h2>
+      <p>
+        This link goes directly to the login page. Since no RestartResponseAtInterceptPageException
+        is used, and since the previous InterceptData should have been cleared by now, the
+        continueToOriginalDestination() on the Login page will return false. This branch of the
+        code should send you to the Success page.
+      </p>
+      <p>
+        <strong>However due to a bug, the InterceptData is apparently never cleared.</strong>
+        Therefore the Success page is never reached. Instead, you will be sent to Secure Page because
+        the InterceptData from step 1 is still in the Session.
+      </p>
+      <p>Click:</p>
+      <blockquote><a href="LoginPage.html">Success page via Login</a></blockquote>
+    </wicket:link>
+    
+  </body>
+</html>

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.java?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/HomePage.java Wed Sep 21 08:51:58 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.intercept;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+/**
+ * 
+ */
+public class HomePage extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param parameters
+	 */
+	public HomePage(final PageParameters parameters)
+	{
+		super(parameters);
+	}
+}

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/InterceptDataCleanedAfterReadTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/InterceptDataCleanedAfterReadTest.java?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/InterceptDataCleanedAfterReadTest.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/InterceptDataCleanedAfterReadTest.java Wed Sep 21 08:51:58 2011
@@ -0,0 +1,60 @@
+/*
+ * 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.intercept;
+
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.util.tester.FormTester;
+import org.junit.Test;
+
+/**
+ * https://issues.apache.org/jira/browse/WICKET-4066
+ */
+public class InterceptDataCleanedAfterReadTest extends WicketTestCase
+{
+	@Override
+	protected WebApplication newApplication()
+	{
+		return new Wicket4066Application();
+	}
+
+	/**
+	 * Tests that InterceptData is cleared after the first successful read.
+	 * 
+	 * https://issues.apache.org/jira/browse/WICKET-4066
+	 */
+	@Test
+	public void wicket4066()
+	{
+		// go to a secured page (a redirect to LoginPage with interception will be done)
+		tester.startPage(SecurePage.class);
+		tester.assertRenderedPage(LoginPage.class);
+
+		FormTester formTester = tester.newFormTester("form");
+		formTester.submit();
+		// continueToOriginalDestination() should return us to SecurePage
+		tester.assertRenderedPage(SecurePage.class);
+
+		// go directly to LoginPage (without interception)
+		tester.startPage(LoginPage.class);
+		FormTester formTester2 = tester.newFormTester("form");
+		formTester2.submit();
+		// no original destination then go to SuccessPage
+		tester.assertRenderedPage(SuccessPage.class);
+	}
+
+}

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.html?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.html Wed Sep 21 08:51:58 2011
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Login</title>
+</head>
+<body>
+  <form wicket:id="form">
+    <input type="submit" value="Login"/>
+  </form>
+</body>
+</html>

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.java?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/LoginPage.java Wed Sep 21 08:51:58 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.intercept;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+/**
+ * 
+ */
+public class LoginPage extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param parameters
+	 */
+	public LoginPage(final PageParameters parameters)
+	{
+		super(parameters);
+
+		add(new Form<Void>("form")
+		{
+			@Override
+			public void onSubmit()
+			{
+				((MySession)getSession()).setAnonymous(false);
+
+				if (!continueToOriginalDestination())
+				{
+					setResponsePage(SuccessPage.class);
+				}
+			}
+		});
+	}
+}

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/MySession.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/MySession.java?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/MySession.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/MySession.java Wed Sep 21 08:51:58 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.intercept;
+
+import org.apache.wicket.protocol.http.WebSession;
+import org.apache.wicket.request.Request;
+
+/**
+ * 
+ */
+public class MySession extends WebSession
+{
+	private boolean anonymous = true;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param request
+	 */
+	public MySession(Request request)
+	{
+		super(request);
+	}
+
+	/**
+	 * @return {@code false} if the user is authenticated
+	 */
+	public boolean isAnonymous()
+	{
+		return anonymous;
+	}
+
+	/**
+	 * Authenticates the session
+	 * 
+	 * @param flag
+	 *            the authentication flag
+	 */
+	public void setAnonymous(boolean flag)
+	{
+		anonymous = flag;
+	}
+}

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.html?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.html Wed Sep 21 08:51:58 2011
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Secure</title>
+</head>
+<body>
+  <wicket:link>
+    <h1>Secure Page</h1>
+    <p>
+      <a href="HomePage.html">Continue</a>
+    </p>
+  </wicket:link>
+</body>
+</html>
\ No newline at end of file

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.java?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SecurePage.java Wed Sep 21 08:51:58 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.intercept;
+
+import org.apache.wicket.RestartResponseAtInterceptPageException;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+/**
+ * The protected page.
+ */
+public class SecurePage extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param parameters
+	 */
+	public SecurePage(final PageParameters parameters)
+	{
+		super(parameters);
+	}
+
+	@Override
+	protected void onBeforeRender()
+	{
+		if (((MySession)getSession()).isAnonymous())
+		{
+			throw new RestartResponseAtInterceptPageException(LoginPage.class);
+		}
+		super.onBeforeRender();
+	}
+}

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.html?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.html (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.html Wed Sep 21 08:51:58 2011
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Success!</title>
+</head>
+<body>
+  <h1>Success!</h1>
+</body>
+</html>

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.java?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/SuccessPage.java Wed Sep 21 08:51:58 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.intercept;
+
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+/**
+ * The page that should be shown after successful login
+ */
+public class SuccessPage extends WebPage
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param parameters
+	 */
+	public SuccessPage(final PageParameters parameters)
+	{
+		super(parameters);
+	}
+}

Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/Wicket4066Application.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/Wicket4066Application.java?rev=1173530&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/Wicket4066Application.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/intercept/Wicket4066Application.java Wed Sep 21 08:51:58 2011
@@ -0,0 +1,40 @@
+/*
+ * 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.intercept;
+
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.request.Request;
+import org.apache.wicket.request.Response;
+
+/**
+ * Application object for your web application. If you want to run this application without
+ * deploying, run the Start class.
+ */
+public class Wicket4066Application extends WebApplication
+{
+	@Override
+	public Class<HomePage> getHomePage()
+	{
+		return HomePage.class;
+	}
+
+	@Override
+	public MySession newSession(Request request, Response response)
+	{
+		return new MySession(request);
+	}
+}