Package com.jpoweredcart.common.security

Source Code of com.jpoweredcart.common.security.AffiliateUserDetailService

package com.jpoweredcart.common.security;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.jpoweredcart.common.entity.sale.Affiliate;
import com.jpoweredcart.common.service.UserService;

public class AffiliateUserDetailService implements UserDetailsService {

  private static final Logger logger = LoggerFactory.getLogger(AffiliateUserDetailService.class);
 
  @Inject
  private UserService userService;
 
  @Override
  public UserDetails loadUserByUsername(String email)
      throws UsernameNotFoundException {
    try{
      Affiliate affiliate = userService.getAffiliateByEmail(email);
      if(affiliate==null) throw new EmptyResultDataAccessException(1);
     
      CartUserDetails userDetails = new CartUserDetails();
      userDetails.userId = affiliate.getId();
      userDetails.salt = affiliate.getSalt();
      userDetails.password = affiliate.getPassword();
      userDetails.username = affiliate.getEmail();
      userDetails.enabled = affiliate.getStatus()==1;
     
      logger.debug("Found user email={}, enabled={}", email, userDetails.enabled);
     
      return userDetails;
     
    }catch(EmptyResultDataAccessException e){
      logger.debug("Email: {} not found", email);
      throw new UsernameNotFoundException(email+" not found");
    }
  }
 
}
TOP

Related Classes of com.jpoweredcart.common.security.AffiliateUserDetailService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.