|
|
|
@ -32,28 +32,41 @@ import org.springframework.context.ApplicationContextAware; |
|
|
|
import org.springframework.core.Ordered; |
|
|
|
import org.springframework.core.Ordered; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Used by the <code>SecurityEnforcementFilter</code> to commence authentication via the {@link |
|
|
|
* Used by the <code>SecurityEnforcementFilter</code> to commence |
|
|
|
* BasicProcessingFilter}.<P>Once a user agent is authenticated using BASIC authentication, logout requires that |
|
|
|
* authentication via the {@link BasicProcessingFilter}. |
|
|
|
* the browser be closed or an unauthorized (401) header be sent. The simplest way of achieving the latter is to call |
|
|
|
* <P> |
|
|
|
* the {@link #commence(ServletRequest, ServletResponse, AuthenticationException)} method below. This will indicate to |
|
|
|
* Once a user agent is authenticated using BASIC authentication, logout |
|
|
|
* the browser its credentials are no longer authorized, causing it to prompt the user to login again.</p> |
|
|
|
* requires that the browser be closed or an unauthorized (401) header be sent. |
|
|
|
* |
|
|
|
* The simplest way of achieving the latter is to call the |
|
|
|
|
|
|
|
* {@link #commence(ServletRequest, ServletResponse, AuthenticationException)} |
|
|
|
|
|
|
|
* method below. This will indicate to the browser its credentials are no longer |
|
|
|
|
|
|
|
* authorized, causing it to prompt the user to login again. |
|
|
|
|
|
|
|
* </p> |
|
|
|
|
|
|
|
* |
|
|
|
* @author Ben Alex |
|
|
|
* @author Ben Alex |
|
|
|
* @version $Id: BasicProcessingFilterEntryPoint.java 1822 2007-05-17 12:20:16Z vishalpuri $ |
|
|
|
* @version $Id: BasicProcessingFilterEntryPoint.java 1822 2007-05-17 12:20:16Z |
|
|
|
|
|
|
|
* vishalpuri $ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class BasicProcessingFilterEntryPoint implements AuthenticationEntryPoint, InitializingBean, Ordered, ApplicationContextAware { |
|
|
|
public class BasicProcessingFilterEntryPoint implements AuthenticationEntryPoint, InitializingBean, Ordered, |
|
|
|
//~ Instance fields ================================================================================================
|
|
|
|
ApplicationContextAware { |
|
|
|
|
|
|
|
// ~ Static fields/initializers
|
|
|
|
|
|
|
|
// =====================================================================================
|
|
|
|
private static final int DEFAULT_ORDER = Integer.MAX_VALUE; |
|
|
|
private static final int DEFAULT_ORDER = Integer.MAX_VALUE; |
|
|
|
private String realmName; |
|
|
|
|
|
|
|
private int order = DEFAULT_ORDER; |
|
|
|
|
|
|
|
private ApplicationContext applicationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//~ Methods ========================================================================================================
|
|
|
|
// ~ Instance fields
|
|
|
|
|
|
|
|
// ================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String realmName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int order = DEFAULT_ORDER; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationContext applicationContext; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ~ Methods
|
|
|
|
|
|
|
|
// ========================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
public int getOrder() { |
|
|
|
public int getOrder() { |
|
|
|
return order; |
|
|
|
return order; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -66,22 +79,22 @@ public class BasicProcessingFilterEntryPoint implements AuthenticationEntryPoint |
|
|
|
if (order == DEFAULT_ORDER) { |
|
|
|
if (order == DEFAULT_ORDER) { |
|
|
|
OrderedUtils.copyOrderFromOtherClass(BasicProcessingFilter.class, applicationContext, this, true); |
|
|
|
OrderedUtils.copyOrderFromOtherClass(BasicProcessingFilter.class, applicationContext, this, true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void commence(ServletRequest request, ServletResponse response, AuthenticationException authException) |
|
|
|
public void commence(ServletRequest request, ServletResponse response, AuthenticationException authException) |
|
|
|
throws IOException, ServletException { |
|
|
|
throws IOException, ServletException { |
|
|
|
HttpServletResponse httpResponse = (HttpServletResponse) response; |
|
|
|
HttpServletResponse httpResponse = (HttpServletResponse) response; |
|
|
|
httpResponse.addHeader("WWW-Authenticate", "Basic realm=\"" + realmName + "\""); |
|
|
|
httpResponse.addHeader("WWW-Authenticate", "Basic realm=\"" + realmName + "\""); |
|
|
|
httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); |
|
|
|
httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getRealmName() { |
|
|
|
public String getRealmName() { |
|
|
|
return realmName; |
|
|
|
return realmName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setRealmName(String realmName) { |
|
|
|
public void setRealmName(String realmName) { |
|
|
|
this.realmName = realmName; |
|
|
|
this.realmName = realmName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setApplicationContext(ApplicationContext applicationContext) { |
|
|
|
public void setApplicationContext(ApplicationContext applicationContext) { |
|
|
|
this.applicationContext = applicationContext; |
|
|
|
this.applicationContext = applicationContext; |
|
|
|
|