WebUserAuthenticationProvider.java
/*
* Copyright 2026 Global Crop Diversity Trust
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root folder or http://www.apache.org/licenses/LICENSE-2.0
*/
package org.gringlobal.custom.security;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetailsService;
/**
* A wrapper class for {@link DaoAuthenticationProvider} which allows us to provide
* another implementation of {@link UserDetailsService}.
*
* Don't override logic of {@link DaoAuthenticationProvider}!
*
* @author Maxym Borodenko
*/
public class WebUserAuthenticationProvider extends DaoAuthenticationProvider {
public WebUserAuthenticationProvider() {
super();
}
// FIXME looks hacky
@Override
public Authentication authenticate(Authentication auth) throws AuthenticationException {
// we use logic of DaoAuthenticationProvider so we need UsernamePasswordAuthenticationToken
var token = new UsernamePasswordAuthenticationToken(auth.getPrincipal(), auth.getCredentials());
return super.authenticate(token);
}
@Override
public boolean supports(Class<?> authentication) {
return WebUserAuthenticationToken.class.isAssignableFrom(authentication);
}
}