spring security:如何配置一组测试数据进行身份验证

时间:2015-08-26 13:26:12

标签: java spring spring-mvc spring-security

我想设置一些测试数据用户名 - 密码,我按照不同的例子,我在spring-security.xml中使用了后续代码:

 <security:http auto-config='true'>
   <security:intercept-url pattern="/logged" access= 'ROLE_USER' />
   <security:form-login login-page='/login.jsp'/>
</security:http>

<security:authentication-manager>
 <security:authentication-provider>
  <security:user-service>
    <security:user name="user" password="password" authorities="ROLE_USER" />
  </security:user-service>
</security:authentication-provider>

当我访问logged.jsp页面时,它会抛出以下异常:

java.lang.IllegalArgumentException: Failed to evaluate expression 'ROLE_USER'

root cause: org.springframework.expression.spel.SpelEvaluationException:
EL1008E:(pos 0): Property or field 'ROLE_USER' cannot be found on object of type
'org.springframework.security.web.access.expression.WebSecurityExpressionRoot'
- maybe not public?

任何想法?

1 个答案:

答案 0 :(得分:0)

不只是因为你在'ROLE_USER'中有单引号吗?

这个:

prism :: (s ~ exists r . Either r a) -> Prism s a

uncons = prism (iso fwd bck) where
  fwd []     = Left () -- failure!
  fwd (a:as) = Right (a, as)
  bck (Left ())       = []
  bck (Right (a, as)) = a:as