I am trying to implement logout for site with basic authentication with spring boot. The below solution works only for chrome not working in firefox
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Override
public void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/js/**", "/fonts/**", "/css/**", "/images/**", "/againlogin**")
.permitAll()
.anyRequest()
.fullyAuthenticated()
.and().httpBasic()
.and().csrf().disable();
}
}
From html I trigger ajax call for logout
<a href="javascript:logoutUser()">Logout</a>
In Javascript
function logoutUser() {
ClearAuthentication("/againlogin.html");
}
function ClearAuthentication(LogOffPage)
{
var IsInternetExplorer = false;
try
{
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("msie") != -1) { IsInternetExplorer = true; }
}
catch(e)
{
IsInternetExplorer = false;
};
if (IsInternetExplorer)
{
// Logoff Internet Explorer
document.execCommand("ClearAuthenticationCache");
window.location = LogOffPage;
}
else
{
// Logoff every other browsers
$.ajax({
username: 'unknown',
password: 'WrongPassword',
url: '/logout',
type: 'GET',
beforeSend: function(xhr)
{
xhr.setRequestHeader("Authorization", "Basic AAAAAAAAAAAAAAAAAAA=");
},
error: function(err)
{
window.location = LogOffPage;
}
});
}
}
I am not getting logged out.
Can some help me fix this issue