16 package org.openkilda.northbound.utils;
25 import org.springframework.http.HttpHeaders;
26 import org.springframework.http.MediaType;
27 import org.springframework.security.core.AuthenticationException;
28 import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
29 import org.springframework.stereotype.Component;
31 import java.io.IOException;
32 import java.util.Optional;
33 import javax.servlet.ServletException;
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.http.HttpServletResponse;
45 private static final String DEFAULT_REALM =
"Kilda";
51 setRealmName(DEFAULT_REALM);
58 public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception)
59 throws IOException, ServletException {
60 String realm = String.format(
"Basic realm=%s", getRealmName());
61 response.addHeader(HttpHeaders.WWW_AUTHENTICATE, realm);
62 response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
63 response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
65 String correlationId = Optional.ofNullable(request.getHeader(CORRELATION_ID)).orElse(DEFAULT_CORRELATION_ID);
68 response.getWriter().print(MAPPER.writeValueAsString(error));
NorthboundBasicAuthenticationEntryPoint()
static final ObjectMapper MAPPER
void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception)
static final String DEFAULT_CORRELATION_ID
static final String CORRELATION_ID