| @@ -0,0 +1,23 @@ | |||||
| package com.iformall.config; | |||||
| import com.iformall.plugin.MultiTenancy; | |||||
| import org.apache.ibatis.reflection.MetaObject; | |||||
| import org.springframework.context.annotation.Bean; | |||||
| import org.springframework.context.annotation.Configuration; | |||||
| import java.util.Properties; | |||||
| @Configuration | |||||
| public class MyBatisConfiguration { | |||||
| @Bean | |||||
| public MultiTenancy multiTenancy() { | |||||
| MultiTenancy multiTenancy = new MultiTenancy(); | |||||
| Properties properties = new Properties(); | |||||
| properties.setProperty("tenantIdColumn", "tenant_id"); | |||||
| properties.setProperty("dialect", "mysql"); | |||||
| properties.setProperty("tenantInfo", "com.iformall.tenant.TenantInfoImpl"); | |||||
| multiTenancy.setProperties(properties); | |||||
| return multiTenancy; | |||||
| } | |||||
| } | |||||
| @@ -41,7 +41,7 @@ public class BaseController { | |||||
| } | } | ||||
| public String getTenantId(){ | public String getTenantId(){ | ||||
| MallUserInfo user = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||||
| return user.getTenantId(); | |||||
| String tenantId = (String)SecurityUtils.getSubject().getSession().getAttribute(UserSession.tenantId); | |||||
| return tenantId; | |||||
| } | } | ||||
| } | } | ||||
| @@ -3,6 +3,7 @@ package com.iformall.shiro; | |||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import com.iformall.service.MallUserInfoService; | import com.iformall.service.MallUserInfoService; | ||||
| import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion; | |||||
| import org.apache.shiro.SecurityUtils; | import org.apache.shiro.SecurityUtils; | ||||
| import org.apache.shiro.authc.AuthenticationException; | import org.apache.shiro.authc.AuthenticationException; | ||||
| import org.apache.shiro.authc.AuthenticationInfo; | import org.apache.shiro.authc.AuthenticationInfo; | ||||
| @@ -18,6 +19,7 @@ import org.apache.shiro.util.ByteSource; | |||||
| import com.iformall.domain.po.MallUserInfo; | import com.iformall.domain.po.MallUserInfo; | ||||
| import com.iformall.service.MallPermissionService; | import com.iformall.service.MallPermissionService; | ||||
| import org.springframework.boot.autoconfigure.security.SecurityProperties; | |||||
| /** | /** | ||||
| * Created by yangqj on 2017/4/21. | * Created by yangqj on 2017/4/21. | ||||
| @@ -68,6 +70,7 @@ public class MyShiroRealm extends AuthorizingRealm { | |||||
| Session session = SecurityUtils.getSubject().getSession(); | Session session = SecurityUtils.getSubject().getSession(); | ||||
| session.setAttribute(UserSession.userInfo, user); | session.setAttribute(UserSession.userInfo, user); | ||||
| session.setAttribute(UserSession.userId, user.getId()); | session.setAttribute(UserSession.userId, user.getId()); | ||||
| session.setAttribute(UserSession.tenantId, user.getTenantId()); | |||||
| return authenticationInfo; | return authenticationInfo; | ||||
| } | } | ||||
| @@ -6,4 +6,6 @@ public class UserSession { | |||||
| public static String userId ="userSessionId"; | public static String userId ="userSessionId"; | ||||
| public static String tenantId ="TENANT_ID"; | |||||
| } | } | ||||
| @@ -0,0 +1,74 @@ | |||||
| package com.iformall.tenant; | |||||
| import com.iformall.plugin.TenantInfo; | |||||
| import com.iformall.shiro.UserSession; | |||||
| import org.apache.ibatis.mapping.MappedStatement; | |||||
| import org.apache.shiro.SecurityUtils; | |||||
| import org.apache.shiro.session.InvalidSessionException; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| public class TenantInfoImpl implements TenantInfo { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Override | |||||
| public String getTenantId() { | |||||
| String tenantId = ""; | |||||
| try { | |||||
| tenantId = (String) SecurityUtils.getSubject().getSession().getAttribute(UserSession.tenantId); | |||||
| } catch (InvalidSessionException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return tenantId; | |||||
| } | |||||
| @Override | |||||
| public boolean doTableFilter(String tableName) { | |||||
| if ("mall_permission".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("mall_user_role".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_channel".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_business".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_coupon_type".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_game_template".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_group".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_mall_apply".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_tags".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_tags_group".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_tags_type".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_user_channel".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| // wx_profit_sharing_receiver | |||||
| // wx_profit_sharing_result | |||||
| return false; | |||||
| } | |||||
| @Override | |||||
| public boolean doMappedStatementFIlter(MappedStatement ms) { | |||||
| if ("com.iformall.mapper.MallUserInfoMapper.selectByUserName".equals(ms.getId())) | |||||
| return true; | |||||
| return false; | |||||
| } | |||||
| } | |||||
| @@ -68,11 +68,9 @@ public class BaseController { | |||||
| } | } | ||||
| public String getTenantId() { | public String getTenantId() { | ||||
| Long bUserId = getUserId(); | |||||
| WxMerchantBUser user = wxMerchantBUserService.getById(bUserId); | |||||
| if (user == null) | |||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
| return user.getTenantId(); | |||||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||||
| String tenantId = (String) request.getAttribute(AuthorizationInterceptor.TENANT_ID); | |||||
| return tenantId; | |||||
| } | } | ||||
| public WxAppinfo getAppInfo(String appId) { | public WxAppinfo getAppInfo(String appId) { | ||||
| @@ -10,6 +10,8 @@ import java.util.Map; | |||||
| public interface MallUserInfoMapper extends CommonMapper<MallUserInfo, String> { | public interface MallUserInfoMapper extends CommonMapper<MallUserInfo, String> { | ||||
| List<MallUserInfo> findList(MallUserInfo mallUserInfo); | List<MallUserInfo> findList(MallUserInfo mallUserInfo); | ||||
| MallUserInfo selectByUserName(@Param("username") String username); | |||||
| Integer hasButtonPermission(@Param("userId") Long userId, @Param("permission") String permission); | Integer hasButtonPermission(@Param("userId") Long userId, @Param("permission") String permission); | ||||
| @@ -74,9 +74,7 @@ public class MallUserInfoServiceImpl implements MallUserInfoService { | |||||
| @Override | @Override | ||||
| public MallUserInfo getByUsername(String username) { | public MallUserInfo getByUsername(String username) { | ||||
| MallUserInfo userInfo = new MallUserInfo(); | |||||
| userInfo.setUsername(username); | |||||
| return mallUserInfoMapper.selectOne(userInfo); | |||||
| return mallUserInfoMapper.selectByUserName(username); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -88,6 +88,14 @@ | |||||
| select <include refid="allColumns" /> from mall_user_info | select <include refid="allColumns" /> from mall_user_info | ||||
| <include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
| </select> | </select> | ||||
| <select id="selectByUserName" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from mall_user_info | |||||
| where 1=1 | |||||
| <if test=" null != username "> | |||||
| and username=#{username} | |||||
| </if> | |||||
| </select> | |||||
| <select id="hasButtonPermission" resultType="java.lang.Integer"> | <select id="hasButtonPermission" resultType="java.lang.Integer"> | ||||
| SELECT 1 | SELECT 1 | ||||