Custom security service using annotation Spring Boot

Custom security service using annotation Spring Boot:

Create our security service

package com.yamicode.utils;

//service that you should replace with your implementation
import com.yamicode.domain.User;
import com.yamicode.service.UserService;

//java imports
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("YamiSecurityService")
public class YamiSecurityService {

    @Autowired
    UserService userService;

    public boolean isNotForbidden(){
    	//replace this by your security implementation of user
        User user = userService.getAuthenticatedUser();

        //test: you can do whatever you want to do
        return !user.isForbidden();
    }
}

Usage

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.web.bind.annotation.*;

@CrossOrigin("*")
@RestController
@RequestMapping(value = "/api/yamicode")
public class YamiCodeRest{

	@GetMapping("")
    @PostAuthorize("@YamiSecurityService.isNotForbidden()")
    void getResource() {
        //wathever you planning to do
    }

}