预批注没有任何区别

时间:2019-12-27 07:37:38

标签: spring-boot spring-security

我有一个休息控制器,如下所示:

package excel_reader;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelReader2d {
    ExcelReader link = new ExcelReader();
    Scanner scan = new Scanner(System.in);

    // instance data
    private static int numberGrid[][] = null;
    private static String stringGrid[][] = null;

    // constructor
    public ExcelReader2d(String desLink) {

    }

    // methods
    public void ExeScan() throws FileNotFoundException, IOException {
        Scanner scan = new Scanner(System.in);
        XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream("C:\\Users\\Sonic\\Desktop\\20191223 IMPORTS.xlsx"));

        XSSFSheet sheet = workbook.getSheetAt(0);
        final int rowStart = Math.min(15, sheet.getFirstRowNum()), rowEnd = Math.max(1400, sheet.getLastRowNum());

        System.out.print("Enter the rows that you want to search for: (for ex. the rows that stores customer's name) ");
        int searchRows = scan.nextInt();
        System.out.print("Enter the customer's name that you are looking for: ");
        String name = scan.nextLine();
        //int rowNum;

        // Search given row
        XSSFRow row = sheet.getRow(searchRows);
        try {
            for (int j = 4; j < rowEnd; j++) {
                Row r = sheet.getRow(j);
                if (name.equalsIgnoreCase(name)) {
                    row.getCell(j).getStringCellValue();
                }

                // skip to next iterate if that specific cell is empty
                if (r == null)
                    continue;

            }
        } catch (Exception e){
            System.out.println("Something went wrong.");
        }



    }

}

安全配置如下:

@RestController
@RequestMapping("/payments")
public class RestController {
    @Autowired
    PaymentService paymentService;
    @Autowired
    private Environment env;

    @PostMapping("/create")
    @PreAuthorize("isAuthenticated()")
    public ResponseEntity<String> create(@Valid @RequestBody DownPayment downpayment) {

        Customer customer;
        Charge charge;
        User user = new User();
       ............
   }


}

我想使用preAuthorize注释(方法级别)代替http安全性。付款/创建终结点是可公开访问的,可以正常运行而不会引发任何未经授权的错误。

0 个答案:

没有答案