如何确保定义了@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()方法不像原始问题中描述的那样引发异常。 如果您遇到这种异常,代码中会出现另一个错误。 用户first()的正确方法并检查结果: $user = User::where('mobile', Input::get('mobile'))->first(); // model or null if (!$user) { // Do stuff if it doesn't exist. } 其他技术(不推荐,不必要的开销): $user = User::where('mobile', In ...
-
仅在属性存在时测试它?(Test a property only if it exists?)[2023-01-18]
响应没有msgs [0]属性 这是不正确的。 它抛出一个错误,因为它没有msgs属性,不是因为它没有0属性。 在测试0之前,您需要测试msgs存在。 if (response.msgs && response.msgs[0] === "published") { ... } response does not have a msgs[0] property This is incorrect. It throws an error because it doesn't have a msgs proper ... -
属性'$'的对象(Property '$' of object)[2022-07-06]
尝试在document.ready的顶部添加jQuery.noConflict() 。 这将取消绑定$变量,这应该摆脱你的冲突。 回应我们在评论中的讨论,并帮助其他人看到这个问题,这里有一些概述: jQuery和jQuery.noConflicts()如何工作: 当你加载jQuery库时,会创建一个名为jQuery的变量,它代表“jQuery”函数。 还创建了名为$ jQuery的别名。 无论出于何种原因,其他几个javascript库都会更改$ alias来表示自己的函数。 当发生这种情况时,你会发生冲突 ... -
使用依赖注入将类std::istringstream的对象std::istringstream给对象。 为您的类创建一个构造函数,该构造函数接受一个额外的std::istream &参数并将其分配给此类型的成员。 例如: MyClass { public: MyClass(std::istream &stream, /* other constructor args */) : stream_(stream) { ... } ... ...
-
result是一个包含一个对象的数组。 用这个: result[0].username result is an array with one object in it. Use this: result[0].username
-
在javascript中,测试属性是否深深嵌套在对象图中?(In javascript, test for property deeply nested in object graph?)[2024-02-09]
function isset(obj, propStr) { var parts = propStr.split("."); var cur = obj; for (var i=0; i如何在AutoIt中读取其值之前测试对象上是否存在属性?(How to test if object property exists before reading its value?)[2023-06-21]
您将需要使用InetGet函数来保存PDF并检查URL以查看它是否是PDF文件。 这是一个使用InetGet的简单示例。 InetGet("http://careers.stackoverflow.com/stack_overflow_careers.pdf", @ScriptDir & "\stack_overflow_careers.pdf") 以下是在页面上查找所有PDF URL并下载这些PDF的示例。 #include#include Download ... 检查是否存在财产(Check if property exists)[2023-08-04]
使用__isset()和isset() : public function __isset($key) { return isset($this->vars[$key]); } $test = new Test; $test->myvar = 'yay!'; if (isset($test->myvar)) { } Use __isset() and isset(): public function __isset($key) { return isset($this->vars[ ...在调用property::exists需要引用属性的名称。 所以就是这样:我怀疑你的问题在于你使用jQuery的filter方法的方式: var thisIsAvailable = $(assignedHours).filter(function(){ return assignedHours.hour == thisHour && assignedHours.date == day.date.toString("yyyy-MM-dd"); }); 如果我没弄错的话, assignedHours.hour将始终未定义,因为它总是引用你的assignedHours数组(你 ...相关文章
更多- solrcore.properties定义server是否是master
- elasticsearch 口水篇(6) Mapping 定义索引
- js 缺少对象
- tomcat设置成utf8,怎样确保从用户手动在浏览器里输入的url中的中文参数
- Solr与Mysql集成指南
- Scala函数定义与调用
- Scala定义变量
- Lua 函数定义与使用
- 自己定义的vo对象比较,应该如何实现才能做到高效?
- Hadoop 自定义InputFormat实现自定义Split
最新问答
更多- Runnable上的NetworkOnMainThreadException(NetworkOnMainThreadException on Runnable)
- C ++ 11 + SDL2 + Windows:多线程程序在任何输入事件后挂起(C++11 + SDL2 + Windows: Multithreaded program hangs after any input event)
- AccessViolationException未处理[VB.Net] [Emgucv](AccessViolationException was unhandled [VB.Net] [Emgucv])
- 计算时间和日期差异(Calculating Time and Date difference)
- 以编程方式标签NSMutableAttributedString swift 4(Label NSMutableAttributedString programmatically swift 4)
- C#对象和代码示例(C# objects and code examples)
- 在python中是否有数学nCr函数?(Is there a math nCr function in python? [duplicate])
- 检索R中列的最大值和第二个最大值的行名(Retrieve row names of maximum and second maximum values of a column in R)
- 给定md5哈希时如何查找特定文件(How to find specific file when given md5 Hash)
- Python字典因某些原因引发KeyError(Python Dictionary Throwing KeyError for Some Reason)
- 如何让Joomla停止打开新标签中的每个链接?(How do I get Joomla to stop opening every link in a new tab?)
- DNS服务器上的NS记录不匹配(Mismatched NS records at DNS server)
- Python屏幕捕获错误(Python screen capture error)
- 如何在帧集上放置div叠加?(How to put a div overlay over framesets?)
- 页面刷新后是否可以保留表单(html)内容数据?(Is it possible to retain the form(html) content data after page refreshed?)
- 使用iTeardownMyAppFrame和iStartMyAppInAFrame在OPA5测试中重新启动应用程序超时(Restart app within OPA5 test using iTeardownMyAppFrame and iStartMyAppInAFrame timed out)
- 自动拆分文本内容到列(Automatically splitting text content into even columns)
- 在r中的循环中将模型名称分配给gbm.step(assigning model names to gbm.step in loop in r)
- 昆明哪里有电脑等级考试二级C培训?
- C ++模板实例化,究竟是什么意思?(C++ template instantiation, what exactly does it mean?)
- 帮助渲染来自fields_for的部分内容(Help to render a partial from fields_for)
- 将url.action作为json对象返回mvc(return url.action as json object mvc)
- 使用.BAT中的.application文件类型运行ac#Console App(Run a c# Console App with .application file type from a .BAT)
- 将bindingRedirect添加到.Net标准库(Adding a bindingRedirect to a .Net Standard library)
- Laravel版本升级会影响您的控制器吗?(Laravel version upgrade affects your controller?)
- imaplib.error:命令SEARCH在状态AUTH中非法,只允许在SELECTED状态(imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED)
- 如何在eclipse debug impala前端
- 如何通过Ajax API处理多个请求?(How to handle multiple requests through an Ajax API? [closed])
- 使用Datetime索引来分析数据框数据(Using Datetime indexing to analyse dataframe data)
- JS 实现一个菜单效果