/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
apache-httpclient4/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java
30 строк
1 KB
Dhawal Kapil
JAVA-15014 Renamed httpclient4 to apache-httpclient4 (#13516)
24 фев 2023, 10:26
24 фев 2023, 10:26
3f9b886
Код
Авторство
О чём код?
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(); } }