package com.cf.imes.module.system.dal.redis.listener;

import com.cf.imes.framework.mq.redis.core.pubsub.AbstractRedisSimpleMessageListener;
import com.cf.imes.framework.security.core.service.SecurityFrameworkService;
import com.cf.imes.module.system.dal.redis.RedisRefreshChannelTopicConstants;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.stereotype.Component;

/**
 * system PERMISSION_REFRESH redis监听器
 *
 * @author Gqr
 * @since 2024/6/13 10:32
 */
@Component
public class SystemPermissionRefreshRedisListener extends AbstractRedisSimpleMessageListener {

    private final SecurityFrameworkService securityFrameworkService;

    public SystemPermissionRefreshRedisListener(SecurityFrameworkService securityFrameworkService) {
        super.setTopic(new ChannelTopic(RedisRefreshChannelTopicConstants.PERMISSION_REFRESH));
        this.securityFrameworkService = securityFrameworkService;
    }

    @Override
    public void onMessage(Message message, byte[] bytes) {
        securityFrameworkService.invalidateAll();
    }
}
