
org.springframework.security.web.authentication.HttpStatusEntryPointCustom Maven / Gradle / Ivy
package org.springframework.security.web.authentication;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.util.Assert;
/**
* @see org.springframework.security.web.authentication.HttpStatusEntryPoint
*/
public class HttpStatusEntryPointCustom implements AuthenticationEntryPoint {
protected final Log logger = LogFactory.getLog(getClass());
private final HttpStatus httpStatus;
/**
* Creates a new instance.
*
* @param httpStatus the HttpSatus to set
*/
public HttpStatusEntryPointCustom(HttpStatus httpStatus) {
Assert.notNull(httpStatus, "httpStatus cannot be null");
this.httpStatus = httpStatus;
}
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
if (logger.isTraceEnabled()) {
logger.trace(authException.getMessage(), authException);
}
else if (logger.isWarnEnabled()) {
logger.warn(authException.getMessage());
}
response.setStatus(this.httpStatus.value());
response.getWriter().flush();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy