问题描述
我想使用此链接:
如果你没有得到日志
Log.info(user.username + ' Has one of Roles: ' + rolesToStepUp.toString());
检查你的情况.如果您的角色是内部角色,请按如下方式更改rolesToStepUp
变量并尝试.var rolesToStepUp = ['Internal/Role1'];
为了使用户登录失败,仅返回 false 是行不通的.使用
sendError
实用函数 (https://docs.wso2.com/display/IS570/Adaptive+Authentication+JS+API+Reference#AdaptiveAuthenticationJSAPIReference-sendError(url,parameters)).检查基于用户年龄的脚本以了解 sendError 用法(https://docs.wso2.com/display/IS570/Configuring+User-Age-Based+Adaptive+Authentication)
I want Use this link:
https://docs.wso2.com/display/IS570/Adaptive+Authentication
I want Role1 Can't Login to my Application and Write this Code:and it's Don't Work and Role1 can login to my application.How can Write this script?
// Role-Based from Template...
// This script will step up authentication for any user belonging
// to one of the given roles
// If the user has any of the below roles, authentication will be stepped up
var rolesToStepUp = ['Role1'];
function onLoginRequest(context) {
executeStep(1, {
onSuccess: function (context) {
// Extracting authenticated subject from the first step
var user = context.currentKnownSubject;
// Checking if the user is assigned to one of the given roles
var hasRole = hasAnyOfTheRoles(user, rolesToStepUp);
if (hasRole) {
Log.info(user.username + ' Has one of Roles: ' + rolesToStepUp.toString());
return false;
}
}
});
}
// End of Role-Based.......
If you didn't get the log
Log.info(user.username + ' Has one of Roles: ' + rolesToStepUp.toString());
check your condition. If your Role is an internal role, changerolesToStepUp
variable as follows and try out.var rolesToStepUp = ['Internal/Role1'];
Have a look on https://stackoverflow.com/a/66013019/10055162 for more details
In order to fail the user login, just returning false doesn't work. Use
sendError
utility function (https://docs.wso2.com/display/IS570/Adaptive+Authentication+JS+API+Reference#AdaptiveAuthenticationJSAPIReference-sendError(url,parameters)).Check user-age-based script for sendError usage (https://docs.wso2.com/display/IS570/Configuring+User-Age-Based+Adaptive+Authentication)
这篇关于wso2 身份服务器 5.7.0 如何为 Role1 编写脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!