简体   繁体   English

Spring 中的方法安全性

[英]Method security in Spring Security

I have a question regarding using Spring Security to protect against SQL injection.我有一个关于使用 Spring Security 来防止 SQL 注入的问题。 First of all, I know that use prepared statement can protect from any SQL injection.首先,我知道使用准备好的语句可以防止任何 SQL 注入。 But In my project I want to show that use Spring Security could help to protect or mitigate against this kind of attack.但在我的项目中,我想展示使用 Spring Security 可以帮助保护或减轻这种攻击。 what i did so far, i made connection using JDBC & Spring and I applied Spring Security and every thing is fine.到目前为止,我做了什么,我使用 JDBC 和 Spring 建立了连接,并应用了 Spring 安全性,一切都很好。 My question is in my project i used two ways to protect against SQL injection.我的问题是在我的项目中,我使用了两种方法来防止 SQL 注入。 The first one is Santizing user input and the second one is using Spring Security.第一个是清理用户输入,第二个是使用 Spring 安全性。 I could pass malicious input through Sanitizaing and I want to show that the role of spring security.我可以通过 Sanitizaing 传递恶意输入,我想证明 spring 安全性的作用。 for example, I pass this input:例如,我通过这个输入:

TV' UNION SELECT credit_no From credit;--

In this case how I can tell Spring security that it doesnot give any users the credit number.在这种情况下,我怎么能告诉 Spring 安全它不给任何用户信用号码。 By the way, I used method security level.顺便说一句,我使用了方法安全级别。 Just I want to give me an easy way to analyze the user input to see If it has access to data which he asked such as credit.只是我想给我一个简单的方法来分析用户输入,看看它是否可以访问他要求的数据,例如信用。

I hope that clear我希望清楚

Well, your question is not 100% clear, and it may vary on your architecture, but pre post annotations can work well to grab user input.好吧,您的问题不是 100% 清楚,并且可能因您的架构而异,但pre post annotations可以很好地获取用户输入。
You can create your own permission evaluator and check permission for pre authorization in your methods.您可以创建自己的权限评估器并在您的方法中检查预授权的权限。

@PostFilter("hasPermission(filterObject, 'customoperation')")
public CreditCard getCreditCard(String userInput) {
    //
}

and your hasPermission method (that you've read about in the link above) goes something like:并且您的hasPermission方法(您已在上面的链接中阅读过)类似于:

public boolean hasPermission(Authentication authentication,
        Object target, Object permission) {
    if ("customoperation".equals(permission)) {
        //your logic here, returning true or false, filtering the object
    }
    return false;
}

You can also extend the expression handler to use custom functions.您还可以扩展表达式处理程序以使用自定义函数。 Check this answer .检查这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM