gpt4 book ai didi

java - Keycloak登录后返回403

转载 作者:行者123 更新时间:2023-12-01 23:26:58 24 4
gpt4 key购买 nike

我有一个 Keycloak 服务器和我的 Web 应用程序。当我尝试登录应用程序时,Keycloak 总是返回 403 - Forbidden。

这是我在网络项目中的配置,

application.properties

server.port = 38080
keycloak.realm=FocusocKeycloak
keycloak.auth-server-url=http://localhost:8080/auth
keycloak.ssl-required=external
keycloak.resource=login-provider-web
keycloak.public-client=false
keycloak.credentials.secret=XXXX
keycloak.securityConstraints[0].authRoles[0] = USER
keycloak.securityConstraints[0].securityCollections[0].patterns[0] = /*

# Turn off the logs
logging.level.root=OFF
logging.level.org.springframework.boot=OFF
spring.main.banner-mode=OFF

keycloak.json

{
"realm": "FocusocKeycloak",
"auth-server-url": "http://127.0.0.1:8080/auth",
"ssl-required": "external",
"resource": "login-app",
"verify-token-audience": true,
"credentials": {
"secret": "XXXX"
},
"use-resource-role-mappings": true,
"confidential-port": 0
}

这是客户端的配置, enter image description here

而且我只注册了角色 ROLE_USER。

最佳答案

解决了!是config类中的configure方法有点错误,这里我没有改

...
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.logout().logoutSuccessUrl("/home")
.and()
.authorizeRequests()
.antMatchers("/**").hasAuthority("user");
}
...

而且必须是

...
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.logout().logoutSuccessUrl("/home")
.and()
.authorizeRequests()
.antMatchers("/**").hasAuthority("ROLE_USER");
}
...

现在错误 403 不再出现,但现在/home 页面不显示。

关于java - Keycloak登录后返回403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58304452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com