Commit 7dc02a8d authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

added ldap check to the local auth provider

parent 8113e8e8
package lcsb.mapviewer.web.config;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.interfaces.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
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;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
......@@ -20,11 +24,15 @@ public class LocalAuthenticationProvider implements AuthenticationProvider {
private UserDetailsService userDetailsService;
private PasswordEncoder passwordEncoder;
private IUserService userService;
@Autowired
public LocalAuthenticationProvider(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder) {
public LocalAuthenticationProvider(UserDetailsService userDetailsService,
PasswordEncoder passwordEncoder,
IUserService userService) {
this.userDetailsService = userDetailsService;
this.passwordEncoder = passwordEncoder;
this.userService = userService;
}
@PostConstruct
......@@ -35,6 +43,14 @@ public class LocalAuthenticationProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName();
if (username.isEmpty()) {
throw new UsernameNotFoundException("Username must not be empty.");
}
User user = userService.getUserByLogin(username);
if (user == null || user.isConnectedToLdap()) {
throw new InternalAuthenticationServiceException("Provider cannot authenticate user.");
}
return daoAuthenticationProvider.authenticate(authentication);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment