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

com.sap.hcp.cf.logging.sample.springboot.security.SampleAppAuthenticationEntryPoint Maven / Gradle / Ivy

package com.sap.hcp.cf.logging.sample.springboot.security;

import java.io.IOException;

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;

/**
 * Customization for failing authentication.
 */
@Component
public class SampleAppAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {

	private static final String REALM_NAME = "Logging-Sample";

	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException authException) throws IOException {
		response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName());
		response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
		response.getWriter().println("HTTP Status 401 - " + authException.getMessage());
	}

	@Override
	public void afterPropertiesSet() {
		setRealmName(REALM_NAME);
		super.afterPropertiesSet();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy