1)首先将以下依赖项添加到您的
build.gradle(我正在使用gradle,但是
pom.xml如果您是Maven ,则这是相同的):
// keycloakcompile 'org.keycloak:keycloak-spring-boot-adapter:2.5.1.Final'compile 'org.keycloak:keycloak-tomcat8-adapter:2.5.1.Final'
2)然后在
application.properties文件中提供您的Keycloak配置(这时您应该已经配置了领域并通过Keycloak Web-
ui添加了客户端):
keycloak.realm=[YOUR-REALM]keycloak.bearer-only=truekeycloak.auth-server-url=https://[YOUR-KEYCLOAK-INSTANCE-ADDRESS]:[PORT]/authkeycloak.ssl-required=externalkeycloak.resource=[CLIEND-ID]keycloak.credentials.secret=[YOUR-CLIENT-SECRET-ID]keycloak.cors=truekeycloak.securityConstraints[0].securityCollections[0].name=insecure stuffkeycloak.securityConstraints[0].securityCollections[0].patterns[0]=/test-endpoint-1/*keycloak.securityConstraints[1].securityCollections[0].name=admin stuffkeycloak.securityConstraints[1].securityCollections[0].authRoles[0]=[ROLE-2]keycloak.securityConstraints[1].securityCollections[0].patterns[0]=/test-endpoint-2/*
在这里,我允许任何人访问处的所有内容
/test-endpoint-1/*,而具有[ROLE-2]角色的管理员用户可以访问处的任何内容
/test-endpoint-2/*。
啊,忘了提,客户
Access Type是
bearer-only。是的,通过此设置,您不需要
keycloak.json。希望这可以帮助 :)更新
新的API进行了一些更改,因此提供了最新版本:
kotlinVersion = '1.3.10'springBootVersion = '2.1.1.RELEASE'keycloakVersion = '4.6.0.Final'dependencyManagement { imports { mavenBom "org.keycloak.bom:keycloak-adapter-bom:${keycloakVersion}" }}dependencies { // keycloak compile 'org.keycloak:keycloak-spring-boot-starter'}
application.properties在这种情况下将如下所示:
keycloak.realm=[YOUR-REALM]keycloak.bearer-only=truekeycloak.auth-server-url=https://[YOUR-KEYCLOAK-INSTANCE-ADDRESS]:[PORT]/authkeycloak.ssl-required=externalkeycloak.resource=[CLIEND-ID]keycloak.credentials.secret=[YOUR-CLIENT-SECRET-ID]keycloak.cors=truekeycloak.enabled=truekeycloak.securityConstraints[0].securityCollections[0].name=insecure stuffkeycloak.securityConstraints[0].securityCollections[0].patterns[0]=/test-endpoint-1/*keycloak.securityConstraints[1].securityCollections[0].name=admin stuffkeycloak.securityConstraints[1].authRoles[0]=[ROLE-2]keycloak.securityConstraints[1].securityCollections[0].patterns[0]=/test-endpoint-2/*
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)