package com.jkcredit.invoice.hub.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

import java.io.Serializable;

/**
 * @description:
 * @author: xusonglin
 * @create: 2020/1/8 23:20
 * @version: V1.0
 **/
@Configuration
public class MyPermissionEvaluator implements PermissionEvaluator {
    @Override
    public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
        boolean accessible = false;
        String privilege = targetDomainObject + ":" + permission;
        for (GrantedAuthority authority : authentication.getAuthorities()) {
            if (privilege.equalsIgnoreCase(authority.getAuthority())) {
                accessible = true;
                break;
            }
        }
        return accessible;
    }

    @Override
    public boolean hasPermission(Authentication authentication, Serializable serializable, String s, Object o) {
        return false;
    }
}
