Search in sources :

Example 6 with SysMenuInfo

use of tk.ainiyue.danyuan.application.softm.sysmenu.po.SysMenuInfo in project danyuan-application by 514840279.

the class CustomUserDetailsService method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
    SysUserBaseInfo user;
    try {
        user = sysUserBaseService.findByName(userName);
    } catch (Exception e) {
        throw new UsernameNotFoundException("user select fail");
    }
    if (user == null) {
        throw new UsernameNotFoundException("no user found");
    } else {
        try {
            List<SysMenuInfo> menu = sysUserBaseService.getRoleByUser(user.getUuid());
            List<GrantedAuthority> gas = new ArrayList<>();
            if (menu != null) {
                for (SysMenuInfo sysMenuInfo : menu) {
                    gas.add(new SimpleGrantedAuthority(sysMenuInfo.getName()));
                }
            }
            // gas.add(new SwitchUserGrantedAuthority("ROLE_USER", new Authentication()));
            UserDetails users = new User(user.getUserName(), user.getPassword(), true, true, true, true, gas);
            return users;
        } catch (Exception e) {
            throw new UsernameNotFoundException("user role select fail");
        }
    }
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UserDetails(org.springframework.security.core.userdetails.UserDetails) User(org.springframework.security.core.userdetails.User) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SysMenuInfo(tk.ainiyue.danyuan.application.softm.sysmenu.po.SysMenuInfo) ArrayList(java.util.ArrayList) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) SysUserBaseInfo(tk.ainiyue.danyuan.application.user.userbase.po.SysUserBaseInfo)

Aggregations

SysMenuInfo (tk.ainiyue.danyuan.application.softm.sysmenu.po.SysMenuInfo)6 AuthorityzTreeVO (tk.ainiyue.danyuan.application.softm.sysmenu.vo.AuthorityzTreeVO)4 ArrayList (java.util.ArrayList)1 PageRequest (org.springframework.data.domain.PageRequest)1 Sort (org.springframework.data.domain.Sort)1 Order (org.springframework.data.domain.Sort.Order)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 User (org.springframework.security.core.userdetails.User)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 SysRolesJurisdictionInfo (tk.ainiyue.danyuan.application.crm.jurisdiction.po.SysRolesJurisdictionInfo)1 SysRolesJurisdictionInfoPK (tk.ainiyue.danyuan.application.crm.jurisdiction.po.SysRolesJurisdictionInfoPK)1 SysUserBaseInfo (tk.ainiyue.danyuan.application.user.userbase.po.SysUserBaseInfo)1