package your.microservice.core.security.idp.security;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import your.microservice.core.security.idp.model.base.YourEntity;
import your.microservice.core.security.idp.model.security.YourMicroserviceUserDetails;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedCredentialsNotFoundException;
import org.springframework.stereotype.Service;
import your.microservice.core.security.idp.repository.IdentityProviderEntityManager;

/**
 * YourMicroserviceUserDetailsService
 *
 * @author jeff.a.schenk@gmail.com
 */
@Service
public class YourMicroserviceUserDetailsService implements UserDetailsService {
    /**
     * Common Logger
     */
    protected final static org.slf4j.Logger LOGGER =
            LoggerFactory.getLogger(YourMicroserviceUserDetailsService.class);
    /**
     * Entity Manager
     */
    @Autowired
    private IdentityProviderEntityManager identityProviderEntityManager;

    @Override
    public UserDetails loadUserByUsername(String uName) throws UsernameNotFoundException {
        if (uName == null || uName.isEmpty()) {
            throw new PreAuthenticatedCredentialsNotFoundException("No User Email Address Supplied for Obtaining User, Ignoring!");
        }
        LOGGER.info("Authenticating:[{}]",uName);
        YourEntity yourEntity = identityProviderEntityManager.findYourEntityByEmail(uName);
        if (yourEntity == null) {
            LOGGER.warn("YourEntity Object Not Found based Upon Email:[{}]",uName);
            throw new UsernameNotFoundException("No User with email address '" + uName + "' could be found.");
        }
        LOGGER.info("YourEntity Object Found based Upon Email:[{}]",uName);
        return new YourMicroserviceUserDetails(yourEntity);
    }
}

@@ -757,16 +757,61 @@
 nager;%0A%0A
+import javax.persistence.NoResultException;%0A%0A
 /**%0A * Y
@@ -1376,16 +1376,55 @@
 ption %7B%0A
+        YourEntity yourEntity =  null;%0A
         
@@ -1597,32 +1597,50 @@
 g!%22);%0A        %7D%0A
+        try %7B%0A    
         LOGGER.i
@@ -1661,24 +1661,25 @@
 ating:%5B%7B%7D%5D%22,
+ 
 uName);%0A    
@@ -1678,34 +1678,27 @@
 e);%0A        
-YourEntity
+   
  yourEntity 
@@ -1763,24 +1763,28 @@
 e);%0A        
+    
 if (yourEnti
@@ -1793,32 +1793,187 @@
  == null) %7B%0A    
+            raiseNotFoundCondition(uName);%0A            %7D%0A        %7D catch(NoResultException nre) %7B%0A                raiseNotFoundCondition(uName);%0A        %7D%0A
         LOGGER.w
@@ -1975,12 +1975,12 @@
 GER.
-warn
+info
 (%22Yo
@@ -1999,12 +1999,8 @@
 ect 
-Not 
 Foun
@@ -2044,120 +2044,126 @@
     
-    throw new UsernameNotFoundException(%22No User with email address '%22 + uName + %22' could be found.%22);%0A        %7D
+return new YourMicroserviceUserDetails(yourEntity);%0A    %7D%0A    %0A    private void raiseNotFoundCondition(String uName) %7B
 %0A   
@@ -2166,36 +2166,36 @@
 %0A        LOGGER.
-info
+warn
 (%22YourEntity Obj
@@ -2190,32 +2190,36 @@
 urEntity Object 
+Not 
 Found based Upon
@@ -2251,57 +2251,104 @@
     
-return new YourMicroserviceUserDetails(yourEntity
+throw new UsernameNotFoundException(%22No User with email address '%22 + uName + %22' could be found.%22
 );%0A 

Fix Auth on not Found User.