如何确保定义了@PreAuthorize?(How to ensure @PreAuthorize has been defined?)
我们使用Spring Security
@PreAuthorize
批注来检查基于Jersey的REST API的正确角色和权限。 我们担心的是我们从某种方法中忘记了注释,使其不安全。有没有办法确保所有API都有注释,即使它只是
@PreAuthorize("permitAll")
(即明确允许所有内容)?我们设想如果API不使用注释,则阻止请求(以便不能使用API)会记录错误(以便我们快速注意到错误)。
一种方法是创建一个自定义表达式,将表示请求的请求属性添加为“安全”。 然后,Web过滤器可以检查请求属性是否到位,如果不是,则记录错误。
有没有更清洁的方法来做到这一点? 例如,将
"denyAll"
设置为未注释方法的默认策略,并且需要根据需要覆盖它?We're using Spring Security
@PreAuthorize
annotation to check proper roles and permissions of Jersey-based REST APIs. What we're worried about is that we forget the annotation from some method, leaving it unsecured.Is there a way to ensure that all APIs have the annotation, even if it is just
@PreAuthorize("permitAll")
(i.e. explicitly permitting everything)?We're envisioning that if an API does not use the annotation, either the request is blocked (so that the API cannot be used) an error is logged (so that we notice the mistake quickly).
One way would be to make a custom expression that adds a request attribute marking the request as "secured". Then a web filter can check that the request attribute is in place and log an error if it is not.
Is there any cleaner way to do this? For example set
"denyAll"
as the default policy for un-annotated methods, and require overriding it as appropriate?
原文:https://stackoverflow.com/questions/37184318
满意答案
您将需要使用InetGet函数来保存PDF并检查URL以查看它是否是PDF文件。
这是一个使用InetGet的简单示例。
InetGet("http://careers.stackoverflow.com/stack_overflow_careers.pdf", @ScriptDir & "\stack_overflow_careers.pdf")
以下是在页面上查找所有PDF URL并下载这些PDF的示例。
#include <IE.au3> #include <Array.au3> DownloadAllPDFs("http://careers.stackoverflow.com/resources/great-job-listing") Func DownloadAllPDFs($URL) Local $oIE = _IECreate($URL) Local $oLinks = _IELinkGetCollection($oIE) Dim $aPDFLinks[1] For $oLink In $oLinks If StringInStr($oLink.href, ".pdf") Then _ArrayAdd($aPDFLinks, $oLink.href) EndIf Next Local $iArraySize = UBound($aPDFLinks) - 1 ConsoleWrite("Number of PDF Files found: " & $iArraySize) ;_ArrayDisplay($aPDFLinks) If $iArraySize > 0 Then For $i = 1 To $iArraySize InetGet($aPDFLinks[$i], @ScriptDir & "\" & $i & ".pdf") Next EndIf EndFunc ;==>DownloadAllPDFs
以下是导航到URL并下载文件(如果是PDF)的示例。
#include <IE.au3> NavigateAndDownload() Func NavigateAndDownload() Local $oIE = _IECreate() _IENavigate($oIE, "http://careers.stackoverflow.com/stack_overflow_careers.pdf", 0) Sleep(5000) $sURL = _IEPropertyGet($oIE, "locationurl") If StringInStr($sURL, ".pdf") Then InetGet($sURL, @ScriptDir & "\test.pdf") EndFunc
You will want to use the InetGet function to save the PDF's and check the URL to see if it is a PDF file.
Here is a simple example using InetGet.
InetGet("http://careers.stackoverflow.com/stack_overflow_careers.pdf", @ScriptDir & "\stack_overflow_careers.pdf")
Here is an example of finding all PDF URL's on a page and downloading those PDF's.
#include <IE.au3> #include <Array.au3> DownloadAllPDFs("http://careers.stackoverflow.com/resources/great-job-listing") Func DownloadAllPDFs($URL) Local $oIE = _IECreate($URL) Local $oLinks = _IELinkGetCollection($oIE) Dim $aPDFLinks[1] For $oLink In $oLinks If StringInStr($oLink.href, ".pdf") Then _ArrayAdd($aPDFLinks, $oLink.href) EndIf Next Local $iArraySize = UBound($aPDFLinks) - 1 ConsoleWrite("Number of PDF Files found: " & $iArraySize) ;_ArrayDisplay($aPDFLinks) If $iArraySize > 0 Then For $i = 1 To $iArraySize InetGet($aPDFLinks[$i], @ScriptDir & "\" & $i & ".pdf") Next EndIf EndFunc ;==>DownloadAllPDFs
Here is an example of navigating to a URL, and downloading the file if it is a PDF.
#include <IE.au3> NavigateAndDownload() Func NavigateAndDownload() Local $oIE = _IECreate() _IENavigate($oIE, "http://careers.stackoverflow.com/stack_overflow_careers.pdf", 0) Sleep(5000) $sURL = _IEPropertyGet($oIE, "locationurl") If StringInStr($sURL, ".pdf") Then InetGet($sURL, @ScriptDir & "\test.pdf") EndFunc
相关问答
更多雄辩 - > first()如果 - > exists()(Eloquent ->first() if ->exists())
仅在属性存在时测试它?(Test a property only if it exists?)
属性'$'的对象(Property '$' of object)
如何从std :: istream测试类读取?(How to test class reading from std::istream?)
读取JavaScript对象中的对象属性值(Reading object property value in JavaScript object)
在javascript中,测试属性是否深深嵌套在对象图中?(In javascript, test for property deeply nested in object graph?)
如何在AutoIt中读取其值之前测试对象上是否存在属性?(How to test if object property exists before reading its value?)
检查是否存在财产(Check if property exists)
NAnt属性:: exists()与新定义的属性?(NAnt property::exists() with newly defined property?)
如何测试Javascript数组中是否存在对象?(How do I test if an object exists in a Javascript array?)
相关文章
更多solrcore.properties定义server是否是master
elasticsearch 口水篇(6) Mapping 定义索引
js 缺少对象
tomcat设置成utf8,怎样确保从用户手动在浏览器里输入的url中的中文参数
Solr与Mysql集成指南
Scala函数定义与调用
Scala定义变量
自己定义的vo对象比较,应该如何实现才能做到高效?
Hadoop 自定义InputFormat实现自定义Split
最新问答
更多在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
Java中的不可变类(Immutable class in Java)
寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
EXCEL VBA 基础教程下载
RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!