【发布时间】:2020-06-30 09:31:06
【问题描述】:
我在使用自定义角色登录帐户时无法访问任何网址。
为了为我的应用创建新角色,我在 AuthoritiesConstants 类和 authorities.csv 中添加了新角色。
然后我在我的 h2 数据库中手动插入了我想要的新角色:ROLE_STUDENT 和 ROLE_PROFESOR。
然后我登录管理员帐户并尝试并成功创建了一个新用户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。我手动检查了我的数据库以查看用户是否已创建并具有正确的角色。一切都很好。 有人可以帮我解决这个问题吗?
【问题讨论】:
标签: java spring-boot spring-security jhipster roles