首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Grails + Selenium + EasyB +spring-security-core: ifAnyGranted不工作

Grails + Selenium + EasyB +spring-security-core: ifAnyGranted不工作
EN

Stack Overflow用户
提问于 2010-10-16 04:33:03
回答 1查看 527关注 0票数 0

Grails 1.3.5,并安装了selenium-rc、easyb和spring-security-core插件。除了我遇到的这一个案例之外,一切似乎都很顺利。我有一个我正在测试的页面,它有以下标记:

代码语言:javascript
复制
<sec:ifAnyGranted roles='ROLE_ADMIN'>
    <span class="menuButton">
      <g:link mapping="adminPage">
        <g:message code="default.admin.label" default="--Admin--"/>
      </g:link>
    </span>
</sec:ifAnyGranted>

当应用程序正常运行时,一切工作正常。如果我以普通用户身份登录,则不会显示Admin链接。如果我以管理员身份登录,链接就会显示出来。在运行我的测试时,无论谁登录,检查都会失败,因此Admin链接永远不会被呈现。

代码语言:javascript
复制
scenario "An Admin User logs into the system", {
   when "the user completes the login form with proper credentials", {

   grailsApplication = ApplicationHolder.application
   springSecurityService = ApplicationHolder.application.mainContext.getBean("springSecurityService")

   def userAdmin = new User(username: 'testAdmin', firstName: 'Test', lastName: 'Admin', enabled: true, password: springSecurityService.encodePassword("password")).save(flush: true)
   def roleAdmin = new Role(authority: 'ROLE_ADMIN').save(flush: true)
   UserRole.create(userAdmin, roleAdmin)

   selenium.openAndWait("/platform/login/auth")
   selenium.type('j_username', 'testAdmin')
   selenium.type('j_password', 'password')
   selenium.clickAndWait('signInBtn')

 }
 then "the user should be logged in and viewing their My Account page, as an admin", {
   selenium.isTextPresent("Welcome Test").shouldBe true
   selenium.isElementPresent('link=Admin').shouldBe true

 }
}

其他标签也可以正常工作,比如ifLoggedIn和ifNotLoggedIn。有没有人知道这是一个已知的问题,或者关于它的任何其他信息?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-16 05:09:33

尝试添加表面齐平

代码语言:javascript
复制
 UserRole.create(userAdmin, roleAdmin, true)

http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/guide/4%20Required%20and%20Optional%20Domain%20Classes.html#4.2%20Authority%20Class

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3945913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档