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

com.netgrif.application.engine.auth.service.LdapUserDetailsService Maven / Gradle / Ivy

Go to download

System provides workflow management functions including user, role and data management.

There is a newer version: 6.3.3
Show newest version
package com.netgrif.application.engine.auth.service;

import com.netgrif.application.engine.auth.domain.IUser;
import com.netgrif.application.engine.auth.domain.LoggedUser;
import com.netgrif.application.engine.auth.domain.UserState;
import com.netgrif.application.engine.ldap.domain.LdapUser;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

@ConditionalOnExpression("${nae.ldap.enabled:false}")
public class LdapUserDetailsService extends UserDetailsServiceImpl {

    @Override
    protected LoggedUser getLoggedUser(String email) throws UsernameNotFoundException {
        IUser user = userRepository.findByEmail(email);
        if(user == null) {
            throw new UsernameNotFoundException("No user was found for login: " + email);
        } else if (user.getState() != UserState.ACTIVE) {
            throw new UsernameNotFoundException("User with login "+email+" cannot be logged in!");
        } else if (user instanceof LdapUser) {
            throw new UsernameNotFoundException("Ldap has not verified the user " + email + "!");
        }

        return user.transformToLoggedUser();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy