Spring Boot-禁止将KeyCloak定向到403 [英] Spring Boot - KeyCloak directed to 403 forbidden

查看:338
本文介绍了Spring Boot-禁止将KeyCloak定向到403的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Keycloak的新手,我使用的是官方教程项目 https://github.com/sebastienblanc/spring-boot-keycloak-tutorial

I am new to Keycloak, I am using the official tutorial project on https://github.com/sebastienblanc/spring-boot-keycloak-tutorial

为了与Springboot应用程序集成,我已经成功设置了KeyCloak服务器,并且在提供了指向禁止页面的正确凭据之后,spring boot应用程序还定向到了我在KeyCloak上创建的领域上创建的客户端应用程序

for integrating with Springboot application, I have setup the KeyCloak server successfully and the spring boot application also directing to the client application I have created on the Realm I have created on KeyCloak, after providing the correct credentials it directs to the forbidden page.

@Controller
class ProductController {

@GetMapping(path = "/products")
public String getProducts(Model model){
    model.addAttribute("products", Arrays.asList("iPad","iPhone","iPod"));
    return "products";
}

@GetMapping(path = "/logout")
public String logout(HttpServletRequest request) throws ServletException {
    request.logout();
    return "/";
}
}

Application.properties文件

Application.properties file

keycloak.auth-server-url=http://localhost:8080/auth
keycloak.realm=springdemo
keycloak.resource=product-app
keycloak.public-client=true

keycloak.security-constraints[0].authRoles[0]=testuser
keycloak.security-
constraints[0].securityCollections[0].patterns[0]=/products/*

server.port=8081

我没有从KeyCloak控制台或spring嵌入式tomcat控制台收到任何错误消息.

I am not getting any error message from KeyCloak console or spring embedded tomcat console.

在此处检查tomcat控制台-没有错误

谢谢.

推荐答案

我认为您有错字 keycloak.security-constraints[0].authRoles[0]=testuser,您应该在此处指定角色,而不是用户. 如果您按照博客文章的说明进行操作,则应为: keycloak.security-constraints[0].authRoles[0]=user

I think you have a typo at keycloak.security-constraints[0].authRoles[0]=testuser , you should specify the role here and not the user. If you follow the blogpost instructions it should be : keycloak.security-constraints[0].authRoles[0]=user

这篇关于Spring Boot-禁止将KeyCloak定向到403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆