| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.whyc.mapper.*; |
| | | import com.whyc.pojo.Permission; |
| | | import com.whyc.mapper.RolePermissionMapper; |
| | | import com.whyc.mapper.UserMapper; |
| | | import com.whyc.mapper.UserRoleMapper; |
| | | import com.whyc.pojo.User; |
| | | import org.apache.shiro.authz.AuthorizationInfo; |
| | | import org.apache.shiro.authz.SimpleAuthorizationInfo; |
| | | import org.springframework.cache.annotation.CacheConfig; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 处理 shiro认证,授权,和数据库交互 |
| | | */ |
| | | @Service |
| | | //Unified Naming |
| | | @CacheConfig(cacheNames ={"userBridge"}) |
| | | public class UserBridgeService { |
| | | |
| | | @Resource |
| | |
| | | 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,"用户不存在"); |
| | | } |
| | | return userMapper.selectOne(queryWrapper); |
| | | |
| | | } |
| | | |
| | | @Cacheable(key = "#root.methodName+#p0.id") |
| | | public AuthorizationInfo getAuthorizationInfo(User user) { |
| | | System.out.println("=========执行了UserBridgeService.getAuthorization方法=========="); |
| | | SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); |
| | |
| | | return authorizationInfo; |
| | | } |
| | | |
| | | //@Cacheable(key = "#root.methodName+#userId") |
| | | private List<String> findPermissionsByUserId(int userId) { |
| | | List<String> perms = rolePermissionMapper.findPermissionsByUserId(userId); |
| | | return perms; |
| | | } |
| | | |
| | | //@Cacheable(key="#root.methodName+#userId") |
| | | private List<String> findRolesByUserId(int userId) { |
| | | List<String> roles =userRoleMapper.findRolesByUserId(userId); |
| | | //roles.add("dev"); |