SEC-712: HttpSessionContextIntegrationFilter "context" property should be renamed

http://jira.springframework.org/browse/SEC-712
This commit is contained in:
Luke Taylor 2008-03-11 14:16:40 +00:00
parent ed08ba10ba
commit 089bffa10f
2 changed files with 21 additions and 21 deletions

View File

@ -49,7 +49,7 @@ import org.springframework.security.ui.FilterChainOrder;
* If a valid <code>SecurityContext</code> cannot be obtained from the * If a valid <code>SecurityContext</code> cannot be obtained from the
* <code>HttpSession</code> for whatever reason, a fresh * <code>HttpSession</code> for whatever reason, a fresh
* <code>SecurityContext</code> will be created and used instead. The created * <code>SecurityContext</code> will be created and used instead. The created
* object will be of the instance defined by the {@link #setContext(Class)} * object will be of the instance defined by the {@link #setContextClass(Class)}
* method (which defaults to {@link org.springframework.security.context.SecurityContextImpl}. * method (which defaults to {@link org.springframework.security.context.SecurityContextImpl}.
* </p> * </p>
* <p/> * <p/>
@ -58,7 +58,7 @@ import org.springframework.security.ui.FilterChainOrder;
* does not exist, a <code>HttpSession</code> will <b>only</b> be created if * does not exist, a <code>HttpSession</code> will <b>only</b> be created if
* the current contents of the <code>SecurityContextHolder</code> are not * the current contents of the <code>SecurityContextHolder</code> are not
* {@link java.lang.Object#equals(java.lang.Object)} to a <code>new</code> * {@link java.lang.Object#equals(java.lang.Object)} to a <code>new</code>
* instance of {@link #setContext(Class)}. This avoids needless * instance of {@link #setContextClass(Class)}. This avoids needless
* <code>HttpSession</code> creation, but automates the storage of changes * <code>HttpSession</code> creation, but automates the storage of changes
* made to the <code>SecurityContextHolder</code>. There is one exception to * made to the <code>SecurityContextHolder</code>. There is one exception to
* this rule, that is if the {@link #forceEagerSessionCreation} property is * this rule, that is if the {@link #forceEagerSessionCreation} property is
@ -108,7 +108,7 @@ public class HttpSessionContextIntegrationFilter extends SpringSecurityFilter im
//~ Instance fields ================================================================================================ //~ Instance fields ================================================================================================
private Class context = SecurityContextImpl.class; private Class contextClass = SecurityContextImpl.class;
private Object contextObject; private Object contextObject;
@ -149,7 +149,7 @@ public class HttpSessionContextIntegrationFilter extends SpringSecurityFilter im
* allowed to affect the security identitiy in other threads associated with * allowed to affect the security identitiy in other threads associated with
* the same <code>HttpSession</code>. For unusual cases where this is not * the same <code>HttpSession</code>. For unusual cases where this is not
* permitted, change this value to <code>true</code> and ensure the * permitted, change this value to <code>true</code> and ensure the
* {@link #context} is set to a <code>SecurityContext</code> that * {@link #contextClass} is set to a <code>SecurityContext</code> that
* implements {@link Cloneable} and overrides the <code>clone()</code> * implements {@link Cloneable} and overrides the <code>clone()</code>
* method. * method.
*/ */
@ -170,10 +170,10 @@ public class HttpSessionContextIntegrationFilter extends SpringSecurityFilter im
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
if ((this.context == null) || (!SecurityContext.class.isAssignableFrom(this.context))) { if ((this.contextClass == null) || (!SecurityContext.class.isAssignableFrom(this.contextClass))) {
throw new IllegalArgumentException("context must be defined and implement SecurityContext " throw new IllegalArgumentException("context must be defined and implement SecurityContext "
+ "(typically use org.springframework.security.context.SecurityContextImpl; existing class is " + "(typically use org.springframework.security.context.SecurityContextImpl; existing class is "
+ this.context + ")"); + this.contextClass + ")");
} }
if (forceEagerSessionCreation && !allowSessionCreation) { if (forceEagerSessionCreation && !allowSessionCreation) {
@ -407,7 +407,7 @@ public class HttpSessionContextIntegrationFilter extends SpringSecurityFilter im
public SecurityContext generateNewContext() throws ServletException { public SecurityContext generateNewContext() throws ServletException {
try { try {
return (SecurityContext) this.context.newInstance(); return (SecurityContext) this.contextClass.newInstance();
} }
catch (InstantiationException ie) { catch (InstantiationException ie) {
throw new ServletException(ie); throw new ServletException(ie);
@ -425,12 +425,12 @@ public class HttpSessionContextIntegrationFilter extends SpringSecurityFilter im
this.allowSessionCreation = allowSessionCreation; this.allowSessionCreation = allowSessionCreation;
} }
public Class getContext() { protected Class getContextClass() {
return context; return contextClass;
} }
public void setContext(Class secureContext) { public void setContextClass(Class secureContext) {
this.context = secureContext; this.contextClass = secureContext;
} }
public boolean isForceEagerSessionCreation() { public boolean isForceEagerSessionCreation() {

View File

@ -85,7 +85,7 @@ public class HttpSessionContextIntegrationFilterTests extends TestCase {
HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter(); HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter();
try { try {
filter.setContext(null); filter.setContextClass(null);
filter.afterPropertiesSet(); filter.afterPropertiesSet();
fail("Shown have thrown IllegalArgumentException"); fail("Shown have thrown IllegalArgumentException");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
@ -93,8 +93,8 @@ public class HttpSessionContextIntegrationFilterTests extends TestCase {
} }
try { try {
filter.setContext(Integer.class); filter.setContextClass(Integer.class);
assertEquals(Integer.class, filter.getContext()); assertEquals(Integer.class, filter.getContextClass());
filter.afterPropertiesSet(); filter.afterPropertiesSet();
fail("Shown have thrown IllegalArgumentException"); fail("Shown have thrown IllegalArgumentException");
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
@ -127,7 +127,7 @@ public class HttpSessionContextIntegrationFilterTests extends TestCase {
// Prepare filter // Prepare filter
HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter(); HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter();
filter.setContext(SecurityContextImpl.class); filter.setContextClass(SecurityContextImpl.class);
filter.afterPropertiesSet(); filter.afterPropertiesSet();
// Execute filter // Execute filter
@ -179,7 +179,7 @@ public class HttpSessionContextIntegrationFilterTests extends TestCase {
// Prepare filter // Prepare filter
HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter(); HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter();
filter.setContext(SecurityContextImpl.class); filter.setContextClass(SecurityContextImpl.class);
filter.afterPropertiesSet(); filter.afterPropertiesSet();
// Execute filter // Execute filter
@ -206,7 +206,7 @@ public class HttpSessionContextIntegrationFilterTests extends TestCase {
// Prepare filter // Prepare filter
HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter(); HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter();
filter.setContext(SecurityContextImpl.class); filter.setContextClass(SecurityContextImpl.class);
// don't call afterPropertiesSet to test case when Spring filter.afterPropertiesSet(); isn't called // don't call afterPropertiesSet to test case when Spring filter.afterPropertiesSet(); isn't called
// Execute filter // Execute filter
@ -226,7 +226,7 @@ public class HttpSessionContextIntegrationFilterTests extends TestCase {
// Prepare filter // Prepare filter
HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter(); HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter();
filter.setContext(SecurityContextImpl.class); filter.setContextClass(SecurityContextImpl.class);
filter.setForceEagerSessionCreation(true); // non-default filter.setForceEagerSessionCreation(true); // non-default
filter.afterPropertiesSet(); filter.afterPropertiesSet();
@ -246,7 +246,7 @@ public class HttpSessionContextIntegrationFilterTests extends TestCase {
// Prepare filter // Prepare filter
HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter(); HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter();
filter.setContext(SecurityContextImpl.class); filter.setContextClass(SecurityContextImpl.class);
filter.afterPropertiesSet(); filter.afterPropertiesSet();
// Execute filter // Execute filter
@ -276,7 +276,7 @@ public class HttpSessionContextIntegrationFilterTests extends TestCase {
// Prepare filter // Prepare filter
HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter(); HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter();
filter.setContext(SecurityContextImpl.class); filter.setContextClass(SecurityContextImpl.class);
filter.afterPropertiesSet(); filter.afterPropertiesSet();
// Execute filter // Execute filter
@ -308,7 +308,7 @@ public class HttpSessionContextIntegrationFilterTests extends TestCase {
// Prepare filter // Prepare filter
HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter(); HttpSessionContextIntegrationFilter filter = new HttpSessionContextIntegrationFilter();
filter.setContext(SecurityContextImpl.class); filter.setContextClass(SecurityContextImpl.class);
filter.afterPropertiesSet(); filter.afterPropertiesSet();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {