luk*_*ell 5 saml single-sign-on keycloak idp
keycloak我的awx(ansible塔)网页有一个客户。我只需要一个特定keycloak组中的用户即可通过此客户端登录。
如何禁止所有其他用户(一个特定的组除外)使用此keycloak客户端?
Cyr*_*lle 13
在 Keycloak 管理控制台上,转到“客户端”菜单,选择您的客户端。在客户端配置页面,设置Authorization Enabled: On,点击Save。应该会出现一个新的Authorization选项卡,转到它,然后到下面的Policies选项卡,单击Create Policy并选择Group-based policy。在那里,您可以限制对特定组的访问,假设您已经通过组菜单定义了您的组。
--编辑 2019-11-08--
正如评论中提到的,客户端协议必须设置为openid-connect并且访问类型必须设置为机密,以便使授权启用选项可见。
如果有帮助,这里有一个脚本可以帮助为任何客户端实现此行为:如果客户端包含给定的角色(此处称为feature:authenticate),则脚本检查用户是否具有该角色并显示错误页面(一个新的需要在主题中部署的模板)如果没有。
AuthenticationFlowError = Java.type("org.keycloak.authentication.AuthenticationFlowError");
function authenticate(context) {
var MANDATORY_ROLE = 'feature:authenticate';
var username = user ? user.username : "anonymous";
var client = session.getContext().getClient();
LOG.debug("Checking access to authentication for client '" + client.getName() + "' through mandatory role '" + MANDATORY_ROLE + "' for user '" + username + "'");
var mandatoryRole = client.getRole(MANDATORY_ROLE);
if (mandatoryRole === null) {
LOG.debug("No mandatory role '" + MANDATORY_ROLE + "' for client '" + client.getName() + "'");
return context.success();
}
if (user.hasRole(mandatoryRole)) {
LOG.info("Successful authentication for user '" + username + "' with mandatory role '" + MANDATORY_ROLE + "' for client '" + client.getName() + "'");
return context.success();
}
LOG.info("Denied authentication for user '" + username + "' without mandatory role '" + MANDATORY_ROLE + "' for client '" + client.getName() + "'");
return denyAccess(context, mandatoryRole);
}
function denyAccess(context, mandatoryRole) {
var formBuilder = context.form();
var client = session.getContext().getClient();
var description = !mandatoryRole.getAttribute('deniedMessage').isEmpty() ? mandatoryRole.getAttribute('deniedMessage') : [''];
var form = formBuilder
.setAttribute('clientUrl', client.getRootUrl())
.setAttribute('clientName', client.getName())
.setAttribute('description', description[0])
.createForm('denied-auth.ftl');
return context.failure(AuthenticationFlowError.INVALID_USER, form);
}
Run Code Online (Sandbox Code Playgroud)
艾伦回答的后续行动:他的方法是有效的(对我来说 ;-) ),尽管我在如何部署它方面遇到了一些困难。我是这样做的:
-Dkeycloak.profile.feature.scripts=enabled
feature:authenticate。不承担该角色的用户将无法访问该应用程序。小智 7
我找到了一个不需要脚本扩展或对流程进行任何更改的解决方案。
此解决方案的关键是客户端范围。想要授权用户的应用程序需要一个范围,如电子邮件或 uid,对吗?如果您只将它们传递给某个用户在特定组中的应用程序会怎样?
在下面,我的客户端应用程序名称是 App1。
解决方案:
现在,您将无法再登录客户端应用程序 App1,因为“访问”角色未分配给任何用户或组。你可以试试。
让我们创建一个新组并为其分配角色和用户。
瞧,所选用户可以登录 App1。
我是这样解决的:
user.hasRole(realm.getRole("yourRoleName")))。| 归档时间: |
|
| 查看次数: |
4181 次 |
| 最近记录: |