io.lsn.spring.auth.middleware.HttpStatusEntryPoint Maven / Gradle / Ivy
package io.lsn.spring.auth.middleware;
import io.lsn.spring.auth.configuration.properties.SecurityProperties;
import io.lsn.spring.auth.transport.cookie.CookieAuthHelper;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class HttpStatusEntryPoint implements AuthenticationEntryPoint {
private SecurityProperties.TransportMethod transportMethod;
public HttpStatusEntryPoint(SecurityProperties.TransportMethod transportMethod) {
this.transportMethod = transportMethod;
}
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
response.setStatus(HttpStatus.UNAUTHORIZED.value());
if (SecurityProperties.TransportMethod.COOKIE.equals(transportMethod)) {
response.addCookie(CookieAuthHelper.buildCookie(request, null, true));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy