package com.cm.common.plugin.oauth.service.rbac.impl;

import com.cm.common.plugin.oauth.service.rbac.IClientRbacService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: ClientRbacServiceImpl
 * @Description: 客户端RBAC权限校验
 * @Author: WangGeng
 * @Date: 2019/11/11 3:27 下午
 * @Version: 1.0
 **/
@Component("clientRbacService")
public class ClientRbacServiceImpl implements IClientRbacService {

    @Override
    public boolean hasPermission(HttpServletRequest request, Authentication authentication) {
        boolean hasPermission = false;
        Object principal = authentication.getPrincipal();
        if (Objects.isNull(principal) || StringUtils.equals("anonymousUser", principal.toString())) {
            return false;
        }
        return true;
    }

}
