2014-01-22 57 views
2

我正在使用Grails 2.2.2,Spring WebFlow 2.0.0和Spring-Security-Core 2.0-RC2插件。我想确保流程中的最后一步,但一直无法完成。使用Spring Security无法保护Grails中的流程步骤

grails.plugin.springsecurity.interceptUrlMap = [ 
    '/myController/connect?execution=e*s3': ["isFullyAuthenticated()"] 
] 

当用户尝试去流程的最后一步,如果他们没有完全验证我想重定向他们到登录页面。这适用于我的项目中的其他操作,但不适用于webflow。

我发现一些文档提示Spring Web Flows和Spring Security可以一起使用:http://docs.spring.io/spring-webflow/docs/2.0.x/reference/html/ch07s04.html

任何想法?这在Grails中可能吗?

回答

2

查询字符串在安全检查前从网址中删除,因此我认为您需要执行此操作来明确检查您自己。

isFullyAuthenticated()SecurityExpressionRoot的实现

public final boolean isFullyAuthenticated() { 
    return !trustResolver.isAnonymous(authentication) && !trustResolver.isRememberMe(authentication); 
} 

所以你可以依赖项注入authenticationTrustResolver豆,做同样的检查,例如

class MyController { 
    def authenticationTrustResolver 
    def springSecurityService 

    def action() { 

     if (params.execution == 'e*s3' && !isFullyAuthenticated()) { 
     response.sendError 401 
     return 
     } 

     ... 
    } 

    private boolean isFullyAuthenticated() { 
     def authentication = springSecurityService.authentication 
     !authenticationTrustResolver.isAnonymous(authentication) && !authenticationTrustResolver.isRememberMe(authentication) 
    } 
} 
+0

因此,使用这种方法,我将能够向用户发送到登录页面,然后让他们重定向到这一步的流程? – brwngrldev

2

或者,你可以做这样的事情:

grails.plugin.springsecurity.interceptUrlMap = [ 
    '/myController/connect': ["(request.getParameter('execute')?:'').matches('^e.*?s3\$') ? fullyAuthenticated : permitAll"] 
] 

的想法是,HttpServletRequest的暴露的表达,所以如果返回或者返回permitAll fullyAuthenticated我们可以决定。

+0

很酷的东西--SpEL为Spring Security增加了大量的功能 –

+0

@RobWinch谢谢,这增加了流程步骤的安全性,但是一旦用户进行身份验证,它就会将它重定向到流程的开始。有没有办法重定向到流程中的当前步骤? – brwngrldev

0

你不能只导入这个类,并添加这个注释和matchin角色让你的用户进入你的step's方法吗?

import grails.plugins.springsecurity.Secured 

class MyClass() { 

    @Secured(['ROLE_USER']) 
    def lastStep() { 
     // do things 
    } 

} 

未通过身份验证的用户将被重定向到登录页面

+0

请注意,webflow操作是关闭而非方法。 –

相关问题