| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.whyc.config.CaffeineConfig; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.Permission; |
| | | import com.whyc.pojo.User; |
| | | import com.whyc.pojo.UserInf; |
| | | import org.apache.shiro.authz.AuthorizationInfo; |
| | | import org.apache.shiro.authz.SimpleAuthorizationInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.cache.Cache; |
| | | import org.springframework.cache.CacheManager; |
| | | import org.springframework.cache.annotation.CacheConfig; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.cache.caffeine.CaffeineCache; |
| | | import org.springframework.context.annotation.DependsOn; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.core.annotation.AliasFor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | private UserMapper userMapper; |
| | | |
| | | @Resource |
| | | private UserRoleMapper userRoleMapper; |
| | | |
| | | @Resource |
| | | private RolePermissionMapper rolePermissionMapper; |
| | | |
| | | @Resource |
| | | private CacheManager caffeineCacheManager; |
| | | |
| | | public User findPasswordAndSlatByUserName(String userName) { |
| | | QueryWrapper<User> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("id","name","password","salt").eq("name",userName); |
| | | try{ |
| | | return userMapper.selectOne(queryWrapper); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new User(0,"用户不存在"); |
| | | } |
| | | public UserInf findPasswordByUserName(String userName) { |
| | | UserInf userInf = null; |
| | | QueryWrapper<UserInf> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("uId","uName","upassword","UKey_ID","uRole","uSex","uMobilephone","uEmail","uAddr","uDepartment","uBirthDay").eq("uName",userName); |
| | | userInf = userMapper.selectOne(queryWrapper); |
| | | |
| | | return userInf==null?new UserInf(0L,"用户不存在"):userInf; |
| | | } |
| | | |
| | | public UserInf findUserByMobilephone(String mobilephone){ |
| | | QueryWrapper<UserInf> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("uId","uName","upassword","UKey_ID","uRole","uMobilephone").eq("uMobilephone",mobilephone); |
| | | List<UserInf> list = userMapper.selectList(queryWrapper); |
| | | return list.size()==0?new UserInf(0L,"用户不存在"):list.get(0); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | //@Cacheable(key = "#root.methodName+#p0.id") |
| | | public AuthorizationInfo getAuthorizationInfo(User user) { |
| | | public AuthorizationInfo getAuthorizationInfo(UserInf user) { |
| | | System.out.println("=========执行了UserBridgeService.getAuthorization方法=========="); |
| | | SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); |
| | | //添加Roles和Permissions |
| | | List<String> roles = findRolesByUserId(user.getId()); |
| | | List<String> perms = findPermissionsByUserId(user.getId()); |
| | | //List<String> roles = findRolesByUserId(user.getUId()); |
| | | //List<String> perms = findPermissionsByUserId(user.getUId()); |
| | | |
| | | authorizationInfo.addRoles(roles); |
| | | authorizationInfo.addStringPermissions(perms); |
| | | //authorizationInfo.addRoles(roles); |
| | | //authorizationInfo.addStringPermissions(perms); |
| | | return authorizationInfo; |
| | | } |
| | | |
| | | private List<String> findPermissionsByUserId(int userId) { |
| | | List<String> perms = rolePermissionMapper.findPermissionsByUserId(userId); |
| | | return perms; |
| | | /* private List<String> findPermissionsByUserId(Long userId) { |
| | | *//* List<String> perms = rolePermissionMapper.findPermissionsByUserId(userId); |
| | | return perms;*//* |
| | | return null; |
| | | } |
| | | |
| | | private List<String> findRolesByUserId(int userId) { |
| | | List<String> roles =userRoleMapper.findRolesByUserId(userId); |
| | | private List<String> findRolesByUserId(Long userId) { |
| | | //List<String> roles =userRoleMapper.findRolesByUserId(userId); |
| | | //roles.add("dev"); |
| | | return roles; |
| | | } |
| | | return null; |
| | | }*/ |
| | | } |