我有一个问题,当我使用自定义的ROLE登录到accont时无法访问任何URL。
要为我的应用创建新角色,我在AuthoritiesConstants
类和authorities.csv
中添加了新角色。然后,我在我的h2-数据库中手动插入了我想要的新角色:ROLE_STUDENT
和ROLE_PROFESOR
。
然后登录到admin帐户,并尝试并成功使用ROLE_STUDENT
创建了一个新用户。然后,我登录到该新帐户并尝试访问http://localhost:9000/api/users
以获取完整的用户列表。我收到以下错误:
2020-03-19 10:59:05.687 DEBUG 13892 --- [ XNIO-1 task-15] base.aop.logging.LoggingAspect : Enter: base.repository.CustomAuditEventRepository.add() with argument[s] = [AuditEvent [timestamp=2020-03-19T08:59:05.686Z, principal=anonymousUser, type=AUTHORIZATION_FAILURE, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null, type=org.springframework.security.access.AccessDeniedException, message=Access is denied}]]
2020-03-19 10:59:05.691 DEBUG 13892 --- [ XNIO-1 task-15] base.aop.logging.LoggingAspect : Exit: base.repository.CustomAuditEventRepository.add() with result = null
2020-03-19 10:59:05.693 WARN 13892 --- [ XNIO-1 task-15] o.z.problem.spring.common.AdviceTraits : Unauthorized: Full authentication is required to access this resource
2020-03-19 10:59:05.695 WARN 13892 --- [ XNIO-1 task-15] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.security.authentication.InsufficientAuthenticationException: Full authentication is required to access this resource]
在我的SecurityConfiguration
类中,该网址属于.antMatchers("/api/**").authenticated()
。因此,只要登录即可,我应该可以从任何帐户访问它。
令我沮丧的是,似乎无法从此帐户访问除主页以外的任何URL。我手动检查了数据库,以查看是否已创建用户并具有正确的角色。一切都很好。有人可以帮我解决这个问题吗?
编辑:也许与SessionId: null
有关,来自上面的消息?
我有一个问题,当我使用自定义的ROLE登录到accont时,无法访问任何URL。为了为我的应用创建新角色,我在AuthoritiesConstants类中添加了新角色,然后...
您也必须打开通往新角色的路由,这是在客户端完成的。如果使用angular,这或多或少是看起来。