如何确保定义了@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
2024-03-26 11:03

满意答案

您将需要使用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())

注意: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...

仅在属性存在时测试它?(Test a property only if it exists?)

响应没有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 p...

属性'$'的对象(Property '$' of object)

尝试在document.ready的顶部添加jQuery.noConflict() 。 这将取消绑定$变量,这应该摆脱你的冲突。 回应我们在评论中的讨论,并帮助其他人看到这个问题,这里有一些概述: jQuery和jQuery.noConflicts()如何工作: 当你加载jQuery库时,会创建一个名为jQuery的变量,它代表“jQuery”函数。 还创建了名为$ jQuery的别名。 无论出于何种原因,其他几个javascript库都会更改$ alias来表示自己的函数。 当发生这种情况时,你...

如何从std :: istream测试类读取?(How to test class reading from std::istream?)

使用依赖注入将类std::istringstream的对象std::istringstream给对象。 为您的类创建一个构造函数,该构造函数接受一个额外的std::istream &参数并将其分配给此类型的成员。 例如: MyClass { public: MyClass(std::istream &stream, /* other constructor args */) : stream_(stream) { ... } ......

读取JavaScript对象中的对象属性值(Reading object property value in JavaScript object)

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?)

function isset(obj, propStr) { var parts = propStr.split("."); var cur = obj; for (var i=0; i<parts.length; i++) { if (!cur[parts[i]]) return false; cur = cur[parts[i]]; } return true; } 请注意,第二个参数是一个字符串...

如何在AutoIt中读取其值之前测试对象上是否存在属性?(How to test if object property exists before reading its value?)

您将需要使用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> Dow...

检查是否存在财产(Check if property exists)

使用__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->...

NAnt属性:: exists()与新定义的属性?(NAnt property::exists() with newly defined property?)

在调用property::exists需要引用属性的名称。 所以就是这样: <if test="${not property::exists('testprop')}"> <echo message="property doesn't exists... WTF?" /> <!-- don't swear --> </if> 更新:您的示例中发生了什么? 在调用函数property::exists ,不带引号的属性testprop将替换为它的值。 所以你实际上正在探测属性test val...

如何测试Javascript数组中是否存在对象?(How do I test if an object exists in a Javascript array?)

我怀疑你的问题在于你使用jQuery的filter方法的方式: var thisIsAvailable = $(assignedHours).filter(function(){ return assignedHours.hour == thisHour && assignedHours.date == day.date.toString("yyyy-MM-dd"); }); 如果我没弄错的话, assignedHours.hour将始终未定义,因为它总是引用你的assignedHour...

相关文章

更多

solrcore.properties定义server是否是master

If the configuration directory for a Solr core cont ...

elasticsearch 口水篇(6) Mapping 定义索引

前面我们感觉ES就想是一个nosql数据库,支持Free Schema。 接触过Lucene、solr ...

js 缺少对象

报的是错误是 drawcharts is not defined ,但是我的定义没错啊? js代码 ...

tomcat设置成utf8,怎样确保从用户手动在浏览器里输入的url中的中文参数

如题,tomcat必须设置成utf-8,获取的url是用户手动输入的(不是程序里写的),url里含有中 ...

Solr与Mysql集成指南

Solr与Mysql集成指南 chuanliang于 2011-9-24,20:28 Comm ...

Scala函数定义与调用

定义一个函数的格式是def 函数名([参数名[:参数类型][,参数名[:参数类型]......]])[ ...

Scala定义变量

Scala中定义常量使用val,相当于java中的final,一量初始化就不允许修改。 示例: ...

自己定义的vo对象比较,应该如何实现才能做到高效?

自己定义的vo对象比较,应该如何实现才能做到高效?

Hadoop 自定义InputFormat实现自定义Split

上一篇文章中提到了如何进行RecordReader的重写(见 http://www.linuxidc. ...

最新问答

更多

在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)

我建议你制作一个新的TableView Cell,在这个newTableViewCell中,加载第2节中的所有单元格,然后为newTableViewCell提供边框。 但如果您不想这样做,那么您可以使用以下代码: @property(strong,nonatomic) CAShapeLayer* borderPath; -(void)viewDidLayoutSubviews{ [_borderPath removeFromSuperlayer]; UIView *viewToGiveBord

Java中的不可变类(Immutable class in Java)

1.如果我只有final变量的课程? 这会让你远离但不是全部。 这些变量的类型也需要是不可变的。 考虑一下 class MyImmutableClass { // final variable, referring to a mutable type final String[] arr = { "hello" }; // ... } 这允许有人做 myImmutableObject.arr[0] = "world"; 并有效地改变你的不可变类的对象。 此外,建议禁

寻求多次出现的表达式(Seeking for more than one occurrence of an expression)

你的编码是非常古老的风格。 你得到错误是因为: 替换... ... 遍历整个表并将记录指针留在底部。 然后跳过导致错误。 您的代码也非常难以阅读和遵循。 我会修改为: Update dl Set chosen = .T. Where subdir In (Select subdir From ctw) Your coding is very old style. You get the error because: replace ... for ... traverses the whole

linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录

find . -type f -name *.txt 在当前目录下查找后缀为txt的所有文件(会搜索子目录)。 其中,点号.表示当前目录;-type f 表示查找的为文件。

Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)

问题在于您使用两种不同的逻辑。 第一个是基于通配符的字符串,带有*通配符; 您必须在正则表达式模式中转换此基于通配符的模式。 要做到这一点,一个快速而肮脏的解决方案是做一些字符串替换,如: 用.*替换模式中的*通配符 转义基于通配符的模式中对正则表达式“特殊”的字符(例如用.替换. \. 考虑到这一逻辑,您将转换基于通配符的模式,如: http://*.mydomain.com 进入正则表达式模式: http:\/\/.*\.mydomain\.com 你可以用来测试你的字符串。 编辑 :

懒惰地初始化AutoMapper(Lazily initializing AutoMapper)

您可以使用FindTypeMapFor : if (Mapper.FindTypeMapFor() == null) Mapper.CreateMap(); // Map object 还有一个带有类型参数的重载。 You can use FindTypeMapFor: if (Mapper.FindTypeMapFor() == null)

使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)

您可以使用幻灯片事件 。 $('#myCarousel').on('slide.bs.carousel', function (e) { var index = $(e.relatedTarget).index(); var obj = $('[data-slide-to="' + index + '"]').attr('id'); $('.lookingGlass').hide(); // all individual hid

Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)

上一个问题的答案: WP7:图像集合似乎表明您可能需要在调用GetResourceSet之前获取流: var NOT_USED = rm.GetStream("app.xaml"); // without getting a stream, next statement doesn't work - bug? 听起来有点hacky,但如果它有效;) The answer to this previous question: WP7: collection of images seems to i

EXCEL VBA 基础教程下载

http://lib.verycd.com/2005/06/13/0000053997.html

RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)

太棒了!!! 我找到了解决方案 不使用partial,我在我的视图中使用了这个,所以我可以在DB中包含ERB !! <%= render :inline => @body_db.html.html_safe, :layout => false %> 谢谢大家 ! Great !!! I found solution! Without using partial, I used this in my view, so i can include ERB in DB !! <%= render :