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

com.base4j.mvc.auth.SysUserDetailsService Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
package com.base4j.mvc.auth;

import com.base4j.mvc.sys.entity.SysUser;
import com.base4j.mvc.sys.mapper.SysUserMapper;
import com.base4j.mybatis.base.QueryParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class SysUserDetailsService implements UserDetailsService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (username == null || username.trim().equals("")) {
            throw new UsernameNotFoundException("username maybe is null or empty");
        }
        QueryParams params = new QueryParams(SysUser.class);
        QueryParams.Criteria criteria = params.createCriteria();
        criteria.andEqualTo("username", username);
        SysUser sysUser = sysUserMapper.selectOneByParams(params);
        if (sysUser == null) {
            throw new UsernameNotFoundException("User:" + username + "not found");
        }
        SecurityUser securityUser = new SecurityUser(sysUser);
        return securityUser;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy