All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.security.web.authentication.LoggingHttpStatusEntryPoint Maven / Gradle / Ivy

The newest version!
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 LoggingHttpStatusEntryPoint implements AuthenticationEntryPoint {
  protected final Log logger = LogFactory.getLog(getClass());
  private final HttpStatus httpStatus;

  /**
   * Creates a new instance.
   *
   * @param httpStatus the HttpSatus to set
   */
  public LoggingHttpStatusEntryPoint(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());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy