【发布时间】:2021-11-25 16:25:57
【问题描述】:
在启用策略执行器配置时,对于未经身份验证的请求,Keyclock 返回 403 而不是 401。删除策略执行器配置时,它返回 401。
有了这个配置,我得到一个 403 空响应。
keycloak:
realm: ${KEYCLOAK_REALM}
auth-server-url: ${KEYCLOAK_AUTH_SERVER_URL}
ssl-required: external
resource: ${KEYCLOAK_CLIENT_ID}
credentials.secret: ${KEYCLOAK_CLIENT_SECRET}
use-resource-role-mappings: true
cors: true
public-client: false
bearer-only: true
policy-enforcer-config:
lazy-load-paths: true
http-method-as-scope: true
path-cache-config:
max-entries: 1000
lifespan: 1000
paths:
- name: Insecure Resource
path: /
enforcement-mode: DISABLED
- name: Swagger UI
path: /swagger-ui/*
enforcement-mode: DISABLED
- name: Swagger Resources
path: /swagger-resources/*
enforcement-mode: DISABLED
- name: Swagger api Resources
path: /api-docs
enforcement-mode: DISABLED
securityConstraints:
- authRoles:
- '*'
securityCollections:
- name: protected
patterns:
- '/v1/*'
- '/intranet/*'
如果我像这样删除策略执行器
keycloak:
realm: ${KEYCLOAK_REALM}
auth-server-url: ${KEYCLOAK_AUTH_SERVER_URL}
ssl-required: external
resource: ${KEYCLOAK_CLIENT_ID}
credentials.secret: ${KEYCLOAK_CLIENT_SECRET}
use-resource-role-mappings: true
cors: true
public-client: false
bearer-only: true
# policy-enforcer-config:
# lazy-load-paths: true
# http-method-as-scope: true
# path-cache-config:
# max-entries: 1000
# lifespan: 1000
# paths:
# - name: Insecure Resource
# path: /
# enforcement-mode: DISABLED
# - name: Swagger UI
# path: /swagger-ui/*
# enforcement-mode: DISABLED
# - name: Swagger Resources
# path: /swagger-resources/*
# enforcement-mode: DISABLED
# - name: Swagger api Resources
# path: /api-docs
# enforcement-mode: DISABLED
securityConstraints:
- authRoles:
- '*'
securityCollections:
- name: protected
patterns:
- '/v1/*'
- '/intranet/*'
返回 401
{
"timestamp": "2021-10-05T11:25:33.116+0000",
"status": 401,
"error": "Unauthorized",
"message": "No message available",
"path": "/v1/approve-documents"
}
所有请求都在执行策略,即使它没有经过身份验证。如果令牌无效或丢失,如何返回 401。
【问题讨论】:
-
你能分享这两种情况的堆栈跟踪吗?为了启用政策执行者,我得到了
There was an unexpected error (type=Internal Server Error, status=500). Failed to obtain policy enforcer -
策略执行应该发生在所有请求上,无论它们是经过身份验证还是未经身份验证。您想在这里实现什么目标?
-
@Abhijeet 如果提供了无效令牌,我想跳过策略执行。在这里追踪github.com/prajintst/log
标签: spring-boot authentication spring-security authorization keycloak