package ink.wgink.common.service.access.impl;

import ink.wgink.common.manager.access.WhiteListManager;
import ink.wgink.common.service.access.IAccessService;
import ink.wgink.common.service.rbac.IRbacService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: AccessWhiteListServiceImpl
 * @Description: 访问白名单
 * @Author: wanggeng
 * @Date: 2022/7/27 11:03
 * @Version: 1.0
 */
@Service("accessWhiteList")
public class AccessServiceImpl implements IAccessService {

    @Autowired
    private IRbacService rbacService;

    @Override
    public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
        boolean isAccess = WhiteListManager.getInstance().isMatch(request.getRequestURI().replace(request.getContextPath(), ""));
        if (isAccess) {
            return true;
        }
        return rbacService.hasPermission(request, authentication);
    }
}
