mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-06 18:52:13 +00:00
Removed out of date javadoc reference to SecurityEnforcementFilter.
This commit is contained in:
parent
7265a70f0a
commit
9bb64d1974
@ -46,21 +46,17 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
* <p>
|
* <p>
|
||||||
* This filter is necessary because it provides the bridge between Java exceptions and HTTP responses.
|
* This filter is necessary because it provides the bridge between Java exceptions and HTTP responses.
|
||||||
* It is solely concerned with maintaining the user interface. This filter does not do any actual security enforcement.
|
* It is solely concerned with maintaining the user interface. This filter does not do any actual security enforcement.
|
||||||
* </p>
|
|
||||||
* <p>
|
* <p>
|
||||||
* If an {@link AuthenticationException} is detected, the filter will launch the <code>authenticationEntryPoint</code>.
|
* If an {@link AuthenticationException} is detected, the filter will launch the <code>authenticationEntryPoint</code>.
|
||||||
* This allows common handling of authentication failures originating from any subclass of
|
* This allows common handling of authentication failures originating from any subclass of
|
||||||
* {@link org.springframework.security.intercept.AbstractSecurityInterceptor}.
|
* {@link org.springframework.security.intercept.AbstractSecurityInterceptor}.
|
||||||
* </p>
|
|
||||||
* <p>
|
* <p>
|
||||||
* If an {@link AccessDeniedException} is detected, the filter will determine whether or not the user is an anonymous
|
* If an {@link AccessDeniedException} is detected, the filter will determine whether or not the user is an anonymous
|
||||||
* user. If they are an anonymous user, the <code>authenticationEntryPoint</code> will be launched. If they are not
|
* user. If they are an anonymous user, the <code>authenticationEntryPoint</code> will be launched. If they are not
|
||||||
* an anonymous user, the filter will delegate to the {@link org.springframework.security.ui.AccessDeniedHandler}.
|
* an anonymous user, the filter will delegate to the {@link org.springframework.security.ui.AccessDeniedHandler}.
|
||||||
* By default the filter will use {@link org.springframework.security.ui.AccessDeniedHandlerImpl}.
|
* By default the filter will use {@link org.springframework.security.ui.AccessDeniedHandlerImpl}.
|
||||||
* </p>
|
|
||||||
* <p>
|
* <p>
|
||||||
* To use this filter, it is necessary to specify the following properties:
|
* To use this filter, it is necessary to specify the following properties:
|
||||||
* </p>
|
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><code>authenticationEntryPoint</code> indicates the handler that
|
* <li><code>authenticationEntryPoint</code> indicates the handler that
|
||||||
* should commence the authentication process if an
|
* should commence the authentication process if an
|
||||||
@ -76,34 +72,34 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
*/
|
*/
|
||||||
public class ExceptionTranslationFilter extends SpringSecurityFilter implements InitializingBean {
|
public class ExceptionTranslationFilter extends SpringSecurityFilter implements InitializingBean {
|
||||||
|
|
||||||
//~ Instance fields ================================================================================================
|
//~ Instance fields ================================================================================================
|
||||||
|
|
||||||
private AccessDeniedHandler accessDeniedHandler = new AccessDeniedHandlerImpl();
|
private AccessDeniedHandler accessDeniedHandler = new AccessDeniedHandlerImpl();
|
||||||
private AuthenticationEntryPoint authenticationEntryPoint;
|
private AuthenticationEntryPoint authenticationEntryPoint;
|
||||||
private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl();
|
private AuthenticationTrustResolver authenticationTrustResolver = new AuthenticationTrustResolverImpl();
|
||||||
private PortResolver portResolver = new PortResolverImpl();
|
private PortResolver portResolver = new PortResolverImpl();
|
||||||
private ThrowableAnalyzer throwableAnalyzer = new DefaultThrowableAnalyzer();
|
private ThrowableAnalyzer throwableAnalyzer = new DefaultThrowableAnalyzer();
|
||||||
private boolean createSessionAllowed = true;
|
private boolean createSessionAllowed = true;
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint must be specified");
|
Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint must be specified");
|
||||||
Assert.notNull(portResolver, "portResolver must be specified");
|
Assert.notNull(portResolver, "portResolver must be specified");
|
||||||
Assert.notNull(authenticationTrustResolver, "authenticationTrustResolver must be specified");
|
Assert.notNull(authenticationTrustResolver, "authenticationTrustResolver must be specified");
|
||||||
Assert.notNull(throwableAnalyzer, "throwableAnalyzer must be specified");
|
Assert.notNull(throwableAnalyzer, "throwableAnalyzer must be specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doFilterHttp(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException,
|
public void doFilterHttp(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException,
|
||||||
ServletException {
|
ServletException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Chain processed normally");
|
logger.debug("Chain processed normally");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
@ -129,110 +125,112 @@ public class ExceptionTranslationFilter extends SpringSecurityFilter implements
|
|||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthenticationEntryPoint getAuthenticationEntryPoint() {
|
public AuthenticationEntryPoint getAuthenticationEntryPoint() {
|
||||||
return authenticationEntryPoint;
|
return authenticationEntryPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthenticationTrustResolver getAuthenticationTrustResolver() {
|
public AuthenticationTrustResolver getAuthenticationTrustResolver() {
|
||||||
return authenticationTrustResolver;
|
return authenticationTrustResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PortResolver getPortResolver() {
|
public PortResolver getPortResolver() {
|
||||||
return portResolver;
|
return portResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleException(ServletRequest request, ServletResponse response, FilterChain chain,
|
private void handleException(ServletRequest request, ServletResponse response, FilterChain chain,
|
||||||
SpringSecurityException exception) throws IOException, ServletException {
|
SpringSecurityException exception) throws IOException, ServletException {
|
||||||
if (exception instanceof AuthenticationException) {
|
if (exception instanceof AuthenticationException) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Authentication exception occurred; redirecting to authentication entry point", exception);
|
logger.debug("Authentication exception occurred; redirecting to authentication entry point", exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendStartAuthentication(request, response, chain, (AuthenticationException) exception);
|
sendStartAuthentication(request, response, chain, (AuthenticationException) exception);
|
||||||
}
|
}
|
||||||
else if (exception instanceof AccessDeniedException) {
|
else if (exception instanceof AccessDeniedException) {
|
||||||
if (authenticationTrustResolver.isAnonymous(SecurityContextHolder.getContext().getAuthentication())) {
|
if (authenticationTrustResolver.isAnonymous(SecurityContextHolder.getContext().getAuthentication())) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Access is denied (user is anonymous); redirecting to authentication entry point",
|
logger.debug("Access is denied (user is anonymous); redirecting to authentication entry point",
|
||||||
exception);
|
exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendStartAuthentication(request, response, chain, new InsufficientAuthenticationException(
|
sendStartAuthentication(request, response, chain, new InsufficientAuthenticationException(
|
||||||
"Full authentication is required to access this resource"));
|
"Full authentication is required to access this resource"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Access is denied (user is not anonymous); delegating to AccessDeniedHandler",
|
logger.debug("Access is denied (user is not anonymous); delegating to AccessDeniedHandler",
|
||||||
exception);
|
exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
accessDeniedHandler.handle(request, response, (AccessDeniedException) exception);
|
accessDeniedHandler.handle(request, response, (AccessDeniedException) exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If <code>true</code>, indicates that <code>SecurityEnforcementFilter</code> is permitted to store the target
|
* If <code>true</code>, indicates that <code>ExceptionTranslationFilter</code> is permitted to store the target
|
||||||
* URL and exception information in the <code>HttpSession</code> (the default).
|
* URL and exception information in the <code>HttpSession</code> (the default).
|
||||||
* In situations where you do not wish to unnecessarily create <code>HttpSession</code>s - because the user agent
|
* In situations where you do not wish to unnecessarily create <code>HttpSession</code>s - because the user agent
|
||||||
* will know the failed URL, such as with BASIC or Digest authentication - you may wish to
|
* will know the failed URL, such as with BASIC or Digest authentication - you may wish to set this property to
|
||||||
* set this property to <code>false</code>. Remember to also set the
|
* <code>false</code>.
|
||||||
* {@link org.springframework.security.context.HttpSessionContextIntegrationFilter#allowSessionCreation}
|
* <p>
|
||||||
* to <code>false</code> if you set this property to <code>false</code>.
|
* Remember to also set
|
||||||
*
|
* {@link org.springframework.security.context.HttpSessionSecurityContextRepository#setAllowSessionCreation(boolean)}
|
||||||
* @return <code>true</code> if the <code>HttpSession</code> will be
|
* to <code>false</code> if you set this property to <code>false</code>.
|
||||||
* used to store information about the failed request, <code>false</code>
|
*
|
||||||
* if the <code>HttpSession</code> will not be used
|
* @return <code>true</code> if the <code>HttpSession</code> will be
|
||||||
*/
|
* used to store information about the failed request, <code>false</code>
|
||||||
public boolean isCreateSessionAllowed() {
|
* if the <code>HttpSession</code> will not be used
|
||||||
return createSessionAllowed;
|
*/
|
||||||
}
|
public boolean isCreateSessionAllowed() {
|
||||||
|
return createSessionAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
protected void sendStartAuthentication(ServletRequest request, ServletResponse response, FilterChain chain,
|
protected void sendStartAuthentication(ServletRequest request, ServletResponse response, FilterChain chain,
|
||||||
AuthenticationException reason) throws ServletException, IOException {
|
AuthenticationException reason) throws ServletException, IOException {
|
||||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||||
|
|
||||||
SavedRequest savedRequest = new SavedRequest(httpRequest, portResolver);
|
SavedRequest savedRequest = new SavedRequest(httpRequest, portResolver);
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Authentication entry point being called; SavedRequest added to Session: " + savedRequest);
|
logger.debug("Authentication entry point being called; SavedRequest added to Session: " + savedRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createSessionAllowed) {
|
if (createSessionAllowed) {
|
||||||
// Store the HTTP request itself. Used by AbstractProcessingFilter
|
// Store the HTTP request itself. Used by AbstractProcessingFilter
|
||||||
// for redirection after successful authentication (SEC-29)
|
// for redirection after successful authentication (SEC-29)
|
||||||
httpRequest.getSession().setAttribute(AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY, savedRequest);
|
httpRequest.getSession().setAttribute(AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY, savedRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SEC-112: Clear the SecurityContextHolder's Authentication, as the
|
// SEC-112: Clear the SecurityContextHolder's Authentication, as the
|
||||||
// existing Authentication is no longer considered valid
|
// existing Authentication is no longer considered valid
|
||||||
SecurityContextHolder.getContext().setAuthentication(null);
|
SecurityContextHolder.getContext().setAuthentication(null);
|
||||||
|
|
||||||
authenticationEntryPoint.commence(httpRequest, response, reason);
|
authenticationEntryPoint.commence(httpRequest, response, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccessDeniedHandler(AccessDeniedHandler accessDeniedHandler) {
|
public void setAccessDeniedHandler(AccessDeniedHandler accessDeniedHandler) {
|
||||||
Assert.notNull(accessDeniedHandler, "AccessDeniedHandler required");
|
Assert.notNull(accessDeniedHandler, "AccessDeniedHandler required");
|
||||||
this.accessDeniedHandler = accessDeniedHandler;
|
this.accessDeniedHandler = accessDeniedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthenticationEntryPoint(AuthenticationEntryPoint authenticationEntryPoint) {
|
public void setAuthenticationEntryPoint(AuthenticationEntryPoint authenticationEntryPoint) {
|
||||||
this.authenticationEntryPoint = authenticationEntryPoint;
|
this.authenticationEntryPoint = authenticationEntryPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthenticationTrustResolver(AuthenticationTrustResolver authenticationTrustResolver) {
|
public void setAuthenticationTrustResolver(AuthenticationTrustResolver authenticationTrustResolver) {
|
||||||
this.authenticationTrustResolver = authenticationTrustResolver;
|
this.authenticationTrustResolver = authenticationTrustResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreateSessionAllowed(boolean createSessionAllowed) {
|
public void setCreateSessionAllowed(boolean createSessionAllowed) {
|
||||||
this.createSessionAllowed = createSessionAllowed;
|
this.createSessionAllowed = createSessionAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPortResolver(PortResolver portResolver) {
|
public void setPortResolver(PortResolver portResolver) {
|
||||||
this.portResolver = portResolver;
|
this.portResolver = portResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThrowableAnalyzer(ThrowableAnalyzer throwableAnalyzer) {
|
public void setThrowableAnalyzer(ThrowableAnalyzer throwableAnalyzer) {
|
||||||
this.throwableAnalyzer = throwableAnalyzer;
|
this.throwableAnalyzer = throwableAnalyzer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user