- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为一个仍然使用 Acegi 插件(而不是较新的 Spring Core Security 插件)的项目编写测试用例,截至目前,我已经成功完成了本网站的工作(http://www.zorched.net/2008/09/01/grails-testing-acegi-security/)
建议检测当前登录的用户。但是,在我的 Controller 中,我有如下内容:
def list = {
// code for an "admin account"
}
def list_others = {
// code for other accounts
}
现在,我不在 Controller 中检查登录用户。相反,我在 SecurityConfig.groovy 中定义了这些,例如:
security {
...
requestMapString = """\
/someController/list=ROLE_ADMIN
/someController/list_others=ROLE_OTHERS
"""
...
}
因此,如果我有一个看起来像这样的测试:
void testTrial() {
// define here that otherUser has a role of ROLE_OTHERS
authenticate(otherUser, "other") // this calls the authenticate methode in the site I gave earlier
controller.list()
// I do an assertion here to check where this goes to
}
事情是,当我做断言时,当然列表会告诉我它转发到 list.gsp... 即使“登录”用户具有 ROLE_OTHERS 角色而不是管理员。
但是,我需要的是如何测试登录用户只能访问什么?在这种情况下,假设调用是对 *.list() 的调用并且登录用户具有 ROLE_OTHERS 角色,我应该被转发到“拒绝”页面。
帮助?谢谢!
最佳答案
您需要为此进行功能测试。单元测试只是 Groovy 或 Java 类加上一些模拟。没有 Spring 应用程序上下文、没有 Hibernate、没有数据库,对于这种情况最重要的是没有插件。
集成测试为您提供了更多功能,但即使有请求也大多是模拟的,并且由于没有容器,因此不会触发过滤器。 Spring Security(Acegi 插件使用)基于一系列 servlet 过滤器。因此,如果您想测试您的安全规则是否得到正确应用,您将需要一个正在运行的服务器,因此需要进行功能测试。
功能测试有多种选择,最流行的是 WebTest:http://grails.org/plugin/webtest ,功能测试插件:http://grails.org/plugin/functional-test ,以及 Selenium RC 插件:http://grails.org/plugin/selenium-rc .
最新的是 Geb:http://grails.org/plugin/geb .手册位于 http://geb.codehaus.org/最近有一篇关于它的博客文章:http://blog.springsource.com/2010/08/28/the-future-of-functional-web-testing/
关于unit-testing - 在 grails + acegi 中测试 securityConfig 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3836473/
我正在尝试使用 Spring Security,所有这些都使用一个角色。 protected void configure(HttpSecurity http) throws Exception {
我是 Spring 新手,正在尝试使用 Spring 为 RESTful API 创建身份验证。我收到以下错误,如何解决此问题? 堆栈跟踪: Error creating bean with name
我正在尝试使用 Spring Security,所有这些都使用一个角色。 我想根据角色重定向到2个不同的站点,但框架始终重定向到最后一个defaultSuccessUrl("/...")**。这可能吗
我创建了一个基于 this tutorial 的小型网络应用程序。原始版本按预期工作。然后我做了一些更改,它停止工作,也就是说我可以在不登录的情况下访问/hello 页面。我正在学习这个神奇的自动配置
我有一个运行 Jersey Spring 调度程序的应用程序,我想与 Spring Security 集成。我可以让它与命名空间配置一起使用——即在 web.xml 中包含过滤器并使用 和 bean
过去几天我一直面临着 j_spring_security_check 的 404 错误,我想我能解决这个问题。我已经阅读了与此问题相关的几个堆栈溢出问题,但似乎没有什么可以改变结果。我希望有人能够发现
我尝试使用本教程通过 jwt token 创建身份验证:https://www.callicoder.com/spring-boot-spring-security-jwt-mysql-react-a
我在 web.xml 中遇到了这段代码,但我不明白如何添加 securityConfig.xml与 dispatcherContext.xml 一起添加到类路径 contextConfigLo
我正在为一个仍然使用 Acegi 插件(而不是较新的 Spring Core Security 插件)的项目编写测试用例,截至目前,我已经成功完成了本网站的工作(http://www.zorched.
在 webapp 本身中,一切运行都没有任何问题。身份验证按预期工作。但是,由于我的类路径上有 Spring Security,我所有的 Controller 测试现在都失败了,因为正在加载默认的 S
我正在使用 spring-boot (使用 JWT 和 spring security ),并且我在 spring-boot 中有一个类 configSecurity ,代码如下: @Configur
我已经有一个基于 XML 的 Spring 应用程序。我被要求将 Spring Security 集成到其中。我想使用基于 Java 的配置。我已经按照此处的说明对其进行了初始化:Java Confi
我正在尝试结合 Java-config 和 xml-config 进行 spring 安全认证。但是我收到一个错误: Error creating bean with name 'securityCo
'org.springframework.security.access.SecurityConfig':通过构造函数参数 0 表示的不满足的依赖关系:没有 [java.lang.String] 类型
我试图让 Spring SecuirtyConfig 与 Spring MVC 和 JavaConfig 一起工作,但我收到以下错误: java.lang.IllegalStateException:
奇怪的问题在这里。我的模板gsp中有一个sec:ifNotLogged in标记,它失败并显示以下错误/堆栈跟踪。但是,如果删除标签以便可以登录,然后在登录后再添加回标签,则可以正常工作。我有一个扩展
我正在做图书馆管理系统的 spring boot 安全应用。当我运行我的应用程序时,出现上述错误。有人可以帮帮我吗?提前致谢! //安全配置 @Configuration @EnableWebSecu
当我运行网络应用程序时,我遇到此错误: SEVERE: Context initialization failed org.springframework.beans.factory.BeanCrea
我是一名优秀的程序员,十分优秀!