فاطمه شریفی
فاطمه شریفی

Reputation: 71

wso2 identity server 5.7.0 How write Script for Role1?

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.......

enter image description here

Upvotes: 0

Views: 104

Answers (1)

Anuradha Karunarathna
Anuradha Karunarathna

Reputation: 3057

  1. 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, change rolesToStepUp variable as follows and try out.

    var rolesToStepUp = ['Internal/Role1'];

    Have a look on https://stackoverflow.com/a/66013019/10055162 for more details

  2. 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)

Upvotes: 1

Related Questions