Spring安全性:不需要对本地请求进行身份验证

时间:2017-04-18 10:31:16

标签: java spring spring-security

我有一个带有几个REST控制器的Spring Boot Web应用程序。它使用Spring Security进行基于表单的身份验证(1)

此外,应用程序正在读取存储的请求并将它们分发给自己。为此,我有一个自定义的Spring Dispatcher servlet和一个用于存储请求的过滤器链。调用时,它允许Spring DispatcherServlet将HTTP请求分派给正确的REST控制器(2)

我想以一种不需要对(2)情况进行身份验证的方式设置Spring安全性 - 即http请求来自应用程序本身。

有没有人知道如何实现这个目标?

2 个答案:

答案 0 :(得分:4)

您可以创建自定义standard draft

  

匹配LEFT RIGHT OUTTER的简单策略。

用您的逻辑来决定是否应该忽略该请求。

然后使用RequestMatcher添加自定义observe({ if (input$startkegg != 0) { kegg <- reactive({ enrichKEGG(entrezIDs(), pAdjustMethod=input$adjmk, pvalueCutoff=input$keggp, qvalueCutoff=input$keggq)}) output$pathway1 <- renderImage({ width <- session$clientData$output_pathway1_width height <- session$clientData$output_pathway1_height #This is the file that will be saved outfile <- paste0(tempdir(),"\\",as.matrix(as.data.frame(kegg())[1])[1:1], ".png") #Save the file in the temp folder pathview(gene.data=entrezIDs(), pathway.id=as.matrix(as.data.frame(kegg())[1])[1:1],species = "hsa", limit=3, kegg.dir = tempdir()) # Pathview generates a png file (it is possible to generate many png at once by changing '[1:1]' by other numbers) list(src = outfile, contentType = 'image/png+xml', width = width, height = height, alt = "plotGoGraph") }, deleteFile =FALSE) } })

  

将RequestMatcher实例列表与HttpServletRequest

相关联

AbstractRequestMatcherRegistry#requestMatchers的忽略RequestMatcher列表:

  

允许添加Spring Security应忽略的AbstractConfigAttributeRequestMatcherRegistry个实例。

在您的WebSecurity#ignoring方法中:

  

重写此方法以配置RequestMatcher。例如,如果您希望忽略某些请求。

例如:

RequestMatcher

答案 1 :(得分:0)

添加以下来自应用程序的路径的url拦截。

    <security:intercept-url pattern="path" access="IS_AUTHENTICATED_ANONYMOUSLY" />