如何允许某些实体API给jhipster中的所有用户

问题描述 投票:0回答:2

我正在使用 jhipster 4.6.2 和 Angular 1+

我希望所有用户都允许这个问题实体。在互联网上搜索后,我知道在 SecurityConfiguration.java 中添加以下行。但添加这些行后,API 将在后端被调用。但在日志中出现此错误。

org.springframework.expression.spel.SpelEvaluationException:EL1008E:在“java.lang.String”类型的对象上找不到属性或字段“用户名” - 也许不是公开的?

        .antMatchers("/api/**").permitAll()
        .antMatchers("/api/questions").permitAll()
        .antMatchers("/api/questions/id").permitAll()

我怎样才能实现这个目标?我希望所有用户无需登录即可获得更多实体。

java spring spring-security jhipster
2个回答
1
投票

Spring Security 文档中所述:每个匹配器都按照声明的顺序进行考虑。另外,您应该保留经过身份验证的要求或 /api/**

试试这个:

    .antMatchers("/api/questions").permitAll()
    .antMatchers("/api/questions/id").permitAll()
    .antMatchers("/api/**")..authenticated()

0
投票

Jhipster 8.3中,我需要在配置包下编辑

SecurityConfiguration.java
。在功能中
filterChain

.requestMatchers(mvc.pattern("/content/**")).permitAll()
.requestMatchers(mvc.pattern("/swagger-ui/**")).permitAll()
.requestMatchers(mvc.pattern(HttpMethod.POST, "/api/authenticate")).permitAll()
.requestMatchers(mvc.pattern(HttpMethod.GET, "/api/authenticate")).permitAll()
.requestMatchers(mvc.pattern("/api/register")).permitAll()
.requestMatchers(mvc.pattern("/api/activate")).permitAll()
.requestMatchers(mvc.pattern("/api/categories")).permitAll() // <-- added
.requestMatchers(mvc.pattern("/api/account/reset-password/init")).permitAll()
.requestMatchers(mvc.pattern("/api/account/reset-password/finish")).permitAll()
.requestMatchers(mvc.pattern("/api/admin/**")).hasAuthority(AuthoritiesConstants.ADMIN)
.requestMatchers(mvc.pattern("/api/**")).authenticated()
.requestMatchers(mvc.pattern("/v3/api-docs/**")).hasAuthority(AuthoritiesConstants.ADMIN)
.requestMatchers(mvc.pattern("/management/health")).permitAll()
.requestMatchers(mvc.pattern("/management/health/**")).permitAll()
.requestMatchers(mvc.pattern("/management/info")).permitAll()
.requestMatchers(mvc.pattern("/management/prometheus")).permitAll()
.requestMatchers(mvc.pattern("/management/**")).hasAuthority(AuthoritiesConstants.ADMIN)

可以在此处找到完整文件示例。

© www.soinside.com 2019 - 2024. All rights reserved.