node.js密钥库中的策略实施

时间:2018-12-11 05:48:35

标签: node.js adapter keycloak

如何在keycloak node.js应用程序中启用策略强制。我已经将spring boot应用程序与keycloak集成在一起。如何在node.js应用程序中进行相同的配置?下面是Application.properties文件。我必须在node.js中进行所有相同的配置。

server.port=8180
keycloak.realm = Multiple
keycloak.auth-server-url = http://localhost:8080/auth
keycloak.resource = multipleparams
keycloak.public-client=false
keycloak.enabled=true
keycloak.credentials.secret=4f0579b0-516f-4eb4-8ad1-47f0613f49cd
keycloak.ssl-required = external
#keycloak.cors=true
keycloak.use-resource-role-mappings=true

keycloak.security-constraints[0].auth-roles[0]=User
keycloak.security-constraints[0].security-collections[0].patterns[0]=/*
keycloak.policy-enforcer-config.enforcement-mode=PERMISSIVE

keycloak.policy-enforcer-config.lazy-load-paths=true
keycloak.policy-enforcer-config.paths[0].path=/multiple/*
keycloak.policy-enforcer-config.paths[0].claimInformationPointConfig.claims[location]={request.parameter['location']}
keycloak.policy-enforcer-config.paths[0].claimInformationPointConfig.claims[branch]={request.parameter['branch']}

keycloak.policy-enforcer-config.on-deny-redirect-to=/accessDenied 

1 个答案:

答案 0 :(得分:0)

我认为它尚未正式记录下来,但是您可以在此处看到有关如何执行政策的示例:https://github.com/keycloak/keycloak-nodejs-connect/blob/master/example/index.js

app.get('/protected/resource', keycloak.enforcer(['resource:view', 'resource:write'], {
  resource_server_id: 'nodejs-apiserver'
}), function (req, res) {
  res.render('index', {
    result: JSON.stringify(JSON.parse(req.session['keycloak-token']), null, 4),
    event: '1. Access granted to Default Resource\n'
  });
});