我正在使用 spring boot 适配器和 keycloak spring boot 适配器来执行多租户,我可以使用 ip 和域名访问页面。但是当我运行 gradlew 脚本时,似乎没有检测到这个 bean,没有发生任何变化。即使我包含了一个记录器,日志也不会打印,所以我认为这个文件根本没有被读取。我错过了什么吗?或者是否有任何可用于多租户的实现。谢谢。
KeycloakTomcatContextCustomizer
@Component
public class KeycloakTomcatContextCustomizer implements TomcatContextCustomizer
{
private static final Logger logger = LoggerFactory.getLogger(KeycloakTomcatContextCustomizerBean.class);
@Override
public void customize(Context context)
{
LoginConfig loginConfig = new LoginConfig();
loginConfig.setAuthMethod("--KEYCLOAK--");
context.setLoginConfig(loginConfig);
context.addSecurityRole("myproject");
SecurityConstraint constraint = new SecurityConstraint();
constraint.addAuthRole("myproject");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/contexts");
constraint.addCollection(collection);
context.addConstraint(constraint);
context.addParameter("keycloak.config.resolver", HostBasedKeycloakResolver.class.getName());
}
public class HostBasedKeycloakResolver extends KeycloakSpringBootConfigResolver
{
private KeycloakDeployment keycloakDeployment;
@Autowired
private AdapterConfig adapterConfig;
@Override
public KeycloakDeployment resolve(OIDCHttpFacade.Request request) {
if (keycloakDeployment != null) {
return keycloakDeployment;
}
//get the host part here
//build keycloakdeployment
keycloakDeployment = KeycloakDeploymentBuilder.build(adapterConfig);
adapterConfig.setAuthServerUrl("https://"+host+"/auth");
System.out.println(adapterConfig.getAuthServerUrl());
return keycloakDeployment;
}
}
}
我的应用程序.yml \
keycloak:
cors: true
realm: Boot-Project
realmKey: AARjANBgkqhkiYUitdhjnCAQ8AMIIBCgKCAQEArOS/TTjkgjdoiQ7F6m5x206lJ+K9VBpEjkjrignxIdH7pJDWv9UMg2CL1q3Tfkjg/YdjkljgkbsnqrSzjBcIU5HQ2AQLkRm2eCPuLIB23d2VS3hZGqvbyqN42hbk/oRhloS0tS2/frq4fIeU53KQiRPPiBt1IEO7DINoDUXdyOWS7g/rSrMkjjUm9SohXdv8u3aB+mnI8gNwEag17Cj+wqoc1smPj5jb/8Ab3MynQHv4ekgXYFPI5BEQSXXflBLbL2kjqR2xP8y8XTsOz58XLyWBydjN2R37uds9D2TqipU3tdc286b276RhNCwIDAQAB
auth-server-url: https://${__AUTH_VM__:localhost}/auth
ssl-required: none
resource: myproject
bearer-only: true
public-client: false
credentials:
secret: ls5f7c3g-d045-444f-8234-6cth6970726y
securityConstraints[0]:
securityCollections[0]:
name: secured context api and app
authRoles:
- commongui
patterns:
- /contexts/*
- /config.json