JAVA-15014 Renamed httpclient4 to apache-httpclient4 (#13516)

This commit is contained in:
Dhawal Kapil
2023-02-24 12:56:20 +05:30
committed by GitHub
parent 000e3f0ebb
commit 90b76a3439
30 changed files with 5 additions and 5 deletions

View File

@@ -0,0 +1,30 @@
package com.baeldung.basic;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
import org.springframework.stereotype.Component;
@Component
public class MyBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
@Override
public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException {
response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\"");
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
final PrintWriter writer = response.getWriter();
writer.println("HTTP Status " + HttpServletResponse.SC_UNAUTHORIZED + " - " + authException.getMessage());
}
@Override
public void afterPropertiesSet() {
setRealmName("Baeldung");
super.afterPropertiesSet();
}
}